Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > unsigned vs integer

Reply
Thread Tools

unsigned vs integer

 
 
dsd dsd is offline
Junior Member
Join Date: Nov 2007
Posts: 1
 
      11-01-2007
Are there any advantages to using unsigned (or signed for that matter) versus using integer? I can't see that they are different from a logic perspective, but I suspect that the actual compiler could handle them different (some might handle one better than the other).

There are not that many differences when it comes to the actual allowable use, as illustrated below,

PHP Code:
-- counter using unsigned
signal counter_uv 
unsigned(7 downto 0);
process(rstclk)
begin
  
if (rst '1'then
    counter_uv 
<= to_unsigned(08);  -- reset the counter to zero
  elsif rising_edge
(clkthen
    counter_uv 
<= counter_uv 1;     -- increment counter
  end 
if;
end process;

-- 
counter using integer
signal counter_i 
integer range 0 to 255;
process(rstclk)
begin
  
if (rst '1'then
    counter_i 
<= 0;               -- reset the counter to zero
  elsif rising_edge
(clkthen
    counter_i 
<= counter_i 1;   -- increment counter
  end 
if;
end process
If you want to convert to std_logic_vector, then using unsigned is a bit more readable,

PHP Code:
-- convert between unsigned and slv
counter_slv 
<= std_logic_vector(counter_uv);
counter_uv  <= unsigned(counter_slv);

-- 
covert between integer and slv
counter_slv 
<= std_logic_vectorto_unsigned (counter_i8) );
counter_i   <= to_integerunsigned (counter_slv) ); 
As I said before, from a logic perspective I can't see how they would differ if they are declared correctly.

Any perspectives on which one is better, if any? (FYI I'm using Quartus compiler)
 
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
(int) -> (unsigned) -> (int) or (unsigned) -> (int) -> (unsigned):I'll loose something? pozz C Programming 12 03-20-2011 11:32 PM
conversion of signed integer to unsigned integer junky_fellow@yahoo.co.in C Programming 14 06-18-2005 02:29 PM
unsigned long to unsigned char ashtonn@gmail.com Python 1 06-01-2005 07:00 PM
unsigned int const does not match const unsigned int Timo Freiberger C++ 3 10-30-2004 07:02 PM
Assigning unsigned long to unsigned long long George Marsaglia C Programming 1 07-08-2003 05:16 PM



Advertisments