-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOUTDEC.asm
45 lines (45 loc) · 1017 Bytes
/
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
OUTDEC PROC
; prints AX as a signed decimal integer
; input: AX
; output: none
PUSH AX ;save registers
PUSH BX
PUSH CX
PUSH DX
; if AX < 0
CMP AX, 0 ; AX < 0?
JGE @END_IF1 ; no, > 0
; then
PUSH AX ; save number
MOV DL, '-' ; get '-'
MOV AH, 2 ; print char function
INT 21H ; print '-'
POP AX ; get AX back
NEG AX ; AX = -AX
@END_IF1:
; get decimal digits
MOV CX, 0 ; CX counts digits
MOV BX, 10D ; BX has divisor
@REPEAT1:
MOV DX, 0 ; prepare high word of dividend
DIV BX ; AX = quotient, DX = remainder
PUSH DX ; save remainder on stack
INC CX ; count = count + 1
; until
CMP AX, 0 ; quotient = 0 ?
JNE @REPEAT1 ; no, keep going
; convert digits to characters and print
MOV AH, 2 ; print char fucntion
; for count times do
@PRINT_LOOP:
POP DX ; digit in DL
ADD DL, 30H ; convert to character
INT 21H ; print digit
LOOP @PRINT_LOOP ; loop until done
; end_for
POP DX ; restore registers
POP CX
POP BX
POP AX
RET
OUTDEC ENDP