def execution(read_data1: Register, read_data2: Register, sign_extend: Bin, write_reg: Register, control_signal: dict, instruction_eng): temp = namedtuple('Execution', [ 'alu_result', 'write_data', 'write_reg', 'control_signal', 'instruction_eng' ]) if read_data1 is None or\ read_data2 is None or\ sign_extend is None or\ write_reg is None or\ control_signal is None: return temp(None, None, None, None, None) alu_control = alu_control_unit(control_signal.pop('alu_op'), sign_extend[0:6]) read_data_2_alu = mux([read_data2.read_data(), sign_extend], control_signal.pop('alu_src')) alu_out = alu(read_data1.read_data(), read_data_2_alu, alu_control) return temp(alu_out.result, read_data2, write_reg, control_signal, instruction_eng)
def memory(alu_result: Bin, write_data: Register, write_reg: Register, control_signal: dict, instruction_eng): temp = namedtuple('Memory', [ 'read_data', 'alu_result', 'write_reg', 'control_signal', 'instruction_eng' ]) if alu_result is None or\ write_data is None or\ write_reg is None or\ control_signal is None: return temp(None, None, None, None, None) if control_signal.pop('mem_write'): data_mem[int(alu_result)] = write_data.read_data() if control_signal.pop('mem_read'): read_data = data_mem[int(alu_result)] else: read_data = None return temp(read_data, alu_result, write_reg, control_signal, instruction_eng)