with and without Semicolon at the end of delay statement in Verilog

Status
Not open for further replies.

imbichie

Full Member level 6
Joined
Jul 30, 2010
Messages
381
Helped
55
Reputation
110
Reaction score
54
Trophy points
1,308
Location
Cochin/ Kerala/ India or Bangalore/ Karnataka/ Ind
sites.google.com
Activity points
3,580
Hi All,

What is the difference between a without putting a semicolon at the end of @ (posedge spit_clk) and with a semicolon at the end of @ (posedge spit_clk), in the below task.

Means how it will affects the below if condition.

Code:
task Write_End;
    begin
        [B]@ (posedge spit_clk)[/B]
        if (spit_pready == 1'b1) 
        begin
            spit_psel    = 1'b0;   
            spit_penable = 1'b0;
            spit_pwrite  = 1'b0;
        end
    end
endtask
Code:
task Write_End;
    begin
        [B]@ (posedge spit_clk)[COLOR="#FF0000"];[/COLOR][/B]
        if (spit_pready == 1'b1) 
        begin
            spit_psel    = 1'b0;   
            spit_penable = 1'b0;
            spit_pwrite  = 1'b0;
        end
    end
endtask


also what is the difference between #20 and #20; and how it will affects the below statements
 
Last edited:

The semicolon closes the always block, an always block that doesn't enclose other instructions is meaningless.
 

What FvM said is gibberish.

Any procedural statement can be proceeded by one or more delay controls @(...) or timing controls #nnn. So

#20 @(posedge clk) A = A + 1;

could also be written as

#20; @(posedge clk); A = A + 1;

This assumes you are inside a begin/end block where the statements are executed serially. You can think of it as

#20 null_statement ; @(posedge clk) null_statement; A = A + 1;

You need to be careful how statements are grouped where only single statements are allowed. For example if you had

Code:
begin
  A = expr1;
  if (A ==5 ) #20; B = expr2;
  C = expr3;
end

The semicolon adter #20 creates two separate statements, and the B = expr2 is now unconditionally executed.
 
Reactions: FvM and imbichie

    imbichie

    Points: 2
    Helpful Answer Positive Rating

    FvM

    Points: 2
    Helpful Answer Positive Rating
#20 means "wait 20 time units before proceeding to execute the immediately following statement".

#20; means "wait 20 time units before proceeding to execute the immediately following statement, and oh BTW the immediately following statement is the empty statement".

"Empty statement?!? O_O" you ask? Yes.

Code:
always @(posedge clk) begin
;
;
;
;
end


There we go, 4 empty statements. Doesn't do all that much, but totally legit code.

So #20; effectively just waits 20 time units.

- - - Updated - - -

Repeat after me: refresh page before posting. refresh page before posting... Doh!

I see you already answered it.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…