quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bullet_green_ball.gif Memory Modeling

To help modeling of memory, Verilog provides support for two dimensions arrays. Behavioral models of memories are modeled by declaring an array of register variables; any word in the array may be accessed using an index into the array. A temporary variable is required to access a discrete bit within the array.

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Syntax

reg [wordsize:0] array_name [0:arraysize]

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Examples
   

space.gif

  ../images/main/bullet_star_pink.gif Declaration

reg [7:0] my_memory [0:255];

   

space.gif

Here [7:0] is the memory width and [0:255] is the memory depth with the following parameters:

  • Width : 8 bits, little endian
  • Depth : 256, address 0 corresponds to location 0 in the array.
   

space.gif

  ../images/main/bullet_star_pink.gif Storing Values

my_memory[address] = data_in;

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Reading Values

data_out = my_memory[address];

   

space.gif

  ../images/main/bullet_star_pink.gif Bit Read

Sometimes there may be need to read just one bit. Unfortunately Verilog does not allow to read or write only one bit: the workaround for such a problem is as shown below.

   

space.gif

data_out = my_memory[address];

   

space.gif

data_out_it_0 = data_out[0];

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Initializing Memories

A memory array may be initialized by reading memory pattern file from disk and storing it on the memory array. To do this, we use system tasks $readmemb and $readmemh. $readmemb is used for binary representation of memory content and $readmemh for hex representation.

   

space.gif

  ../images/main/bullet_star_pink.gif Syntax

$readmemh("file_name",mem_array,start_addr,stop_addr);

Note : start_addr and stop_addr are optional.

   

space.gif

  ../images/main/bullet_star_pink.gif Example - Simple memory
   

space.gif


 1 module  memory();
 2 reg [7:0] my_memory [0:255];
 3 
 4 initial begin
 5  $readmemh("memory.list", my_memory);
 6 end
 7 endmodule
You could download file memory.v here
   

space.gif

  ../images/main/bullet_star_pink.gif Example - Memory.list file
   

space.gif


 1 //Comments are allowed 
 2 1100_1100   // This is first address i.e 8'h00
 3 1010_1010   // This is second address i.e 8'h01
 4 @ 55        // Jump to new address 8'h55
 5 0101_1010   // This is address 8'h55
 6 0110_1001   // This is address 8'h56
You could download file memory.list here
   

space.gif

$readmemh system task can also be used for reading testbench vectors. I will cover this in detail in the test bench section ... when I find time.

   

space.gif

Refer to the examples section for more details on different types of memories.

   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com