Forum Discussion
Altera_Forum
Honored Contributor
8 years agoTricky's answer is certainly the most elegant way to do exactly what you asked.
If you wanted to test all possibilities, another way would be to use an unsigned 8-bit signal and just increment it by one each clock cycle. first is the upper 4-bits and second is the lower 4-bits. You could even get rid of first and second and just write:
signal counter : unsigned(7 downto 0) := (others => '0');
process
begin
wait until CLK'EVENT and CLK = '1';
counter <= counter + 1;
a3 <= counter(7);
a2 <= counter(6);
...
b3 <= counter(3);
...
b0 <= counter(0);
end process;
If your operands were larger, say 32-bits, you could increment by a value > 1 to limit the number of tests. If you're allowed to make a and b arrays (maybe call them first and second), it would get even simpler and then easily scales to other size operands.