-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sweet_16.a65
194 lines (159 loc) · 3.13 KB
/
test_sweet_16.a65
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
; Tests for the Sweet-16 ported to the Commander X 16
.list off
.include "test65.i65"
.include "../asminc/set_16.i65"
.include "../asminc/eql_16.i65"
.include "../asminc/sweet_16.i65"
.include "../asminc/sweet_16_test.i65"
.list on
.export _main
.pc02
.data
; Reserve space for the Sweet-16 stack.
; Note: The Sweet-16 stack grows upward. The opposite of usual.
sw16_stack: .res 10
; Reserve a buffer to test memory operations.
buffer: .res 6
.code
_main:
; Set up some initial register values.
begin_sw16
set R12, sw16_stack
set R0,$1234
sw16_fail_eq 30
sw16_fail_cs 31
set R1,$5678
sw16_fail_eq 32
sw16_fail_cs 33
sw16_fail_m 34
set R7,$A678
sw16_fail_p 35
sw16_fail_m1 36
set R8,$FFFF
sw16_fail_nm1 37
end_sw16
; Test some register values.
eql_16 sw16_r0,$1234
fail_ne 10
eql_16 sw16_r1,$5678
fail_ne 11
; Add some numbers and test.
begin_sw16
add R1
sw16_fail_cs 38
end_sw16
eql_16 sw16_r0,$68AC
fail_ne 12
eql_16 sw16_r1,$5678
fail_ne 13
; Restore values by subtracting and test.
begin_sw16
sub R1
sw16_fail_cc 39
end_sw16
eql_16 sw16_r0,$1234
fail_ne 14
eql_16 sw16_r1,$5678
fail_ne 15
; Test using the Fibonacci sequence.
begin_sw16
set R0,$0
set R1,$1
set R5,fib_table ; R5 points to the expected values. 0 is the end marker.
test_loop:
bs fib ; Compute the next value in the series.
; Get the test value into R4
st R2 ; Save R0
ldd @R5 ; Get the next table entry.
bz fib_test_done ; However, zero marks the end of the test.
st R4
ld R2 ; Restore R0
; Do the values match?
cpr R4
sw16_fail_ne 20
br test_loop ; Go again!
fib_test_done:
end_sw16
jmp test_group_2
.setcpu "sweet16"
; Compute the next entry in the Fibonacci sequence.
fib:
; Swap R0 and R1
mov r_1,r_2
st R1
ld R2
; st R2
; ld R1
; st R3
; ld R2
; st R1
; ld R3
; Add R1 to R0
add R1
rs
.pc02
tests_fail 254
fib_table:
.word 1
.word 1
.word 2
.word 3
.word 5
.word 8
.word 13
.word 21
.word 34
.word 55
.word 89
.word 144
.word 233
.word 377
.word 610
.word 987
.word 1597
.word 2584
.word 4181
.word 6765
.word 10946
.word 17711
.word 28657
.word 46368
.word 0
test_group_2:
begin_sw16
jump jump_target
.byte $0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F
jump_target:
; Test again using the Fibonacci sequence.
set R0,$0
set R1,$1
set R5,fib_table ; R5 points to the expected values. 0 is the end marker.
test_loop2:
js fib ; Compute the next value in the series. (Test js)
; Get the test value into R4
st R2 ; Save R0
ldd @R5 ; Get the next table entry.
bz fib_test_done2 ; However, zero marks the end of the test.
st R4
ld R2 ; Restore R0
; Do the values match?
cpr R4
sw16_fail_ne 60
br test_loop2 ; Go again!
fib_test_done2:
; Test some basic memory operations.
set R1,buffer
set R2,buffer
set R0,0
st @R1
inr R0
st @R1
ld @R2
sw16_fail_ne 70
ld @R2
sw16_fail_eq 71
dcr R0
sw16_fail_ne 72
sw16_tests_pass
end_sw16
tests_fail 255