-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dec16bitOutput.asm
62 lines (43 loc) · 1.65 KB
/
Dec16bitOutput.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
;-------------------------------- OUTDEC --------------------------------;
OUTDEC PROC
; this procedure will display a decimal number
; input : AX
; output : none
; uses : MAIN
PUSH BX
PUSH CX
PUSH DX
CMP AX, 0 ; compare AX with 0
JGE @START ; jump to label @START if AX>=0
MOV DL, "-" ; set DL=\'-\'
CALL OUTDEC_printByteIn_DL
NEG AX ; take 2\'s complement of AX
@START: ; jump label
XOR CX, CX ; CX counts number of digits
MOV BX, 10 ; set BX=10
@OUTPUT:
XOR DX, DX ; clear DX
DIV BX ; divide AX by BX
PUSH DX ; push DX onto the STACK
INC 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:
POP DX
OR DL, 30H ; convert decimal to ascii code
INT 21H
LOOP @DISPLAY ; jump to label @DISPLAY if CX!=0
POP DX
POP CX
POP BX
RET
OUTDEC ENDP
; prints the Byte in DL
OUTDEC_printByteIn_DL proc
PUSH AX
MOV AH,2
INT 21h
POP AX
RET
OUTDEC_printByteIn_DL endp