diff 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
line wrap: on
line diff
--- a/python/msp430.py	Fri Jun 07 18:59:57 2013 +0200
+++ b/python/msp430.py	Sun Jun 09 16:06:49 2013 +0200
@@ -7,26 +7,43 @@
         super().__init__(name)
         self.num = num
 
-# 8 bit variants:
+# 8 bit registers:
 PCB = MSP430Reg(0, 'r0')
-R14B = MSP430Reg(14, 'r14')
-R15B = MSP430Reg(15, 'r15')
+r13 = MSP430Reg(13, 'r13')
+r14 = MSP430Reg(14, 'r14')
+r15 = MSP430Reg(15, 'r15')
 
 # .. etc
 
 #GR8 = RegisterClass((PCB, R15B))
 
+# Two operand arithmatic instructions:
+
 class TwoOpArith(Instruction):
-    def __init__(self, opc, name):
-        super().__init__(opc)
-        self.name = name
+    operands = (MSP430Reg, MSP430Reg)
+    def __init__(self, op1, op2):
+        self.op1 = op1
+        self.op2 = op2
+    def encode(self):
+        # TODO:
+        b1 = (self.opcode << 4)
+        b2 = 0
+        ba = bytearray([b1, b2])
+        return bytes(ba)
 
-mov_ins = TwoOpArith(4, 'mov')
-add_ins = TwoOpArith(5, 'add')
+class mov_ins(TwoOpArith):
+    # class variables:
+    mnemonic = 'mov'
+    opcode = 4
+
+class add_ins(TwoOpArith):
+    mnemonic = 'add'
+    opcode = 5
 
 class MSP430(Target):
     def __init__(self):
-        self.registers = [PCB, R14B, R15B]
+        self.registers = [PCB, r13, r14, r15]
         self.instructions = [mov_ins, add_ins]
 
+t = MSP430()