-
Notifications
You must be signed in to change notification settings - Fork 0
/
OUTDEC.ASM
50 lines (37 loc) · 1.89 KB
/
OUTDEC.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
OUTDEC PROC
; this procedure will display a decimal number
; input : AX
; output : none
; uses : MAIN
PUSH BX ; push BX onto the STACK
PUSH CX ; push CX onto the STACK
PUSH DX ; push DX onto the STACK
CMP AX, 0 ; compare AX with 0
JGE @START ; jump to label @START if AX>=0
PUSH AX ; push AX onto the STACK
MOV AH, 2 ; set output function
MOV DL, "-" ; set DL=\'-\'
INT 21H ; print the character
POP AX ; pop a value from STACK into AX
NEG AX ; take 2\'s complement of AX
@START: ; jump label
XOR CX, CX ; clear CX
MOV BX, 10 ; set BX=10
@OUTPUT: ; loop label
XOR DX, DX ; clear DX
DIV BX ; divide AX by BX
PUSH DX ; push DX onto the STACK
INC CX ; increment CX
OR AX, AX ; take OR of Ax with AX
JNE @OUTPUT ; jump to label @OUTPUT if ZF=0
MOV AH, 2 ; set output function
@DISPLAY: ; loop label
POP DX ; pop a value from STACK to DX
OR DL, 30H ; convert decimal to ascii code
INT 21H ; print a character
LOOP @DISPLAY ; jump to label @DISPLAY if CX!=0
POP DX ; pop a value from STACK into DX
POP CX ; pop a value from STACK into CX
POP BX ; pop a value from STACK into BX
RET ; return control to the calling procedure
OUTDEC ENDP