Integer left shift operation

C

cltsaig

Hi all,

I got an syntax error with the following left shfit operation assignment.
# Assignment target incompatible with right side. Expected type
"INTEGER".
# Cannot find function to_integer for these actuals.
# Undefined type of expression.

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.math_real.al

process
variable ip1, nprev: integer;
begin
nprev:=20;
ip1:=to_integer(to_StdLogicVector(nprev) sll 1);
end process;

Any help will be very appreciate!!!

Kindest regards,
Stanley
 
N

Nicolas Matringe

cltsaig a écrit:
Hi all,

I got an syntax error with the following left shfit operation assignment.
# Assignment target incompatible with right side. Expected type
"INTEGER".
# Cannot find function to_integer for these actuals.
# Undefined type of expression.
[...]
ip1:=to_integer(to_StdLogicVector(nprev) sll 1);
end process;

Any help will be very appreciate!!!

You don't use sll with the right syntax:
ip1:=to_integer(sll(to_StdLogicVector(nprev),1));

but I'm not sure this will work. IIRC, sll can only be used with
bit_vector type.
 
A

Alan Fitch

cltsaig said:
Hi all,

I got an syntax error with the following left shfit operation assignment.
# Assignment target incompatible with right side. Expected type
"INTEGER".
# Cannot find function to_integer for these actuals.
# Undefined type of expression.

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.math_real.al

process
variable ip1, nprev: integer;
begin
nprev:=20;
ip1:=to_integer(to_StdLogicVector(nprev) sll 1);
end process;

Any help will be very appreciate!!!

In Numeric_std, sll is defined for types signed and unsigned.
So you need to do

a) convert your integer to unsigned
b) shift left, producing an unsigned result
c) convert from unsigned back to integer

ip1 := to_integer( to_unsigned(nprev, 5) sll 1 );

Note that to_unsigned takes a second argument specifying the
width of the resultant vector.

Regarding the problem, you could of course with your
example code simply say

ip1 := 40; -- only joking! :)

It might be worth trying (depending on your synthesis tool)

ip1 := nprev * 2;

as multiplication by a constant power of 2 is understood
by many tools and can be implemented by a shift in hardware.

If you want to use integers, and they are for representing
unsigned values, I would declare them as "natural" rather than
"integer".

You may find that if you are doing lots of bit shifting
and arithmetic operations, it is easier to use the vector
types unsigned and signed, and then convert the final output
to the required type.

regards
Alan


--
Alan Fitch
Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * Perl * Tcl/Tk * Verification * Project
Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24
1AW, UK
Tel: +44 (0)1425 471223 mail:
(e-mail address removed)
Fax: +44 (0)1425 471573 Web:
http://www.doulos.com

The contents of this message may contain personal views which are not
the
views of Doulos Ltd., unless specifically stated.
 
C

cltsaig

Hi Alan and all,

Greatly thanks for your supports and I'll try the way you just told me!!

Many thanks!!!

BR,
Stanley
 
R

rickman

cltsaig said:
Hi all,

I got an syntax error with the following left shfit operation assignment.
# Assignment target incompatible with right side. Expected type
"INTEGER".
# Cannot find function to_integer for these actuals.
# Undefined type of expression.

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.math_real.al

process
variable ip1, nprev: integer;
begin
nprev:=20;
ip1:=to_integer(to_StdLogicVector(nprev) sll 1);
end process;

Doesn't to_StdLogicVector() require TWO prameters? I think you need to
define the width of the vector.

--

Rick "rickman" Collins

(e-mail address removed)
Ignore the reply address. To email me use the above address with the XY
removed.

Arius - A Signal Processing Solutions Company
Specializing in DSP and FPGA design URL http://www.arius.com
4 King Ave 301-682-7772 Voice
Frederick, MD 21701-3110 301-682-7666 FAX
 

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,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top