Registers and Banks don't need an enable, should be ignored using MUXes
This commit is contained in:
@@ -259,43 +259,32 @@ module comparator_tb();
|
|||||||
endmodule
|
endmodule
|
||||||
|
|
||||||
module decoder (
|
module decoder (
|
||||||
input wire en,
|
|
||||||
input wire [1:0] index,
|
input wire [1:0] index,
|
||||||
output reg [3:0] regOut);
|
output reg [3:0] regOut);
|
||||||
|
|
||||||
always @(en, index)begin
|
always @ (index)
|
||||||
if(en == 0)begin
|
case(index)
|
||||||
case(index)
|
2'b00: regOut <= 4'b1110;
|
||||||
2'b00: regOut <= 4'b1110;
|
2'b01: regOut <= 4'b1101;
|
||||||
2'b01: regOut <= 4'b1101;
|
2'b10: regOut <= 4'b1011;
|
||||||
2'b10: regOut <= 4'b1011;
|
2'b11: regOut <= 4'b0111;
|
||||||
2'b11: regOut <= 4'b0111;
|
default: regOut <= 4'b1111;
|
||||||
default: regOut <= 4'b1111;
|
endcase
|
||||||
endcase
|
|
||||||
end
|
|
||||||
else begin
|
|
||||||
regOut <= 4'b1111;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
endmodule
|
endmodule
|
||||||
|
|
||||||
//testbench
|
//testbench
|
||||||
module decoder_tb();
|
module decoder_tb();
|
||||||
reg enable;
|
|
||||||
reg [1:0] indexIn;
|
reg [1:0] indexIn;
|
||||||
wire [3:0] regOut;
|
wire [3:0] regOut;
|
||||||
|
|
||||||
decoder dec0(
|
decoder dec0(
|
||||||
.en(enable),
|
|
||||||
.index(indexIn),
|
.index(indexIn),
|
||||||
.regOut(regOut));
|
.regOut(regOut)
|
||||||
|
);
|
||||||
|
|
||||||
initial begin
|
initial begin
|
||||||
enable = 0;
|
|
||||||
indexIn = 2'b00;
|
indexIn = 2'b00;
|
||||||
#5
|
#5
|
||||||
enable = 1;
|
|
||||||
#5
|
|
||||||
indexIn = 2'b01;
|
indexIn = 2'b01;
|
||||||
#5
|
#5
|
||||||
indexIn = 2'b10;
|
indexIn = 2'b10;
|
||||||
|
|||||||
@@ -2,20 +2,21 @@
|
|||||||
|
|
||||||
module CPU9bits(
|
module CPU9bits(
|
||||||
input wire reset, clk,
|
input wire reset, clk,
|
||||||
|
output reg [8:0] result,
|
||||||
output wire done
|
output wire done
|
||||||
);
|
);
|
||||||
|
|
||||||
wire [8:0] instr, op1, op0, FUAddr,FUJB,PCout,JBRes,FUJ,FUB,AddiOut,AluOut,RFIn, loadMux, dataMemOut, linkData, SE1N, SE2N, SE3N, bankData, bankOP,jumpNeg;
|
wire [8:0] instr, op1, op0, FUAddr,FUJB,PCout,JBRes,FUJ,FUB,AddiOut,AluOut,RFIn, loadMux, dataMemOut, linkData, SE1N, SE2N, SE3N, bankData, bankOP,jumpNeg;
|
||||||
wire [2:0] FU;
|
|
||||||
wire [3:0] aluOp;
|
wire [3:0] aluOp;
|
||||||
|
wire [2:0] FU;
|
||||||
wire [1:0] bankS;
|
wire [1:0] bankS;
|
||||||
wire addiS, RegEn, loadS, fetchBranch, halt, cout0, cout1, link, js, dataMemEn;
|
wire addiS, RegEn, loadS, fetchBranch, halt, cout0, cout1, link, js, dataMemEn;
|
||||||
|
|
||||||
instructionMemory iM(
|
instructionMemory iM(
|
||||||
.address(PCout),
|
.address(PCout),
|
||||||
.readData(instr)
|
.readData(instr)
|
||||||
);
|
);
|
||||||
|
|
||||||
dataMemory dM(
|
dataMemory dM(
|
||||||
.clk(clk),
|
.clk(clk),
|
||||||
.writeEnable(dataMemEn),
|
.writeEnable(dataMemEn),
|
||||||
@@ -23,11 +24,10 @@ module CPU9bits(
|
|||||||
.address(op1),
|
.address(op1),
|
||||||
.readData(dataMemOut)
|
.readData(dataMemOut)
|
||||||
);
|
);
|
||||||
|
|
||||||
RegFile RF(
|
RegFile RF(
|
||||||
.clk(clk),
|
.clk(clk),
|
||||||
.reset(reset),
|
.reset(reset),
|
||||||
.enable(RegEn),
|
|
||||||
.write_index(instr[4:3]),
|
.write_index(instr[4:3]),
|
||||||
.op0_idx(instr[4:3]),
|
.op0_idx(instr[4:3]),
|
||||||
.op1_idx(instr[2:1]),
|
.op1_idx(instr[2:1]),
|
||||||
@@ -35,11 +35,10 @@ module CPU9bits(
|
|||||||
.op0(op0),
|
.op0(op0),
|
||||||
.op1(op1)
|
.op1(op1)
|
||||||
);
|
);
|
||||||
|
|
||||||
RegFile Bank(
|
RegFile Bank(
|
||||||
.clk(clk),
|
.clk(clk),
|
||||||
.reset(reset),
|
.reset(reset),
|
||||||
.enable(bankS[1]),
|
|
||||||
.write_index(instr[2:1]),
|
.write_index(instr[2:1]),
|
||||||
.op0_idx(instr[2:1]),
|
.op0_idx(instr[2:1]),
|
||||||
.op1_idx(2'b00),//Doesn't matter
|
.op1_idx(2'b00),//Doesn't matter
|
||||||
@@ -47,7 +46,7 @@ module CPU9bits(
|
|||||||
.op0(bankOP),
|
.op0(bankOP),
|
||||||
.op1()
|
.op1()
|
||||||
);
|
);
|
||||||
|
|
||||||
FetchUnit FetchU(
|
FetchUnit FetchU(
|
||||||
.clk(clk),
|
.clk(clk),
|
||||||
.reset(reset),
|
.reset(reset),
|
||||||
@@ -55,14 +54,14 @@ module CPU9bits(
|
|||||||
.AddrIn(FUAddr),
|
.AddrIn(FUAddr),
|
||||||
.AddrOut(PCout)
|
.AddrOut(PCout)
|
||||||
);
|
);
|
||||||
|
|
||||||
ALU alu(
|
ALU alu(
|
||||||
.opcode(aluOp),
|
.opcode(aluOp),
|
||||||
.operand0(op0),
|
.operand0(op0),
|
||||||
.operand1(op1),
|
.operand1(op1),
|
||||||
.result(AluOut)
|
.result(AluOut)
|
||||||
);
|
);
|
||||||
|
|
||||||
ControlUnit CU(
|
ControlUnit CU(
|
||||||
.instIn(instr[8:5]),
|
.instIn(instr[8:5]),
|
||||||
.functBit(instr[0]),
|
.functBit(instr[0]),
|
||||||
@@ -77,10 +76,10 @@ module CPU9bits(
|
|||||||
.bank(bankS),
|
.bank(bankS),
|
||||||
.js(js)
|
.js(js)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
//-----------------------Fetch Unit Stuff
|
//-----------------------Fetch Unit Stuff
|
||||||
|
|
||||||
add_9bit JBAdder(
|
add_9bit JBAdder(
|
||||||
.A(PCout),
|
.A(PCout),
|
||||||
.B(JBRes),
|
.B(JBRes),
|
||||||
@@ -88,47 +87,47 @@ module CPU9bits(
|
|||||||
.Sum(FUJB),
|
.Sum(FUJB),
|
||||||
.Cout(cout0)
|
.Cout(cout0)
|
||||||
);
|
);
|
||||||
|
|
||||||
mux_2_1 mux0(
|
mux_2_1 mux0(
|
||||||
.A(op0),
|
.A(op0),
|
||||||
.B(FUJB),
|
.B(FUJB),
|
||||||
.out(FUAddr),
|
.out(FUAddr),
|
||||||
.switch(FU[1])
|
.switch(FU[1])
|
||||||
);
|
);
|
||||||
|
|
||||||
twos_compliment_9bit two_comp0(
|
twos_compliment_9bit two_comp0(
|
||||||
.A({4'b0000,instr[4:0]}),
|
.A({4'b0000,instr[4:0]}),
|
||||||
.B(jumpNeg)
|
.B(jumpNeg)
|
||||||
);
|
);
|
||||||
|
|
||||||
mux_2_1 mux1(
|
mux_2_1 mux1(
|
||||||
.A({4'b0000,instr[4:0]}),
|
.A({4'b0000,instr[4:0]}),
|
||||||
.B(jumpNeg),
|
.B(jumpNeg),
|
||||||
.out(SE2N),
|
.out(SE2N),
|
||||||
.switch(js)
|
.switch(js)
|
||||||
);
|
);
|
||||||
|
|
||||||
mux_2_1 mux2(
|
mux_2_1 mux2(
|
||||||
.A(SE2N), //Jump -- Change with signer module!
|
.A(SE2N), //Jump -- Change with signer module!
|
||||||
.B(SE1N),//Branch -- Change with signer module!
|
.B(SE1N),//Branch -- Change with signer module!
|
||||||
.out(JBRes),
|
.out(JBRes),
|
||||||
.switch(FU[2])
|
.switch(FU[2])
|
||||||
);
|
);
|
||||||
|
|
||||||
sign_extend_3bit SE1(
|
sign_extend_3bit SE1(
|
||||||
.A(instr[2:0]),
|
.A(instr[2:0]),
|
||||||
.B(SE1N)
|
.B(SE1N)
|
||||||
);
|
);
|
||||||
|
|
||||||
bit1_mux_2_1 BranMux( // BEQ MUX
|
bit1_mux_2_1 BranMux( // BEQ MUX
|
||||||
.A(FU[0]),
|
.A(FU[0]),
|
||||||
.B(AluOut[0]),
|
.B(AluOut[0]),
|
||||||
.out(fetchBranch),
|
.out(fetchBranch),
|
||||||
.switch(FU[2]) // FU[2] only goes high when BEQ
|
.switch(FU[2]) // FU[2] only goes high when BEQ
|
||||||
);
|
);
|
||||||
|
|
||||||
///--------------------------Addi Stuff
|
///--------------------------Addi Stuff
|
||||||
|
|
||||||
add_9bit Addier(
|
add_9bit Addier(
|
||||||
.A(SE3N), // Change with signer module!
|
.A(SE3N), // Change with signer module!
|
||||||
.B(op0),
|
.B(op0),
|
||||||
@@ -136,19 +135,19 @@ module CPU9bits(
|
|||||||
.Sum(AddiOut),
|
.Sum(AddiOut),
|
||||||
.Cout(cout1)
|
.Cout(cout1)
|
||||||
);
|
);
|
||||||
|
|
||||||
sign_extend_3bit SE3(
|
sign_extend_3bit SE3(
|
||||||
.A(instr[2:0]),
|
.A(instr[2:0]),
|
||||||
.B(SE3N)
|
.B(SE3N)
|
||||||
);
|
);
|
||||||
|
|
||||||
mux_2_1 mux3(
|
mux_2_1 mux3(
|
||||||
.A(AluOut),
|
.A(AluOut),
|
||||||
.B(AddiOut),
|
.B(AddiOut),
|
||||||
.out(loadMux),
|
.out(loadMux),
|
||||||
.switch(addiS)
|
.switch(addiS)
|
||||||
);
|
);
|
||||||
|
|
||||||
///--------------------------Mem stuff
|
///--------------------------Mem stuff
|
||||||
|
|
||||||
mux_2_1 mux4(
|
mux_2_1 mux4(
|
||||||
@@ -157,26 +156,51 @@ module CPU9bits(
|
|||||||
.out(bankData),
|
.out(bankData),
|
||||||
.switch(loadS)
|
.switch(loadS)
|
||||||
);
|
);
|
||||||
|
|
||||||
///--------------------------Bank stuff
|
///--------------------------Bank stuff
|
||||||
|
|
||||||
mux_2_1 mux5(
|
mux_2_1 mux5(
|
||||||
.A(bankData),
|
.A(bankData),
|
||||||
.B(bankOP),
|
.B(bankOP),
|
||||||
.out(RFIn),
|
.out(RFIn),
|
||||||
.switch(bankS[0])
|
.switch(bankS[0])
|
||||||
);
|
);
|
||||||
|
|
||||||
///--------------------------Link Stuff
|
///--------------------------Link Stuff
|
||||||
|
|
||||||
mux_2_1 mux6(
|
mux_2_1 mux6(
|
||||||
.A(loadMux),
|
.A(loadMux),
|
||||||
.B(PCout),
|
.B(PCout),
|
||||||
.out(linkData),
|
.out(linkData),
|
||||||
.switch(link)
|
.switch(link)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
always @ (instr, op0, op1)
|
||||||
|
begin
|
||||||
|
case(instr[8:5])
|
||||||
|
4'b0001: // Load Byte
|
||||||
|
result <= dataMemOut;
|
||||||
|
4'b0011: // Link
|
||||||
|
result <= linkData;
|
||||||
|
4'b0101: // Add/Subtract
|
||||||
|
result <= AluOut;
|
||||||
|
4'b0110: // Add Immediate
|
||||||
|
result <= AddiOut;
|
||||||
|
4'b0111: // Set if Less Than
|
||||||
|
result <= AluOut;
|
||||||
|
4'b1010: // Bank Load/Bank Store
|
||||||
|
result <= RFIn;
|
||||||
|
4'b1101: // NOR
|
||||||
|
result <= AluOut;
|
||||||
|
4'b1110: // OR/AND
|
||||||
|
result <= AluOut;
|
||||||
|
4'b1111: // Shift Right Logical/Shift Left Logical
|
||||||
|
result <= AluOut;
|
||||||
|
default:
|
||||||
|
result <= 9'bXXXXXXXXX;
|
||||||
|
endcase
|
||||||
|
end
|
||||||
|
|
||||||
endmodule
|
endmodule
|
||||||
|
|
||||||
module CPU9bits_tb();
|
module CPU9bits_tb();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
`timescale 1ns / 1ps
|
`timescale 1ns / 1ps
|
||||||
|
|
||||||
module RegFile(input wire clk, reset, enable,
|
module RegFile(input wire clk, reset,
|
||||||
input wire [1:0] write_index, op0_idx, op1_idx,
|
input wire [1:0] write_index, op0_idx, op1_idx,
|
||||||
input wire [8:0] write_data,
|
input wire [8:0] write_data,
|
||||||
output wire [8:0] op0, op1);
|
output wire [8:0] op0, op1);
|
||||||
@@ -11,7 +11,6 @@ module RegFile(input wire clk, reset, enable,
|
|||||||
// To select a register En input must be 2'b00
|
// To select a register En input must be 2'b00
|
||||||
|
|
||||||
decoder d0(
|
decoder d0(
|
||||||
.en(enable),
|
|
||||||
.index(write_index),
|
.index(write_index),
|
||||||
.regOut(decOut)
|
.regOut(decOut)
|
||||||
);
|
);
|
||||||
@@ -67,7 +66,7 @@ endmodule
|
|||||||
module regFile_tb();
|
module regFile_tb();
|
||||||
reg [8:0] write_d;
|
reg [8:0] write_d;
|
||||||
reg [1:0] w_idx, op0_idx, op1_idx;
|
reg [1:0] w_idx, op0_idx, op1_idx;
|
||||||
reg reset,clk, enable;
|
reg reset,clk;
|
||||||
wire [8:0] op0,op1;
|
wire [8:0] op0,op1;
|
||||||
|
|
||||||
initial begin
|
initial begin
|
||||||
@@ -79,7 +78,6 @@ module regFile_tb();
|
|||||||
|
|
||||||
RegFile regFile0(
|
RegFile regFile0(
|
||||||
.clk(clk),
|
.clk(clk),
|
||||||
.enable(enable),
|
|
||||||
.reset(reset),
|
.reset(reset),
|
||||||
.write_index(w_idx),
|
.write_index(w_idx),
|
||||||
.op0_idx(op0_idx),
|
.op0_idx(op0_idx),
|
||||||
@@ -94,7 +92,6 @@ module regFile_tb();
|
|||||||
reset = 1;
|
reset = 1;
|
||||||
#5
|
#5
|
||||||
reset = 0;
|
reset = 0;
|
||||||
enable = 1;
|
|
||||||
w_idx = 2'b00;
|
w_idx = 2'b00;
|
||||||
op0_idx = 2'b00;
|
op0_idx = 2'b00;
|
||||||
op1_idx = 2'b00;
|
op1_idx = 2'b00;
|
||||||
|
|||||||
Reference in New Issue
Block a user