@@ -18,7 +18,7 @@ def nice_opcode(o):
18
18
return o [:3 ] + "_" + o [3 :8 ] + "_" + o [8 :]
19
19
20
20
21
- class TestNop (unittest .TestCase ):
21
+ class AssembleChecks (unittest .TestCase ):
22
22
def assertAssemblesTo (self , source , expected ):
23
23
actual = adafruit_pioasm .assemble (source )
24
24
expected_bin = [nice_opcode (x ) for x in expected ]
@@ -35,6 +35,8 @@ def assertAssemblyFails(self, source, match=None, errtype=RuntimeError):
35
35
else :
36
36
self .assertRaises (errtype , adafruit_pioasm .assemble , source )
37
37
38
+
39
+ class TestNop (AssembleChecks ):
38
40
def testNonsense (self ):
39
41
self .assertAssemblyFails ("nope" )
40
42
@@ -55,12 +57,6 @@ def testSidesetOpt(self):
55
57
)
56
58
self .assertAssemblesTo (".side_set 1 opt\n nop [1]" , [0b101_00001_010_00_010 ])
57
59
58
- def testMov (self ):
59
- # non happy path
60
- self .assertAssemblyFails (
61
- "mov x, blah" , match = "Invalid mov source 'blah'" , errtype = ValueError
62
- )
63
-
64
60
def testSet (self ):
65
61
# non happy path
66
62
self .assertAssemblyFails (
@@ -94,3 +90,23 @@ def testWait(self):
94
90
self .assertAssemblesTo ("wait 0 irq 0 rel" , [0b001_00000_0_10_10000 ])
95
91
self .assertAssemblesTo ("wait 1 irq 0" , [0b001_00000_1_10_00000 ])
96
92
self .assertAssemblesTo ("wait 0 irq 1 rel" , [0b001_00000_0_10_10001 ])
93
+
94
+
95
+ class TestMov (AssembleChecks ):
96
+ def testMovNonHappy (self ):
97
+ # non happy path
98
+ self .assertAssemblyFails (
99
+ "mov x, blah" , match = "Invalid mov source 'blah'" , errtype = ValueError
100
+ )
101
+
102
+ def testMovInvert (self ):
103
+ # test moving and inverting
104
+ self .assertAssemblesTo ("mov x, ~ x" , [0b101_00000_001_01_001 ])
105
+ self .assertAssemblesTo ("mov x, ~ x" , [0b101_00000_001_01_001 ])
106
+ self .assertAssemblesTo ("mov x, ~x" , [0b101_00000_001_01_001 ])
107
+ self .assertAssemblesTo ("mov x, !x" , [0b101_00000_001_01_001 ])
108
+
109
+ def testMovReverse (self ):
110
+ # test moving and reversing bits
111
+ self .assertAssemblesTo ("mov x, :: x" , [0b101_00000_001_10_001 ])
112
+ self .assertAssemblesTo ("mov x, ::x" , [0b101_00000_001_10_001 ])
0 commit comments