VHDL shift_left 操作出错
getting error for VHDL shift_left operation
我已经搜索了一段时间,但无法在线复制任何已发布的解决方案,所以我希望你们中的一些好人能帮助我。
我正在创建一个 ALU。我有两个 32 位输入和一个 32 位输出以及一个 5 位信号和一个 4 位控制信号。我的代码如下,错误位置已注释。
library ieee;
use ieee.std_logic_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use ieee.numeric_std.all;
Entity mips_alu IS
PORT(ALUControl : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
inputA, inputB : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
shamt : IN STD_LOGIC_VECTOR(4 DOWNTO 0);
Zero : OUT STD_LOGIC;
ALU_Result : OUT STD_LOGIC_VECTOR(31 DOWNTO 0)
);
END mips_alu;
ARCHITECTURE behavior of mips_alu IS
BEGIN
PROCESS(ALUControl)
BEGIN
CASE ALUControl is
WHEN "0000" =>
ALU_Result <= inputA AND inputB;
WHEN "0001" =>
ALU_Result <= inputA OR inputB;
WHEN "0010" =>
ALU_Result <= inputA + inputB;
WHEN "0110" =>
ALU_Result <= inputA - inputB;
WHEN "0111" =>
IF (inputA < inputB) THEN
ALU_Result <= inputA;
END IF;
WHEN "1000" =>
ALU_Result <= shift_left(inputB, to_integer(unsigned(shamt)));
-- The line above is where i get my first error, The following lines will have the same issue
WHEN "1001" =>
ALU_Result <= shift_right(inputB, shamt);
WHEN "1010" =>
ALU_Result <= shift_left(inputB, inputA);
WHEN "1011" =>
ALU_Result <= shift_right(inputB, inputA);
WHEN "1100" =>
ALU_Result <= inputA NOR inputB;
WHEN "1101" =>
ALU_Result <= inputB(31 DOWNTO 16);
WHEN OTHERS =>
ALU_Result <= inputA;
END CASE;
END PROCESS;
END behavior;
我得到的错误是:
10511 VHDL Qualified Expression error at mips_alu.vhd(33): shift_left type specified in qualified expression must match std_logic_vector type that is implied for expression by context
我已经尝试了几种变体,所以如果我遗漏了什么,请告诉我,感谢所有帮助,因为我是 vhdl 的新手
在 numeric_std 文档中,您可以找到函数 shift_left
或 shift_right
。在这两个描述中,您可以看到 function SHIFT_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED;
。因此,您需要将 std_logic_vector
转换为 unsigned
。
在您的情况下,它看起来像:
ALU_Result <= std_logic_vector(shift_left(unsigned(inputB), to_integer(unsigned(shamt))));
end 等用于您使用 shift_left
或 shift_right
函数的其他行。
我平时做的就是这样:
ALU_Result <= inputB(30 downto 0) & '0';
这存储 ALU_Result 一个等于 InputB 移位一次的向量。
如果您想多次移动它,可以使用循环。
while (i<to_integer(unsigned(shamt))) loop
ALU_Result <= inputB(30 downto 0) & '0';
i:=i+1;
end loop;
这不是一个优雅的解决方案,但它可能会奏效。
向右移动:
ALU_Result <= '0' & inputB(31 downto 1);
我已经搜索了一段时间,但无法在线复制任何已发布的解决方案,所以我希望你们中的一些好人能帮助我。 我正在创建一个 ALU。我有两个 32 位输入和一个 32 位输出以及一个 5 位信号和一个 4 位控制信号。我的代码如下,错误位置已注释。
library ieee;
use ieee.std_logic_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use ieee.numeric_std.all;
Entity mips_alu IS
PORT(ALUControl : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
inputA, inputB : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
shamt : IN STD_LOGIC_VECTOR(4 DOWNTO 0);
Zero : OUT STD_LOGIC;
ALU_Result : OUT STD_LOGIC_VECTOR(31 DOWNTO 0)
);
END mips_alu;
ARCHITECTURE behavior of mips_alu IS
BEGIN
PROCESS(ALUControl)
BEGIN
CASE ALUControl is
WHEN "0000" =>
ALU_Result <= inputA AND inputB;
WHEN "0001" =>
ALU_Result <= inputA OR inputB;
WHEN "0010" =>
ALU_Result <= inputA + inputB;
WHEN "0110" =>
ALU_Result <= inputA - inputB;
WHEN "0111" =>
IF (inputA < inputB) THEN
ALU_Result <= inputA;
END IF;
WHEN "1000" =>
ALU_Result <= shift_left(inputB, to_integer(unsigned(shamt)));
-- The line above is where i get my first error, The following lines will have the same issue
WHEN "1001" =>
ALU_Result <= shift_right(inputB, shamt);
WHEN "1010" =>
ALU_Result <= shift_left(inputB, inputA);
WHEN "1011" =>
ALU_Result <= shift_right(inputB, inputA);
WHEN "1100" =>
ALU_Result <= inputA NOR inputB;
WHEN "1101" =>
ALU_Result <= inputB(31 DOWNTO 16);
WHEN OTHERS =>
ALU_Result <= inputA;
END CASE;
END PROCESS;
END behavior;
我得到的错误是:
10511 VHDL Qualified Expression error at mips_alu.vhd(33): shift_left type specified in qualified expression must match std_logic_vector type that is implied for expression by context
我已经尝试了几种变体,所以如果我遗漏了什么,请告诉我,感谢所有帮助,因为我是 vhdl 的新手
在 numeric_std 文档中,您可以找到函数 shift_left
或 shift_right
。在这两个描述中,您可以看到 function SHIFT_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED;
。因此,您需要将 std_logic_vector
转换为 unsigned
。
在您的情况下,它看起来像:
ALU_Result <= std_logic_vector(shift_left(unsigned(inputB), to_integer(unsigned(shamt))));
end 等用于您使用 shift_left
或 shift_right
函数的其他行。
我平时做的就是这样:
ALU_Result <= inputB(30 downto 0) & '0';
这存储 ALU_Result 一个等于 InputB 移位一次的向量。 如果您想多次移动它,可以使用循环。
while (i<to_integer(unsigned(shamt))) loop
ALU_Result <= inputB(30 downto 0) & '0';
i:=i+1;
end loop;
这不是一个优雅的解决方案,但它可能会奏效。
向右移动:
ALU_Result <= '0' & inputB(31 downto 1);