The definition and initialization of the Tilde Array

Source: Internet
Author: User

The memory model here refers to the memory behavior model. The two-dimensional array is provided in OpenGL to help us establish the memory behavior model. Specifically, the memory can be declared as an array of Reg type, and any unit in this array can be accessed through a subscript. The definition of such an array is as follows:

Reg [wordsize: 0] array_name [0: arraysize];

For example:

Reg [] my_memory [];

[] Indicates the memory width, and [] indicates the memory depth (that is, the number of storage units). The width is 8 bits and the depth is 256. Address 0 corresponds to the 0 storage unit in the array.

If you want to store a value in a cell, you can do this:

My_memory [address] = data_in;

If you want to read the value from a unit, you can do this:

Data_out = my_memory [address];

However, if you only need to read one or more digits, you need to worry a little bit, because you are not allowed to read/write a single digit in OpenGL. At this time, you need to use a variable to convert it: (Wolf comment: cainiao easy to make mistakes, note !)

For example:

Data_out = my_memory [address];

Data_out_it_0 = data_out [0];

Here, we first read the data from a unit and then extract the value of a certain bit of the data.

Initialize memory

There are multiple methods to initialize the memory. Here we will introduce how to use $ readmemb and $ readmemh system tasks to fill in the data stored in the file into the memory unit. $ Readmemb is similar to $ readmemh, except that $ readmemb is used for binary representation of memory, while $ readmemh is used for hexadecimal representation of memory content. Here we will introduce $ readmemh system tasks.

Syntax

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

Note:

File_name is the text file name containing data, mem_array is the name of the memory unit array to be initialized, and start_addr and stop_addr are optional, indicating the start address and end address of the unit to be initialized.

The following is a simple example:

Module memory ();

Reg [] my_memory [];

 

Initial begin

$ Readmemh ("memory. list", my_memory );

End

Endmodule

The memory file memory. List is used to initialize the my_memory array.

The following is an example of a memory file.

// Comments are allowed !)

CC // This is first address I. e 8' H00

AA // This is second address I. e 8 'h01

@ 55 // jump to new address 8 'h55

5A // This is address 8 'h55

69 // This is address 8 'h56

 

Pay attention to the following points for memory files:

A. annotation mark // allowed in the memory file;

B. Use the @ symbol to jump to the new target address. If the @ symbol is not used, the address increases sequentially.

 

This system task has the following common usage:

1. Initialize all array units in sequence;

In this case, you can use the @ symbol to indicate the address, or you can only store the data to be stored in each row without using it.

In this way, data is stored sequentially by address, starting from 0.

 

2. Only initialize partial array units;

In this case, you can use the @ symbol to indicate the next address to be initialized, and then initialize the address unit. Example

For example, only 8 'h00, 8' h01, 8' h55, and 8' h564 memory address units are initialized for the following memory files.

// Comments are allowed

CC // This is first address I. e 8' H00

AA // This is second address I. e 8 'h01

@ 55 // jump to new address 8 'h55

5A // This is address 8 'h55

69 // This is address 8 'h56

 

3. Only initialize some units in the address range of the array.

You can also use the start_addr and stop_addr options of the $ readmemh task to specify the initialization range.

For example, you can initialize only the five units from 100 to 104:

The memory file memory. List is defined:

CC

AA

55

5A

 

69

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.