0

我有一个关于在 if 语句中使用 for 循环的问题。if 语句在流程语句中。问题是当我执行这部分代码时,for循环被执行但只执行一次,而不管B的值如何。我什至尝试输入显式值并忽略B,但循环只执行一次。我错过了什么吗?

该代码是 ALU 行为模型的一部分,用于在不使用 sll 的情况下应用逻辑左移。

        elsif ALU_Control = "100" then
            -- implement shift logic left by B units 
            if (B > X"00000000") then
                -- Use value of B input as the shift position
                shift_value := TO_INTEGER(UNSIGNED(B)); 
                -- concatenate a 0 to end of A          
                for index in 0 to shift_value loop
                    temp_A := (A(30 downto 0) & '0');
                end loop;

                ALU_out <= temp_A(31 downto 0) after 100 ps;
            else
                ALU_out <= A after 100 ps; 
            end if;
4

2 回答 2

3

在此处查看您的代码的这一部分:

for index in 0 to shift_value loop
  temp_A := (A(30 downto 0) & '0');
end loop;

循环的每次迭代都会做同样的事情,所以无论循环运行多少次,你都会得到相同的结果。也许你真的想拥有这样的东西:

temp_A := A;
for index in 0 to shift_value loop
  temp_A := temp_A(30 downto 0) & '0';
end loop;
于 2012-06-13T04:32:24.960 回答
2

没有循环:

temp_A := (others => '0');
temp_A(A'high downto shift_value) := A(A'high-shift_value downto A'low);
于 2012-06-13T12:57:16.087 回答