Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Integer arithmetic

Reply
Thread Tools

Integer arithmetic

 
 
nfirtaps
Guest
Posts: n/a
 
      12-01-2006
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;

 
Reply With Quote
 
 
 
 
KJ
Guest
Posts: n/a
 
      12-02-2006

"nfirtaps" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Arithmetic conversions and integer constants Spiros Bousbouras C Programming 6 01-14-2009 04:30 PM
Arbitrary precision integer arithmetic: ceiling? Alasdair Python 15 03-09-2008 12:09 PM
integer promotion and arithmetic conversion sarathy C Programming 6 08-24-2006 03:03 AM
Arithmetic/Comparison between different integer types Frederick Gotham C++ 2 07-07-2006 06:48 PM
Usual Arithmetic Conversions-arithmetic expressions joshc C Programming 5 03-31-2005 02:23 AM



Advertisments