Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

VHDL if statement enquiry

Status
Not open for further replies.

drifterz

Newbie level 5
Joined
Aug 12, 2006
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,328
Hi

I'm new to VHDL so please pardon my "silliness".
when I declare a signal (signal_a) as std_logic_vector and I wish to check for sign, is the statement below valid?
if (signal_a>=0) then
or should I specific the MSB explicitly:
if(MSB of signal_a ='0' )then

Thanks in advance.
 

The signal for eg, a is "10001010".Here the MSB is '1'.Hence this means the sign is -ve(I guess) and viceversa....Always check this way
If(a(7) ='1') THEN
{
Statements;
}
end if;
I guess it's ok for you to get it...Correct me if wrong
Regrds.
 

std_logic_vector as such has no sign, you would have to cast the variable to signed to perform a signed compare.
Code:
if signed(signal_a)>=0 then
I assume, that package IEEE.STD_LOGIC_ARITH is used in the design. Alternatively IEEE.STD_LOGIC_SIGNED could be used, that treats all std_logic_vector as signed. The suitable solution depends on if you are using other arithmetic operations in your design. With extended arithmetics, variables representing a signed value would most likely defined as signed.

Direct test of sign bit, as suggested, has the advantage not to depend on a package and also never to conflict with a package.
 

what is the implication of using the following package?
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

thanks.
 

The packages declarare operators and functions to use in logic synthesis. To my opinion, STD_LOGIC_1164 and STD_LOGIC_ARITH are the packages that should be suitable for most designs. STD_LOGIC_UNSIGNED could be used additional. It introduces a Verilog similar behavior as all std_logic_vector is also regarded as unsigned number. Personally, I prefer declaring SIGNED and UNSIGNED explicitely, possibly requiring some additional type casts but getting more clarity.
 

Watch out, the
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
packages are both non standard Synopsys packages that "hijack" the IEEE namespace.

The correct way to do unsigned and signed math on std_logic is to include only:

use IEEE.numeric_std.all;

That's all, from then on you can use signed and unsigned types and do math on them. And it's official IEEE.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top