def __init__(self, instruction, opcodes, opcodeStr, dataval, address, arg1, arg2, arg3, arg1Str, arg2Str, arg3Str, numInstructions, destReg, src1Reg, src2Reg): self.instruction = instruction self.opcode = opcodes self.dataval = dataval self.address = address self.numInstructions = numInstructions self.arg1 = arg1 self.arg2 = arg2 self.arg3 = arg3 self.arg1Str = arg1Str self.arg2Str = arg2Str self.arg3Str = arg3Str self.destReg = destReg self.src1Reg = src1Reg self.src2Reg = src2Reg self.opcodeStr = opcodeStr self.PC = 96 self.cycle = 1 self.R = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] self.postMemBuff = [-1, -1] # first number is value, second is instr index self.postALUBuff = [-1, -1] # first number is value, second is instr index self.preMemBuff = [-1, -1] self.preALUBuff = [-1, -1] self.preIssueBuff = [-1, -1, -1, -1] #uncomment these lines as the classes are developed :) self.WB = writeBack.WriteBack(self.R, self.postMemBuff, self.postALUBuff, destReg) self.ALU = alu.ALU(self.R, self.postALUBuff, self.preALUBuff, opcodeStr, arg1, arg2, arg3) self.MEM = mem.MEM(self.R, self.postMemBuff, self.preMemBuff, opcodeStr, arg1, arg2, arg3, dataval, address, self.numInstructions) self.cache = cache.Cache(self.numInstructions, self.instruction, self.dataval, self.address) self.issue = issue.Issue(instruction, opcodes, opcodeStr, dataval, address, arg1, arg2, arg3, self.numInstructions, destReg, src1Reg, src2Reg, self.preIssueBuff, self.preALUBuff, self.preMemBuff, self.postALUBuff, self.postMemBuff) self.fetch = fetch.Fetch(instruction, opcodeStr, dataval, address, arg1, arg2, arg3, self.numInstructions, destReg, src1Reg, src2Reg, self.preALUBuff, self.postALUBuff, self.PC, cache, self.preIssueBuff) self.outputFileName = SetUp.get_output_filename()
def __init__(self, instructions, opcode, opcodeStr, dataval, address, arg1, arg2, arg3, arg1Str, arg2Str, arg3Str, numInstructions, destReg, src1Reg, src2Reg): self.instructions = instructions self.opcode = opcode self.opcodeStr = opcodeStr self.dataval = dataval self.address = address self.arg1 = arg1 self.arg2 = arg2 self.arg3 = arg3 self.arg1Str = arg1Str self.arg2Str = arg2Str self.arg3Str = arg3Str self.numInstructions = numInstructions self.destReg = destReg self.src1Reg = src1Reg self.src2Reg = src2Reg self.PC = 96 self.cycle = 1 ### LISTS ### self.cycleList = [0] self.R = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] self.postMemBuff = [-1, -1] # first number is value, second is instr index self.postALUBuff = [-1, -1] self.preMemBuff = [-1, -1] self.preALUBuff = [-1, -1] self.preIssueBuff = [-1, -1, -1, -1] ### OBJECTS ### self.WB = writeBack.WriteBack(self.R, self.postMemBuff, self.postALUBuff, destReg) self.cache = cache.Cache(numInstructions, instructions, dataval, address) self.ALU = alu.ALU(self.R, self.postALUBuff, self.preALUBuff, opcodeStr, arg1, arg2, arg3) self.MEM = memory.Memory(self.R, self.postMemBuff, self.preMemBuff, opcodeStr, arg1, arg2, arg3, dataval, self.numInstructions, self.cache, self.cycleList) self.issue = issue.Issue(instructions, opcodeStr, dataval, address, arg1, arg2, arg3, self.numInstructions, destReg, src1Reg, src2Reg, self.R, self.preIssueBuff, self.preMemBuff, self.postMemBuff, self.preALUBuff, self.postALUBuff) self.fetch = fetch.Fetch(instructions, opcodeStr, dataval, address, arg1, arg2, arg3, self.numInstructions, destReg, src1Reg, src2Reg, self.R, self.preIssueBuff, self.preMemBuff, self.postMemBuff, self.preALUBuff, self.postALUBuff, self.PC, self.cache) self.outputFileName = Setup.get_output_filename()
def __init__(self, opcode, dataval, address, numInstructs, arg1, arg2, arg3, opcodeStr, arg1Str, arg2Str, arg3Str, destReg, src1Reg, src2Reg, instructions): self.opcode = opcode self.opcodeStr = opcodeStr self.dataval = dataval self.address = address self.arg1 = arg1 self.arg2 = arg2 self.arg3 = arg3 self.arg1Str = arg1Str self.arg2Str = arg2Str self.arg3Str = arg3Str self.numInstructs = numInstructs self.destReg = destReg self.src1Reg = src1Reg self.src2Reg = src2Reg self.instruction = instructions self.PC = 96 self.cycle = 1 self.cycleList = [0] self.R = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] self.postMemBuff = [-1, -1] # first number is value, second is index self.postALUBuff = [-1, -1] # first number is value, second is index self.preMemBuff = [-1, -1] # first number is index, second is index self.preALUBuff = [-1, -1] # first number is index, second is index self.preIssueBuff = [-1, -1, -1, -1] "functional units" self.WB = writeBack.WriteBack(self.R, self.postMemBuff, self.postALUBuff, destReg) self.cache = cache.Cache(numInstructs, instructions, dataval, address) self.ALU = alu.ALU(self.R, self.preALUBuff, self.postALUBuff, opcodeStr, arg1, arg2, arg3) self.MEM = memory.Memory(self.R, self.postMemBuff, self.preMemBuff, opcodeStr, arg1, arg2, arg3, dataval, address, self.numInstructs, self.cache, self.cycleList)
class ALUtest: R = [ 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] opcodeStr = ["ADD", "ADD"] src2Reg = [1, 2] src1Reg = [3, 4] preALUbuff = [0, 1] postALUbuff = [-1, -1] destReg = [3, 5, 6, 12, 14, 6] test = alu.ALU(R, opcodeStr, destReg, src2Reg, src1Reg, preALUbuff, postALUbuff) print("ALUTEST INSTRUCTION INDEX 0: ", str(preALUbuff[0])) print("ALUTEST INSTRUCTION INDEX 1: ", str(preALUbuff[1])) postALUbuff = test.run() print("ALUTEST RESULT: ", str(postALUbuff[0])) print("ALUTEST INSTRUCTION INDEX 0: ", str(preALUbuff[0])) print("ALUTEST INSTRUCTION INDEX 1: ", str(preALUbuff[1])) postALUbuff = test.run() print("ALUTEST RESULT: ", str(postALUbuff[0]))
def setUp(self): self.alu = alu.ALU()
def main(): arq = open('programa.asm', 'r') instrucao = arq.readlines() for linha in instrucao: linha = linha.replace('$', '') # substituindo '$' por '' (nada) linha = linha.replace(',', '') # substituindo ',' por '' (nada) linha = linha.strip( ) # tirado espaços a direita e esquerda desnecessarios result = linha.split() # separando cada palavra em uma lista print(result) Registers = registers.Registers() Control = control.Control() AL = alu.ALU() if (result[0] == 'ADD'): Control.setIntrucion('000000', '32') Control.control() if (Control.getRegWrite() == True): register_1(result[2], Registers) register_2(result[3], Registers) register_Witre(result[1], Registers) AL.setRd(Registers.getValor_write()) AL.setRs(Registers.getValor_register_1()) AL.setRt(Registers.getValor_register_2()) result_op = AL.alu(Control.getALUOp()) print(result_op) Registers.setWrite_data(result_op) elif (result[0] == 'ADDI'): Control.setIntrucion('001000', '8') Control.control() if (Control.getRegWrite() == True): register_1(result[2], Registers) register_2(result[3], Registers) register_Witre(result[1], Registers) AL.setRd(Registers.getValor_write()) AL.setRt(Registers.getAux()) result_op = AL.alu(Control.getALUOp()) print(result_op) Registers.setWrite_data(result_op) elif (result[0] == 'SUB'): Control.setIntrucion('000000', '34') Control.control() if (Control.getRegWrite() == True): register_1(result[2], Registers) register_2(result[3], Registers) register_Witre(result[1], Registers) AL.setRd(Registers.getValor_write()) AL.setRs(Registers.getValor_register_1()) AL.setRt(Registers.getValor_register_2()) result_op = AL.alu(Control.getALUOp()) print(result_op) Registers.setWrite_data(result_op) arq.close()
import registers import alu import instructionMemory import dataMemory reg = registers.Registers() IM = instructionMemory.Memory() DM = dataMemory.Memory() alu = alu.ALU() with open('test') as f: IM.memory = [line.rstrip('\n') for line in open('test')] print(IM.memory) def Fetch(PC): Decode(IM.getInstruction(reg.PC), reg) reg.incrementPC() def Decode(instruction, reg): #instruction is a MIPS instruction decodedIns = str(instruction).translate( {ord(c): None for c in ','}).split() #translate removes the ',' from the string print("CURRENT INSTRUCTION: ", instruction) for i in range(len(decodedIns))[1:]: decodedIns[i] = (str(decodedIns[i]).translate( {ord(c): None for c in '$'})) #strip $ and put the remaining value in rd