std_logic_vector ==> interger?

U

uvbaz

hallo, everyone

op: in std_logic_vector(3 downto 1);
............
........
if( int(op(3 downto 1)) = 2#110# ) then....

this is part of the code, i got the following error:
(vcom-1136) Unknown identifier "int".

thanks for your help
 
K

KJ

uvbaz said:
hallo, everyone

op: in std_logic_vector(3 downto 1);
...........
.......
if( int(op(3 downto 1)) = 2#110# ) then....

this is part of the code, i got the following error:
(vcom-1136) Unknown identifier "int".

thanks for your help

I think what you want is..

if( to_integer(unsigned(op(3 downto 1)))) = 2#110# ) then....

You'll also need to include the numeric_std package outside of the
architecture which is the package that contains the definition of
'unsigned' and 'to_integer'

use ieee.numeric_std.all;

KJ
 
A

Andy

"int" is a conversion function that someone has written themselves.
Make sure you have correct versions of the packages that are used for
this module.

Another way to do the conversion would be, assuming op(3 downto 1) is
really all of op:

if unsigned(op) = 2#110# then

using ieee.numeric_std package

Andy
 
J

Jim Lewis

Uvbaz,
For "=" and "/=" there is no reason not to
use std_logic_vector directly in the comparision.
Hence, your code becomes:

if( op(3 downto 1) = "110" ) then


For using ">", ">", ">=", and "<=", it is easiest to
use a type conversion to convert to unsigned
(as Andy suggested). Also make sure to use the
package "numeric_std". So if you were doing ">",

use ieee.numeric_std.all ; -- before the entity
....

if( unsigned(op(3 downto 1)) > "110" ) then

Due to overloading in numeric_std, it is also valid
to use integer literals with unsigned, and hence the
following are also valid:

if( unsigned(op(3 downto 1)) > 6 ) then
if( unsigned(op(3 downto 1)) > 2#110# ) then

Note that 2#110# is an integer literal (use where integers
can be used), whereas, "110" is a string literal, which
can be use with any array type based on character types
(such as unsigned, std_logic_vector, ...). A few character
based types are character, bit, std_ulogic and std_logic.

Cheers,
Jim

P.S.
Ironically in VHDL understanding types and values is one
of the hard things. However, once you get past beginner
mistakes, these will start to work in your favor - ie: find
bugs at compile time that would otherwise take simulation
and a good testbench to find.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jim Lewis
Director of Training mailto:[email protected]
SynthWorks Design Inc. http://www.SynthWorks.com
1-503-590-4787

Expert VHDL Training for Hardware Design and Verification
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
U

uvbaz

firstly, thanks a lot to Kevin, Andy and Jim.

if( op(3 downto 1) = "110" ) then <------------------ this works.

however, there is an error, when i try to compile

if( unsigned(op(3 downto 1)) = 2#110# ) then <----------------- XXX,
error!

error:
(vcom-1078) Identifier "unsigned" is not directly visible.
Potentially visible declarations are:
ieee.numeric_std.unsigned (type)
ieee.std_logic_arith.unsigned (type)

although i have the following declaration in the code.
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.numeric_std.all;

thanks again, everyone. You are so kindly.
 
P

Paul Uiterlinden

uvbaz said:
firstly, thanks a lot to Kevin, Andy and Jim.

if( op(3 downto 1) = "110" ) then <------------------ this works.

however, there is an error, when i try to compile

if( unsigned(op(3 downto 1)) = 2#110# ) then <----------------- XXX,
error!

error:
(vcom-1078) Identifier "unsigned" is not directly visible.
Potentially visible declarations are:
ieee.numeric_std.unsigned (type)
ieee.std_logic_arith.unsigned (type)

although i have the following declaration in the code.
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.numeric_std.all;

thanks again, everyone. You are so kindly.

You should get rid of the use ieee.std_logic_arith.all statement and
never use it again.

In stead, use numeric_std. That is an IEEE standardized package, where
std_logic_arith is not (it is by Synopsys)

So just use numeric_std.
 
U

uvbaz

Paul said:
You should get rid of the use ieee.std_logic_arith.all statement and
never use it again.

In stead, use numeric_std. That is an IEEE standardized package, where
std_logic_arith is not (it is by Synopsys)

So just use numeric_std.

Yes, it works...
thanks, Paul
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top