Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to access individual bits in registers ?

2,507 views
Skip to first unread message

Daku

unread,
Oct 20, 2009, 10:30:11 AM10/20/09
to
Could some Verilog guru please help ? I am stumped.
I have:
parameter DATA_WIDTH = 24;
parameter MAX = 10;

/* Some memory */
reg [0: DATA_WIDTH - 1] dataArray[0 : MAX - 1];
reg [0: DATA_WIDTH - 1] tmp;

Now in a loop, I want to access individual elements of dataArray, and
then manipulate individual bits in each of these.
A statement like :
tmp = dataArray[i];
Generates errors due to register/wire mismatch.
How do I resolve this issue ?
Any hints, suggestions would be greatly appreciated. Thanks in advance
for your help.

gabor

unread,
Oct 20, 2009, 11:12:38 AM10/20/09
to

What sort of loop? This statement can't just sit there
by itself. If you have it inside an always block it should
work. Can you post the loop code?

Jason Zheng

unread,
Oct 20, 2009, 11:26:23 AM10/20/09
to
On Tue, 20 Oct 2009 07:30:11 -0700 (PDT)
Daku <daku...@gmail.com> wrote:

> A statement like :
> tmp = dataArray[i];
> Generates errors due to register/wire mismatch.

Are you sure the error is really referring to this line? tmp was
declared as reg type and this seems alright to me.

~Zheng

pallav

unread,
Oct 20, 2009, 3:33:33 PM10/20/09
to
On Oct 20, 10:30 am, Daku <dakup...@gmail.com> wrote:

I think it is better to declare registers as reg[DATA_WIDTH-1:0] tmp;
For memories, reg[DATA_WIDTH-1:0] dataArray[0:MAX-1]; Its easier to
think MSB -> LSB in
a register.

As others have stated, seeing the code might help.

Daku

unread,
Oct 20, 2009, 11:09:51 PM10/20/09
to
Well, the source code is below, and after that the compile-time error
message. I am using Icarus Verilog 0.9.1

module queuetest(clock, rd, wr);

input clock;
input rd;
input wr;

parameter MAX = 10;
parameter DATA_WIDTH = 24;

reg [MAX - 1:0] indexArray;
reg [MAX - 1:0] priorityArray;
reg [DATA_WIDTH - 1:0] dataArray[MAX - 1:0];
reg [DATA_WIDTH - 1:0] tmp;
integer i;
integer j;
integer num;
integer head;
integer tail;


initial
begin
num = 0;
head = 0;
tail = 0;

begin
for(i = 0; i < MAX; i = i + 1)
indexArray[i] = 0;
priorityArray[i] = 0;
tmp = DataArray[i];
end
i = 0;
j = 0;
end

always @ (posedge clock)
begin
if(num < MAX)
begin
if(wr && !rd)
begin
sethead(indexArray);
indexArray[head] = 1;
dataArray[head] = 1;
num <= num + 1;
$display("Data enqueued at %g", head);
end
end
else
$display("queue is full");
end

always @ (negedge clock)
begin
if(num > 0)
begin
if(rd && !wr)
begin
settail(indexArray);
indexArray[tail] = 0;
dataArray[tail] = 0;
num <= num - 1;
$display("Data dequeued from %g", tail);
end
end
else
$display("Queue is empty");
end

task sethead;
input [MAX - 1:0] a;
integer lindex;

begin
for(lindex = 0; lindex < MAX; lindex = lindex +1)
if(a[lindex] == 0) head = lindex; disable sethead;
end
endtask

task settail;
input [MAX - 1:0] a;
integer lindex;

begin
for(lindex = 0; lindex < MAX; lindex = lindex + 1)
if(a[lindex] == 1) tail = lindex; disable settail;
end
endtask


endmodule

The error message is:
/root/verilog/queue.vl:31: error: Unable to bind wire/reg/memory
`DataArray[i]' in `queuetb.qtest'
1 error(s) during elaboration.

My basic problem is how do I access individual bits in a register, or
what is a workaround ?

Thanks in abvance for your help.

glen herrmannsfeldt

unread,
Oct 21, 2009, 1:04:30 AM10/21/09
to
Daku <daku...@gmail.com> wrote:
> Well, the source code is below, and after that the compile-time error
> message. I am using Icarus Verilog 0.9.1

> module queuetest(clock, rd, wr);

> input clock;
> input rd;
> input wr;

> parameter MAX = 10;
> parameter DATA_WIDTH = 24;

> reg [MAX - 1:0] indexArray;
> reg [MAX - 1:0] priorityArray;
> reg [DATA_WIDTH - 1:0] dataArray[MAX - 1:0];
> reg [DATA_WIDTH - 1:0] tmp;
(snip)


> The error message is:
> /root/verilog/queue.vl:31: error: Unable to bind wire/reg/memory
> `DataArray[i]' in `queuetb.qtest'
> 1 error(s) during elaboration.

> My basic problem is how do I access individual bits in a register, or
> what is a workaround ?

I am not sure it completely answers your question, but don't
access (set) individual bits. Instead make indexArray and
priorityArray one bit wide memories.

You should read/write whole words of dataArray, which I thought
was what you were doing.

You will find verilog much easier if you think like hardware
instead of like software.

-- glen

sh...@cadence.com

unread,
Oct 21, 2009, 1:29:34 AM10/21/09
to
The identifier DataArray is not the same as dataArray. Names are case-
sensitive in Verilog.
0 new messages