Skip to content

Commit 44d2b8f

Browse files
committed
CMP instructions
unit tests for CMP instructions
1 parent 7ace237 commit 44d2b8f

File tree

5 files changed

+306
-0
lines changed

5 files changed

+306
-0
lines changed

test_cmp.spin

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
dat
2+
orgh 0
3+
org 0
4+
5+
andn outb, ##$FFFF
6+
or dirb, ##$FFFF
7+
8+
mov cnt, testc
9+
mov ptra, #@tests
10+
11+
_test rdlong d, ptra++
12+
rdlong s, ptra++
13+
rdlong cz, ptra++
14+
15+
setcz cz wc, wz
16+
17+
cmp d, s wc, wz ' TEST INSTRUCTION
18+
19+
setbc cz, #1 ' store C/Z
20+
setbz cz, #0
21+
22+
rdlong r, ptra++ ' get the expected result
23+
rdlong rcz, ptra++ ' get the expected flags
24+
25+
cmp d, r wz
26+
if_nz jmp #_next
27+
28+
cmp cz, rcz wz
29+
if_nz jmp #_next
30+
31+
mov d, testc ' set LED 0 to N
32+
sub d, cnt
33+
setb outb, d
34+
35+
_next
36+
djnz cnt, #_test
37+
38+
end jmp #end
39+
40+
41+
testc long 8
42+
' d s cz r rcz
43+
tests long $0000_0003, $0000_0002, %00, $0000_0003, %00
44+
long $0000_0003, $0000_0003, %00, $0000_0003, %01
45+
long $0000_0003, $0000_0004, %00, $0000_0003, %10
46+
long $8000_0000, $7FFF_FFFF, %00, $8000_0000, %00
47+
long $7FFF_FFFF, $8000_0000, %00, $7FFF_FFFF, %10
48+
long $FFFF_FFFE, $FFFF_FFFF, %00, $FFFF_FFFE, %10
49+
long $FFFF_FFFE, $FFFF_FFFE, %00, $FFFF_FFFE, %01
50+
long $FFFF_FFFE, $FFFF_FFFD, %00, $FFFF_FFFE, %00
51+
52+
cnt res 1
53+
d res 1
54+
s res 1
55+
cz res 1
56+
r res 1
57+
rcz res 1

test_cmps.spin

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
dat
2+
orgh 0
3+
org 0
4+
5+
andn outb, ##$FFFF
6+
or dirb, ##$FFFF
7+
8+
mov cnt, testc
9+
mov ptra, #@tests
10+
11+
_test rdlong d, ptra++
12+
rdlong s, ptra++
13+
rdlong cz, ptra++
14+
15+
setcz cz wc, wz
16+
17+
cmps d, s wc, wz ' TEST INSTRUCTION
18+
19+
setbc cz, #1 ' store C/Z
20+
setbz cz, #0
21+
22+
rdlong r, ptra++ ' get the expected result
23+
rdlong rcz, ptra++ ' get the expected flags
24+
25+
cmp d, r wz
26+
if_nz jmp #_next
27+
28+
cmp cz, rcz wz
29+
if_nz jmp #_next
30+
31+
mov d, testc ' set LED 0 to N
32+
sub d, cnt
33+
setb outb, d
34+
35+
_next
36+
djnz cnt, #_test
37+
38+
end jmp #end
39+
40+
41+
testc long 10
42+
' d s cz r rcz
43+
tests long $0000_0003, $0000_0002, %00, $0000_0003, %00
44+
long $0000_0003, $0000_0003, %00, $0000_0003, %01
45+
long $0000_0003, $0000_0004, %00, $0000_0003, %10
46+
long $8000_0000, $7FFF_FFFF, %00, $8000_0000, %10
47+
long $7FFF_FFFF, $8000_0000, %00, $7FFF_FFFF, %00
48+
long $8000_0000, $0000_0001, %00, $8000_0000, %10
49+
long $7FFF_FFFF, $FFFF_FFFF, %00, $7FFF_FFFF, %00
50+
long $FFFF_FFFE, $FFFF_FFFF, %00, $FFFF_FFFE, %10
51+
long $FFFF_FFFE, $FFFF_FFFE, %00, $FFFF_FFFE, %01
52+
long $FFFF_FFFE, $FFFF_FFFD, %00, $FFFF_FFFE, %00
53+
54+
cnt res 1
55+
d res 1
56+
s res 1
57+
cz res 1
58+
r res 1
59+
rcz res 1

