Namal University, Mianwali: Department of Computer Science
Namal University, Mianwali: Department of Computer Science
Lab -6
Marks Obtained
1|Page
Spring 2025 CA Lab-6
Document History
Rev. Date Comment Author
1.0 24/02/2025 Initial draft Engr. Majid Ali
Instructions
Objectives
To design and implement instruction and data memory units in Verilog and
verify their functionality through simulation.
Learning Outcomes
Introduction
2|Page
Spring 2025 CA Lab-6
In modern computer architecture, memory units play a critical role in storing and managing
both program instructions and data required for processing. This lab focuses on designing two
fundamental memory units in Verilog: The Instruction Memory and Data Memory.
Instruction Memory stores all the instructions according to the instruction format. Each
instruction is stored in 32-bit format. The instruction address is also 32-bit wide. RISC-V
deals with everything in byte addresses. The difference between two successive instruction
addresses in 4. Therefore, 4 is added along with pc to fetch next instruction. The layout of
instruction memory is displayed in Fig. 1.
The Data Memory on the other hand, is a read-write memory that stores variable data
manipulated during program execution. It allows for both storage and retrieval operations,
essential for tasks such as storing intermediate results and processing data
Word-Addressable Memory:
lw t1, 5(s0)
lw <rd>, <offset>(<base register>)
Address calculation:
add offset (5) to the base address (s0)
address = (s0 + 5)
Destination register (rd):
t1 holds the value at address (s0 + 5)
RISC-V uses byte-addressable memory (i.e. byte has a unique address), so each 32-bit word
uses 4-byte addresses.
32-bit operands in memory occupies 4 bytes. Some processor uses one unique address for
each 32-bit words. MIPS processor is one such example. Everything instruction or data word
has a unique address – it is “word addressable” processor. RISC-V uses byte-addressable to
access memory, where EVERY BYTE has a unique address.
Byte-addressable Memory:
Each data byte has a unique address Load/store words or single bytes: load byte (lb) and store
byte (sb) 32-bit word = 4 bytes, so word address increments by 4.
The address of a memory word must now be multiplied by 4.
For example,
the address of memory word 2 is 2 × 4 = 8
the address of memory word 10 is 10 × 4 = 40 (0x28)
RISC-V is byte-addressed, not word-addressed
4|Page
Spring 2025 CA Lab-6
Therefore, in RISC-V, every 32-bit occupies four unique addresses. Since all RISC-V
instructions are 32-bit, addresses of the instruction memory are all aligned to an increment of
4.
Lab Task 1:
Design Instruction Memory Unit for RISC-V Datapath with 32-bit address.
module dataMem_TB;
module dataMem( clk , rst , mwrite , mread ,
address , wdata , memout ); reg clk , rst , mwrite , mread;
input clk , rst , mwrite , mread; reg [31:0] address , wdata;
input [31:0] address , wdata; wire [31:0] memout;
output [31:0] memout;
dataMem
reg [31:0] Dmem[63:0]; uut( .clk(clk) , .rst(rst) , .mwrite(mwrite
) , .mread(mread) , .address(address) ,
integer a; .wdata(wdata) , .memout(memout) );
5|Page
Spring 2025 CA Lab-6
end mread = 0;
end #20;
else if (mwrite)
begin rst = 1'b0;
Dmem[address]=wdata; #20;
end
end address = 32'd1;
wdata = 32'h000C;
assign memout= mread ? Dmem[address] : mwrite = 1'b1;
32'h0000; mread = 1'b0;
#20;
endmodule
mwrite = 1'b0;
#20;
address = 32'd1;
mread = 1'b1;
#20;
mread = 1'b0;
#20;
$stop;
end
endmodule
Waveform:
6|Page
Spring 2025 CA Lab-6
Lab Task 2:
Design of a Single-Port Data Memory Unit for a RISC-V Datapath with 32-Bit Addressing,
Supporting Read and Write Functionality.
Waveform:
Conclusion:
7|Page
Spring 2025 CA Lab-6
Marks
Domain Criteria Excellent (10) Good (8-9) Satisfactory (6-7) Improvement (4-5)
Obtained
RISC-V
Designed an efficient Implemented the Designed a basic Incomplete or
Psychomotor Datapath in
RISC-V datapath with RISC-V datapath datapath with some incorrect design with
(P3) HDL
correct functionality with minor errors issues major errors
(CLO-1)
8|Page