-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAIN.ASM
291 lines (230 loc) · 3.08 KB
/
MAIN.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
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
ASSUME CS:CODE,DS:DATA
CODE SEGMENT
;Initializing Data Segment
MOV DX,DATA
MOV DS,DX
MOV ES,DX
;Clearing the screen
MOV AX,3
INT 10H
;Welcome Screen
MOV CX,80
MOV AX,0200H
MOV DL,'='
;Print the first line
LINE0: INT 21H
LOOP LINE0
;Skip a line
MOV DL,10
INT 21H
;Print the second line
MOV DL,'='
MOV CX,80
LINE1: INT 21H
LOOP LINE1
;Move caret position
MOV DX,0105H
INT 10H
;Turn off the cursor
MOV CX,2607H
MOV AH,1
INT 10H
;Title animation
MOV AH,02H
LEA SI,WM
XOR CX,CX
MOV AH,02H
PEC:
MOV DL,[SI+BX]
INT 21H
MOV DX,5000H
MOV AH,86H
INT 15H
MOV AH,02H
INC BX
CMP BX,68
JNE PEC
;Move cursor back to original position
MOV DX,0400H
XOR BX,BX
INT 10H
;Turn on the cursor back
MOV CX,0607H
MOV AH,1
INT 10H
;Print the display message
LEA DX,DM
MOV AH,09H
INT 21H
;Initialize pointer(s) for the start and the end array address
LEA SI,S
LEA DI,S+20
;BP will temporarily store the value until it's passed into the array
;BH shall store the number of digits the number currently has
;CX shall hold the sum (to avoid re-iteration during addition)
MOV BX,000AH
XOR CX,CX
XOR BP,BP
SCAN:
;Wait for a char
MOV AX,0800H
INT 21H
;If the user has pressed enter
CMP AL,13
JNE backspace
TEST BH,BH
JNZ GV
MOV AX,[SI-2]
MOV [SI],AX
MOV BP,SP
MOV BX,000AH
$$$$: XOR DX,DX
DIV BX
PUSH DX
TEST AX,AX
JNZ $$$$
MOV AH,02H
$$$: POP DX
ADD DL,30H
INT 21H
CMP SP,BP
JL $$$
JMP WHILST
GV: MOV [SI],BP
XOR BP,BP
WHILST:
MOV AH,02H
MOV DL,0AH
INT 21H
XOR BX,BX
ADD CX,[SI]
JNC &
INC C
&:
ADD SI,2
CMP DI,SI
JE CALC
JMP SCAN
backspace:
CMP AL,08H
JNE CHAR
TEST BH,BH
JZ SCAN
MOV AH,02H
MOV DL,08H
INT 21H
MOV DL,20H
INT 21H
MOV DL,08H
INT 21H
MOV AX,BP
XOR DX,DX
MOV BP,000AH
DIV BP
MOV BP,AX
DEC BH
JMP SCAN
CHAR:
;Wait for enter or backspace if the no. of digits is 4
CMP BH,4
JE SCAN
;Only accept numbers
CMP AL,47
JNG SCAN
CMP AL,58
JNL SCAN
CMP BH,1
JNE &&
TEST BP,BP
JZ NI
&&:
INC BH
MOV DL,AL
MOV AH,02H
INT 21H
MOV BL,DL
XOR DX,DX
MOV AX,BP
MOV BP,000AH
MUL BP
MOV BP,AX
MOV DL,BL
ADD BP,DX
SUB BP,30H
NI:
JMP SCAN
CALC:
MOV BP,CX
INT 21H
MOV CX,80
MOV DL,'='
MOV AH,02H
f0: INT 21H
LOOP f0
MOV CX,0BH
MOV DL,' '
LOOP3: INT 21H
LOOP LOOP3
LEA DX,TAI
MOV AH,09H
INT 21H
MOV CX,80
MOV DL,'='
MOV AH,02H
fl: INT 21H
LOOP fl
MOV AX,BP
MOV BX,000AH
XOR DX,DX
LEA SI,R+5
MOV DL,C
DIV BX
ADD DL,30H
XCHG byte ptr [SI],DL
DEC SI
MOV byte ptr [SI],'.'
@: DIV BX
ADD DX,30H
DEC SI
MOV [SI],DL
XOR DX,DX
TEST AX,AX
JNZ @
;Turn off the cursor
MOV CX,2607H
MOV AH,1
INT 10H
MOV BP,SI
LEA DI,R+6
SUB DI,SI
XOR BX,BX
INC BL
CPRINTF:
INC BL
MOV AH,13H
MOV DX,113CH
MOV CX,DI
INT 10H
MOV AH,86H
MOV CX,0CH
MOV DX,0F850H
INT 15H
CMP BL,0FH
JNE CPRINTF
;Turn on the cursor back
MOV CX,0607H
MOV AH,1
INT 10H
EXIT:
MOV AX,4C00H
INT 21H
CODE ENDS
DATA SEGMENT
WM DB 'An assembly program to print the average of salaries of 10 employees'
DM DB 'Please enter the 4-digit salary of any 10 of your employees:',10,'$'
TAI DB 'The average salary of the above ten employees is',10,'$'
C DB 0 ;COUNT
S DW 10 DUP(0) ;SAL
R DB 6 DUP(0) ;RES
DATA ENDS
END