view 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 source

from target import Register, Instruction, Target

# Target description for the MSP430 processor

class MSP430Reg(Register):
    def __init__(self, num, name):
        super().__init__(name)
        self.num = num

# 8 bit registers:
PCB = MSP430Reg(0, 'r0')
r13 = MSP430Reg(13, 'r13')
r14 = MSP430Reg(14, 'r14')
r15 = MSP430Reg(15, 'r15')

# .. etc

#GR8 = RegisterClass((PCB, R15B))

# Two operand arithmatic instructions:

class TwoOpArith(Instruction):
    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)

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, r13, r14, r15]
        self.instructions = [mov_ins, add_ins]

t = MSP430()