Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

` timescale 1 ns / 1 ps module TestBenchForCache; / / Inputs reg clk; reg reset; reg [ 3 1 : 0 ] read _

`timescale 1ns /1ps
module TestBenchForCache;
// Inputs
reg clk;
reg reset;
reg [31:0] read_data;
// Outputs
wire [31:0] pc;
wire [31:0] alu_result;
wire [31:0] write_data;
// Instantiate the RISC-V Single Cycle Processor
RiscV_SingleCycle uut (
.clk(clk),
.reset(reset),
.pc(pc),
.alu_result(alu_result),
.write_data(write_data),
.read_data(read_data)
);
// Clock generation
initial begin
clk =0;
forever #5 clk = ~clk;
end
// Task to display register contents
task display_registers;
integer i;
begin
$display("Registers:");
for (i =0; i <32; i = i +1) begin
$display("x%0d: %h", i, uut.registers[i]);
end
end
endtask
// Task to display memory contents
task display_memory;
integer i;
begin
$display("Memory:");
for (i =0; i <1024; i = i +1) begin
if (uut.memory[i]!==32'h00000000)// Display non-zero memory locations
$display("Address %0d: %h", i, uut.memory[i]);
end
end
endtask
// Testbench procedure
initial begin
// Initialize Inputs
reset =1;
read_data =32'h00000000;
// Load instructions into instruction memory
// ADDI instructions to load values into registers
uut.instruction_memory[0]=32'b00000000000100000000000010010011; // ADDI x1, x0,1
uut.instruction_memory[1]=32'b00000000001000000000000100010011; // ADDI x2, x0,2
uut.instruction_memory[2]=32'b00000000001100000000000110010011; // ADDI x3, x0,3
uut.instruction_memory[3]=32'b00000000010000000000001000010011; // ADDI x4, x0,4
// Memory read (hit)
uut.instruction_memory[4]=32'b00000000000100010000001010000011; // LW x5,1(x2)-- Should hit
// Memory read (miss)
uut.instruction_memory[5]=32'b00000000001000010000001100000011; // LW x6,2(x2)-- Should miss
// Memory write (hit)
uut.instruction_memory[6]=32'b00000000000100010000001100100011; // SW x1,2(x2)-- Should hit
// Memory write (miss)
uut.instruction_memory[7]=32'b00000000001100010000001100100011; // SW x3,2(x2)-- Should miss
// JAL instruction to end the test and loop indefinitely
uut.instruction_memory[8]=32'b00000000000000000000000001101111; // JAL x0,0
// Initialize memory with values for hit and miss scenarios
// Memory hits
uut.memory[3]=32'h12345678; // Address 3
uut.memory[4]=32'h9abcdef0; // Address 4
// Memory misses will access uninitialized memory addresses
// Release reset
#10 reset =0;
// Run simulation for a sufficient time to observe behavior
#200 display_registers;
#200 display_memory;
// Run simulation for a sufficient time to observe behavior
#400 display_registers;
#400 display_memory;
#600 $finish;
end
// Monitor the outputs
initial begin
$monitor("Time: %t, PC: %d, ALU Result: %d, Write Data: %d",
$time, pc, alu_result, write_data);
end
// VCD file generation
initial begin
$dumpfile("TestBenchForCache.vcd"); // Specify the name of the VCD file
$dumpvars(0, TestBenchForCache); // Dump all variables in this module
end
endmodule WHY THIS CODE ALU_RESULT XXXXX? HOW I CAN EDIT?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions