-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.asm
78 lines (75 loc) · 1.49 KB
/
print.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
;
; transmit a character in a
;--------------------------
putChar:
push bc
ld b,a ;save the character for later
putChar1:
in a,(STATUS) ;get the ACIA status
bit 1,a
jr z,putChar1 ;no, the TDR is not empty
ld a,b ;yes, get the character
out (TDR),a ;and put it in the TDR
pop bc
ret
printStr:
EX (SP),hl ; swap
call putStr
inc hl ; inc past null
EX (SP),hl ; put it back
ret
putStr0:
call putChar
inc hl
putStr:
ld a,(hl)
or A
jr NZ,putStr0
ret
; hl = value
printDec:
bit 7,h
jr z,printDec2
ld a,'-'
call putChar
xor a
sub l
ld l,a
sbc a,a
sub h
ld h,a
printDec2:
push bc
ld c,0 ; leading zeros flag = false
ld de,-10000
call printDec4
ld de,-1000
call printDec4
ld de,-100
call printDec4
ld e,-10
call printDec4
inc c ; flag = true for at least digit
ld e,-1
call printDec4
pop bc
ret
printDec4:
ld b,'0'-1
printDec5:
inc b
add hl,de
jr c,printDec5
sbc hl,de
ld a,'0'
cp b
jr nz,printDec6
xor a
or c
ret z
jr printDec7
printDec6:
inc c
printDec7:
ld a,b
jp putChar