Mercurial > lcfOS
comparison 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 |
comparison
equal
deleted
inserted
replaced
199:a690473b79e2 | 200:5e391d9a3381 |
---|---|
5 class MSP430Reg(Register): | 5 class MSP430Reg(Register): |
6 def __init__(self, num, name): | 6 def __init__(self, num, name): |
7 super().__init__(name) | 7 super().__init__(name) |
8 self.num = num | 8 self.num = num |
9 | 9 |
10 # 8 bit variants: | 10 # 8 bit registers: |
11 PCB = MSP430Reg(0, 'r0') | 11 PCB = MSP430Reg(0, 'r0') |
12 R14B = MSP430Reg(14, 'r14') | 12 r13 = MSP430Reg(13, 'r13') |
13 R15B = MSP430Reg(15, 'r15') | 13 r14 = MSP430Reg(14, 'r14') |
14 r15 = MSP430Reg(15, 'r15') | |
14 | 15 |
15 # .. etc | 16 # .. etc |
16 | 17 |
17 #GR8 = RegisterClass((PCB, R15B)) | 18 #GR8 = RegisterClass((PCB, R15B)) |
18 | 19 |
20 # Two operand arithmatic instructions: | |
21 | |
19 class TwoOpArith(Instruction): | 22 class TwoOpArith(Instruction): |
20 def __init__(self, opc, name): | 23 operands = (MSP430Reg, MSP430Reg) |
21 super().__init__(opc) | 24 def __init__(self, op1, op2): |
22 self.name = name | 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) | |
23 | 33 |
24 mov_ins = TwoOpArith(4, 'mov') | 34 class mov_ins(TwoOpArith): |
25 add_ins = TwoOpArith(5, 'add') | 35 # class variables: |
36 mnemonic = 'mov' | |
37 opcode = 4 | |
38 | |
39 class add_ins(TwoOpArith): | |
40 mnemonic = 'add' | |
41 opcode = 5 | |
26 | 42 |
27 class MSP430(Target): | 43 class MSP430(Target): |
28 def __init__(self): | 44 def __init__(self): |
29 self.registers = [PCB, R14B, R15B] | 45 self.registers = [PCB, r13, r14, r15] |
30 self.instructions = [mov_ins, add_ins] | 46 self.instructions = [mov_ins, add_ins] |
31 | 47 |
48 t = MSP430() | |
32 | 49 |