def parse_instructions(f): instr_lst = [] yaml_obj = yaml.load(open(f, 'r').read(), Loader=Loader) for instr in yaml_obj['instructions']: name = instr['name'] opcode = instr['opcode'] if opcode > 63: raise Exception("Invalid Opcode: %i" % opcode) instr_desc = instr['description'] operand = bool(instr['requires_operand']) instruction = Instruction(name, opcode, instr_desc, operand) for key in instr['flags'].keys(): if key.lower() not in ['other', 'cf', 'zf', 'pf']: raise Exception("Invalid Flag: %s" % key) for step in instr['flags'][key]: sigs = step['signals'] if sigs is None: sigs = [] else: new_sigs = [] for sig in sigs: new_sigs.append(CtrlSigs[sig]) sigs = new_sigs step_desc = step['description'] microstep = MicroStep(sigs, step_desc) instruction.insert_step(microstep, key) instr_lst.append(instruction) return instr_lst
from classes import Instruction, CtrlSigs, MicroStep instr_lst = [] # No Operation NOP = Instruction('NOP', 0b000000, "Do absolutely nothing") NOP.insert_step(MicroStep([], "Do absolutely nothing")) instr_lst.append(NOP) # A Load instructions LDA = Instruction('LDA', 0b000001, "Load RAM contents to Register A", True) LDA.insert_step(MicroStep([CtrlSigs.IO, CtrlSigs.MI], "Move IR Address to MAR")) LDA.insert_step(MicroStep([CtrlSigs.RO, CtrlSigs.AI], "Move RAM contents to reg. A")) instr_lst.append(LDA) LAI = Instruction('LAI', 0b000010, "Load a value to Register A immediately", True) LAI.insert_step(MicroStep([CtrlSigs.IO, CtrlSigs.AI], "Move IR value to reg. A")) instr_lst.append(LAI) # B Load Instructions LDB = Instruction('LDB', 0b000011, "Load RAM contents to Register B", True) LDB.insert_step(MicroStep([CtrlSigs.IO, CtrlSigs.MI], "Move IR contetns to MAR")) LDB.insert_step(MicroStep([CtrlSigs.RO, CtrlSigs.BI], "Move RAM contents to reg. B")) instr_lst.append(LDB) LBI = Instruction('LBI', 0b000100, "Load a value to Register B immediately, True) LBI.insert_step(MicroStep([CtrlSigs.IO, CtrlSigs.BI], "Move IR value to reg. B")) instr_lst.append(LBI) # C Load Instructions LDC = Instruction('LDC', 0b000101, "Load RAM contents to Register C", True)