To_stdlogicvector

A

ashu

on comipiling the follwoing prgram i am getting syntax error

a1 := to_stdlogicvector(a);
^
**Error: /pe_users/guest6/vhdl/adder.vhd line 23
Syntax error. (VSS-1081)

am i using to_stdlogicvector function incorrectly ?
_____________________________________________________________________
library ieee ;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
USE ieee.std_logic_unsigned.all;

entity adder is

port (
a : in bit_vector( 7 downto 0) ;
b : in bit_vector( 7 downto 0) ;

sum : out bit_vector(8 downto 0));

end adder;

architecture arch of adder is
variable a1: std_logic_vector(7 downto 0);
variable b1: std_logic_vector(7 downto 0);
variable sum1: std_logic_vector(8 downto 0);

begin -- arch

a1 := to_stdlogicvector(a);
b1: = to_stdlogicvector(b);

sum1:= To_StdLogicVector(a1 + b1);

sum <= sum1;

end arch;


library ieee ;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
USE ieee.std_logic_unsigned.all;

entity adder is

port (
a : in bit_vector( 7 downto 0) ;
b : in bit_vector( 7 downto 0) ;

sum : out bit_vector(8 downto 0));

end adder;

architecture arch of adder is
variable a1: std_logic_vector(7 downto 0);
variable b1: std_logic_vector(7 downto 0);
variable sum1: std_logic_vector(8 downto 0);

begin -- arch

a1 := to_stdlogicvector(a);
b1: = to_stdlogicvector(b);

sum1:= To_StdLogicVector(a1 + b1);

sum <= sum1;

end arch;
 
R

Ralf Hildebrandt

ashu wrote:

a1 := to_stdlogicvector(a);
^
**Error: /pe_users/guest6/vhdl/adder.vhd line 23
Syntax error. (VSS-1081)

am i using to_stdlogicvector function incorrectly ?

USE ieee.std_logic_arith.all;
USE ieee.std_logic_unsigned.all;

This is not the reason for your problem, but you should not use them.
Use Numeric_std instead!

begin -- arch

a1 := to_stdlogicvector(a);
b1: = to_stdlogicvector(b);

Variables (except shared variables, which is something very special)
cannot exist outside of processes. Make a1, b1 and the others a signal
or move them into a process!

Ralf
 
A

ashu

ralf
thanks so much
my problem is that i want to add two 8 bit bit_vectors ...
and store the result in a 9 bit bit_vector

now since addtion operation is not defined on two bit vectors ...

i tried converting them to std_logic and hence had to use this function
:(

can u suggest me a another way to add two bit_vectors using + sign ?

thanks
ashu
 
R

Ralf Hildebrandt

ashu wrote:

my problem is that i want to add two 8 bit bit_vectors ...

It is strongly recommended to not use bit / bit_vector. The reason:
There is no 'X' (and all the other driver values) for bit(_vector) you
cannot see an error if you connect two drivers to one bus.

now since addtion operation is not defined on two bit vectors ...

i tried converting them to std_logic and hence had to use this function

std_ulogic(_vector) / std_logic(_vector) has no arithmetics defined,
because the tool cannot know, if the signal is signed or unsigned. For
addition there is no difference, but for a comparison it is, because is
"111" equal to 7 or -1?

can u suggest me a another way to add two bit_vectors using + sign ?


use IEEE.Numeric_std.ALL;

signal a,b : std_ulogic_vector(15 downto 0);
signal res : std_ulogic_vector(15 downto 0);

res<=std_ulogic_vector( unsigned(a) + unsigned(b) );


You may also declare a,b,res as signed or unsiged to avoid the
conversions. Another option is to use the type integer.

Ralf
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top