arrays and functions

M

Moritz Beller

Guest
Hello,

I want to construct an array consisting of 4 rows with 8 columns,
every single cell reprensenting a byte of 8 bits, given by

reg [7:0] expandedkey [8:0][3:0];
reg [7:0] cipherstate [8:0][3:0];

(1) Is this syntheziable Verilog code? Are the rows/columns in order?
(2) Is

function [7:0] AddRoundKey [8:0][3:0];
input [7:0] value1 [8:0][3:0];

AddRoundKey = value1 ^ cipherstate;
endfunction

a valid function then, making cipherstate = AddRoundKey(expandedkey) a
correct assignment?

best regards
Moritz Beller
--
web http://www.4momo.de
mail momo dot beller at t-online dot de
gpgkey http://gpg.notlong.com
 
On Mon, 1 Aug 2005 14:13:58 +0200, Moritz Beller
<momo.beller.No-Spam@t-online.de> wrote:

Hello,

I want to construct an array consisting of 4 rows with 8 columns,
every single cell reprensenting a byte of 8 bits, given by

reg [7:0] expandedkey [8:0][3:0];
reg [7:0] cipherstate [8:0][3:0];
I suspect you mean [7:0] instead of [8:0], but that's a detail...

(1) Is this syntheziable Verilog code?
Yes, if your simulator and synthesis tool is Verilog-2001 compliant.

(1a) Are the rows/columns in order?
Only if you loop through them in order. The right-hand-side
subscripts effectively index a bunch of independent objects.
You cannot, for example, do...

always @...
cipherstate [4] = expandedkey[3];

because that's trying to copy an array on to an array.
You *can* manipulate complete array elements...

cipherstate[4][2] = expandexkey[3][1] ^ expandedkey[4][2];

and even index or part-select their bits:

cipherstate[4][2][3:0] = { 3'b000, expandedkey[4][2][0] };

(2) Is

function [7:0] AddRoundKey [8:0][3:0];
input [7:0] value1 [8:0][3:0];

AddRoundKey = value1 ^ cipherstate;
endfunction

a valid function then, making cipherstate = AddRoundKey(expandedkey) a
correct assignment?
No. XOR works only between vectors. value1[4][2] is a vector
(eight bits long); otherwise, you just have a collection of
independent vectors. You need a pair of nested FOR loops.

Furthermore, you cannot copy or reference complete arrays
as single objects in Verilog-2001. So, even if the XOR
operation were legal, you could never assign *anything*
to the complete result array AddRoundKey.
It's probably easier to manipulate your arrays using tasks.

SystemVerilog lifts many of these restrictions, and adds
useful meaning to multiple dimensions declared before the
array object, but still has no whole-array operators.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:jonathan.bromley@doulos.com
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
On Mon, 01 Aug 2005 13:51:41 +0100
Jonathan Bromley <jonathan.bromley@doulos.com> wrote:

(2) Is

function [7:0] AddRoundKey [8:0][3:0];
input [7:0] value1 [8:0][3:0];

AddRoundKey = value1 ^ cipherstate;
endfunction

a valid function then, making cipherstate = AddRoundKey(expandedkey)
a correct assignment?

No.
OK, thanks a lot. Can a function or a task alter - or at least access -
a reg that is outside its scope (as in the example of my previous mail),
but within the same module?

best regards
Moritz Beller
--
web http://www.4momo.de
mail momo dot beller at t-online dot de
gpgkey http://gpg.notlong.com
 
On Tue, 2 Aug 2005 14:42:17 +0200, Moritz Beller
<momo.beller.No-Spam@t-online.de> wrote:


Can a function or a task alter - or at least access -
a reg that is outside its scope but within the same module?
Absolutely, yes.

In this respect, functions and tasks in a module can be
thought of rather in the same way as methods of a class.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:jonathan.bromley@doulos.com
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 

Welcome to EDABoard.com

Sponsor

Back
Top