-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProj1_sanchreg.asm
228 lines (195 loc) · 5.8 KB
/
Proj1_sanchreg.asm
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
TITLE Proj1_sanchreg (Proj1_sanchreg.asm)
; Author: Regina Sanchez
; Last Modified: 10/24/2023
; OSU email address: [email protected]
; Course number/section: CS271 Section 400
; Project Number: 1 Due Date: 10/22/2023 - using two grace days
; Description: This file performs basic arithmetic from 3 user inputs. It displays a hello
; and goodbye message, shows the arithmetic on the user inputs, and then exits
INCLUDE Irvine32.inc
.data
introMessage BYTE "Elementary Arithmetic by Regina Sanchez", 0 ; first message to appear to user
displayRules BYTE "Enter 3 Numbers A > B > C, and I'll show you the sums and differences", 0 ; rules for user to follow
userFirst BYTE "First Number: ", 0 ; displayed to get first user input
userSecond BYTE "Second Number: ", 0 ; displayed to get second user input
userThird BYTE "Third Number: ", 0 ; displayed to get third user input
firstNumber DWORD ? ; will be entered by user, a
secondNumber DWORD ? ; will be entered by user, b
thirdNumber DWORD ? ; will be entered by user, c
aPlusB DWORD ? ; calculation for a + b
aMinusB DWORD ? ; calculation for a - b
aPlusC DWORD ? ; calculation for a + c
aMinusC DWORD ? ; calculation for a - c
bPlusC DWORD ? ; calculation for b + c
bMinusC DWORD ? ; calculation for b - c
totalSum DWORD ? ; caculation for a + b + c
additionSign BYTE " + ", 0 ; print to user the + symbol
subtractionSign BYTE " - ", 0 ; print to user the - symbol
equalSign BYTE " = ", 0 ; print to user the = symbol
outroMessage BYTE "Thanks for using Elementary Arithmetic! Goodbye!",0 ; message displayed to user at the end
.code
main PROC
; -------------------------------------------------------------
; Introduction to user, outputs hello message
; -------------------------------------------------------------
mov edx, OFFSET introMessage
call WriteString
call CrLf
; -------------------------------------------------------------
; Get user's data, the three numbers they would like to use
; -------------------------------------------------------------
mov edx, OFFSET displayRules
call WriteString
call CrLf
mov edx, OFFSET userFirst
call WriteString
call ReadDec
mov firstNumber, EAX
mov edx, OFFSET userSecond
call WriteString
call ReadDec
mov secondNumber, EAX
mov edx, OFFSET userThird
call WriteString
call ReadDec
mov thirdNumber, EAX
; -------------------------------------------------------------
; Calculate arithmetic, uses three numbers from user inputs
; -------------------------------------------------------------
; gets a + b
mov eax, firstNumber
mov ebx, secondNumber
add eax, ebx
mov aPlusB, eax
; gets a - b
mov eax, firstNumber
mov ebx, secondNumber
sub eax, ebx
mov aMinusB, eax
; gets a + c
mov eax, firstNumber
mov ebx, thirdNumber
add eax, ebx
mov aPlusC, eax
; gets a - c
mov eax, firstNumber
mov ebx, thirdNumber
sub eax, ebx
mov aMinusC, eax
; gets b + c
mov eax, secondNumber
mov ebx, thirdNumber
add eax, ebx
mov bPlusC, eax
; gets b - c
mov eax, secondNumber
mov ebx, thirdNumber
sub eax, ebx
mov bMinusC, eax
; adds a + b + c
mov eax, firstNumber
mov ebx, secondNumber
add eax, ebx
mov ebx, thirdNumber
add eax, ebx
mov totalSum, eax
; -------------------------------------------------------------
; Display Results, prints the a + b = c format, varying
; -------------------------------------------------------------
; displays a + b
mov eax, firstNumber ; don't need to use offset
call WriteDec
mov edx, OFFSET additionSign
call WriteString
mov eax, secondNumber
call WriteDec
mov edx, OFFSET equalSign
call WriteString
mov eax, aPlusB
call WriteDec
call CrLf
; displays a - b
mov eax, firstNumber
call WriteDec
mov edx, OFFSET subtractionSign
call WriteString
mov eax, secondNumber
call WriteDec
mov edx, OFFSET equalSign
call WriteString
mov eax, aMinusB
call WriteDec
call CrLf
; displays a + c
mov eax, firstNumber
call WriteDec
mov edx, OFFSET additionSign
call WriteString
mov eax, thirdNumber
call WriteDec
mov edx, OFFSET equalSign
call WriteString
mov eax, aPlusC
call WriteDec
call CrLf
; displays a - c
mov eax, firstNumber
call WriteDec
mov edx, OFFSET subtractionSign
call WriteString
mov eax, thirdNumber
call WriteDec
mov edx, OFFSET equalSign
call WriteString
mov eax, aMinusC
call WriteDec
call CrLf
; displays b + c
mov eax, secondNumber
call WriteDec
mov edx, OFFSET additionSign
call WriteString
mov eax, thirdNumber
call WriteDec
mov edx, OFFSET equalSign
call WriteString
mov eax, bPlusC
call WriteDec
call CrLf
; display b - c
mov eax, secondNumber
call WriteDec
mov edx, OFFSET subtractionSign
call WriteString
mov eax, thirdNumber
call WriteDec
mov edx, OFFSET equalSign
call WriteString
mov eax, bMinusC
call WriteDec
call CrLf
; displays a + b + c
mov eax, firstNumber
call WriteDec
mov edx, OFFSET additionSign
call WriteString
mov eax, secondNumber
call WriteDec
mov edx, OFFSET additionSign
call WriteString
mov eax, thirdNumber
call WriteDec
mov edx, OFFSET equalSign
call WriteString
mov eax, totalSum
call WriteDec
call CrLf
; -------------------------------------------------------------
; Say's Goodbye to user
; -------------------------------------------------------------
mov edx, OFFSET outroMessage
call WriteString
call CrLf
Invoke ExitProcess,0 ; exit to operating system
main ENDP
END main