Verilog GATE AND DATA FLOW
Verilog GATE AND DATA FLOW
Behavioral Description
Logic Synthesis
Layout Verification
implementation
Levels of Abstraction-1
Switch Level: Module implemented with
switches and interconnects. Lowest level of
Abstraction
Example:
module adder(sum,a,b);
…..
<functions>
…..
endmodule
Basic Concepts
Lexical Conventions
―White space – blank space\b, tabs\t, newline\n
―Comments – one line”\”, multiple line “/*”
―Operators – unary – a = ~b;
binary – a = b&&c;
ternary – a = b ? C : d;
Number specification
― Sized
― <size>'<baseformat><number>
―Unsized
― <baseformat>
Negative numbers
— Negative numbers are represented in 2’s complement form
— - 8`d12 // stored as 11110100
— - 6’d3 // 8 bit negative number stored as 2’s complement of 3
— 7’d-2 // illegal specification
X or Z values
Processor
wire r_w; // scalar signal
Memory
data
wire [7:0] data; // vector signal
wire [9:0] addr; // vector signal r_w
……
— Selecting a single bit or a portion of vector signals
data[2] single bit
data [5:3] 3 bits
― wire a;
― wire b, c;
Registers
― Registers represent data storage elements. Registers
retain value until another value is placed onto them.
― In Verilog, the term register merely means a variable
that can hold a value.
― Unlike a net, a register does not need a driver.
……
reg done; // scalar signal
reg [7:0] count; // vector signal
……
Fall delay
bufif0 #(4, 5, 6) b1(out, in, control); // rise =4, fall = 5, turn off = 6
module D(out, a, b, c);
// IO ports declarations
output out;
input a, b, c;
// Internal nets
wire e;
// instantiate primitive gates to build the circuit
and #5 (e, a, b);
or #4 (out, e, c);
endmodule
Test bench
◊ Continuous Assignments
basic statement
keywords
assign
syntax
left hand side always scalar or vector net
always active.
RHS can be registers or nets
delay values are of time units
Implicit Continuous Assignment
instead of declaring net and then wiring both can do as
follows
2. Operands
3. Operators
- operator types
3.1 Arithmetic Operators
- two types – binary and unary
Binary
- *, /, +, - , %
Unary
- +, - work as unary
3.2 Logical Operator
- logical and (&&), logical or(||), logical not(!)
3.3 Relational Operators
- greater (>), less (<), greater than or equal (>=) and less
than or equal (<=)
// A = 4, B = 3
// X = 4’b1010, Y = 4’b1101, Z = 4’b1xxx
// x = 4’b1010, y = 4’b0000
x | y //result is 4’b1010
x || y //result is 1
3.6 Reduction Operators
-and (&), or (|), xor (^), xnor (~^ or ^~), nand (~&),
nor (~|)
- // x = 4’b1010
y = { 4{A} }; // y = 4’b1111
y = { 4{A}, 2{B} } // y = 8’b11110000
3.10 Conditional Operators
- condition_expr ? True_expr : false_expr;
- assign addr_bus = driver_enable ? addr_out : 36’bz;
- assign out = control ? In1 : in0;
Condition can be nested
- assign out = (A = = 3) ? (control ? X : Y) : (control ? M : N);
3.11 Operator Precedence
4:1 MUX – method 1
module mux4_1(out, i0, i1, i2, i3, s0, s1);
output out;
input i0, i1, i2, i3;
input s0, s1;
assign out = (~s1 & ~s0 & i0) |
(~s0 & s1 & i1) |
(s0 & ~s1 & i2) |
(s0 & s1 & i3);
endmodule
4:1 MUX – method 2
module mux4_1(out, i0, i1, i2, i3, s0, s1);
output out;
input i0, i1, i2, i3;
input s0, s1;
// using net conditional operator
assign out = s1 ? (s0 ? i3 : i2) : (s0 ? i1 : i0);
endmodule
a
x
AND
b
OR
o
c
A
In
out
Design Module
module and_in2 (A,B,Q); //declare design module
input A, B; // declare inputs
output Q; // and output
wire Q; // declare output as net
assign Q = A & B; // realize and gate
endmodule
Test Bench Module