Answered step by step
Verified Expert Solution
Question
1 Approved Answer
` timescale 1 ns / 1 ps module TestBenchForCache; / / Inputs reg clk; reg reset; reg [ 3 1 : 0 ] read _
timescale ns ps
module TestBenchForCache;
Inputs
reg clk;
reg reset;
reg : readdata;
Outputs
wire : pc;
wire : aluresult;
wire : writedata;
Instantiate the RISCV Single Cycle Processor
RiscVSingleCycle uut
clkclk
resetreset
pcpc
aluresultaluresult
writedatawritedata
readdatareaddata
;
Clock generation
initial begin
clk ;
forever # clk ~clk;
end
Task to display register contents
task displayregisters;
integer i;
begin
$displayRegisters:;
for i ; i ; i i begin
$displayxd: h i uut.registersi;
end
end
endtask
Task to display memory contents
task displaymemory;
integer i;
begin
$displayMemory:;
for i ; i ; i i begin
if uutmemoryih Display nonzero memory locations
$displayAddress d: h i uut.memoryi;
end
end
endtask
Testbench procedure
initial begin
Initialize Inputs
reset ;
readdata h;
Load instructions into instruction memory
ADDI instructions to load values into registers
uut.instructionmemoryb; ADDI x x
uut.instructionmemoryb; ADDI x x
uut.instructionmemoryb; ADDI x x
uut.instructionmemoryb; ADDI x x
Memory read hit
uut.instructionmemoryb; LW xx Should hit
Memory read miss
uut.instructionmemoryb; LW xx Should miss
Memory write hit
uut.instructionmemoryb; SW xx Should hit
Memory write miss
uut.instructionmemoryb; SW xx Should miss
JAL instruction to end the test and loop indefinitely
uut.instructionmemoryb; JAL x
Initialize memory with values for hit and miss scenarios
Memory hits
uut.memoryh; Address
uut.memoryhabcdef; Address
Memory misses will access uninitialized memory addresses
Release reset
# reset ;
Run simulation for a sufficient time to observe behavior
# displayregisters;
# displaymemory;
Run simulation for a sufficient time to observe behavior
# displayregisters;
# displaymemory;
# $finish;
end
Monitor the outputs
initial begin
$monitorTime: t PC: d ALU Result: d Write Data: d
$time, pc aluresult, writedata;
end
VCD file generation
initial begin
$dumpfileTestBenchForCachevcd; Specify the name of the VCD file
$dumpvars TestBenchForCache; Dump all variables in this module
end
endmodule WHY THIS CODE ALURESULT XXXXX HOW I CAN EDIT?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started