for循环只执行一次

时间:2012-06-13 02:26:45

标签: vhdl

我有一个关于在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;

2 个答案:

答案 0 :(得分: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;

答案 1 :(得分:2)

没有循环:

temp_A := (others => '0');
temp_A(A'high downto shift_value) := A(A'high-shift_value downto A'low);