annotate python/msp430.py @ 200:5e391d9a3381

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