如何在VHDL中正确嵌套if语句

时间:2015-12-12 20:17:10

标签: if-statement nested vhdl

process (bit1,bit2,j)
begin
if j = '1' then

if (bit1 = '1' and bit2 = '1') then
V <= '1' xor g;
bit3 <= '1' xor g;
elsif (bit1 = '1' and bit2 = '0') then
V <= '0' xor g;
bit3 <= '0' xor g;
elsif (bit1 = '0' and bit2 = '0') then
V <= '1' xor g;
bit3 <= '1' xor g;
elsif (bit1 = '0' and bit2 = '1') then
V <= '0' xor g;
bit3 <= '0' xor g;
end if;

else

if j = '0' then

if (bit1 = '1' and bit2 = '1') then
V <= '0' xor g;
bit3 <= '0' xor g;
elsif (bit1 = '1' and bit2 = '0') then
V <= '1' xor g;
bit3 <= '1' xor g;
elsif (bit1 = '0' and bit2 = '0') then
V <= '0' xor g;
bit3 <= '0' xor g;
elsif (bit1 = '0' and bit2 = '1') then
V <= '1' xor g;
bit3 <= '1' xor g;
end if;

end if;

end if;

end process;

您好, 我被困在一个VHDL编程任务上,我真的可以使用一些帮助。

任务是编程一个两个补码加法器,并在加法后设置相应的标志。

当我编写代码时,我要做的第一件事是初始化我的两个输入,以便两个向量具有相同的长度。在此之后携带等。

问题出现在process (bit1,bit2,j)

我不知道导致此错误的是什么,但我的V和bit 3从未正确初始化。而且我认为这种情况正在发生,因为if语句过多,或者因为我错误地嵌套它们。编译器也没有说什么。

1 个答案:

答案 0 :(得分:0)

你的if语句不是问题。编译器可能对嵌套if块的深度有实际限制,但该限制肯定比3级更高。

正如Martin所提到的,您引用了一个名为'g'的信号,该信号用作组合逻辑的输入,但未在灵敏度列表中列出。这通常被报告为警告,而不是错误。在它所处的状态下,当'g'上有事件时,大多数模拟器都不会执行该过程。这可能导致未初始化的值。