If I have more reg
declared, every reg
needs to have his own always
block, for example:
output reg[3:0] A;
output reg[3:0] B;
output reg[3:0] C;
always @(posedge clock) begin
if(reset) begin
A <= 4'b0;
end
.
.
.
end
always @(posedge clock) begin
if(reset) begin
B <= 4'b0;
end
.
.
.
end
always @(posedge clock) begin
if(reset) begin
C <= 4'b0;
end
.
.
.
end
What if I have a loop, lets say something like this:
repeat n times
if(C<0) begin
shift C two positions
C <= C + 1;
else
shift A one position
A <= C + 1;
end
As you see here, inside of if(C<0)
block, I can't have
C <= C << 2;
C <= C + 1;
so I will need separate register to store C
shifted, let's say it will be output reg[8:0] shiftC
, so by the way I need separate always
block. And of course, separate always
block for A
too.
My question is, how can I make this loop work, if I use multiple always
blocks?
PS: here, number of bits is just informative, and does not matter.
C <= {C,2'b01};
. For more complex procedural logic I sugest adding a combinationalalways @*
block to assignC_next
(or other name of your choice) with blocking statements (=
), then in the synchronousalways @(posedge clock)
block assign asC <= C_next
\$\endgroup\$