ECE_103_Lecture33
ECE_103_Lecture33
IMPORTANT POINTS:
34
Behavioural Modelling: logic gates
Behavioural level
module logic_gates( input wire a, b, output reg y0,y1, y2, y3, y4, y5 );
always @(a,b)
begin
y0 = ~a;
y1 = a & b;
y2 = a | b;
y3 = ~(a & b);
y4 = ~(a | b);
y5 = a ^ b;
y6 = ~(a ^ b);
end
endmodule
35
Conditional Statements:
• If-else
• case
Synthesizable: Hardware is created.
Loops
• While
• For
• Forever
• Repeat
36
If else conditional statement
Type 1: if block
37
If else conditional statement
Type 3: if else-if…else
38
Example MUX: Behaviroal Modelling
39
If-else
40
case statement
41
4x1 Multiplexer using case - statement
42
Half Adder using case - statement
module ha(s,c,a,b);
input a,b;
output reg s,c;
always@(a,b)
begin
case({a,b})
2'b00 :begin s=1'b0; c=1'b0; end
2'b01 :begin s=1'b1; c=1'b0; end
2'b10 :begin s=1'b1; c=1'b0; end
2'b11 :begin s=1'b0; c=1'b1; end
default : begin s=1'b0; c=1'b0; end
endcase
end
endmodule
43
Loops
There are four types of looping statements in
Verilog:
• while
• for
• repeat
• Forever
44
While Loops
45
for Loop
for Loop contains three parts:
An initial condition;
A check to see if the terminating condition is true;
A procedural assignment to change value of the control variable
NOTE: for Loops are generally used when there is a fixed beginning
and end to the loop. If the Loop is simply looping on a certain
condition, it is better to use the while loop.
46
forever loop
forever loop does not contain any expression and executes forever until the
$finish task is encountered. A forever loop can be exited by the use of the
disable statement.
47
Assignment statements
48
Blocking and Non-blocking assignment
49