Files
WMU-ECE-3570-Lab/lab2CA.srcs/sources_1/new/CPU9bits.v
Johannes cb91f6656a Many Changes
I added a comparator, I updated the control unit so that it now uses the 4 bit ALU opcode instead of the 3 bit from before. I added testbenches to the control unit and the slt and comparator modules. However, like before I unable to run the simulation on my desktop. Finally, i added the program code for the equation solver as a test bench in the CPU9bit module
2019-03-12 21:14:27 -04:00

131 lines
2.6 KiB
Verilog

`timescale 1ns / 1ps
module CPU9bits(input wire [8:0] instr,
input wire reset, clk,
output reg done
);
wire [8:0] op1, op0, FUAddr,FUJB,PCout,JBRes,FUJ,FUB,AddiOut,AluOut,RFIn, loadMux, dataMemOut;
wire [2:0] FU, aluOp;
wire addiS, RegEn, loadS;
RegFile RF(
.clk(clk),
.reset(reset),
.enable(RegEn),
.write_index(instr[4:3]),
.op0_idx(instr[4:3]),
.op1_idx(instr[2:1]),
.write_data(RFIn),
.op0(op0),
.op1(op1)
);
FetchUnit FetchU(
.clk(clk),
.reset(reset),
.op_idx(FU[0]),
.AddrIn(FUAddr),
.AddrOut(PCout)
);
ALU alu(
.opcode(aluOp),
.operand0(op0),
.operand1(op1),
.result(AluOut)
);
ControlUnit CU(
.instIn(instr[8:5]),
.functBit(instr[0]),
.aluOut(aluOp),
.FU(FU),
.addi(addiS),
.mem(loadS),
.load(loadMux)
);
//-----------------------Fetch Unit Stuff
add_9bit JBAdder(
.A(PCout),
.B(JBRes),
.Cin(9'b000000000),
.Sum(FUJB));
mux_2_1 mux1(
.A(op1),
.B(FUJB),
.out(FUAddr),
.switch(FU[1]));
mux_2_1 mux2(
.A({4'b0000,instr[4:0]}),
.B({6'b000000,instr[2:0]}),
.out(JBRes),
.switch(FU[2]));
///--------------------------Addi Stuff
add_9bit Addier(
.A({6'b000000,instr[2:0]}),
.B(op1),
.Cin(9'b000000000),
.Sum(AddiOut));
mux_2_1 mux3(
.A(AluOut),
.B(AddiOut),
.out(loadMux),
.switch(addiS));
mux_2_1 mux4(
.A(loadMux),
.B(dataMemOut),
.out(RFIn),
.switch(loadS));
endmodule
module CPU9bits_tb();
reg [8:0] instruction;
reg clk, reset;
wire done;
initial begin
clk = 1'b0;
end
always begin
#5 clk = ~clk; // Period to be determined
end
CPU9bits CPU9bits0(
.instr(instruction),
.reset(reset),
.clk(clk),
.done(done));
initial begin
reset = 0;
#10
reset = 1;
#10
instruction = 000100000;
#10
instruction = 000101001;
#10
instruction = 010100010;
#10
instruction = 111100000;
#10
instruction = 111100000;
#10
instruction = 000000000;
#10
$finish;
end
endmodule