Professional Documents
Culture Documents
Data Flow & Behavioral Modeling
Data Flow & Behavioral Modeling
Expressions,operators,operands
describes system in terms of expressions instead of primitive gates. Expression formed using operands & operators. Operands are data types used in expression.they are : constant,parameter,net,register,bit select,part select,memory element. eg., c= a+ b => a, b,c operands Operators act on operand to produce desired result.
LOGICAL OPERATORS
&& logical AND || logical OR ! logical NOT Operands evaluated to ONE bit value: 0, 1 or x Result is ONE bit value: 0, 1 or x
A = 6; B = 0; C = x; A && B A || !B C || B 1 && 0 1 || 1 x || 0 0 1 x but C&&B=0
a = 4b1010; b = 4b1100;
c = a ^ b;
a = 4b1010; b = 2b11;
REDUCTION OPERATORS
& | ^ ~& ~| ~^ or ^~
AND
OR
XOR NAND NOR XNOR
SHIFT OPERATORS
>> <<
shift right shift left
CONCATENATION OPERATOR
{op1, op2, ..} concatenates op1, op2, .. to single number Operands must be sized !!
reg a; reg [2:0] b, c; .. a = 1b 1; b = 3b 010; c = 3b 101; catx = {a, b, c}; caty = {b, 2b11, a}; catz = {b, 1}; Replication .. catr = {4{a}, b, 2{c}};
RELATIONAL OPERATORS
> < >= <=
greater than less than greater or equal than less or equal than
b1x1 <= 0
10 < z
1 x x
EQUALITY OPERATORS
== != === !==
Return 0, 1 or x Return 0 or 1
4b 1z0x == 4b 1z0x 4b 1z0x != 4b 1z0x 4b 1z0x === 4b 1z0x 4b 1z0x !== 4b 1z0x
x x 1 0
CONDITIONAL OPERATOR
cond_expr ? true_expr : false_expr
Y = (sel)? A : B;
se l
Operator Precedence
CONTINUOUS ASSIGNEMENTS A
CLOSER LOOK
Syntax:
assign #del <id> = <expr>;
option al net type !!
Properties:
they all execute in parallel are order independent are continuously active
A
B Half Adder
S
C
Multiplexer
INITIAL BLOCKS
Start execution at sim time zero and finish when their last statement executes
module nothing; initial $display(Im first); initial begin #50; $display(Really?); end endmodule
ALWAYS BLOCKS
Start execution at sim time zero and continue until sim finishes
EVENTS (I)
@
always @(signal1 or signal2 or ..) begin execution triggers .. end every
time any signal changes execution triggers every time clk changes from 0 to 1 execution triggers every time clk changes from 1 to 0
Examples
3rd half adder implem
module half_adder(S, C, A,
B); output S, C; input A, B;
EVENTS (II)
wait (expr)
always begin wait (ctrl) execution loops every #10 cnt = cnt + 1; time ctrl = 1 (level #10 cnt2 = cnt2 + 2;
end
Example
re s Y always @(res or posedge clk) begin if (res) begin Y = 0; W = 0; end else begin Y = a & b; W = ~c; end end
a b
c clk
Timing (i)
d
c b 0 5 Time 1 0 1 5
Timing (ii)
d initial begin fork #5 c = 1; #5 b = 0; #5 d = c; join end Assignments are not blocked here c b 0 5 Time 1 0 1 5
PROCEDURAL ASSIGNMENT
Assignment statement within an initial or an always statement . 2 kinds :i)blocking assignments (ii)non-blocking Blocking: = operator is used. statements executed in they order they are specified. reg a = 2b 11; reg b = reg a Non-blocking: <= operator used allows scheduling without blocking execution of statements in sequential block. always @ (posedge clk) begin reg1 <= in1; reg2 <= reg 1;//old value of reg1 end
TIMING CONTROLS
Provides simulation time at which procedural statements execute. 3 forms:1)delay based(2)event(3)level sensitive Delay : i)regular :time between when statement is encountered and when executed. # 3 a=2b11; ii)intra-assignment :assignment to right x = 0;z=0; y = #10 x+z; iii)zero delay : statement executed last # 0 x=1; Level sensitive: waits for certain condition to be true before statement wait(enable) # 20 c=c+1;
CONTD.,
Event based timing control: change in value on reg or net.
Regular event: @(clk) q=d; Event or control:-transition on any one of multiple signals. always @ ( rst or clk or d) - Named event : declared by keyword event, triggered by symbol.
BLOCK STATEMENTS
Used to group multiple statement to act together. Sequential block: begin and end executed sequentially. Parallel block : fork and join executed concurrently. ordering controlled by delay. reg x,y; reg[1:0]z,w; initial fork x=1b0; #5 y=1b1; # 10 z = {x,y}; # 20 w = {y,x}; join
Procedural Statements: if
E.g. 4-to-1 mux:
module mux4_1(out, in, sel); output out; input [3:0] in; input [1:0] sel; reg out; wire [3:0] in; wire [1:0] sel;
always @(in or sel) if (sel == 0) out = in[0]; else if (sel == 1) out = in[1]; else if (sel == 2) out = in[2]; else out = in[3]; endmodule
case (expr) item_1, .., item_n: stmt1; item_n+1, .., item_m: stmt2; .. default: def_stmt; endcase
module mux4_1(out, in, sel); output out; input [3:0] in; input [1:0] sel; reg out; wire [3:0] in; wire [1:0] sel; always @(in or sel) case (sel) 0: out = in[0]; 1: out = in[1]; 2: out = in[2]; 3: out = in[3]; endcase endmodule
initial
Y = 0; always @(posedge start) for (i = 0; i < 3; i = i + 1) #10 Y = Y + 1; endmodule
initial Y = 0; always @(posedge start) begin i = 0; while (i < 3) begin #10 Y = Y + 1; i = i + 1; end end endmodule
forever stmt;
Executes until sim finishes
Mixed Model
Code that contains various both structure and behavioral styles
module simple(Y, c, clk, res); output Y; input c, clk, res;
re s c clk n Y