# Assign statement

**URL:** <https://verificationacademy.com/forums/t/assign-statement/42240>\
**Category:** SystemVerilog\
**Tags:** Dave-Rich, SystemVerilog, System-Verilog, Chris-Spear\
**Created:** [August 29, 2023, 10:23am UTC](https://verificationacademy.com/forums/t/assign-statement/42240 "2023-08-29T10:23:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![m\_v](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/a3d4f5/32.png) [@m\_v](https://verificationacademy.com/forums/u/m_v)\
**Post date:** [August 29, 2023, 10:23am UTC](https://verificationacademy.com/forums/t/assign-statement/42240/1 "2023-08-29T10:23:24Z")

</div>

```verilog
module test;
  reg [2:0]a = 3'b011;
  reg[2:0] b = 3'b010;
  reg[2:0] c = 3'b110;
  reg[2:0] out;
  
  
  initial begin
    assign out = (a == b) ? 1:0;
    $display("out = %b",out);
  end
endmodule

```

This code is working fine!  
can we write assign statement in initial begin?

---

<div class="post-metadata">

**Author:** ![cgales](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@cgales](https://verificationacademy.com/forums/u/cgales)\
**Post date:** [August 29, 2023, 11:45am UTC](https://verificationacademy.com/forums/t/assign-statement/42240/2 "2023-08-29T11:45:22Z")

</div>

_In reply to [m\_v](https://verificationacademy.com/forums/t/assign-statement/42240):_

Section 10.3 of the LRM discusses continuous assignments, and section 10.6 discusses procedural continuous assignments. You should read both sections and you can determine how your code is functioning.

---

<div class="post-metadata">

**Author:** ![m\_v](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/a3d4f5/32.png) [@m\_v](https://verificationacademy.com/forums/u/m_v)\
**Post date:** [August 31, 2023, 4:51am UTC](https://verificationacademy.com/forums/t/assign-statement/42240/3 "2023-08-31T04:51:36Z")

</div>

_In reply to [cgales](https://verificationacademy.com/forums/t/assign-statement/42240/2):_

Hi, i also checked same question on verification academy :-[https://verificationacademy.com/forums/systemverilog/drive-reg-using-continuous-assign](https://verificationacademy.com/forums/systemverilog/drive-reg-using-continuous-assign), Problem here is that in **Verilog** we can not write **reg type** variable on the **L.H.S** of the **assign statement**.

**Verilog** there are 3 types of assignments 1.continuous assignment 2.procedral assignment 3. procedural continuous assignment, and for **continuous assignment** at the **L.H.S**  **must be a net** it **can not be a reg type** , but when it is **procedural continuous assignment** then it is **valid to have reg at L.H.S** but we **can not write net**.

**System Verilog** also has this 3 types but here with **continuous assignment** when we write **reg** at **L.H.S** it is **valid** and **net** type also **valid** , with the **procedural continuous** assignment the L.H.S must be **reg** , **wire** is **invalid.**

Also one observation is that in **system Verilog** when you drive net with assign statement then the display is executed first(out = x) and then the assignment to the net is done if i put #0 delay as per the code the display will be executed in inactive region and the new value will be displayed(out = 1) and with reg it is working fine no need to put #0 delay, i am not able to find out why this is happening?

```verilog
module test;
  reg a = 1'b1;
  wire out;
  
  assign out = a ? 1:0;
  
  initial begin
    #0 $display("out = %b",out);
  end
endmodule

```

Thank you.

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [August 31, 2023, 11:03pm UTC](https://verificationacademy.com/forums/t/assign-statement/42240/4 "2023-08-31T23:03:09Z")

</div>

_In reply to [m\_v](https://verificationacademy.com/forums/t/assign-statement/42240/3):_

It is a time 0 race condition. Both results are valid.
