Professional Documents
Culture Documents
UNIVERSITY
Objectives
After completing this lecture, you will be able to: Understand the features of loop constructs
FALL 2011
S.Sivanantham
Loop Constructs
Loop constructs control the execution of a statement zero, one, or more times. i Loop constructs can appear only inside an initial or always block. block may contain delay expressions. Four types yp while loop executes a statement until an expression becomes false. for loop repeatedly executes a statement. repeat loop executes a statement a fixed number of times. forever f l loop continuously ti l executes t a statement. t t t
ECE301 VLSI System Design FALL 2011 S.Sivanantham
FALL 2011
S.Sivanantham
Note that: If we replace the blocking assignments by nonblocking assignments, the resulting program will not work properly. Why ? Try it! Explain it.
ECE301 VLSI System Design FALL 2011 S.Sivanantham
Note that: Please distinguish g the difference between this example p and the previous one.
ECE301 VLSI System Design FALL 2011 S.Sivanantham
is equivalent q to
init_expr; while (condition_expr) begin statement; t t t update_expr; end
FALL 2011
S.Sivanantham
Note that: If we replace the blocking assignments by nonblocking assignments, the resulting program will not work properly. Why ? Try it! Explain it.
ECE301 VLSI System Design FALL 2011 S.Sivanantham
// an example illustrating how to count the trailing zeros in a byte. module trailing_zero_for (data, out); input [7:0] data; output reg [3:0] out; // output declared as register integer i; // loop counter always @(data) begin out = 0; for (i = 0; data[i] == 0 && i <= 7; i = i + 1) // complex condition out = out + 1; end endmodule
Note that: Please distinguish the difference between this example and the previous one.
ECE301 VLSI System Design FALL 2011 S.Sivanantham
counter_expr t can be b a constant, t t a variable i bl or a signal i l value. counter_expr p is evaluated only y once before starting g the execution of statement (loop).
FALL 2011
S.Sivanantham
FALL 2011
S.Sivanantham
FALL 2011
S.Sivanantham