Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Integer left shift operation

Reply
Thread Tools

Integer left shift operation

 
 
cltsaig
Guest
Posts: n/a
 
      10-07-2004
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

 
Reply With Quote
 
 
 
 
Nicolas Matringe
Guest
Posts: n/a
 
      10-07-2004
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.

--
____ _ __ ___
| _ \_)/ _|/ _ \ Adresse de retour invalide: retirez le -
| | | | | (_| |_| | Invalid return address: remove the -
|_| |_|_|\__|\___/

 
Reply With Quote
 
 
 
 
Alan Fitch
Guest
Posts: n/a
 
      10-07-2004

"cltsaig" <> wrote in message
news: lkaboutprogramming.com...
> 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:

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.

 
Reply With Quote
 
cltsaig
Guest
Posts: n/a
 
      10-07-2004
Hi Alan and all,

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

Many thanks!!!

BR,
Stanley


 
Reply With Quote
 
rickman
Guest
Posts: n/a
 
      10-07-2004
cltsaig wrote:
>
> 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


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
 
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
shift left/shift right in VHDL deepak21 Software 0 05-06-2012 09:01 AM
left shift operator behaves like left rotate when the operand is a variable. pc C Programming 2 06-08-2011 06:58 PM
Java left shift and right shift operators. Sanny Java 38 04-29-2011 10:02 PM
Left Shift / Right Shift Operators Santosh Nayak C Programming 16 11-30-2006 05:10 PM
left shift then right shift an unsigned int Wenjie C++ 3 07-11-2003 08:22 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57