`include "opcodes.sv" module datapath( DataBus, Address, IR, ZReg, Function, UpdateZ, EnableACC, LoadACC, EnableX, LoadX, EnableS, LoadS, EnablePC, LoadPC, IncPC, SelPC, LoadIR, LoadMAR, EnableReg, Clock, nReset ); inout [15:0] DataBus; output [15:0] Address, IR; output ZReg; input [3:0] Function; input UpdateZ, EnableACC, LoadACC, EnableX, LoadX, EnableS, LoadS; input EnablePC, LoadPC, IncPC, SelPC, LoadIR, LoadMAR, EnableReg; input Clock, nReset; reg [15:0] IR, ACC, X, S, PC, MAR; reg ZReg; wire [15:0] ALUoutBus, RegBus, Address; // // ALU Instance // alu ALU ( ALU_Zflag, ALUoutBus, RegBus, DataBus, Function); // // Drive RegBus and DataBus as required // assign RegBus = (EnableACC) ? ACC : 16'bz; assign RegBus = (EnableX) ? X : 16'bz; assign RegBus = (EnableS) ? S : 16'bz; assign RegBus = (EnablePC) ? PC : 16'bz; assign DataBus = ( EnableReg ) ? RegBus : 16'bz; // // Address multiplexor // assign Address = (SelPC) ? PC : MAR; // // Update Registers as required // always_ff @(posedge Clock, negedge nReset) if (!nReset) begin PC <= 0; IR <= 0; ACC <= 0; X <= 0; S <= 0; MAR <= 0; ZReg <= 0; end else begin if (LoadPC) PC <= #20ns ALUoutBus; else if (IncPC) PC <= #20ns PC + 1; if (LoadIR) IR <= #20ns DataBus; if (LoadACC) ACC <= #20ns ALUoutBus; if (LoadX) X <= #20ns ALUoutBus; if (LoadS) S <= #20ns ALUoutBus; if (LoadMAR) MAR <= #20ns ALUoutBus; if (UpdateZ) ZReg <= #20ns ALU_Zflag; end endmodule