Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Doubt on blocking and non_blocking statements ?

Status
Not open for further replies.

kbkdec15

Junior Member level 1
Joined
May 27, 2013
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,397
following two set of statements are result same.

set1:
fd1 =$fopen("binary.txt","r");
fd2 =$fopen("binary.txt","w");
fd3 =$fopen("hex.txt","r");
fd4 =$fopen("hex.txt","w");

set2:
fd1 <=$fopen("binary.txt");
fd2 <=$fopen("binary.txt");
fd3 <=$fopen("hex.txt");
fd4 <=$fopen("hex.txt");

what is difference between use of blocking and non blocking in this case ?
the two sets are executed in ISE 12 tool.

please clarify this .


regards
kbkdec15
 

You should get it into your head that non-blocking assignments are used to prevent race conditions when there are multiple processes synchronous to the same clock edge, otherwise you should always use blocking assignments.

What is a race condition? When one process tries to write and another process tries to read the same signal within a certain time-frame that the ordering cannot be guaranteed to know whether the read sees the new or the old value of the signal.

You have only shown the write statements, and not the reads, nor have you shown the processes that these statements are in.

If instead you had shown us

Code:
initial begin
        fd1 =$fopen("binary.txt","r");
        c = $fgetc(fd1);
       end
Then it makes a big difference which assignment operator writes to fd1.

A blocking assignment "blocks" the process until the assignment completes so that the next procedural statement in the process sees the new value. In a most blocking assignments, there is no specified delay so the process never gets suspended. It behaves just like any other normal assignment in most programming languages.
The non-blocking assignment is unique to RTL description languages, and I would have preferred to call it the RTL assignment operator. It does not complete the assignment before letting the next procedural statement execute, it never blocks. The assignment gets scheduled later, after all statements in all processes scheduled for the current time have executed. Then, just before the simulator would advance time, it updates all the assignment values, which might trigger more things to happen at the current time.

So by using a blocking assignment, the first statement writes to fd1 and the second statement reads the new value of fd1 just written.
If you had used a non blocking assignment, the second statement would see the old, uninitialized value of fd1.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top