Question: testbench.sv module testCPU; reg clk , reset; wire [ 7 : 0 ] DMem; int errors = 0 ; reg [ 7 : 0 ]
testbench.sv
module testCPU;
reg clk reset;
wire : DMem;
int errors ;
reg : DMemexpected:;
integer i j;
topCPU CPU
DrddataDMem
clkclk
resetreset
;
always # clk ~clk;
initial begin
$dumpfiledumpvcd;
$dumpvars;
$readmembDmemexpected.tv DMemexpected, ;
i ;
j ;
clk b;
reset b;
$displayReset;
# reset ;
end
always @negedge clk begin
if reset begin
if i && i begin
if DMem DMemexpectedj begin
$display# ERROR: id jd DMemd DMemexpectedd i j DMem, DMemexpectedj;
errors errors ;
end else begin
$display# CORRECT: id jd DMemd DMemexpectedd i j DMem, DMemexpectedj;
end
j j ;
end
if i begin
$display# of Errors d errors;
$finish;
end
i i ;
end
end
endmodule
Dmemexpected.tv
design.sv
include "controller.sv
include "registerfile.sv
include "ALU.sv
include "memories.sv
include "parameterizedmux.sv
module topCPU
input clk
input reset,
output : Drddata
;
wire RFWwe DMEMwe;
wire : ALUcontrol, MuxM MuxM;
wire : instruction;
wire : aluresult, A B DMem;
wire : address;
Instantiate the controller
controller ctrl
opcodeinstruction: Opcode bits
RFWweRFWwe
DMEMweDMEMwe
ALUcontrolALUcontrol
MuxMMuxM
MuxMMuxM
;
Instantiate the ALU
ALU alu
Resultaluresult
ALUcontrolALUcontrol
AA Operand A
BB Operand B
;
Instantiate the register file
registerfile rf
clkclk
resetreset
Raddrinstruction: Source register
Raddrinstruction: Source register
Waddrinstruction: Destination register
Wdataaluresult Data to write
WweRFWwe Write enable
RdataA Output to ALU A
RdataB Output to ALU B
;
Instantiate data memory
dmem memory
clkclk
weDMEMwe
addraddress
wrdataB Data to write comes from register file B
rddataDMem Data read from memory
;
Instruction memory
imem instructionmemory
addraddress: Instruction address
rddatainstruction Instruction output
;
Multiplexer to select data from ALU or memory
Muxx #N mux
inaluresult ALU result
inDMem Data from memory
selMuxM Select signal
outDrddata Output
;
Generate address
assign address instruction:; Use instruction address bits
endmodule
register.sv
module registerfile
input wire clk
input wire reset,
input wire : Raddr,
output reg : Rdata,
input wire : Raddr,
output reg : Rdata,
input wire : Waddr,
input wire : Wdata,
input wire Wwe
;
reg : rf :; registers, each bits wide
Read ports
always @ begin
Rdata rfRaddr;
Rdata rfRaddr;
$display# DEBUG: Reading Rdatad Rdatad Rdata, Rdata;
end
Write port
always @posedge clk or posedge reset begin
if reset begin
integer i;
for i ; i ; i i begin
rfib;
end
$display# DEBUG: Resetting register file.";
end else if Wwe begin
rfWaddr Wdata;
$display# DEBUG: Writing d to rfd Wdata, Waddr;
end
end
endmodule
parameterizedmux.sv
module Muxx #parameter N
input N: in
input N: in
input sel,
output N: out
;
assign out sel in : in; Select between in and in
endmodule
Please help me to all of this code have the correct ouput like this output:Reset
# CORRECT: i j DMem DMemexpected
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
