首页 > 解决方案 > 找到运算符“-”的“0”定义,无法确定“-”的精确重载匹配定义

问题描述

如何处理给定代码中的以下错误

找到运算符“-”的“0”定义,无法确定“-”的精确重载匹配定义

代码:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
use IEEE.NUMERIC_STD.ALL;
library STD, WORK; 
use STD.STANDARD.all;
entity sqrrootofnum is
    Port ( d : in  STD_LOGIC_VECTOR (31 downto 0);
         `` output : out  STD_LOGIC_VECTOR (15 downto 0)
           );
end sqrrootofnum;

architecture Behavioral of sqrrootofnum is
  signal regi:STD_LOGIC_VECTOR (31 downto 0);
  signal q:STD_LOGIC_VECTOR (15 downto 0);
  signal j:STD_LOGIC_VECTOR (1 downto 0);
  signal z:STD_LOGIC_VECTOR (14 downto 0);
begin
  process(d)
  begin
    j<="01"; if d(31 downto 30) > 01 then
      regi(1 downto 0) <= d(31 downto 30)-01; q(15 downto 15)<="1";
    else
      regi(1 downto 0) <= d(31 downto 30); q(15 downto 15)<="0";
    end if;
    for k in 2 to 16 loop
      if ((regi(2*(k-1)-1 downto 0) & d(2*(k-1) downto 2*(k-1)-1))-(z(k-2  downto 0) & q(15 downto 15-(k-2)) & j)) then
        regi(2*(k-1)+1 downto 0)<= ((regi(2*(k-1)-1 downto 0) & d(2*(k-1) downto 2*(k-1)-1))-(z(k-2 downto 0) & q(15 downto 15-(k-2)) & j))
        q(15-(k-1) downto 15-(k-1)) <= "1";
      else
        regi(2*(k-1)+1 downto 0) <= (regi(2*(k-1)-1 downto 0) & d(2*(k-1) downto 2*(k-1)-1));
        q(15-(k-1) downto 15-(k-1))<="0";
      end if;
    end loop;
    output <=q;
  end process;

end Behavioral;

标签: vhdl

解决方案


此代码中存在多个问题,但我认为此特定错误是由这一行引起的:

 regi(1 downto 0) <= d(31 downto 30) - 01;

d 是一个 std_logic_vector 所以它不能被解释为一个数字 - 因此你不能使用减法运算符。执行此操作时,您要么需要将 d 声明为无符号,要么将其强制转换为无符号。


推荐阅读