view test/testmsp430asm.py @ 335:582a1aaa3983

Added long branch format
author Windel Bouwman
date Mon, 17 Feb 2014 20:41:30 +0100
parents 6f4753202b9a
children 4d204f6f7d4e
line wrap: on
line source

#!/usr/bin/python

import unittest
from ppci.asmnodes import AInstruction, ABinop, AUnop, ASymbol, ALabel, ANumber
from ppci.assembler import tokenize, Assembler
from ppci.objectfile import ObjectFile
import outstream
from target import Label
from target.target_list import msp430target
from testasm import AsmTestCaseBase


class AssemblerMSP430TestCase(AsmTestCaseBase):
    def setUp(self):
        self.t = msp430target
        self.obj = ObjectFile()
        self.o = outstream.BinaryOutputStream(self.obj)
        self.o.selectSection('.text')
        self.a = Assembler(target=self.t, stream=self.o)

    def testMapMovInstruction(self):
        i = AInstruction('mov', [ASymbol('r14'), ASymbol('r15')])
        ri = self.t.mapInstruction(i)

    def testMapRetiInstruction(self):
        i = AInstruction('reti', [])
        ri = self.t.mapInstruction(i)

    def testMov(self):
        self.feed("mov r14, r15")
        self.check('0F4E')

    def testMov1337(self):
        self.feed("mov 0x1337, r12")
        self.check('3C403713')

    def testAdd(self):
        self.feed("add r15, r13")
        self.check('0D5F')

    def testReti(self):
        self.feed("reti")
        self.check('0013')

    def testMSPinstructionCount(self):
        """ Check that there are 27 instructions """
        self.assertEqual(27, len(self.t.instructions))


if __name__ == '__main__':
    unittest.main()