test_cmpsub.spin

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
dat
2+
orgh 0
3+
org 0
4+
5+
andn outb, ##$FFFF
6+
or dirb, ##$FFFF
7+
8+
mov cnt, testc
9+
mov ptra, #@tests
10+
11+
_test rdlong d, ptra++
12+
rdlong s, ptra++
13+
rdlong cz, ptra++
14+
15+
setcz cz wc, wz
16+
17+
cmpsub d, s wc, wz ' TEST INSTRUCTION
18+
19+
setbc cz, #1 ' store C/Z
20+
setbz cz, #0
21+
22+
rdlong r, ptra++ ' get the expected result
23+
rdlong rcz, ptra++ ' get the expected flags
24+
25+
cmp d, r wz
26+
if_nz jmp #_next
27+
28+
cmp cz, rcz wz
29+
if_nz jmp #_next
30+
31+
mov d, testc ' set LED 0 to N
32+
sub d, cnt
33+
setb outb, d
34+
35+
_next
36+
djnz cnt, #_test
37+
38+
end jmp #end
39+
40+
41+
testc long 3
42+
' d s cz r rcz
43+
tests long $0000_0003, $0000_0002, %00, $0000_0001, %10
44+
long $0000_0003, $0000_0003, %00, $0000_0000, %11
45+
long $0000_0003, $0000_0004, %00, $0000_0003, %00
46+
47+
cnt res 1
48+
d res 1
49+
s res 1
50+
cz res 1
51+
r res 1
52+
rcz res 1

test_cmpsx.spin

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
dat
2+
orgh 0
3+
org 0
4+
5+
andn outb, ##$FFFF
6+
or dirb, ##$FFFF
7+
8+
mov cnt, testc
9+
mov ptra, #@tests
10+
11+
_test rdlong d, ptra++
12+
rdlong s, ptra++
13+
rdlong cz, ptra++
14+
15+
setcz cz wc, wz
16+
17+
cmpsx d, s wc, wz ' TEST INSTRUCTION
18+
19+
setbc cz, #1 ' store C/Z
20+
setbz cz, #0
21+
22+
rdlong r, ptra++ ' get the expected result
23+
rdlong rcz, ptra++ ' get the expected flags
24+
25+
cmp d, r wz
26+
if_nz jmp #_next
27+
28+
cmp cz, rcz wz
29+
if_nz jmp #_next
30+
31+
mov d, testc ' set LED 0 to N
32+
sub d, cnt
33+
setb outb, d
34+
35+
_next
36+
djnz cnt, #_test
37+
38+
end jmp #end
39+
40+
testc long (cnt-tests)/5
41+
42+
' d s cz r rcz
43+
tests long $0000_0003, $0000_0002, %00, $0000_0003, %00
44+
long $0000_0003, $0000_0002, %10, $0000_0003, %00
45+
long $0000_0003, $0000_0002, %11, $0000_0003, %01
46+
long $0000_0003, $0000_0003, %00, $0000_0003, %00
47+
long $0000_0003, $0000_0003, %01, $0000_0003, %01
48+
long $0000_0003, $0000_0003, %10, $0000_0003, %10
49+
long $0000_0003, $0000_0004, %00, $0000_0003, %10
50+
long $0000_0003, $0000_0004, %10, $0000_0003, %10
51+
long $8000_0000, $7FFF_FFFF, %00, $8000_0000, %10
52+
long $7FFF_FFFF, $8000_0000, %00, $7FFF_FFFF, %00
53+
long $8000_0000, $0000_0001, %00, $8000_0000, %10
54+
long $7FFF_FFFF, $FFFF_FFFF, %00, $7FFF_FFFF, %00
55+
long $FFFF_FFFE, $FFFF_FFFF, %00, $FFFF_FFFE, %10
56+
long $FFFF_FFFE, $FFFF_FFFF, %10, $FFFF_FFFE, %10
57+
long $FFFF_FFFE, $FFFF_FFFE, %00, $FFFF_FFFE, %00
58+
long $FFFF_FFFE, $FFFF_FFFE, %01, $FFFF_FFFE, %01
59+
' run second time with "tests" label moved to next line
60+
long $FFFF_FFFE, $FFFF_FFFE, %10, $FFFF_FFFE, %10
61+
long $FFFF_FFFE, $FFFF_FFFD, %00, $FFFF_FFFE, %00
62+
long $FFFF_FFFE, $FFFF_FFFD, %10, $FFFF_FFFE, %00
63+
long $FFFF_FFFE, $FFFF_FFFD, %11, $FFFF_FFFE, %01
64+
65+
cnt res 1
66+
d res 1
67+
s res 1
68+
cz res 1
69+
r res 1
70+
rcz res 1

