Lec10 Slides Memories
Lec10 Slides Memories
Memories in Verilog
Introduction
Multidimensional Array
Memories
Arrays
An array is
list of items
all of same type
indexed by a number.
Arrays
reg [31:0] x[127:0]; // 128-element array of 32-bit wide reg
wire[15:0] y[ 7:0], z[7:0]; //2 arrays of 16-bit wide wires indexed from 7
reg [ 7:0] mema [255:0]; // 256-entry memory mema of 8-bit registers
reg arrayb [ 7:0][255:0]; // two-dimensional array of one bit register
reg [7:0] arrayc [3:0][1:0]; // two-dimensional array of 8-bit register
8 data
module rom(address,data);
input [3:0] address;
output [7:0] data;
endmodule
Setting up ROM data
reg [7:0] mem [0:15] = '{8'h48,8'h31,8'h43, 8'h35,
8'h2B, 8'h39, 8'h3D, 8'h25, 8'h30, 8'h37, 8'h4F,
8'h33, 8'h28, 8'h3D, 8'h3A, 8'h3E};
Reading out selected data item
assign data = mem[address];
Complete Code of the ROM
module rom(address,data);
input [3:0] address;
output [7:0] data;
reg [7:0] mem [0:15] = '{8'h48,8'h31,8'h43, 8'h35,
8'h2B, 8'h39, 8'h3D, 8'h25, 8'h30, 8'h37, 8'h4F,
8'h33, 8'h28, 8'h3D, 8'h3A, 8'h3E};
As address is given, 7 25