view test/testarmasm.py @ 350:2b02bd286fe9

Fixed A9 hello worle
author Windel Bouwman
date Sat, 08 Mar 2014 16:29:03 +0100
parents 13a6e73b448f
children 899ae3aea803
line wrap: on
line source

import unittest
from ppci.outstream import BinaryOutputStream
from ppci.objectfile import ObjectFile
from asm import Assembler
from testasm import AsmTestCaseBase
from ppci.target.target_list import arm_target


a = Assembler(arm_target)

class ArmAssemblerTestCase(AsmTestCaseBase):
    """ ARM-mode (not thumb-mode) instruction assembly test case """
    def setUp(self):
        self.t = arm_target
        self.obj = ObjectFile()
        self.ostream = BinaryOutputStream(self.obj)
        self.ostream.select_section('.text')
        self.a = a #Assembler(target=self.t)

    def testMovImm(self):
        self.feed('mov r4, 100')
        self.check('6440a0e3')

    def testMovImm2(self):
        self.feed('mov sp, 0x6000')
        self.check('06daa0e3')

    def testAdd2(self):
        self.feed('add r12, r11, 300')
        self.check('4bcf8be2')

    def testAdd1(self):
        self.feed('add r9, r7, r2')
        self.check('029087e0')

    def testSub1(self):
        self.feed('sub r5, r6, r2')
        self.check('025046e0')

    def testSub2(self):
        self.feed('sub r0, r1, 0x80000001')
        self.check('060141e2')

    def testOrr1(self):
        self.feed('orr r8, r7, r6')
        self.check('068087e1')

    def testBranches(self):
        self.feed('b sjakie')
        self.feed('ble sjakie')
        self.feed('bgt sjakie')
        self.feed('beq sjakie')
        self.feed('bl sjakie')
        self.feed('sjakie:')
        self.feed('b sjakie')
        self.feed('ble sjakie')
        self.feed('bgt sjakie')
        self.feed('beq sjakie')
        self.feed('bl sjakie')
        self.check('030000ea 020000da 010000ca 0000000a ffffffeb feffffea fdffffda fcffffca fbffff0a faffffeb')

    def testPush(self):
        self.feed('push {r11,r5,r4,lr}')
        self.check('30482de9')

    def testPop(self):
        self.feed('pop {r4,r5,r6}')
        self.check('7000bde8')

    def testStr(self):
        self.feed('str r9, [r2, 33]')
        self.check('219082e5')

    def testLdr(self):
        self.feed('ldr r5, [r3, 87]')
        self.check('575093e5')

    def testLdrLabel(self):
        self.feed('ldr r5, lab1')
        self.feed('ldr r11, lab1')
        self.feed('ldr r10, lab1')
        self.feed('lab1:')
        self.feed('dcd 0x12345566')
        self.check('04509fe5 00b09fe5 04a01fe5 66553412')

    def testSequence1(self):
        self.feed('sub r4,r5,23')
        self.feed('blt x')
        self.feed('x:')
        self.feed('mul r4,r5,r2')
        self.check('174045e2 ffffffba 950204e0')


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