简体   繁体   中英

Adding 2 std_logic_vector in variable type VHDL

I'm working in this school project. I have two std_logic_vector (31 downto 0) A and B, and I have a variable type std_logic_vector (32 downto 0) and I want to add A+B and put the result in my std_logic_vector with 32 bits.

This is my design:

library IEEE;    
use IEEE.STD_LOGIC_1164.ALL;    
USE ieee.numeric_std.ALL;    
use ieee.std_logic_arith.all;

entity Ej3 is
    Port ( A :     in  STD_LOGIC_VECTOR (31 downto 0);   
           B :     in  STD_LOGIC_VECTOR (31 downto 0);    
           S :     out STD_LOGIC_VECTOR (31 downto 0);    
           AluOp : in  STD_LOGIC_VECTOR (3 downto 0);    
           COut :  out STD_LOGIC;   
           Z :     out STD_LOGIC;    
           OFL :   out STD_LOGIC);    
end Ej3;


architecture Behavioral of Ej3 is

    begin

    process(AluOp)    
        variable Temp: STD_LOGIC_VECTOR (32 downto 0);   
    begin

        Temp := A+B;

And I have this error: found '0' definitions of operator "+", cannot determine exact overloaded matching definition for "+"

Can someone help??

First of all you've included the standard library numeric_std and the nonstandard library std_logic_arith together. They conflict with each other so get rid of std_logic_arith .

Both of those packages implement arithmetic using the unsigned and signed types. It is strongly recommend that you use these types if you want to do arithmetic on vectors. It makes it explicitly clear that you want them interpreted in a numeric context. There is no "+" operator defined for the std_logic_vector type implemented in std_logic_1164 which is why you get an error. You can augment that type with arithmetic operators in VHDL-2008 by also including numeric_std_unsigned . Again, it is better to just use the traditional unsigned type:

A : in unsigned(31 downto 0);
B : in unsigned(31 downto 0);

...

process(AluOp)
  variable temp : unsigned(32 downto 0);
begin

  temp := resize(A, temp'length) + B;

The length of the left and right sides of the assignment have to match so first resize the A signal, expanding it to 33 bits before adding the 32-bit signal B.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM