Behavioral Modeling: Unit - Iii
Behavioral Modeling: Unit - Iii
BEHAVIORAL MODELING:
• Introduction
• BEHAVIORAL MODELING
Operations and Assignments
• Functional Bifurcation
• Initial Construct, Always Construct
• Assignments with Delays Wait Construct
• Multiple Always Blocks
• Designs at Behavioral Level
• Blocking and Non-Blocking Assignments
• The case statement
• Simulation Flow
• if and if-else constructs
• assign–deassign construct, repeat construct, for loop, the disable construct,
while loop, forever loop, parallel blocks, force-release construct, Event.
BEHAVIORAL MODELING
BEHAVIORAL MODELING
Behavioral level modeling constitutes design
description at an abstract level.
BEHAVIORAL
executed only Once
MODELING
• In any assignment statement the left-hand side has to be a storage
type of element (and not a net). It can be a reg, integer, or real type
of variable. The right-hand side can be a storage type of variable or
a net.
initial
begin
a = 1'b0;
b = 1'b0;
#2 a = 1'b1;
#3 b = 1'b1;
#100$stop;
end
MULTIPLE INITIAL BLOCKS
modulenil1;
BEHAVIORAL MODELING
initial
reg a, b;
begin
a = 1'b0; b = 1'b0;
$display ($time, "display : a = %b, b = %b", a, b);
#2 a = 1'b1;
end
initial #100$stop;
initial
begin #2 b = 1'b1;
end
endmodule
ALWAYS CONSTRUCT
The always process signifies activities to be executed on
an “always basis.”
BEHAVIORAL MODELING
Its essential characteristics are:
• Any behavioral level design description is done using an
always block.
• The process has to be flagged off by an event or a
change in a net or a reg. Otherwise it ends in a stalemate.
• The process can have one assignment statement or
multiple assignment statements.
• Normally the statements are executed sequentially in the
order they appear.
EVENT CONTROL
The always block is executed repeatedly and endlessly. It
is necessary to specify a condition or a set of conditions,
BEHAVIORAL MODELING
which will steer the system to the execution of the block.
Alternately such a flagging-off can be done by
specifying an event preceded by the symbol “@”.
@(negedge clk) :executes the following block at the negative edge of clk.
@(posedge clk) : executes the following block at the positive edge of the
clk.
@clk : executes the following block at both the edges of clk.
@(prt or clr) :
@(posedge clk1 or negedge clk2) :
@ (a or b or c) can also write as @ (a or b or c) @ (a, b, c) @ (a, b or
c)
EXAMPLE COUNTER
module counterup(a,clk,N);
BEHAVIORAL
input clk;
MODELING
input[3:0]N;
output[3:0]a;
reg[3:0]a;
initial a=4'b0000;
endmodule
ASSIGNMENTS WITH DELAYS
always #3 b = a;
Values of a at the 3rd, 6th, 9th, etc., ns are sampled and assigned to
BEHAVIORAL
b. MODELING
Initial
begin
a = 1’b1;
b = 1’b0;
#1 a = 1’b0;
#3 a = 1’b1;
#1 a = 1’b0;
#2 a = 1’b1;
#3 a = 1’b0;
end
INTRA-ASSIGNMENT DELAYS
The “intra-assignment” delay carries out the assignment
in two parts.
BEHAVIORAL MODELING
An assignment with an intra-assignment has the form
A = # dl expression;
Here the expression is scheduled to be evaluated as soon
as it is encountered.
However, the result of the evaluation is assigned to the
right-hand side quantity a after a delay specified by dl.
dl can be an integer or a constant expression
always #2 a = a + 1;
always #b a = a + 1;
always #(b + c) a = a + 1;
ZERO DELAY
A delay of 0 ns does not really cause any delay.
BEHAVIORAL MODELING
However, it ensures that the assignment following is
executed last in the concerned time slot.
always
begin a = 1;
#0 a = 0;
end
WAIT CONSTRUCT
The wait construct makes the simulator wait for the
specified expression to be true before proceeding with
BEHAVIORAL MODELING
the following assignment or group of assignments.
Its syntax has the form
wait (alpha) assignment1;
alpha can be a variable, the value on a net, or an
expression involving them.
@clk a = b; assigns the value of b to a when clk changes;
wait (clk) #2 a = b; the simulator waits for the clock to
be high and then assigns b to a
BLOCKING AND NONBLOCKING ASSIGNMENTS
And
A=B;
B=A; // A, B will have same value
NONBLOCKING ASSIGNMENTS AND DELAYS
The principle of Delays of the intra-assignment type operation is
similar to that with blocking assignments.
BEHAVIORAL
always @(a or b)
#3 c1 = a&b;
MODELING
which has a delay of 3 ns for the blocking assignment to c1. If a or b
changes, the always block is activated. Three ns later, (a&b) is
evaluated and assigned to c1. The event “(a or b)” will be checked
for change or trigger again. If a or b changes, all the activities are
frozen for 3 ns. If a or b changes in the interim period, the block is
not activated. Hence the module does not depict the desired output.
always @(a or b)
c2 = #3 a&b;
The always block is activated if a or b changes. (a & b) is evaluated
immediately but assigned to c2 only after 3 ns. Only after the
delayed assignment to c2, the event (a or b) checked for change. If a
or b changes in the interim period, the block is not activated.
always @(a or b)
#3 c3 <= a&b;
BEHAVIORAL MODELING
The block is entered if the value of a or b changes but the
evaluation of a&b and the assignment to c3 take place with a
time delay of 3ns. If a or b changes in the interim period, the
block is not activated.
always @(a or b)
c4 <= #3 a&b;
represents the best alternative with time delay. The always block is activated if a or b
changes. (a&b) is evaluated immediately and scheduled for assignment to c4 with a
delay of 3 ns. Without waiting for the assignment to take effect (i.e., at the same time
step as the entry to the block), control is returned to the event control operator.
Further changes to a or b – if any – are again taken cognizance of.
THE CASE STATEMENT
simple construct for multiple branching in a module. The
keywords case, endcase, and default are associated with
BEHAVIORAL MODELING
the case construct.
Format of the case construct is
Case (expression)
Ref1 : statement1;
Ref2 : statement2;
Ref3 : statement3;
.. .
...
default: statementd;
endcase
EXAMPLE
moduledec2_4beh(o,i);
BEHAVIORAL MODELING
output[3:0]o;
input[1:0]i;
reg[3:0]o;
always@(i)
begin
case(i)
2'b00:o=4'h0;
2'b01:o=4'h1;
2'b10:o=4'h2;
2'b11:o=4'h4;
default: begin $display ("error");
o=4'h0;
CASEX AND CASEZ