Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Integer arithmetic

 
Thread Tools Search this Thread
Old 12-01-2006, 08:02 PM   #1
Default Integer arithmetic


Can you do signend arithmetic with integer type. I am negating it here
and seem to be getting strange results.

subtype POINTER is integer range 0 to 16383;
subtype BYTECOUNT is integer range 0 to 16383;

signal readpointer : POINTER;
signal writepointer : POINTER;
signal diffpointer : BYTECOUNT;

.....

if (writepointer >= readpointer) then
diffpointer <= writepointer - readpointer;
else
diffpointer <= (16383-readpointer)+writepointer;
end if;



nfirtaps
  Reply With Quote
Old 12-02-2006, 02:20 AM   #2
KJ
 
Posts: n/a
Default Re: Integer arithmetic


"nfirtaps" <> wrote in message
news: oups.com...
> Can you do signend arithmetic with integer type. I am negating it here
> and seem to be getting strange results.
>
> subtype POINTER is integer range 0 to 16383;
> subtype BYTECOUNT is integer range 0 to 16383;
>
> signal readpointer : POINTER;
> signal writepointer : POINTER;
> signal diffpointer : BYTECOUNT;
>
> ....
>
> if (writepointer >= readpointer) then
> diffpointer <= writepointer - readpointer;
> else
> diffpointer <= (16383-readpointer)+writepointer;
> end if;
>


Try this...
subtype POINTER is integer range 0 to 16383;
subtype BYTECOUNT is integer range -16383 to 16383;

signal readpointer : POINTER;
signal writepointer : POINTER;
signal diffpointer : BYTECOUNT;
....
diffpointer <= writepointer - readpointer;

KJ


  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump