# nonblocking assignment

• non-blocking assignment statements execute in parallel
• In the non-blocking assignment, all the assignments will occur at the same time. (during the end of simulation timestamp)

## Nonblocking assignment example

In the below example,
a and b are initialized with values 10 and 15 respectively, after that b is being assigned to a (a value will become 15), and value 20 is assigned to b.
After assignment values expected in a and b are 15 and 20 respectively.
but these values will get assigned only after the simulation time-stamp.

```module nonblocking_assignment;

//variables declaration
int a,b;

initial begin  //initial block will get executed at starting of simulation
\$display("-----------------------------------------------------------------");
//initializing a and b
a = 10;
b = 15;

//displaying initial value of a and b
\$display("\tBefore Assignment :: Value of a is %0d",a);
\$display("\tBefore Assignment :: Value of b is %0d",b);

a <= b;
b <= 20;

\$display("\tAfter  Assignment :: Value of a is %0d",a);
\$display("\tAfter  Assignment :: Value of b is %0d",b);
\$display("-----------------------------------------------------------------");
end

final begin  //final block will get executed at end of simulation
\$display("-----------------------------------------------------------------");
\$display("\tEnd of Simulation :: Value of a is %0d",a);
\$display("\tEnd of Simulation :: Value of b is %0d",b);
\$display("-----------------------------------------------------------------");
end
endmodule```

Simulator Output:

```-----------------------------------------------------------------
Before Assignment :: Value of a is 10
Before Assignment :: Value of b is 15
After Assignment :: Value of a is 10
After Assignment :: Value of b is 15
-----------------------------------------------------------------
-----------------------------------------------------------------
End of Simulation :: Value of a is 15
End of Simulation :: Value of b is 20
-----------------------------------------------------------------```

Click to execute on

## Nonblocking assignment example-2

In the below example,
a and b are initialized with value 10 and 15 respectively.
x<=a+b and y<=a+b+x
value of x is sum of a (10) and b (15). -> x=10+15=25.
value of y is sum of a (10) ,b(15) and x (0) -> became at current simulation time-stamp value of x=0.
new value will get assigned at the end of current time stamp, and new value will be available only after the current time-stamp). therefore y=10+15+0=25;

```module nonblocking_assignment;
//variables declaration
int a,b;
int x,y;

initial begin
//initializing a and b
a = 10;
b = 15;

x <= a + b;
y <= a + b + x;

\$display("-----------------------------------------------------------------");
\$display("\tValue of x is %0d",x);
\$display("\tValue of y is %0d",y);
\$display("-----------------------------------------------------------------");
end

final begin
\$display("-----------------------------------------------------------------");
\$display("\tEnd of Simulation :: Value of x is %0d",x);
\$display("\tEnd of Simulation :: Value of y is %0d",y);
\$display("-----------------------------------------------------------------");
end

endmodule```

Simulator Output:

```-----------------------------------------------------------------
Value of x is 0
Value of y is 0
-----------------------------------------------------------------
-----------------------------------------------------------------
End of Simulation :: Value of x is 25
End of Simulation :: Value of y is 25
-----------------------------------------------------------------```

Click to execute on