Verilog之$sreadmemb

来源:转载

1 Memories 

Memories file format is shown below, the address is specified as @ <address> in hexadecimal.

 @003

00000011

00000100

00000101

00000110

00000111

00001000

00001001

With the above file it can be seen if the memory is large it would become very tedious to work out the address of a specific byte, so it is normally a good idea to use milestones along the memory file, so a larger file may look something like the following:

 @003

00000011

00000100

00000101

@006

00000110

00000111

@008

00001000

00001001

  or if the data is contiguous, omit the address entirely.

 

2 Syntax

$readmemb ("<file_name>", <memory_name>"); 
$readmemb ("<file_name>", <memory_name>, memory_start"); 
$readmemb ("<file_name>", <memory_name>, memory_start, memory_finish");

The memory_start and memory_finish are optional.

 

3 Example

Now that a memory file exists to access it, it has to be initialised for memory reading. 

 1 module testmemory;

2 reg [7:0] memory [9:0];

3 integer index;

4

5 initial

6 begin

7 $readmemb("mem.dat", memory);

8

9 for(index = 0; index < 10; index = index + 1)

10 $display("memory[%d] = %b", index[4:0], memory[index]);

11 end

12 endmodule // testmemory

with the file mem.data as

 1000_0001

1000_0010

0000_0000

0000_0001

0000_0010

0000_0011

0000_0100

0000_0101

0000_0110

0000_0000

 


分享给朋友:
您可能感兴趣的文章:
随机阅读: