Professional Documents
Culture Documents
Introduction
Cont..
Different Modeling techniques
A module can be described in any one (or a combination) of the
following modeling techniques.
Gate-level modeling using instantiation of primitive gates and user defined
modules.
This describes the circuit by specifying the gates and how they are connected with each
other.
Dataflow modeling using continuous assignment statements with the keyword
assign.
This is mostly used for describing combinational circuits.
Behavioral modeling using procedural assignment statements with keyword
always.
This is used to describe digital systems at a higher level of abstraction.
Gate-Level or Structural Modeling
Useful for,
gate instances and procedural statements
unnecessary in RTL specification
$<identifier>: System tasks and functions
$time
$stop
$finish
$monitor
#<delay specification>
System Tasks
11
Display tasks
$display : Displays the entire list at the time when statement is encountered
$monitor : Whenever there is a change in any argument, displays the entire list at end
of time step
Time
$time: gives the simulation time
Compiler Directives
12
c = a & b;
c = ~a;
a = 4’b1010;
b = 4’b1100;
c = a ^ b;
a = 4’b1010;
b = 2’b11;
17
Reduction Operators
18
& AND
| OR
^ XOR
~& NAND
~| NOR
~^ or ^~ XNOR
18
Shift Operators
19
19
Concatenation, Replication
Operators 20
• Concatenation
• {op1, op2, ..} concatenates op1, op2, .. to single number
• Operands must be sized !!
catx = {a, b, c};
caty = {b, 2’b11, a};
• Replication
repl = {4{a}, b, 2{c}};
Relational Operators
21
21
Equality Operators
22
== logical equality
Return 0, 1 or x
!= logical inequality
=== case equality
!== case inequality
• A = 3’b001; B = 2’b01; A == B?
22
Conditional Operator
23
cond_expr ? true_expr :
false_expr
23
Operator Precedence
24
Use parentheses to
enforce your
priority
24
Operator Example
25
module operator_eg(x,y,f1,f2);
input x,y;
output f1,f2;
wire [9:0] x,y;
wire [4:0]f1;
wire f2;
assign f1= x[4:0] & y[4:0];
assign f2= x[2] | f1[3];
assign f2= ~& x;
assign f1= f2 ? x[9:5] : x[4:0];
endmodule
Integer Arithmetic
26
Reference
27
Text Book:
Bhasker, Jayaram. A verilog HDL primer. Star Galaxy Publishing, 1999.
ModelSim Software
https://www.mentor.com/company/higher_ed/modelsim-student-edition
THANK YOU
28