-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
string-output.z80
70 lines (59 loc) · 1.43 KB
/
string-output.z80
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
;
; This is a simple program which is designed to print "inline"
; strings.
;
; Of course such a thing is a little crazy, as it really messes
; with disassemblers, but it's still a cute hack.
;
org 0
call print
db "This is a test!\n$"
call print
db "As you can see we're printing INLINE strings!\n$"
halt
;
; This routine is designed to be CALLed, when it is invoked
; the address of the next instruction will be placed on the
; stack, which means we can find the address of the string to
; print from there.
;
; We print each character until we find a '$' character, then
; jmp back to the location after that.
;
print:
;
; The return address, i.e. the instruction after our call, will be
; on the stack. In our case we know that points to the string to be
; printed.
;
print_loop:
pop hl
;
; Load the character in the hl-register into A.
;
ld a,(hl)
;
; Bump to the next.
;
inc hl
;
; Since we've incremented the HL register we're either
; going to get the next character - or the address to
; which we should return. Push it onto the stack either way.
;
push hl
;
; Is the character '$'? If so we return - because we've
; just stored the next address on the stack we'll go to
; the correct location.
;
cp '$'
;
; Return if we're done.
;
ret z
;
; Otherwise output the single character, and start again.
;
out (1),a
jp print_loop