-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProject_I_shape.asm
More file actions
292 lines (234 loc) · 5.93 KB
/
Project_I_shape.asm
File metadata and controls
292 lines (234 loc) · 5.93 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
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
org 100h
.model small
.stack 100h
.data
header DB "- Calculator Application -",0Dh,0Ah
DB "*************************",'$'
NEWLINE DB 10,13,"$"
menu DB 0Dh,0Ah,0Dh,0Ah,"1- Circle.",0Dh,0Ah
DB "2- Square.",0Dh,0Ah
DB "3- Rectangle.",0Dh,0Ah
DB "4- Triangle.",0Dh,0Ah,
DB "5- Exit.",0Dh,0Ah,
DB "Please enter your choice: ",'$'
Radius_msg DB 0Dh,0Ah,0Dh,0Ah,"AREA OF CIRCLE",0Dh,0Ah
DB 0Dh,0Ah,"Please enter the Radius (1-9): ",'$'
Side_msg DB 0Dh,0Ah,0Dh,0Ah,"AREA OF SQUARE",0Dh,0Ah
DB 0Dh,0Ah,"Please enter the Side (1-9): ",'$'
Height_msg DB 0Dh,0Ah,0Dh,0Ah,"Please enter the Height (1-9): ",'$'
Width_msg DB 0Dh,0Ah,0Dh,0Ah,"AREA OF RECTANGLE",0Dh,0Ah
DB 0Dh,0Ah,0Dh,0Ah,"Please enter the Width (1-9): ",'$'
Base_msg DB 0Dh,0Ah,0Dh,0Ah,"AREA OF TRIANGLE",0Dh,0Ah
DB 0Dh,0Ah,"Please enter the Base (1-9): ",'$'
area_msg DB 0Dh,0Ah,0Dh,0Ah,"The area is: ",'$'
op_msg DB 0Dh,0Ah,0Dh,0Ah,"The number of operation you did is: ",'$'
exit DB 0Dh,0Ah,0Dh,0Ah,"Press Enter for Exit:",'$'
result DB 10 DUP ('$')
area DD 0
operation DB 0
.code
begin:
mov ax,@data
mov ds,ax
; print message for the header
MOV AH,09H
LEA DX,header
INT 21H
MOV AH,09H
LEA DX,NEWLINE
INT 21H
;================================================
start:
;code to choose one choice from the menu
MOV AH,09H
LEA DX,menu
INT 21H
get_choice:
; read the user choice
mov ah, 1
int 21h
; first choice
cmp al, '1'
je FIRST_CHOICE
; second choice
cmp al, '2'
je SECOND_CHOICE
; third choice
cmp al, '3'
je THIRD_CHOICE
; forth choice
cmp al, '4'
je FORTH_CHOICE
; fifth choice
cmp al, '5'
je FIFTH_CHOICE
; loop back to get_choice until the user choose
jmp get_choice
;================================================
FIRST_CHOICE:
; print raduis msg
MOV AH,09H
LEA DX,Radius_msg
INT 21H
; read the user choice
mov ah, 1
int 21h
sub al, 48
; Circle (C) Radius Area = 3.14159(Radius)(Radius)
mov ah, 0
mul ax ; (Radius)(Radius)
mov bx, 3
mul bx ; pi
mov area, ax
; print area msg
MOV AH,09H
LEA DX,area_msg
INT 21H
inc operation
jmp PRINT_RESULT
;================================================
SECOND_CHOICE:
; print side msg
MOV AH,09H
LEA DX, side_msg
INT 21H
; read the user choice
mov ah, 1
int 21h
sub al, 48
; Square (S) Side Area = (Side)(Side)
mov ah, 0
mul ax ; (Radius)(Radius)
mov area, ax
; print area msg
MOV AH,09H
LEA DX,area_msg
INT 21H
inc operation
jmp PRINT_RESULT
;================================================
THIRD_CHOICE:
; print width msg
MOV AH,09H
LEA DX,width_msg
INT 21H
; read the user choice
mov ah, 1
int 21h
sub al, 48
mov bl, al ; save the width
; print height msg
MOV AH,09H
LEA DX,height_msg
INT 21H
; read the user choice
mov ah, 1
int 21h
sub al, 48
; Rectangle (R) Height, Width Area = (Width)(Height)
mov ah, 0
mov bh, 0
mul bx ; (Width)(Height)
mov area, ax
; print area msg
MOV AH,09H
LEA DX,area_msg
INT 21H
inc operation
jmp PRINT_RESULT
;================================================
FORTH_CHOICE:
; print Base msg
MOV AH,09H
LEA DX,Base_msg
INT 21H
; read the user choice
mov ah, 1
int 21h
sub al, 48
mov bl, al ; save the base
; print height msg
MOV AH,09H
LEA DX,height_msg
INT 21H
; read the user choice
mov ah, 1
int 21h
sub al, 48
; Triangle (T) Base, Height Area = 0.5 (Base)(Height)
mov ah, 0
mov bh, 0
mul bx ; (Base)(Height)
mov bl, 2
div bl ; (Base)(Height)/2
mov ah, 0
mov area, ax
; print area msg
MOV AH,09H
LEA DX,area_msg
INT 21H
inc operation
jmp PRINT_RESULT
;================================================
FIFTH_CHOICE:
; print operation msg
MOV AH,09H
LEA DX,op_msg
INT 21H
mov ah, 0
mov al, operation
LEA SI, result
MOV CX,0
MOV BX,10
LOOP1:
MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,9
JG LOOP1
ADD AL,30H
MOV [SI],AL
LOOP2:
POP AX
INC SI
MOV [SI],AL
LOOP LOOP2
LEA DX,result
MOV AH,9
INT 21H
LEA DX,exit
MOV AH,9
INT 21H
mov ah,1
int 21h
mov ah,4Ch
int 21h
;================================================
PRINT_RESULT:
; convert decimal to hex to print result
mov ax, area
mov area, 0
LEA SI, result
MOV CX,0
MOV BX,10
LOOP11:
MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,9
JG LOOP11
ADD AL,30H
MOV [SI],AL
LOOP22:
POP AX
INC SI
MOV [SI],AL
LOOP LOOP22
LEA DX,result
MOV AH,9
INT 21H
jmp start