Adding 2 std_logic_vector in variable type VHDL

前端 未结 1 774
滥情空心
滥情空心 2021-01-25 09:19

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 t

1条回答
  •  礼貌的吻别
    2021-01-25 10:09

    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.

    0 讨论(0)
提交回复
热议问题