Shankar Balachandran* Associate Professor, CSE Department Indian Institute of Technology Madras
*Currently a Visiting Professor at IIT Bombay
Digital Circuits and Systems
Spring 2015 Week 8 Module 46
Verilog Modeling (Assignment Statements)
Systems Verilog Modeling (Assignment Statements) Shankar - - PowerPoint PPT Presentation
Spring 2015 Week 8 Module 46 Digital Circuits and Systems Verilog Modeling (Assignment Statements) Shankar Balachandran* Associate Professor, CSE Department Indian Institute of Technology Madras *Currently a Visiting Professor at IIT Bombay
Shankar Balachandran* Associate Professor, CSE Department Indian Institute of Technology Madras
*Currently a Visiting Professor at IIT Bombay
Verilog Modeling (Assignment Statements)
Stuart Sutherland’s Material “Understanding Verilog
Blocking vs Nonblocking Statements 2
Two types
Continuous Procedural
Continuous
Outside of always statements, initial blocks etc Primarily, assign statements Left side should be declared as wires Wires should only one continuous assignment Done with = Example: assign sum = a ^ b;
Procedural
Inside always blocks and other procedural blocks
Blocking vs Nonblocking Statements 3
2/25/2015
Blocking
The assignment must complete before the next line is executed Blocks the flow of the program
Execution flow within the procedure is blocked until the assignment is
complete
Operator is =
always @(posedge clk) begin word[15:8] = word[ 7:0]; word[ 7:0] = word[15:8]; end //swap bytes in word??? always @(posedge clk) begin word[ 7:0] = word[15:8]; word[15:8] = word[ 7:0]; end //swap bytes in word??? These examples will not work if you want to swap the bytes.
2/25/2015
Evaluated and assigned in two steps:
The right-hand side is evaluated immediately The assignment to the left-hand side is postponed until other
Execution flow within the procedure continues until a
Operator is <= Both the following will swap the upper and lower bytes always @(posedge clk) begin word[15:8] <= word[ 7:0]; word[ 7:0] <= word[15:8]; end always @(posedge clk) begin word[ 7:0] <= word[15:8]; word[15:8] <= word[ 7:0]; end
Each Verilog simulation time step is divided into three
Q1 —(in any order) :
Evaluate RHS of all non-blocking assignments Evaluate RHS and change LHS of all blocking assignments Evaluate RHS and change LHS of all continuous assignments Evaluate inputs and change outputs of all primitives
Q2 —(in any order) :
Change LHS of all non-blocking assignments
Q3 —(in any order) :
Evaluate and print output from $monitor and $strobe
...
Blocking vs Nonblocking Statements 6
2/25/2015
The order of evaluation is determinate
A sequential blocking assignment evaluates and assigns before
A sequential non-blocking assignment evaluates, then continues
2/25/2015
The order of evaluation is indeterminate Concurrent blocking assignments have unpredictable
Concurrent nonblocking assignments have predictable
Which one to use for combinational buffer?
Which one to use for flipflop?
Blocking vs Nonblocking Statements 9
2/25/2015
Parallel Flops Shift Register
2/25/2015
Shift Register ???
2/25/2015
Combinational Logic
Generally use blocking assignments
Sequential Logic
Generally use non-blocking assignments
Exception:
Do not use a non-blocking assignment if another statement in the
2/25/2015
A = 5 and B = 5 in both cases
A = 5 and B = 4 in both cases
2/25/2015
A = 5 and B = 5 in both cases
2/25/2015
A(t) = E(t) and B = E(t-1) in Both Cases
A(t) = D(t-1) and B = D(t-2) in Both Cases
Blocking vs Nonblocking Statements 17