Multiple assignments in verilog

OP (Company: student) #3070822
I have written the following verilog codes.....The first one will 
execute in one clock cycle......But due to multiple assignments of 
variable ,the second code is not executing in one clock cycle.....Can 
anyone suggest any method so that the second code also will execute 
fully in one clock cycle????
PLZ HELP


//pgrm 1

always @(posedge clk)
begin

s<=8'h01;
s_rot <= 8'h01;
s_2<= 8'h03;
s_out1<= 8'h01;
s_out2<=8'h01;

end


//pgrm 2

always @(posedge clk)
begin

s<=(DATA_WIDTH-m);
s_rot <= s<<1;
s_2<=s+8'h03;
s_out1<=s_rot+8'h01;
s_out2<=s_rot+s_2;

end
Guest #3071752
I'd suggest you get a good learning book about Verilog, and read it at 
least 3 times. The concepts are not difficult but they are different 
from C programming.

You know '<=' is an unblocking assignment, right ? Good:

On the rising edge of the clock all registers will get updated with the 
current values that are on the right.
The values in the first example are fixed, then all registers get those 
values.

On the second example:

First rising edge

1. s_rot gets s shifted 1 to the left
2. s_2 gets s plus 3
3. s_out gets the current value of s (not yet shifted) plus 1
4. s_out2 gets the current value of s plus whatever value s_2 has

Second rising edge

The same as above... now s_out contains the shifted s plus 1...

Reply

A question of your own? This thread is over 13 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.