由于 z,我无法编译此 VHDL 代码,但我不知道为什么以及如何修复它

I cant compile this VHDL code because of z but i dont know why and how to fix it

我在使用 ModelSim 编译此 VHDL 代码时遇到此错误:

** Error: testVHDL_5.vhd(14): Cannot read output "z".
#   VHDL 2008 allows reading outputs.
#   This facility is enabled by compiling with -2008.

VHDL代码:

library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity gate_1 is
    port(
        a, b, c : in std_logic;
        x, z : out std_logic
        );
end gate_1;

architecture arch1 of gate_1 is 
begin -- rt1
    z <= b or c;
    x <= a and b and z;
end arch1;

testVHDL_5 是我的文件名。 我知道问题是 z 不能在 x 中使用。有人可以解释原因并提出解决方案。谢谢。

I know in the problem is that z cant be used in x.

是的,错误消息就是这么说的。

Can someone explain why

因为在 2008 之前的版本中,您无法读取 VHDL 中的输出。

and suggest a solution.

使用 2008 VHDL 版本编译。

请不要使用像 x 和 z 这样的端口名称。它们很容易与 'X' 和 'Z' 的 std_logic 值混淆。

您可以使用内部信号分配(b 或 c)并将其用于计算 x。

library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity gate_1 is
  port(
    a, b, c : in  std_logic;
    x, z    : out std_logic
    );
end gate_1;

architecture arch1 of gate_1 is
  signal temp : std_logic;
begin 
  temp <= b or c;
  x    <= a and b and temp;
  z    <= temp;
end arch1;

您不需要为此启用 VHDL 2008。

正如@oldfart 所说,请不要使用 x,z。使用有意义的名称。