-
Notifications
You must be signed in to change notification settings - Fork 9
/
exampleProgram.txt
97 lines (77 loc) · 1.91 KB
/
exampleProgram.txt
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
; Example Z80 assembler program to perform Euclid's algorithm
; This isn't written for any actual assembler; it's just my
; notes for me to hand assemble.
; Pseudocode from Wikipedia:
; function gcd(a, c)
; while a != c
; if a > c
; a := a − c
; else
; c := c − a
; return a
; Second version, hand assembled:
ADDR OP HIGH LOW DISASSEMBLY
0000 3E 0011 1110 LD A, #N
0001 36 0011 0110 #52
0002 06 0000 0110 LD B, #N
0003 4E 0100 1110 #78
loop:
0004 B8 1011 1000 CP B
0005 38 0011 1000 JP C +N
0006 05 0000 0101 #6 (b_gt_a)
0007 28 0010 1000 JP Z +N
0008 0A 0000 1010 #10 (done)
0009 90 1001 0000 SUB A, B
0010 18 0001 1000 JP N+2
0011 F8 1111 1000 #-8 (loop)
b_gt_a:
0012 4F 0100 1111 LD C, A
0013 78 0111 1000 LD A, B
0014 91 1001 0001 SUB A, C
0015 47 0100 0111 LD B, A
0016 79 0111 1001 LD A, C
0017 18 0001 1000 JP N+2
0018 F1 1111 0001 #-10 (loop)
done:
0019 32 0011 0010 LD (NN), A
0020 80 1000 0000 #0x80
0021 00 0000 0000 #0x00
0022 18 0001 1000 JP N+2
0023 FB 1111 1011 #-4 (done)
# JP C test:
ADDR OP HIGH LOW DISASSEMBLY
0000 3E 0011 1110 LD A, #N
0001 36 0011 0110 #52
0002 06 0000 0110 LD B, #N
0003 4E 0100 1110 #78
loop:
0004 B8 1011 1000 CP B
0005 38 0011 1000 JP C +N
0006 1111 1110 -1 > #0
This should should execute in a loop and not escape.
Yep, works
So the negative test:
ADDR OP HIGH LOW DISASSEMBLY
0000 3E 0011 1110 LD A, #N
0001 4E 0100 1110 #78
0002 06 0000 0110 LD B, #N
0003 36 0011 0110 #52
loop:
0004 B8 1011 1000 CP B
0005 38 0011 1000 JP C +N
0006 0000 1000 -1 > #0
0007 0000 0000 NOP
0008 0000 0000 NOP
This should execute all the NOPs and not jump to 0009... TEst passes.
# JP Z test:
ADDR OP HIGH LOW DISASSEMBLY
0000 3E 0011 1110 LD A, #N
0001 36 0011 0110 #78
0002 06 0000 0110 LD B, #N
0003 4E 0100 1110 #78
loop:
0004 B8 1011 1000 CP B
0005 38 0010 1000 JP Z +N
0006 1111 1110 -1 > #0
This should sit in a loop and never escape.
Yep, works