-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignment1.cpp
97 lines (88 loc) · 2.53 KB
/
assignment1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
int main()
{
//Data String
char intro[] = "Hi there. This assembly program will count how many values are positive, negative and equal to zero.\n Please enter how many values you would like to enter: ";
char getvalues[] = "Please enter the value: ";
char positives[] = "There are %d positive values.\n";
char negatives[] = "There are %d negative values.\n";
char zero[] = "There are %d values equal to zero.\n";
//Formatting
char format[] = "%d";
int num;
int pos = 0;
int neg = 0;
int zer = 0;
int input;
_asm {
/*Print an introduction message.*/
lea eax, intro
push eax
call printf
add esp, 4
/*Grab first user input needed, how many values are going to be inserted.*/
lea eax, input
push eax
lea eax, format
push eax
call scanf
add esp, 8
/*Move the input into a reg and start the loop*/
mov ecx, input
jmp loop1
loop1:
push ecx;
lea eax, getvalues
push eax
call printf
add esp, 4
lea eax, num
/*Grab number and increment the specific counter*/
push eax
lea eax, format
push eax
call scanf
add esp, 8
mov eax, num
cmp eax, 0
jl negative
je zerr
jg positive
/*we have to clear the ecx before looping again*/
rotate :
pop ecx
loop loop1
jmp display
negative :
add neg, 1 //increment negative counter
jmp rotate
zerr :
add zer, 1 //increment zero counter
jmp rotate
positive : //increment positive counter
add pos, 1
jmp rotate
je display
/* Display the messages with values*/
display :
lea eax, positives //loads passed into eax
push pos //pushes pass int into eax
push eax //stack eax
call printf //prints the passed string and the pass integer
add esp, 8 //remove 8 bytes from the stack pointer
lea eax, negatives //loads failed into eax
push neg //pushes fail int into eax
push eax //stack eax
call printf //prints the failed string and the fail integer
add esp, 8 //remove 8 bytes from the stack pointer
lea eax, zero //loads passed into eax
push zer //pushes pass int into eax
push eax //stack eax
call printf //prints the passed string and the pass integer
add esp, 8 //remove 8 bytes from the stack pointer
}
system("pause");
return 0;
}