Mercurial > lcfOS
comparison python/testasm.py @ 202:f22b431f4113
Added arm add instruction
author | Windel Bouwman |
---|---|
date | Sat, 15 Jun 2013 10:02:50 +0200 |
parents | d5debbfc0200 |
children | ca1ea402f6a1 |
comparison
equal
deleted
inserted
replaced
201:d5debbfc0200 | 202:f22b431f4113 |
---|---|
3 import unittest, cProfile | 3 import unittest, cProfile |
4 from ppci import CompilerError | 4 from ppci import CompilerError |
5 from asmnodes import AInstruction, ABinop, AUnop, ASymbol, ALabel, ANumber | 5 from asmnodes import AInstruction, ABinop, AUnop, ASymbol, ALabel, ANumber |
6 from asm import tokenize, Assembler | 6 from asm import tokenize, Assembler |
7 import msp430 | 7 import msp430 |
8 import arm_cm3 | |
8 | 9 |
9 class AssemblerLexingCase(unittest.TestCase): | 10 class AssemblerLexingCase(unittest.TestCase): |
10 """ Tests the assemblers lexer """ | 11 """ Tests the assemblers lexer """ |
11 | 12 |
12 def testLex0(self): | 13 def testLex0(self): |
128 self.assertEqual(bytes([0x0F, 0x4E]), self.a.binout) | 129 self.assertEqual(bytes([0x0F, 0x4E]), self.a.binout) |
129 | 130 |
130 def testMov1337(self): | 131 def testMov1337(self): |
131 line1 = "mov 0x1337, r12" | 132 line1 = "mov 0x1337, r12" |
132 self.a.assemble_line(line1) | 133 self.a.assemble_line(line1) |
133 self.assertEqual(bytes([0x3C, 0x40, 0x37, 0x13]), self.a.binout) | 134 self.assertEqual(bytes.fromhex('3C403713'), self.a.binout) |
134 | 135 |
135 def testAdd(self): | 136 def testAdd(self): |
136 line1 = "add r15, r13" | 137 line1 = "add r15, r13" |
137 self.a.assemble_line(line1) | 138 self.a.assemble_line(line1) |
138 self.assertEqual(bytes([0x0D, 0x5F]), self.a.binout) | 139 self.assertEqual(bytes.fromhex('0D5F'), self.a.binout) |
139 | 140 |
140 def testReti(self): | 141 def testReti(self): |
141 line1 = "reti" | 142 line1 = "reti" |
142 self.a.assemble_line(line1) | 143 self.a.assemble_line(line1) |
143 self.assertEqual(bytes([0x0, 0x13]), self.a.binout) | 144 self.assertEqual(bytes([0x0, 0x13]), self.a.binout) |
145 def testMSPinstructionCount(self): | 146 def testMSPinstructionCount(self): |
146 """ Check that there are 27 instructions """ | 147 """ Check that there are 27 instructions """ |
147 self.assertEqual(27, len(self.t.instructions)) | 148 self.assertEqual(27, len(self.t.instructions)) |
148 | 149 |
149 | 150 |
151 class AssemblerARMTestCase(unittest.TestCase): | |
152 def setUp(self): | |
153 self.t = arm_cm3.armtarget | |
154 self.a = Assembler(target=self.t) | |
155 | |
156 def testMapOperand(self): | |
157 pass | |
158 | |
159 def testMovImm8(self): | |
160 self.a.assemble('mov r4, 100') | |
161 self.assertEqual(bytes.fromhex('6424'), self.a.binout) | |
162 | |
163 def testYield(self): | |
164 self.a.assemble('yield') | |
165 self.assertEqual(bytes.fromhex('10bf'), self.a.binout) | |
166 | |
167 | |
150 if __name__ == '__main__': | 168 if __name__ == '__main__': |
151 # cProfile.run('unittest.main()') | 169 # cProfile.run('unittest.main()') |
152 unittest.main() | 170 unittest.main() |
153 | 171 |