Reputation: 21
I have a question about using a for loop in an if statement. The if statement is within a process statement. The problem is when I execute this part of the code the for loop is executed but only once regardless of the value of B. I even tried to enter explicit values and ignore B but the loop only executes once. Am I missing something?
The code is part of an ALU behavioral model to apply a logical left shift without using 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;
Upvotes: 0
Views: 1127
Reputation: 16832
Without a loop:
temp_A := (others => '0');
temp_A(A'high downto shift_value) := A(A'high-shift_value downto A'low);
Upvotes: 2
Reputation: 7785
Look at this part of your code here:
for index in 0 to shift_value loop
temp_A := (A(30 downto 0) & '0');
end loop;
That does the same thing every iteration of the loop, so no matter how many times the loop is run, you will get the same result. Perhaps you really meant to have somthing like this:
temp_A := A;
for index in 0 to shift_value loop
temp_A := temp_A(30 downto 0) & '0';
end loop;
Upvotes: 3