vhdl - VHDL shift_left 操作出错

标签 vhdl bit-shift alu

我已经搜索了一段时间,但无法在线复制任何已发布的解决方案,所以我希望你们中的一些好人能帮助我。 我正在创建一个 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_leftshift_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))));

对于您使用 shift_leftshift_right 函数的其他行,结束等。

关于vhdl - VHDL shift_left 操作出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43101604/

相关文章:

java - 我可以将 0 移到开头吗?

variable-assignment - 连续赋值verilog

math - CPU是怎么做减法的?

python - 将软件转换为 FPGA 的 VHDL/Verilog 的更好平台

java - 在堆栈中的动态数组中声明收缩函数

vhdl - vhdl 中逻辑与 (&&) 的等效项是什么?

java - 移位运算符如何在 Java 中工作?

Verilog错误: not a valid l-value

vhdl - VHDL 包 'IEEE.std_logic_arith' 是否随 ghdl 一起提供?

floating-point - 使用 Altera Quartus II 将 *.vhdl 编译成库