-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram1.asm
More file actions
149 lines (129 loc) · 3.8 KB
/
program1.asm
File metadata and controls
149 lines (129 loc) · 3.8 KB
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
INCLUDE Irvine32.inc
.386
.model flat,stdcall
.stack 4096 ;SS register
ExitProcess proto,dwExitCode:dword
;creating variables here
.data ;DS register
intro1 BYTE "Hello I am Joon Yuan!",0
intro2 BYTE "Please enter two numbers and my program will calculate the sum, difference, product, (integer) quotient and remainder of the numbers.",0
prompt1 BYTE "Please enter the first number.",0
prompt2 BYTE "Please enter the second number.",0
outro1 BYTE "Hi ",0
outro2 BYTE "Here are the values of the sum, difference, product, (integer) quotient and remainder of the numbers you entered.",0
num1 DWORD ?
num2 DWORD ?
sum DWORD ?
dif DWORD ?
pro DWORD ?
quo DWORD ?
rem DWORD ?
bye1 BYTE "Thanks for playing! Have a nice day!",0
temp1 BYTE "Here is the value of the sum",0
temp2 BYTE "Here is the value of the dif",0
temp3 BYTE "Here is the value of the product",0
temp4 BYTE "Here is the value of the division",0
temp5 BYTE "Here is the value of the remainder",0
looper BYTE "Please enter 1 if you wish to exit the program. You may choose any other number if u wish to continue",0
warning BYTE "Please ensure that the second number is smaller or equal to the first number!",0
loopnum DWORD ?
.code ;CS register
main proc
Introduction:
mov EDX, OFFSET intro1 ;display welcome message
call WriteString
call Crlf
mov EDX, OFFSET intro2 ;tell user how the program works
call WriteString
call Crlf
mov EDX, OFFSET looper ;ask user if they want to exit the program
call WriteString
call Crlf
call ReadInt
mov loopnum, EAX
cmp EAX,1
jne Get_number1
jmp Good_bye
Get_number1:
mov EDX, OFFSET prompt1 ;prompt user to input first number
call WriteString
call Crlf
mov EDX, OFFSET warning ;tell user to keep the second number smaller or equal to the first number
call WriteString
call Crlf
call ReadInt
mov num1, EAX;add user prompt to num1
Get_number2:
mov EDX, OFFSET prompt2 ;prompt user to input second number
call WriteString
call Crlf
call ReadInt
mov num2, EAX;add user prompt to num2
mov EAX, num1
cmp EAX, num2
jl Get_number1
Calculate_sum:
mov EAX, num1 ;move num1 to eax register
mov EBX, num2 ;move num2 to ebx register
add EAX, EBX ;perform addition
mov sum, EAX ;move value into sum variable
mov EDX, OFFSET temp1
call WriteString
call Crlf
mov EDX, sum
call WriteDec
call Crlf
Calculate_dif:
mov EAX, num1 ;move num1 to eax register
mov EBX, num2 ;move num2 to ebx register
sub EAX, EBX ;perform subtraction
mov EDX, OFFSET temp2
call WriteString
call Crlf
mov EDX,dif ;move value into dif variable
call WriteDec
call Crlf
Calculate_pro:
mov EAX, num1 ;move num1 to eax register
mov EBX, num2 ;move num1 to eax register
mul EBX ;perform subtraction
mov EDX, OFFSET temp3
call WriteString
call Crlf
mov EDX,pro ;move value into pro variable
call WriteDec
call Crlf
Calculate_quotient:
mov EDX,0
mov EAX, num1 ;move num1 to eax register
mov EBX, num2 ;move num1 to eax register
div EBX ;perform division
mov EBX,quo
mov EDX, OFFSET temp4
call WriteString
call Crlf
mov EDX,quo
call WriteDec ;display quotient
call Crlf
Calculate_remainder:
mov EDX,0
mov EAX, num1 ;move num1 to eax register
mov EBX, num2 ;move num1 to eax register
div EBX ;perform division
mov EAX,EDX ;move edx value to eax
mov EDX,rem
mov EDX, OFFSET temp5
call WriteString
call Crlf
;mov EAX,EDX ;move edx value to eax
mov EDX,rem
call WriteDec ;display remainder
call Crlf
jmp Introduction
Good_bye:
mov EDX, OFFSET bye1
call WriteString
call Crlf
invoke ExitProcess,0
main endp
end main