Mercurial > lcfOS
diff python/testasm.py @ 201:d5debbfc0200
Added all 27 core instructions of msp430
author | Windel Bouwman |
---|---|
date | Thu, 13 Jun 2013 00:07:28 +0200 |
parents | 5e391d9a3381 |
children | f22b431f4113 |
line wrap: on
line diff
--- a/python/testasm.py Sun Jun 09 16:06:49 2013 +0200 +++ b/python/testasm.py Thu Jun 13 00:07:28 2013 +0200 @@ -2,7 +2,8 @@ import unittest, cProfile from ppci import CompilerError -from asm import AInstruction, ABinop, AUnop, ASymbol, ALabel, ANumber, tokenize, Assembler +from asmnodes import AInstruction, ABinop, AUnop, ASymbol, ALabel, ANumber +from asm import tokenize, Assembler import msp430 class AssemblerLexingCase(unittest.TestCase): @@ -83,6 +84,7 @@ a = Assembler() with self.assertRaises(CompilerError): a.assemble_line('') + @unittest.skip def testX86(self): testsrc = """ ; tst @@ -98,18 +100,24 @@ class AssemblerMSP430TestCase(unittest.TestCase): def setUp(self): - self.t = msp430.MSP430() + self.t = msp430.msp430target self.a = Assembler(target=self.t) - def testMapInstruction(self): + def testMapMovInstruction(self): i = AInstruction('mov', [ASymbol('r14'), ASymbol('r15')]) - self.t.mapInstruction(i) + ri = self.t.mapInstruction(i) + def testMapRetiInstruction(self): + i = AInstruction('reti', []) + ri = self.t.mapInstruction(i) + + @unittest.skip def testMapOperand(self): o = ASymbol('r14') mo = self.t.mapOperand(o) self.assertEqual(mo, msp430.r14) + @unittest.skip def testMapOperandIndirection(self): o = AUnop('[]', ASymbol('r14')) mo = self.t.mapOperand(o) @@ -117,10 +125,26 @@ def testMov(self): line1 = "mov r14, r15" self.a.assemble_line(line1) + self.assertEqual(bytes([0x0F, 0x4E]), self.a.binout) + + def testMov1337(self): + line1 = "mov 0x1337, r12" + self.a.assemble_line(line1) + self.assertEqual(bytes([0x3C, 0x40, 0x37, 0x13]), self.a.binout) def testAdd(self): - line1 = "add r14, r15" + line1 = "add r15, r13" self.a.assemble_line(line1) + self.assertEqual(bytes([0x0D, 0x5F]), self.a.binout) + + def testReti(self): + line1 = "reti" + self.a.assemble_line(line1) + self.assertEqual(bytes([0x0, 0x13]), self.a.binout) + + def testMSPinstructionCount(self): + """ Check that there are 27 instructions """ + self.assertEqual(27, len(self.t.instructions)) if __name__ == '__main__':