-
Notifications
You must be signed in to change notification settings - Fork 0
/
average.asm
61 lines (46 loc) · 1.13 KB
/
average.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
.model SMALL
.stack
.data
OVERFLOW_STR DB 10, 13, 'OVERFLOW!', '$'
ARRAY DB 1, 2, 3
N DB 3
AVG DB ?
.code
.startup
LEA DI, ARRAY
CALL AVERAGE
.exit
AVERAGE PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH DI
MOV SI, WORD PTR N
XOR CX, CX
SCROLL_ELEM_AVG: MOV DX, CX
MOV AL, [DI]
MOV AH, 0
ADD CX, AX
CMP CX, DX ;OVERFLOW CONTROL
JL OVERFLOW_AVG
INC DI
DEC SI
JNZ SCROLL_ELEM_AVG
MOV AX, CX ;PERFORM DIVISION
MOV BL, BYTE PTR N
DIV BL
MOV AVG, AL
JMP EXIT_AVG
OVERFLOW_AVG: MOV AH, 09h ;PRINT ALERT
MOV DX, OFFSET OVERFLOW_STR
INT 21H
EXIT_AVG:
POP DI
POP DX
POP CX
POP BX
POP AX
RET
AVERAGE ENDP
end