Verilog Code of ROM With Testbenches
Verilog Code of ROM With Testbenches
begin
case (addr1)
3'b000 : dout1_next = loc0 ;
3'b001 : dout1_next = loc1 ;
3'b010 : dout1_next = loc2 ;
3'b011 : dout1_next = loc3 ;
3'b100 : dout1_next = loc4 ;
3'b101 : dout1_next = loc5 ;
3'b110 : dout1_next = loc6 ;
3'b111 : dout1_next = loc7 ;
default : dout1_next = loc0 ;
endcase
case(addr2)
3'b000 : dout2_next = loc0 ;
3'b001 : dout2_next = loc1 ;
3'b010 : dout2_next = loc2 ;
3'b011 : dout2_next = loc3 ;
3'b100 : dout2_next = loc4 ;
3'b101 : dout2_next = loc5 ;
3'b110 : dout2_next = loc6 ;
3'b111 : dout2_next = loc7 ;
default : dout2_next = loc0 ;
endcase
end
Specification:
The data table is arranged as eight locations of size, 64 bits. While reading the
ROM, only one byte is retrieved at a time. Since it is read as 64 × 8 bits, i.e., 2 × 8
bits, we need 6 bits of address. It is organized as 8 × 64 bits, and can be read
byte-wise.
always @ (mem_data)
begin
byte_data [0] = mem_data [63:56] ;
byte_data [1] = mem_data [55:48] ;
byte_data [2] = mem_data [47:40] ;
byte_data [3] = mem_data [39:32] ;
byte_data [4] = mem_data [31:24] ;
byte_data [5] = mem_data [23:16] ;
byte_data [6] = mem_data [15:8] ;
byte_data [7] = mem_data [7:0] ;
end
assign d_next = byte_data [a[2:0]] ;
always @ (posedge clk)
d <= d_next ; // Register byte data.
endmodule
initial
begin
clk = 1'b0 ;
#7 a = 0 ;
for (count = 0; count < 64; count = count+1)
#10 a = count ; // Apply new address
#200
$stop ;
end
always
#`clkperiodby2 clk <= ~clk ; // Generate 100 MHz clock.
endmodule