形式和的实际 s 必须是变量且类型错误

actual s of formal sum must be a variable and type error

我正在 xilinx 学生实验室工作并尝试学习 VHDL,但在修复我的错误时遇到了一些问题。我现在主要专注于让加法部分正常工作。

我得到的错误如下:

[Synth 8-1560] actual s of formal sum must be a variable ["C:/Nexys 4 >Projects/lab4_1_1/lab4_1_1.srcs/sources_1/new/add_two_values_procedure.vhd":54]

[Synth 8-2778] type error near a ; expected type std_ulogic ["C:/Nexys 4 >Projects/lab4_1_1/lab4_1_1.srcs/sources_1/new/add_two_values_procedure.vhd":56]

[Synth 8-2778] type error near b ; expected type std_ulogic ["C:/Nexys 4 >Projects/lab4_1_1/lab4_1_1.srcs/sources_1/new/add_two_values_procedure.vhd":56]

对于第一个错误,我读到如果我不在进程中使用该过程,那么我必须将信号传递给该过程以便将变量 total 分配给它。有人可以阐明如何解决此错误吗?

对于第二个和第三个错误,我在库中查找 std_logic_1164 并看到了这一行

FUNCTION "and" ( l, r : std_logic_vector ) RETURN std_logic_vector;

据我所知(无论它在这个主题上有多小)第 56 行在和 operator/function (?) 的两边使用 std_logic_vector 并且应该 return a std_logic_vector.那么为什么要我使用 std_ulogic。 编辑:我从这个网站 http://www.csee.umbc.edu/portal/help/VHDL/packages/std_logic_1164.vhd 看到的上面那行,但是从我的书《Designer's guide to VHDL》中,包中没有那行。

下面是我的代码

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_SIGNED.ALL;

entity add_two_values_procedure is
    Port ( a : in STD_LOGIC_VECTOR (3 downto 0);
           b : in STD_LOGIC_VECTOR (3 downto 0);
           operand : in STD_LOGIC;
           sum : out STD_LOGIC_VECTOR (3 downto 0);
           cout : out STD_LOGIC);
end add_two_values_procedure;

architecture Behavioral of add_two_values_procedure is
    signal s : STD_LOGIC_VECTOR (3 downto 0);
    procedure add_values (
        a : in STD_LOGIC_VECTOR (3 downto 0);
        b : in STD_LOGIC_VECTOR (3 downto 0);
        operand : in STD_LOGIC;
        sum : out STD_LOGIC_VECTOR (3 downto 0))
    is
        variable total : STD_LOGIC_VECTOR (3 downto 0);
    begin
        case operand is
            when '1' =>
                total := a + b;
            when '0' =>
                total := a - b;
        end case;
    sum := total;
    end procedure add_values;
begin
    add_values(a, b, operand, s);               54
    sum <= s;
    cout <= a and b;                            56
end Behavioral;

关于第 54 行:

引用 VHDL 2008:

If the mode is inout or out, and no object class is explicitly specified, variable is assumed.

所以尝试:

procedure add_values (
    a : in STD_LOGIC_VECTOR (3 downto 0);
    b : in STD_LOGIC_VECTOR (3 downto 0);
    operand : in STD_LOGIC;
    signal sum : out STD_LOGIC_VECTOR (3 downto 0))
is
    variable total : STD_LOGIC_VECTOR (3 downto 0);
begin
    case operand is
        ...

关于第 56 行:

查看cout的类型。 您正在将 std_logic_vector(3 downto 0) 分配给 std_logic