199
|
1 from target import Register, Instruction, Target
|
|
2
|
|
3 # Target description for the MSP430 processor
|
|
4
|
|
5 class MSP430Reg(Register):
|
|
6 def __init__(self, num, name):
|
|
7 super().__init__(name)
|
|
8 self.num = num
|
|
9
|
200
|
10 # 8 bit registers:
|
199
|
11 PCB = MSP430Reg(0, 'r0')
|
200
|
12 r13 = MSP430Reg(13, 'r13')
|
|
13 r14 = MSP430Reg(14, 'r14')
|
|
14 r15 = MSP430Reg(15, 'r15')
|
199
|
15
|
|
16 # .. etc
|
|
17
|
|
18 #GR8 = RegisterClass((PCB, R15B))
|
|
19
|
200
|
20 # Two operand arithmatic instructions:
|
|
21
|
199
|
22 class TwoOpArith(Instruction):
|
200
|
23 operands = (MSP430Reg, MSP430Reg)
|
|
24 def __init__(self, op1, op2):
|
|
25 self.op1 = op1
|
|
26 self.op2 = op2
|
|
27 def encode(self):
|
|
28 # TODO:
|
|
29 b1 = (self.opcode << 4)
|
|
30 b2 = 0
|
|
31 ba = bytearray([b1, b2])
|
|
32 return bytes(ba)
|
199
|
33
|
200
|
34 class mov_ins(TwoOpArith):
|
|
35 # class variables:
|
|
36 mnemonic = 'mov'
|
|
37 opcode = 4
|
|
38
|
|
39 class add_ins(TwoOpArith):
|
|
40 mnemonic = 'add'
|
|
41 opcode = 5
|
199
|
42
|
|
43 class MSP430(Target):
|
|
44 def __init__(self):
|
200
|
45 self.registers = [PCB, r13, r14, r15]
|
199
|
46 self.instructions = [mov_ins, add_ins]
|
|
47
|
200
|
48 t = MSP430()
|
199
|
49
|