Given the following Verilog code, what value of "a" is displayed?
Submitted by: AdministratorGiven the following Verilog code, what value of "a" is displayed?
always @(clk) begin
a = 0;
a <= 1;
$display(a);
end
This is a tricky one! Verilog scheduling semantics basically imply a four-level deep queue for the current simulation time:
1: Active Events (blocking statements)
2: Inactive Events (#0 delays, etc)
3: Non-Blocking Assign Updates (non-blocking statements)
4: Monitor Events ($display, $monitor, etc).
Since the "a = 0" is an active event, it is scheduled into the 1st "queue". The "a <= 1" is a non-blocking event, so it's placed into the 3rd queue. Finally, the display statement is placed into the 4th queue.
Only events in the active queue are completed this sim cycle, so the "a = 0" happens, and then the display shows a = 0. If we were to look at the value of a in the next sim cycle, it would show 1.
Submitted by: Administrator
always @(clk) begin
a = 0;
a <= 1;
$display(a);
end
This is a tricky one! Verilog scheduling semantics basically imply a four-level deep queue for the current simulation time:
1: Active Events (blocking statements)
2: Inactive Events (#0 delays, etc)
3: Non-Blocking Assign Updates (non-blocking statements)
4: Monitor Events ($display, $monitor, etc).
Since the "a = 0" is an active event, it is scheduled into the 1st "queue". The "a <= 1" is a non-blocking event, so it's placed into the 3rd queue. Finally, the display statement is placed into the 4th queue.
Only events in the active queue are completed this sim cycle, so the "a = 0" happens, and then the display shows a = 0. If we were to look at the value of a in the next sim cycle, it would show 1.
Submitted by: Administrator
Read Online Electrical Engineering Job Interview Questions And Answers
Top Electrical Engineering Questions
☺ | CO2 fire extinguishers are indicated by the color code |
☺ | In a star connected three phase transformer the |
☺ | A single-phase double-wound transformer consists of |
☺ | A residual current device will disconnect under |
☺ | The usual method of insulating core laminations is |
Top Best Engineering Categories
☺ | Mechanical Engineering Interview Questions. |
☺ | Civil Engineering Interview Questions. |
☺ | Chemical Engineering Interview Questions. |
☺ | Electrical Engineering Interview Questions. |
☺ | Automobile Engineering Interview Questions. |