test_cmpx.spin

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
dat
2+
orgh 0
3+
org 0
4+
5+
andn outb, ##$FFFF
6+
or dirb, ##$FFFF
7+
8+
mov cnt, testc
9+
mov ptra, #@tests
10+
11+
_test rdlong d, ptra++
12+
rdlong s, ptra++
13+
rdlong cz, ptra++
14+
15+
setcz cz wc, wz
16+
17+
cmpsx d, s wc, wz ' TEST INSTRUCTION
18+
19+
setbc cz, #1 ' store C/Z
20+
setbz cz, #0
21+
22+
rdlong r, ptra++ ' get the expected result
23+
rdlong rcz, ptra++ ' get the expected flags
24+
25+
cmp d, r wz
26+
if_nz jmp #_next
27+
28+
cmp cz, rcz wz
29+
if_nz jmp #_next
30+
31+
mov d, testc ' set LED 0 to N
32+
sub d, cnt
33+
setb outb, d
34+
35+
_next
36+
djnz cnt, #_test
37+
38+
end jmp #end
39+
40+
testc long (cnt-tests)/5
41+
42+
' d s cz r rcz
43+
tests long $0000_0003, $0000_0002, %00, $0000_0003, %00
44+
long $0000_0003, $0000_0002, %10, $0000_0003, %00
45+
long $0000_0003, $0000_0002, %11, $0000_0003, %01
46+
long $0000_0003, $0000_0003, %00, $0000_0003, %00
47+
long $0000_0003, $0000_0003, %01, $0000_0003, %01
48+
long $0000_0003, $0000_0003, %10, $0000_0003, %10
49+
long $0000_0003, $0000_0004, %00, $0000_0003, %10
50+
long $0000_0003, $0000_0004, %10, $0000_0003, %10
51+
long $8000_0000, $7FFF_FFFF, %00, $8000_0000, %00
52+
long $7FFF_FFFF, $8000_0000, %00, $7FFF_FFFF, %10
53+
long $FFFF_FFFE, $FFFF_FFFF, %00, $FFFF_FFFE, %10
54+
long $FFFF_FFFE, $FFFF_FFFF, %10, $FFFF_FFFE, %10
55+
long $FFFF_FFFE, $FFFF_FFFE, %00, $FFFF_FFFE, %00
56+
long $FFFF_FFFE, $FFFF_FFFE, %01, $FFFF_FFFE, %01
57+
long $FFFF_FFFE, $FFFF_FFFE, %10, $FFFF_FFFE, %10
58+
long $FFFF_FFFE, $FFFF_FFFD, %00, $FFFF_FFFE, %00
59+
' run second time with "tests" label moved to next line
60+
long $FFFF_FFFE, $FFFF_FFFD, %10, $FFFF_FFFE, %00
61+
long $FFFF_FFFE, $FFFF_FFFD, %11, $FFFF_FFFE, %01
62+
63+
cnt res 1
64+
d res 1
65+
s res 1
66+
cz res 1
67+
r res 1
68+
rcz res 1

0 commit comments

Comments
 (0)