292
|
1 import unittest
|
342
|
2 from ppci.outstream import BinaryOutputStream
|
335
|
3 from ppci.objectfile import ObjectFile
|
292
|
4 from asm import Assembler
|
|
5 from testasm import AsmTestCaseBase
|
345
|
6 from ppci.target.target_list import arm_target
|
292
|
7
|
|
8
|
346
|
9 a = Assembler(arm_target)
|
292
|
10
|
345
|
11 class ArmAssemblerTestCase(AsmTestCaseBase):
|
340
|
12 """ ARM-mode (not thumb-mode) instruction assembly test case """
|
|
13 def setUp(self):
|
341
|
14 self.t = arm_target
|
340
|
15 self.obj = ObjectFile()
|
346
|
16 self.ostream = BinaryOutputStream(self.obj)
|
|
17 self.ostream.selectSection('.text')
|
|
18 self.a = a #Assembler(target=self.t)
|
340
|
19
|
|
20 def testMovImm(self):
|
|
21 self.feed('mov r4, 100')
|
|
22 self.check('6440a0e3')
|
345
|
23
|
346
|
24 def testMovImm2(self):
|
|
25 self.feed('mov sp, 0x6000')
|
|
26 self.check('06daa0e3')
|
|
27
|
345
|
28 def testAdd2(self):
|
|
29 self.feed('add r12, r11, 300')
|
|
30 self.check('4bcf8be2')
|
|
31
|
|
32 def testAdd1(self):
|
|
33 self.feed('add r9, r7, r2')
|
|
34 self.check('029087e0')
|
|
35
|
|
36 def testSub1(self):
|
|
37 self.feed('sub r5, r6, r2')
|
|
38 self.check('025046e0')
|
|
39
|
|
40 def testSub2(self):
|
|
41 self.feed('sub r0, r1, 0x80000001')
|
|
42 self.check('060141e2')
|
|
43
|
|
44 def testOrr1(self):
|
|
45 self.feed('orr r8, r7, r6')
|
|
46 self.check('068087e1')
|
|
47
|
|
48 def testBranches(self):
|
|
49 self.feed('b sjakie')
|
|
50 self.feed('ble sjakie')
|
|
51 self.feed('bgt sjakie')
|
|
52 self.feed('beq sjakie')
|
|
53 self.feed('bl sjakie')
|
|
54 self.feed('sjakie:')
|
|
55 self.feed('b sjakie')
|
|
56 self.feed('ble sjakie')
|
|
57 self.feed('bgt sjakie')
|
|
58 self.feed('beq sjakie')
|
|
59 self.feed('bl sjakie')
|
|
60 self.check('030000ea 020000da 010000ca 0000000a ffffffeb feffffea fdffffda fcffffca fbffff0a faffffeb')
|
346
|
61
|
|
62 def testPush(self):
|
|
63 self.feed('push {r11,r5,r4,lr}')
|
|
64 self.check('30482de9')
|
|
65
|
|
66 def testPop(self):
|
|
67 self.feed('pop {r4,r5,r6}')
|
|
68 self.check('7000bde8')
|
|
69
|
|
70 def testStr(self):
|
|
71 self.feed('str r9, [r2, 33]')
|
|
72 self.check('219082e5')
|
|
73
|
|
74 def testLdr(self):
|
|
75 self.feed('ldr r5, [r3, 87]')
|
|
76 self.check('575093e5')
|
|
77
|
|
78 def testSequence1(self):
|
|
79 self.feed('sub r4,r5,23')
|
|
80 self.feed('blt x')
|
|
81 self.feed('x:')
|
|
82 self.feed('mul r4,r5,r2')
|
|
83 self.check('174045e2 ffffffba 950204e0')
|
|
84
|
|
85
|
|
86 if __name__ == '__main__':
|
|
87 unittest.main()
|