Question about Assignment of a one-dimensional array to a tw

A

Andres Vazquez

Guest
Hi,

I am trying to convert a Verilog description to a VHDL description for
my project.
There is a Verilog construct of a twodimensional array I do not
understand exactly.
It would be a great help if you could explain it to me.

------------------------------------------------------------------------------------------
Verilog-Code:

parameter COLS=8;
parameter ROWS=256;
parameter ROW_ADDR_BITS=8;
parameter COL_ADDR_BITS=3;

reg[7:0] data_in;
reg[7:0] data[0:COLS*ROWS];
reg[ROW_ADDR_BITS-1 : 0] row_write;
reg[COL_ADDR_BITS-1 :0] last_col[0:ROWS]
--------------------------------------------------------------------------------


What does the following assignment mean? Which of the rows and colomns
of the two dimensional array data
are written with the input data_in? Which function has the '+' ?

--------------------------------------------------------------------------------
data[row_write*COLS + last_col[row_write] ] = data_in;
--------------------------------------------------------------------------------


Thank you very much for your help.

Kind regards


Andrés Lapa
 
vazquez@gdsys.de (Andres Vazquez) wrote in message news:<f011de17.0308250039.3d9e0927@posting.google.com>...
There is a Verilog construct of a twodimensional array I do not
understand exactly.
It would be a great help if you could explain it to me.
Verilog-1995 does not support 2-dimensional arrays. This design appears
to be emulating a 2-dimensional array by using a 1-dimensional array and
appropriate address arithmetic. This is the same kind of address
arithmetic that a compiler does for you to support 2-dimensional arrays.


What does the following assignment mean? Which of the rows and colomns
of the two dimensional array data
are written with the input data_in? Which function has the '+' ?

--------------------------------------------------------------------------------
data[row_write*COLS + last_col[row_write] ] = data_in;
--------------------------------------------------------------------------------
The '+' just does addition. The row address is 'row_write' and the
column address is 'last_col[row_write]'. I don't know why they are
looking up the column address in the array 'last_col', but that is
independent of the 2-dimensional lookup in the array 'data'. To
simplify the example, I will replace 'last_col[row_write]' with
'col_write'. So the expression is

data[row_write*COLS + col_write] = data_in;

This is effectively the same as if data were a 2-dimensional array,
and you used

data[row_write][col_write] = data_in;

The 2-dimensional array is being stored in a 1-dimensional array
by putting the 8 column entries for a row in consecutive elements
of the 1-dimensional array, followed by the 8 column entries for
the next row, and so forth. To access the entry for a particular
row and column, you take the row address and multiply it by 8 (the
number of columns in a row) to get the starting address of that row
in the 1-dimensional array. Then you add the column address to get
the entry for that column.

When you use a 2-dimensional array in a language that supports them,
the compiler does this calculation for you, but it is still doing
the exact same thing.
 

Welcome to EDABoard.com

Sponsor

Back
Top