Integer arithmetic

Discussion in 'VHDL' started by nfirtaps, Dec 1, 2006.

  1. nfirtaps

    nfirtaps Guest

    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, Dec 1, 2006
    #1
    1. Advertising

  2. nfirtaps

    KJ Guest

    "nfirtaps" <> wrote in message
    news:...
    > 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
    KJ, Dec 2, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. joshc
    Replies:
    5
    Views:
    540
    Keith Thompson
    Mar 31, 2005
  2. sarathy

    integer promotion and arithmetic conversion

    sarathy, Aug 16, 2006, in forum: C Programming
    Replies:
    6
    Views:
    516
  3. Frederick Gotham
    Replies:
    2
    Views:
    381
    Frederick Gotham
    Jul 7, 2006
  4. Alasdair
    Replies:
    15
    Views:
    745
    Steven D'Aprano
    Mar 9, 2008
  5. Spiros Bousbouras

    Arithmetic conversions and integer constants

    Spiros Bousbouras, Jan 13, 2009, in forum: C Programming
    Replies:
    6
    Views:
    472
    Keith Thompson
    Jan 14, 2009
Loading...

Share This Page