SlideShare a Scribd company logo
1 of 60
Download to read offline
WA
1
Digital Design Using Verilog
) begin
modulebeta(clk,reset,irq,…
Input[31:0]mem_data;
endm
oduleIf(done)$finish;
Figures by MIT OCW.
PC+4+4*SXT(C)
ASEL
0
1
Data Memory
RD
WD
Adr
R/W
WDSEL
0 1
2
Rc: <25:21>
0
1
XP
PC
JT
+4
Instruction
Memory
A
D
Rb: <15:11>
Ra: <20:16>
RA2SELRc: <25:21>
+
Register
File
RA1
RA2
RD1
RD2
BSEL
0
1
C: SXT(<15:0>)
Z
ALU
A
B
JT
WA
WD
WE
ALUFN
Control Logic
Z
ASEL
BSEL
PCSEL
RA2SEL
WDSEL
ALUFN
Wr
PC+4
0
1
Wr
0
1
2
3
4
XAdr
ILL
OP
WASEL
WASEL
IRQ
WERF
WERF
00
PCSEL
L02 – Verilog6.884 – Spring 2005 02/04/05
always @(posedge clk
assign pcinc = pc + 4;
for (i=0; i < 31; i = i+1) begin
Hardware Description Languages

In the beginning designs involved just a few 

gates, and thus it was possible to verify these 

circuits on paper or with breadboards

6.884 – Spring 2005 02/04/05 L02 – Verilog 2
Hardware Description Languages

As designs grew larger and more complex, designers
began using gate-level models described in a
Hardware Description Language to help with
verification before fabrication
6.884 – Spring 2005 02/04/05 L02 – Verilog 3
Hardware Description Languages

When designers began working
on 100,000 gate designs, these
gate-level models were too low-
level for the initial functional
specification and early high-
level design exploration
6.884 – Spring 2005 02/04/05 L02 – Verilog 4
Hardware Description Languages

Designers again turned to HDLs
specification and a framework
for help – abstract behavioral
models written in an HDL
provided both a precise
for design exploration
6.884 – Spring 2005 02/04/05 L02 – Verilog 5
Advantages of HDLs

Allows designers to talk about what the hardware
should do without actually designing the hardware
itself, or in other words HDLs allow designers to
separate behavior from implementation at various
levels of abstraction
HDLs do this with
modules and interfaces
Figure by MIT OCW.
6.884 – Spring 2005 02/04/05 L02 – Verilog 6
Advantages of HDLs

Allows designers to talk about what the hardware
should do without actually designing the hardware
itself, or in other words HDLs allow designers to
separate behavior from implementation at various
levels of abstraction
6.884 – Spring 2005 02/04/05 L02 – Verilog 7
Advantages of HDLs

Allows designers to talk about what the hardware
should do without actually designing the hardware
itself, or in other words HDLs allow designers to
separate behavior from implementation at various
levels of abstraction
6.884 – Spring 2005 02/04/05 L02 – Verilog 8
Advantages of HDLs

Allows designers to talk about what the hardware
should do without actually designing the hardware
itself, or in other words HDLs allow designers to
separate behavior from implementation at various
levels of abstraction
Processor
A
Processor
B
Processor
C
Network
Memory
A
Memory
B
Bank Bank
6.884 – Spring 2005 02/04/05 L02 – Verilog 9
Advantages of HDLs

Allows designers to talk about what the hardware
should do without actually designing the hardware
itself, or in other words HDLs allow designers to
separate behavior from implementation at various
levels of abstraction
– Designers can develop an executable functional specification
that documents the exact behavior of all the components and
their interfaces
– Designers can make decisions about cost, performance, 

power, and area earlier in the design process

– Designers can create tools which automatically manipulate 

the design for verification, synthesis, optimization, etc.

6.884 – Spring 2005 02/04/05 L02 – Verilog 10
A Tale of Two HDLs

VHDL

ADA-like verbose syntax, lots
of redundancy
Extensible types and
simulation engine
Design is composed of entities
each of which can have
multiple architectures
Gate-level, dataflow, and
behavioral modeling.
Synthesizable subset.
Harder to learn and use, DoD
mandate
Verilog
C-like concise syntax
Built-in types and logic
representations
Design is composed of modules
which have just one
implementation
Gate-level, dataflow, and
behavioral modeling.
Synthesizable subset.
Easy to learn and use, fast
simulation
6.884 – Spring 2005 02/04/05 L02 – Verilog 11
We will use Verilog …

Advantages
– Choice of many US design teams
– Most of us are familiar with C-like syntax
– Simple module/port syntax is familiar way to organize
hierarchical building blocks and manage complexity
– With care it is well-suited for both verification 

and synthesis

Disadvantages
– Some comma gotchas which catch beginners everytime
– C syntax can cause beginners to assume C semantics
– Easy to create very ugly code, good and consistent 

coding style is essential

6.884 – Spring 2005 02/04/05 L02 – Verilog 12
An HDL is NOT a

Software Programming Language

Software Programming Language

– Language which can be translated into machine instructions 

and then executed on a computer

Hardware Description Language

– Language with syntactic and semantic support for modeling the
temporal behavior and spatial structure of hardware
module foo(clk,xi,yi,done);
input [15:0] xi,yi;
output done;
always @(posedge clk)
begin:
if (!done) begin
if (x == y) cd <= x;
else (x > y) x <= x - y;
end
end
endmodule
6.884 – Spring 2005 02/04/05 L02 – Verilog 13
Hierarchical Modeling with Verilog

A Verilog module includes a module name and an
interface in the form of a port list
– Must specify direction and bitwidth for each port
module
input
adder( A, B, cout, sum );
[3:0] A, B;
adder
A B

output cout;
output [3:0] sum;
// HDL modeling of
// adder functionality
cout sum
endmodule
Don't forget the semicolon!
6.884 – Spring 2005 02/04/05 L02 – Verilog 14
Hierarchical Modeling with Verilog

A Verilog module includes a module name and an
interface in the form of a port list
– Must specify direction and bitwidth for each port
– Verilog-2001 introduced a succinct ANSI C style portlist
adder
A B
module adder( input [3:0] A, B,
output cout,
output [3:0] sum );
// HDL modeling of 4 bit
// adder functionality
cout sum endmodule
6.884 – Spring 2005 02/04/05 L02 – Verilog 15
Hierarchical Modeling with Verilog

A module can contain other modules through
module instantiation creating a module hierarchy
– Modules are connected together with nets
– Ports are attached to nets either by position or by name
FA
ba
c
cin
cout
module FA( input a, b, cin
output cout, sum );
// HDL modeling of 1 bit
// adder functionality
endmodule
6.884 – Spring 2005 02/04/05 L02 – Verilog 16
Hierarchical Modeling with Verilog

A module can contain other modules through
module instantiation creating a module hierarchy
– Modules are connected together with nets
– Ports are attached to nets either by position or by name
adder
A B
Scout
FA FA FA FA
module adder( input [3:0] A, B,
output cout,
output [3:0] S );
FA fa0( ... );
FA fa1( ... );
FA fa2( ... );
FA fa3( ... );
endmodule
6.884 – Spring 2005 02/04/05 L02 – Verilog 17
Hierarchical Modeling with Verilog

A module can contain other modules through 

module instantiation creating a module hierarchy

– Modules are connected together with nets
– Ports are attached to nets either by position
adder
A B
module adder( input [3:0] A, B,
output cout,
output [3:0] S );
cout S
wire c0, c1, c2;

FA fa0( A[0], B[0], 0, c0, S[0] );

FA fa1( A[1], B[1], c0, c1, S[1] );

FA fa2( A[2], B[2], c1, c2, S[2] );

FA fa3( A[3], B[3], c2, cout, S[3] );

FA FA FA FA
endmodule
Carry Chain
6.884 – Spring 2005 02/04/05 L02 – Verilog 18
Hierarchical Modeling with Verilog

A module can contain other modules through
module instantiation creating a module hierarchy
– Modules are connected together with nets
– Ports are attached to nets either by position or by name
adder
A B
Scout
FA FA FA FA
module adder( input [3:0] A, B,
output cout,
output [3:0] S );
wire c0, c1, c2;
FA fa0( .a(A[0]), .b(B[0]),
.cin(0), .cout(c0),
.sum(S[0] );
FA fa1( .a(A[1]), .b(B[1]),
...
endmodule
6.884 – Spring 2005 02/04/05 L02 – Verilog 19
Verilog Basics

Data Values Numeric Literals

4’b10_11
0 1 Underscores
are ignored
X Z
 Base format
(d,b,o,h)
Decimal number
representing size in bits
32’h8XXX_XXA3

6.884 – Spring 2005 02/04/05 L02 – Verilog 20
3 Common Abstraction Levels

Behavioral
Gate-Level
Dataflow
Module’s high-level algorithm is
implemented with little concern
for the actual hardware
Module is implemented by
specifying how data flows
between registers
Module is implemented in terms
of concrete logic gates (AND,
OR, NOT) and their
interconnections
6.884 – Spring 2005 02/04/05 L02 – Verilog 21
3 Common Abstraction Levels

Behavioral
Gate-Level
Dataflow
Designers can create
lower-level models from
the higher-level models
either manually or
automatically
The process of
automatically generating a
gate-level model from
either a dataflow or a
behavioral model is called
Logic Synthesis
6.884 – Spring 2005 02/04/05 L02 – Verilog 22
Gate-Level : 4-input Multiplexer

module mux4( input a, b, c, d
input [1:0] sel,
output out );
wire [1:0] sel_b;

not not0( sel_b[0], sel[0] );

not not1( sel_b[1], sel[1] );

Basic logic gates are built-in
primitives meaning there is no
need to define a module for
these gates
wire n0, n1, n2, n3;

and and0( n0, c, sel[1] );

and and1( n1, a, sel_b[1] ); sel[0]

and and2( n2, d, sel[1] );

and and3( n3, b, sel_b[1] );
sel[1]

wire x0, x1;

nor nor0( x0, n0, n1 ); c

nor nor1( x1, n2, n3 );

a
out
wire y0, y1; d
or or0( y0, x0, sel[0] );
bor or1( y1, x1, sel_b[0] );
nand nand0( out, y0, y1 );
endmodule
6.884 – Spring 2005 02/04/05 L02 – Verilog 23
Dataflow : 4-input Multiplexer

module mux4( input a, b, c, d
input [1:0] sel,
output out );
wire out, t0, t1;

assign t0 = ~( (sel[1] & c) | (~sel[1] & a) );

assign t1 = ~( (sel[1] & d) | (~sel[1] & b) );

assign out = ~( (t0 | sel[0]) & (t1 | ~sel[0]) );

endmodule
This is called a continuous assignment
since the RHS is always being evaluated
and the result is continuously being
driven onto the net on the LHS
6.884 – Spring 2005 02/04/05 L02 – Verilog 24
Dataflow : 4-input Multiplexer

module mux4( input a, b, c, d
input [1:0] sel,
output out );
wire t0 = ~( (sel[1] & c) | (~sel[1] & a) );
wire t1 = ~( (sel[1] & d) | (~sel[1] & b) );
wire out = ~( (t0 | sel[0]) & (t1 | ~sel[0]) );
endmodule
An implicit continuous assignment combines
the net declaration with an assign statement
and thus is more succinct
6.884 – Spring 2005 02/04/05 L02 – Verilog 25
Dataflow : 4-input Mux and Adder

// Four input muxltiplexor
module mux4( input a, b, c, d
Dataflow style Veriloginput [1:0] sel,
output out ); enables descriptions
which are more
assign out = ( sel == 0 ) ? a :
( sel == 1 ) ? b :
abstract than gate-
( sel == 2 ) ? c :
level Verilog
( sel == 3 ) ? d : 1’bx;
endmodule
// Simple four bit adder
module adder( input
output [3:0]
[3:0] op1, op2,
sum );
assign sum = op1 + op2;
endmodule
6.884 – Spring 2005 02/04/05 L02 – Verilog 26
Dataflow : Key Points

Dataflow modeling enables the designer to focus
on where the state is in the design and how the
data flows between these state elements without
becoming bogged down in gate-level details
– Continuous assignments are used to connect 

combinational logic to nets and ports

– A wide variety of operators are available including:
Arithmetic: + - * / % **

Logical: ! && || Avoid these 

Relational: > < >= <= operators since 

Equality: == != === !=== they usually 

Bitwise: ~ & | ^ ^~ synthesize poorly

Reduction: & ~& | ~| ^ ^~

Shift: >> << >>> <<<

Concatenation: { }

Conditional: ?:

6.884 – Spring 2005 02/04/05 L02 – Verilog 27
Dataflow : Key Points

Dataflow modeling enables the designer to focus
on where the state is in the design and how the
data flows between these state elements without
becoming bogged down in gate-level details
– Continuous assignments are used to connect 

combinational logic to nets and ports

– A wide variety of operators are available including:
Arithmetic: + - * / % **

Logical: ! && ||

Relational: > < >= <=
assign signal[3:0] 

Equality:
~ & | ^ ^~
& ~& | ~| ^ ^~
>> << >>> <<<
?:
== != === !===
= { a, b, 2’b00 }

Bitwise: 

Reduction: 

Shift: 

Concatenation: { }

Conditional: 

6.884 – Spring 2005 02/04/05 L02 – Verilog 28
Behavioral : 4-input Multiplexer 

module mux4( input a, b, c, d
input [1:0] sel,
output out );
reg out;
always @( a or b or c or d or sel )

begin

if ( sel == 0 )
 An always block is a behavioral
out = a;
block which contains a list of
else if ( sel == 1 )
expressions which are (usually)out = b

else if ( sel == 2 )
 evaluated sequentially
out = c
The code in an always block canelse if ( sel == 3 )

out = d 
 be very abstract (similar to C
end code) – here we implement a mux
with an if/else statement
endmodule
6.884 – Spring 2005 02/04/05 L02 – Verilog 29
Behavioral : 4-input Multiplexer 

module mux4( input a, b, c, d
input [1:0] sel,
output out );
else if ( sel == 2 )

out = c

else if ( sel == 3 )

out = d 

if any of these
signals change then the always
block is executed
reg out;
( a or b or c or d or
begin
if
out = a;
out = b
An always block can include a
sensitivity list –
always @ sel )
( sel == 0 )
else if ( sel == 1 )
end
endmodule
6.884 – Spring 2005 02/04/05 L02 – Verilog 30
Behavioral : 4-input Multiplexer 

module mux4( input a, b, c, d
input [1:0] sel,
output out );
reg out;
begin
if
out = a;
out = b
always @( a, b, c, d, sel )
( sel == 0 )
else if ( sel == 1 )
In Verilog-2001 we can use a
else if ( sel == 2 ) comma instead of the or
out = c
else if ( sel == 3 )
out = d
end
endmodule
6.884 – Spring 2005 02/04/05 L02 – Verilog 31
Behavioral : 4-input Multiplexer 

module mux4( input a, b, c, d
input [1:0] sel,
output out );
reg out;
always @( a, b, c, d, sel )
begin
if ( sel == 0 )
out = a;
else if ( sel == 1 )
out = b
else if ( sel == 2 )
out = c
else if ( sel == 3 )
out = d
end
endmodule
What happens if we accidentally
leave off a signal on the
sensitivity list?
The always block will not
execute if just d changes – so if
sel == 3 and d changes then
out will not be updated
This will cause discrepancies
between simulated and
synthesized hardware – there
are no sensitivity lists in real
hardware so it would work fine!
6.884 – Spring 2005 02/04/05 L02 – Verilog 32
Behavioral : 4-input Multiplexer 

module mux4( input a, b, c, d
input [1:0] sel,
output out );
reg out;
begin
( * )
if
always @
( sel == 0 )
out = a;
else if ( sel == 1 )
out = b
else if ( sel == 2 )
out = c
else if ( sel == 3 )
out = d
end
endmodule
In Verilog-2001 we can use the
@(*) construct which creates a
sensitivity list for all signals
read in the always block
6.884 – Spring 2005 02/04/05 L02 – Verilog 33
Behavioral : 4-input Multiplexer 

module mux4( input a, b, c, d
input [1:0] sel,
output out );
reg out;
always @( * )

begin

case ( sel )

Always blocks can contain case0 : out = a;
statements, for loops, while loops,1 : out = b;
2 : out = c; even functions – they enable
3 : out = d; high-level behavioral modeling
endcase

end

endmodule
6.884 – Spring 2005 02/04/05 L02 – Verilog 34
Behavioral : 4-input Multiplexer 

module mux4( input a, b, c, d
input [1:0] sel,
output out );
reg out; What about this funny No! and whoever
reg statement? decided on the reg
always @( * ) Is this how you create syntax really
begin a register in Verilog? messed things up!
case ( sel )
0 : out = a;
1 : out = b;
2 : out = c;
3 : out = d;
endcase

end

endmodule
35L02 – Verilog02/04/05
Figure by MIT OCW.
6.884 – Spring 2005
Behavioral : 4-input Multiplexer 

module mux4( input a, b, c, d
input [1:0] sel,
output out );
reg out;
In Verilog a reg is just a variable –
always @( * ) when you see reg think variable not
begin
case ( sel )
hardware register!
0 : out = a; Any assignments in an always block
1 : out = b;
2 : out = c;
must assign to a reg variable – the
3 : out = d; reg variable may or may not actually
endcase represent a hardware register
end
If the always block assigns a value to
endmodule the reg variable for all possible
executions then the reg variable is
not actually a hardware register
6.884 – Spring 2005 02/04/05 L02 – Verilog 36
Behavioral : 4-input Multiplexer 

module mux4( input a, b, c, d
input [1:0] sel,
output out );
reg out;
always @( * )
begin
case ( sel )
0 : out = a;
1 : out = b;
2 : out = c;
3 : out = d;
endcase

end

endmodule
What about in this
situation? Will the
generated hardware
include a latch for out?
Figure by MIT OCW.
6.884 – Spring 2005 02/04/05 L02 – Verilog 37
Behavioral : 4-input Multiplexer 

module mux4( input a, b, c, d
input [1:0] sel,
output out );
reg out;
always @( * )
begin
case ( sel )
0 : out = a;
1 : out = b;
2 : out = c;
3 : out = d;
endcase

end

endmodule
Maybe! What if sel == xx?
Then out is unassigned and
the hardware must maintain
the previous value of out!
Figure by MIT OCW.
6.884 – Spring 2005 02/04/05 L02 – Verilog 38
Behavioral : 4-input Multiplexer 

module mux4( input a, b, c, d
input [1:0] sel,
output out );
Fix it with a default clause
in the case statement –reg out;
always @( * )
then no hardware latch is
begin inferred
case ( sel )
default : out = 1’bx;
0 : out = a;
1 : out = b;
2 : out = c;
3 : out = d;
endcase

end

endmodule
Figure by MIT OCW.
6.884 – Spring 2005 02/04/05 L02 – Verilog 39
Behavioral Non-Blocking Assignments

always @( posedge clk )
begin
x = next_x;
end
next_x D Q X
clk
always @( posedge clk )
begin
x = next_x;
y = x;
end
next_x D Q
clk
X
Y
always @( posedge clk )
begin
x <= next_x;
end
next_x D Q X
clk
always @( posedge clk )
begin
x <= next_x;
y <= x;
end
D Q
X
next_x D Q Y
clk clk
6.884 – Spring 2005 02/04/05 L02 – Verilog 40
Behavioral Non-Blocking Assignments

always @( posedge clk )
begin
y = x;
x = y;
end
X Y
Take Away Point - always ask
yourself β€œDo I need blocking or
non-blocking assignments for this
always block?”
Never mix and match!
always @( posedge clk )
begin
y <= x;
x <= y;
end
D Q
D Q
X
clk
Y
clk
6.884 – Spring 2005 02/04/05 L02 – Verilog 41
Which abstraction is the right one?

Designers usually use a mix of all three! Early on in 

the design process they might use mostly behavioral 

models. As the design is refined, the behavioral 

models begin to be replaced by dataflow models. 

Finally, the designers use automatic tools to 

synthesize a low-level gate-level model.

Behavioral
Dataflow
Gate-Level
6.884 – Spring 2005 02/04/05 L02 – Verilog 42
Revisiting Logic Synthesis

Behavioral
Gate-Level
Dataflow
Modern tools are able to
synthesize more and more
behavioral Verilog code
directly to the gate-level
The problem though, is
that it is very hard to
predict what the generated
hardware will look like
This makes it difficult to
perform rational design
space exploration
6.884 – Spring 2005 02/04/05 L02 – Verilog 43
Revisiting Logic Synthesis

Behavioral
Gate-Level
Dataflow
In this course we will
mostly stick to very
predictable dataflow to
gate-level synthesis – we
want to have a good idea
what kind of hardware we
are generating!
6.884 – Spring 2005 02/04/05 L02 – Verilog 44
Writing Parameterized Models

module mux4 #( parameter width )
( input [width-1:0] a, b, c, d
input [1:0] sel,
output [width-1:0] out );
...
endmodule
// Specify parameters at instantiation time
mux4 #( .width(32) )
alu_mux( .a(op1), .b(bypass), .c(
.sel(alu_mux_sel), .out(alu_mux_out) );
32’b0), .d(32’b1),
Parameters enable static configuration of modules at
instantiation time and can greatly increase the
usefulness of your modules
6.884 – Spring 2005 02/04/05 L02 – Verilog 45
Writing Parameterized Models

module adder #( parameter width )
( input [width-1:0] op1,op2,
output cout,
output [width-1:0] sum );
wire [width-1:0] carry;
assign
assign
carry[0] = 0;
cout = carry[width]
genvar i; Generate blocks can
generate
for
begin
( i = 0; i < width; i = i+1 )
: ripple
use parameters to
FA fa( op1[i], op2[i],

carry[i], carry[i+1] );

end

instantiate a variable
number of sub-modules
or to create a variable
number of nets
endgenerate
endmodule
6.884 – Spring 2005 02/04/05 L02 – Verilog 46
Static Elaboration

Model
Synthesis
Gate-Level
Elaborated Model
Static Elaboration
6.884 – Spring 2005 02/04/05 L02 – Verilog 47
Larger Examples

Let’s briefly examine two larger digital designs 

and consider the best way to model 

these designs in Verilog

GCD Beta
6.884 – Spring 2005 02/04/05 L02 – Verilog 48
GCD Behavioral Example

module gcd_behavioral #( parameter width = 16 )
( input [width-1:0] A_in, B_in,
output [width-1:0] Y );
reg [width-1:0] A, B, Y, swap;

integer done;

always @( A_in or B_in )

begin

done = 0;

A = A_in; B = B_in;

while
begin
( !done )
if ( A < B )

begin

We write the generalswap = A;

A = B;
 algorithm in an always block
B = swap;
using a very C-like syntaxend
else if ( B != 0 )

A = A - B;

else
done = 1;
end
Y = A;
end
endmodule
6.884 – Spring 2005 02/04/05 L02 – Verilog 49
module gcd_test;
parameter width = 16;
GCD Behavioral
reg [width-1:0] A_in, B_in;
wire [width-1:0] Y;
Test Harness
gcd_behavioral #( .width(width) )

gcd_unit( .A_in(A_in), .B_in(B_in), .Y(Y) );

initial

begin

// Default inputs if cmdline args
// are not provided
A_in = 27;

B_in = 15;

// Read in cmdline args
$value$plusargs
$value$plusargs
("a-in=%d",A_in);
("b-in=%d",B_in);
// Let the simulation run
#10;
// Output the results
$display(" a-in = %d", A_in );
$display(" b-in = %d", B_in );
$display(" gcd-out = %d", Y );
$finish;
end
endmodule
We use a test harness to drive
the GCD module. The test
harness includes an initial block,
which is similar to always block
except it executes only once at
time = 0.
Special directives which begin
with $ enable the test harness
to read command line arguments,
use file IO, print to the screen,
and stop the simulation
6.884 – Spring 2005 02/04/05 L02 – Verilog 50
Design Strategy
Partition into control and datapath
Keep all functional code in the leaf modules
GCD RTL Example

go done
Control Unit
zero? lt out
A_in

A

sub

B_in

B

Design Strategy
Partition into control and datapath
Keep all functional code in the leaf modules
6.884 – Spring 2005 02/04/05 L02 – Verilog 51
GCD RTL Datapath

module gcd_dpath #( parameter width = 16 )
( input clock,
input A_en, B_en, A_mux_sel, B_mux_sel, out_mux_sel,
input [width-1:0] A_in, B_in,
output B_zero, A_lt_B,
output [width-1:0] Y );
reg [width-1:0] A, B;

assign Y = A;

// Datapath logic
wire [width-1:0] out = ( out_mux_sel ) ? B : A - B;

wire [width-1:0]
wire [width-1:0]
A_next = ( A_mux_sel ) ? out : A_in;
B_next = ( B_mux_sel ) ? A : B_in;

// Generate output control signals
wire
wire
B_zero = ( B == 0 );
A_lt_B = ( A < B );
A mix of dataflow
and behavioral

// Edge-triggered flip-flops Edge-triggered

always @( posedge clock )
flip-flops with
begin

if ( A_en ) enables

A <= A_next;

if ( B_en )

B <= B_next;

end
endmodule
6.884 – Spring 2005 02/04/05 L02 – Verilog 52
GCD RTL Control Unit

module gcd_ctrl ( input
input
clock, reset, go,
B_zero, A_lt_B,
output A_en, B_en, A_mux_sel, B_mux_sel, out_mux_sel,
output done );
// The running bit is one after go goes high and until done goes high
reg running = 0;

always @( posedge clock )

begin

if ( go ) running <= 1;

else if ( done ) running <= 0;

end

// Combinational control logic - we group all the control signals

// onto one bus to make the Verilog more concise

reg [5:0] ctrl_sig;

assign { A_en, B_en, A_mux_sel, B_mux_sel, out_mux_sel, done } = ctrl_sig;

always @(*)

begin
if ( !running ) ctrl_sig = 6'b11_00x_0; // Latch in A and B values
else if ( A_lt_B ) ctrl_sig = 6'b11_111_0; // A <= B and B <= A
else if ( !B_zero ) ctrl_sig = 6'b10_1x0_0; // A <= A - B and B <= B
else ctrl_sig = 6'b00_xxx_1; // Done
end
endmodule
6.884 – Spring 2005 02/04/05 L02 – Verilog 53
GCD Testing

We use the same test inputs to test both the
behavioral and the RTL models. If both models
have the exact same observable behavior then the
RTL model has met the functional specification.
Test Inputs
Behavioral
Model
RTL
Model
Identical
Outputs?
6.884 – Spring 2005 02/04/05 L02 – Verilog 54
WA
Beta Redux
 I thought I already did
ILL

XAdr OP JT
 6.004
PCSEL 4 3 2 1 0
PC 00
A Instruction

Memory

+4 D
Ra: <20:16> Rb: <15:11> Rc: <25:21>
+
0 1 RA2SEL
WASEL
RA2XP
RA1 Register
Rc: <25:21>
1
WA
File
WD
0
RD1 RD2 WE WERF
Z Figure by MIT OCW.
JT
PC+4+4*SXT(C)
C: SXT(<15:0>)
IRQ Z
ASEL 1 0 1 0 BSEL
Control Logic
PCSEL
RA2SEL A B
ASEL
ALUFN ALU WD R/W Wr
BSEL
WDSEL Data Memory
ALUFN Adr RD
Wr
WERF
WASEL
PC+4
0 1 2 WDSEL
6.884 – Spring 2005 02/04/05 L02 – Verilog 55
Goals for the Beta Verilog Description

Readable, correct code that clearly
captures the architecture diagram – β€œcorrect by inspection”
Partition the design into regions appropriate for different
implementation strategies. Big issue: wires are β€œbad” since they
take up area and have capacitance (impacting speed and power).
– Memories: very dense layouts, structured wires pretty much route 

themselves, just a few base cells to design & verify.

– Datapaths: each cell contains necessary wiring, so replicating cells (for N
bits of datapath) also replicates wiring. Data flows between columnar
functional units on horizontal busses and control flows vertically.
– Random Logic: interconnect is β€œrandom” but library of cells can be 

designed ahead of time and characterized.

– Think about physical partition since wires that cross boundaries can take
lots of area and blocks have to fit into the floorplan without wasteful
gaps.
6.884 – Spring 2005 02/04/05 L02 – Verilog 56
Hey! What happened to abstraction?

Wasn’t the plan to 

abstract-away the physical 

details so we could 

concentrate on getting the 

functionality right? Why 

are we worrying about wires 

Because life is short! If you
have the luxury of writing two
models (the first to experiment
with function, the second to
describe the actual partition you
want to have), by all means! But
with a little experience you can
tackle both problems at once.
and floorplans at this stage?
6.884 – Spring 2005 02/04/05 Figure by MIT OCW. L02 – Verilog 57
WA
Divide and Conquer
(C)
01
RD
WD R/W
0 1 2
0
1XP
PC
JT
+4
A
D
+
Register
File
RA1
RD1 RD2
01
)
Z
A B
JT
WA WD
WE
Control Logic
Z
Wr
PC+4
0 1
Wr
01234
ILL
OP
IRQ
00
Step 1: identify memories
1
1
1
Step 2: identify datapaths
2
2
PC
Main Datapath
What’s left is random logic …
PC+4+4*SXT
ASEL
Data Memory
Adr
WDSEL
Rc: <25:21>
Instruction
Memory
Rb: <15:11>Ra: <20:16>
RA2SEL
Rc: <25:21>
RA2
BSEL
C: SXT(<15:0>
ALUALUFN
ASEL
BSEL
PCSEL
RA2SEL
WDSEL
ALUFN
XAdr
WASEL
WASEL
WERF
WERF
PCSEL
6.884 – Spring 2005 02/04/05 L02 – Verilog 58
Take Away Points

Hardware description languages are an essential
part of modern digital design
– HDLs can provide an executable functional specification
– HDLs enable design space exploration early in design process
– HDLs encourage the development of automated tools
– HDLs help manage complexity inherent in modern designs
Verilog is not a software programming language so
always be aware of how your Verilog code will map
into real hardware
Carefully plan your module hierarchy since this will
influence many other parts of your design
6.884 – Spring 2005 02/04/05 L02 – Verilog 59
Laboratory 1

You will be building an RTL model of a 

two-stage MIPS processor

1.	 Read through the lab and the SMIPS processor
spec which is posted on the labs section
2. Look over the Beta Verilog posted on the MIT server

3. Try out the GCD Verilog example
(or on any MIT server/Linux machine)
% setup 6.884

% cp –r /mit/6.884/examples/gcd .

% cat gcd/README

4. Next week’s tutorial will review the Beta
implementation and describe how to use Lab 1
toolchain (vcs, virsim, smips-gcc)
6.884 – Spring 2005 02/04/05	 L02 – Verilog 60

More Related Content

What's hot

Setup and hold time violation in flip-flops
Setup and hold time violation in flip-flopsSetup and hold time violation in flip-flops
Setup and hold time violation in flip-flopsJong Hwan Shin
Β 
Synchronous and asynchronous clock
Synchronous and asynchronous clockSynchronous and asynchronous clock
Synchronous and asynchronous clockNallapati Anindra
Β 
Amba axi 29 3_2015
Amba axi 29 3_2015Amba axi 29 3_2015
Amba axi 29 3_2015kiemnhatminh
Β 
Delays in verilog
Delays in verilogDelays in verilog
Delays in verilogJITU MISTRY
Β 
Day2 Verilog HDL Basic
Day2 Verilog HDL BasicDay2 Verilog HDL Basic
Day2 Verilog HDL BasicRon Liu
Β 
Design and implementation of 32 bit alu using verilog
Design and implementation of 32 bit alu using verilogDesign and implementation of 32 bit alu using verilog
Design and implementation of 32 bit alu using verilogSTEPHEN MOIRANGTHEM
Β 
Multipliers in VLSI
Multipliers in VLSIMultipliers in VLSI
Multipliers in VLSIKiranmai Sony
Β 
RTL-Design for beginners
RTL-Design  for beginnersRTL-Design  for beginners
RTL-Design for beginnersDr.YNM
Β 
axi protocol
axi protocolaxi protocol
axi protocolAzad Mishra
Β 

What's hot (20)

Crash course in verilog
Crash course in verilogCrash course in verilog
Crash course in verilog
Β 
Setup and hold time violation in flip-flops
Setup and hold time violation in flip-flopsSetup and hold time violation in flip-flops
Setup and hold time violation in flip-flops
Β 
Synchronous and asynchronous clock
Synchronous and asynchronous clockSynchronous and asynchronous clock
Synchronous and asynchronous clock
Β 
Amba axi 29 3_2015
Amba axi 29 3_2015Amba axi 29 3_2015
Amba axi 29 3_2015
Β 
Verilog
VerilogVerilog
Verilog
Β 
Verilog hdl
Verilog hdlVerilog hdl
Verilog hdl
Β 
Delays in verilog
Delays in verilogDelays in verilog
Delays in verilog
Β 
8251 USART
8251 USART8251 USART
8251 USART
Β 
Data Flow Modeling
Data Flow ModelingData Flow Modeling
Data Flow Modeling
Β 
Day2 Verilog HDL Basic
Day2 Verilog HDL BasicDay2 Verilog HDL Basic
Day2 Verilog HDL Basic
Β 
Design and implementation of 32 bit alu using verilog
Design and implementation of 32 bit alu using verilogDesign and implementation of 32 bit alu using verilog
Design and implementation of 32 bit alu using verilog
Β 
Behavioral modelling in VHDL
Behavioral modelling in VHDLBehavioral modelling in VHDL
Behavioral modelling in VHDL
Β 
AMBA AHB 5
AMBA AHB 5AMBA AHB 5
AMBA AHB 5
Β 
Multipliers in VLSI
Multipliers in VLSIMultipliers in VLSI
Multipliers in VLSI
Β 
RTL-Design for beginners
RTL-Design  for beginnersRTL-Design  for beginners
RTL-Design for beginners
Β 
Axi protocol
Axi protocolAxi protocol
Axi protocol
Β 
Study of vlsi design methodologies and limitations using cad tools for cmos t...
Study of vlsi design methodologies and limitations using cad tools for cmos t...Study of vlsi design methodologies and limitations using cad tools for cmos t...
Study of vlsi design methodologies and limitations using cad tools for cmos t...
Β 
VHDL CODES
VHDL CODES VHDL CODES
VHDL CODES
Β 
axi protocol
axi protocolaxi protocol
axi protocol
Β 
UART
UARTUART
UART
Β 

Similar to Basics of digital verilog design(alok singh kanpur)

Verilog overview
Verilog overviewVerilog overview
Verilog overviewposdege
Β 
L6_Slides_vhdl coures temporary hair dye for dark hair
L6_Slides_vhdl coures temporary hair dye for dark hairL6_Slides_vhdl coures temporary hair dye for dark hair
L6_Slides_vhdl coures temporary hair dye for dark hairloyad20119
Β 
Floating point ALU using VHDL implemented on FPGA
Floating point ALU using VHDL implemented on FPGAFloating point ALU using VHDL implemented on FPGA
Floating point ALU using VHDL implemented on FPGAAzhar Syed
Β 
Digital design with Systemc
Digital design with SystemcDigital design with Systemc
Digital design with SystemcMarc Engels
Β 
Verilog presentation final
Verilog presentation finalVerilog presentation final
Verilog presentation finalAnkur Gupta
Β 
Short.course.introduction.to.vhdl for beginners
Short.course.introduction.to.vhdl for beginners Short.course.introduction.to.vhdl for beginners
Short.course.introduction.to.vhdl for beginners Ravi Sony
Β 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorialamnis_azeneth
Β 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorialAbhiraj Bohra
Β 
Hardware Description Language
Hardware Description Language Hardware Description Language
Hardware Description Language Prachi Pandey
Β 
Short.course.introduction.to.vhdl
Short.course.introduction.to.vhdlShort.course.introduction.to.vhdl
Short.course.introduction.to.vhdlRavi Sony
Β 
Unit 5_Realizing Applications in FPGA.pdf
Unit 5_Realizing Applications in FPGA.pdfUnit 5_Realizing Applications in FPGA.pdf
Unit 5_Realizing Applications in FPGA.pdfkanyaakiran
Β 
Xilinx Training in Jalandhar Chandigarh
Xilinx Training in Jalandhar ChandigarhXilinx Training in Jalandhar Chandigarh
Xilinx Training in Jalandhar ChandigarhE2Matrix
Β 
Xilinx Training in Phagwara Jalandhar
Xilinx Training in Phagwara JalandharXilinx Training in Phagwara Jalandhar
Xilinx Training in Phagwara JalandharE2Matrix
Β 

Similar to Basics of digital verilog design(alok singh kanpur) (20)

Verilog overview
Verilog overviewVerilog overview
Verilog overview
Β 
L6_Slides_vhdl coures temporary hair dye for dark hair
L6_Slides_vhdl coures temporary hair dye for dark hairL6_Slides_vhdl coures temporary hair dye for dark hair
L6_Slides_vhdl coures temporary hair dye for dark hair
Β 
Floating point ALU using VHDL implemented on FPGA
Floating point ALU using VHDL implemented on FPGAFloating point ALU using VHDL implemented on FPGA
Floating point ALU using VHDL implemented on FPGA
Β 
Digital design with Systemc
Digital design with SystemcDigital design with Systemc
Digital design with Systemc
Β 
Embedded system
Embedded systemEmbedded system
Embedded system
Β 
Verilog presentation final
Verilog presentation finalVerilog presentation final
Verilog presentation final
Β 
Vhdl new
Vhdl newVhdl new
Vhdl new
Β 
Short.course.introduction.to.vhdl for beginners
Short.course.introduction.to.vhdl for beginners Short.course.introduction.to.vhdl for beginners
Short.course.introduction.to.vhdl for beginners
Β 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
Β 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
Β 
Xilinx training in mohali
Xilinx training in mohaliXilinx training in mohali
Xilinx training in mohali
Β 
VLSI
VLSIVLSI
VLSI
Β 
VLSI
VLSIVLSI
VLSI
Β 
slide8.ppt
slide8.pptslide8.ppt
slide8.ppt
Β 
Hardware Description Language
Hardware Description Language Hardware Description Language
Hardware Description Language
Β 
Short.course.introduction.to.vhdl
Short.course.introduction.to.vhdlShort.course.introduction.to.vhdl
Short.course.introduction.to.vhdl
Β 
Unit 5_Realizing Applications in FPGA.pdf
Unit 5_Realizing Applications in FPGA.pdfUnit 5_Realizing Applications in FPGA.pdf
Unit 5_Realizing Applications in FPGA.pdf
Β 
Xilinx Training in Jalandhar Chandigarh
Xilinx Training in Jalandhar ChandigarhXilinx Training in Jalandhar Chandigarh
Xilinx Training in Jalandhar Chandigarh
Β 
Xilinx Training in Phagwara Jalandhar
Xilinx Training in Phagwara JalandharXilinx Training in Phagwara Jalandhar
Xilinx Training in Phagwara Jalandhar
Β 
Introduction to HDLs
Introduction to HDLsIntroduction to HDLs
Introduction to HDLs
Β 

More from Alok Singh

Pre and post lpg In INDIA
Pre and post lpg In INDIAPre and post lpg In INDIA
Pre and post lpg In INDIAAlok Singh
Β 
Sebi(alok singh kanpur )
Sebi(alok singh kanpur )Sebi(alok singh kanpur )
Sebi(alok singh kanpur )Alok Singh
Β 
Rbi(alok singh kanpur)
Rbi(alok singh kanpur)Rbi(alok singh kanpur)
Rbi(alok singh kanpur)Alok Singh
Β 
Indian financial system(alok singh kanpur)
Indian financial system(alok singh kanpur)Indian financial system(alok singh kanpur)
Indian financial system(alok singh kanpur)Alok Singh
Β 
Financial services(alok swingh kanpur)
Financial services(alok swingh kanpur)Financial services(alok swingh kanpur)
Financial services(alok swingh kanpur)Alok Singh
Β 
Capital market(alok singh kanpur)
Capital market(alok singh kanpur)Capital market(alok singh kanpur)
Capital market(alok singh kanpur)Alok Singh
Β 
Money market(alok singh kanpur)
 Money market(alok singh kanpur) Money market(alok singh kanpur)
Money market(alok singh kanpur)Alok Singh
Β 
Switch level modeling 2 x4
Switch level modeling 2 x4Switch level modeling 2 x4
Switch level modeling 2 x4Alok Singh
Β 
2 x4 decoder using switch level(Alok singh kanpur)
2 x4 decoder using switch level(Alok singh kanpur)2 x4 decoder using switch level(Alok singh kanpur)
2 x4 decoder using switch level(Alok singh kanpur)Alok Singh
Β 
Fpga &;cpld(by alok singh)
Fpga &;cpld(by alok singh)Fpga &;cpld(by alok singh)
Fpga &;cpld(by alok singh)Alok Singh
Β 
Industrial automation (cold drink factory)
Industrial automation (cold drink factory)Industrial automation (cold drink factory)
Industrial automation (cold drink factory)Alok Singh
Β 
Alok presentation industrial auto
Alok presentation industrial autoAlok presentation industrial auto
Alok presentation industrial autoAlok Singh
Β 
Electronics Equipments Used in Hospital
Electronics Equipments Used in HospitalElectronics Equipments Used in Hospital
Electronics Equipments Used in HospitalAlok Singh
Β 

More from Alok Singh (15)

NBFC
NBFCNBFC
NBFC
Β 
Nabard
NabardNabard
Nabard
Β 
Pre and post lpg In INDIA
Pre and post lpg In INDIAPre and post lpg In INDIA
Pre and post lpg In INDIA
Β 
Sebi(alok singh kanpur )
Sebi(alok singh kanpur )Sebi(alok singh kanpur )
Sebi(alok singh kanpur )
Β 
Rbi(alok singh kanpur)
Rbi(alok singh kanpur)Rbi(alok singh kanpur)
Rbi(alok singh kanpur)
Β 
Indian financial system(alok singh kanpur)
Indian financial system(alok singh kanpur)Indian financial system(alok singh kanpur)
Indian financial system(alok singh kanpur)
Β 
Financial services(alok swingh kanpur)
Financial services(alok swingh kanpur)Financial services(alok swingh kanpur)
Financial services(alok swingh kanpur)
Β 
Capital market(alok singh kanpur)
Capital market(alok singh kanpur)Capital market(alok singh kanpur)
Capital market(alok singh kanpur)
Β 
Money market(alok singh kanpur)
 Money market(alok singh kanpur) Money market(alok singh kanpur)
Money market(alok singh kanpur)
Β 
Switch level modeling 2 x4
Switch level modeling 2 x4Switch level modeling 2 x4
Switch level modeling 2 x4
Β 
2 x4 decoder using switch level(Alok singh kanpur)
2 x4 decoder using switch level(Alok singh kanpur)2 x4 decoder using switch level(Alok singh kanpur)
2 x4 decoder using switch level(Alok singh kanpur)
Β 
Fpga &;cpld(by alok singh)
Fpga &;cpld(by alok singh)Fpga &;cpld(by alok singh)
Fpga &;cpld(by alok singh)
Β 
Industrial automation (cold drink factory)
Industrial automation (cold drink factory)Industrial automation (cold drink factory)
Industrial automation (cold drink factory)
Β 
Alok presentation industrial auto
Alok presentation industrial autoAlok presentation industrial auto
Alok presentation industrial auto
Β 
Electronics Equipments Used in Hospital
Electronics Equipments Used in HospitalElectronics Equipments Used in Hospital
Electronics Equipments Used in Hospital
Β 

Recently uploaded

Study on Air-Water & Water-Water Heat Exchange in a Finned ο»ΏTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned ο»ΏTube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned ο»ΏTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned ο»ΏTube ExchangerAnamika Sarkar
Β 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
Β 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
Β 
πŸ”9953056974πŸ”!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
πŸ”9953056974πŸ”!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...πŸ”9953056974πŸ”!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
πŸ”9953056974πŸ”!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...9953056974 Low Rate Call Girls In Saket, Delhi NCR
Β 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
Β 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
Β 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
Β 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
Β 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
Β 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
Β 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoΓ£o Esperancinha
Β 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
Β 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
Β 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
Β 
Call Us ≽ 8377877756 β‰Ό Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 β‰Ό Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 β‰Ό Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 β‰Ό Call Girls In Shastri Nagar (Delhi)dollysharma2066
Β 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
Β 

Recently uploaded (20)

Study on Air-Water & Water-Water Heat Exchange in a Finned ο»ΏTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned ο»ΏTube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned ο»ΏTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned ο»ΏTube Exchanger
Β 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
Β 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
Β 
πŸ”9953056974πŸ”!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
πŸ”9953056974πŸ”!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...πŸ”9953056974πŸ”!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
πŸ”9953056974πŸ”!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
Β 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
Β 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
Β 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Β 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
Β 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
Β 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
Β 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
Β 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Β 
young call girls in Green ParkπŸ” 9953056974 πŸ” escort Service
young call girls in Green ParkπŸ” 9953056974 πŸ” escort Serviceyoung call girls in Green ParkπŸ” 9953056974 πŸ” escort Service
young call girls in Green ParkπŸ” 9953056974 πŸ” escort Service
Β 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Β 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
Β 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
Β 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
Β 
Call Us ≽ 8377877756 β‰Ό Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 β‰Ό Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 β‰Ό Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 β‰Ό Call Girls In Shastri Nagar (Delhi)
Β 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
Β 
β˜… CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
β˜… CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCRβ˜… CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
β˜… CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
Β 

Basics of digital verilog design(alok singh kanpur)

  • 1. WA 1 Digital Design Using Verilog ) begin modulebeta(clk,reset,irq,… Input[31:0]mem_data; endm oduleIf(done)$finish; Figures by MIT OCW. PC+4+4*SXT(C) ASEL 0 1 Data Memory RD WD Adr R/W WDSEL 0 1 2 Rc: <25:21> 0 1 XP PC JT +4 Instruction Memory A D Rb: <15:11> Ra: <20:16> RA2SELRc: <25:21> + Register File RA1 RA2 RD1 RD2 BSEL 0 1 C: SXT(<15:0>) Z ALU A B JT WA WD WE ALUFN Control Logic Z ASEL BSEL PCSEL RA2SEL WDSEL ALUFN Wr PC+4 0 1 Wr 0 1 2 3 4 XAdr ILL OP WASEL WASEL IRQ WERF WERF 00 PCSEL L02 – Verilog6.884 – Spring 2005 02/04/05 always @(posedge clk assign pcinc = pc + 4; for (i=0; i < 31; i = i+1) begin
  • 2. Hardware Description Languages In the beginning designs involved just a few gates, and thus it was possible to verify these circuits on paper or with breadboards 6.884 – Spring 2005 02/04/05 L02 – Verilog 2
  • 3. Hardware Description Languages As designs grew larger and more complex, designers began using gate-level models described in a Hardware Description Language to help with verification before fabrication 6.884 – Spring 2005 02/04/05 L02 – Verilog 3
  • 4. Hardware Description Languages When designers began working on 100,000 gate designs, these gate-level models were too low- level for the initial functional specification and early high- level design exploration 6.884 – Spring 2005 02/04/05 L02 – Verilog 4
  • 5. Hardware Description Languages Designers again turned to HDLs specification and a framework for help – abstract behavioral models written in an HDL provided both a precise for design exploration 6.884 – Spring 2005 02/04/05 L02 – Verilog 5
  • 6. Advantages of HDLs Allows designers to talk about what the hardware should do without actually designing the hardware itself, or in other words HDLs allow designers to separate behavior from implementation at various levels of abstraction HDLs do this with modules and interfaces Figure by MIT OCW. 6.884 – Spring 2005 02/04/05 L02 – Verilog 6
  • 7. Advantages of HDLs Allows designers to talk about what the hardware should do without actually designing the hardware itself, or in other words HDLs allow designers to separate behavior from implementation at various levels of abstraction 6.884 – Spring 2005 02/04/05 L02 – Verilog 7
  • 8. Advantages of HDLs Allows designers to talk about what the hardware should do without actually designing the hardware itself, or in other words HDLs allow designers to separate behavior from implementation at various levels of abstraction 6.884 – Spring 2005 02/04/05 L02 – Verilog 8
  • 9. Advantages of HDLs Allows designers to talk about what the hardware should do without actually designing the hardware itself, or in other words HDLs allow designers to separate behavior from implementation at various levels of abstraction Processor A Processor B Processor C Network Memory A Memory B Bank Bank 6.884 – Spring 2005 02/04/05 L02 – Verilog 9
  • 10. Advantages of HDLs Allows designers to talk about what the hardware should do without actually designing the hardware itself, or in other words HDLs allow designers to separate behavior from implementation at various levels of abstraction – Designers can develop an executable functional specification that documents the exact behavior of all the components and their interfaces – Designers can make decisions about cost, performance, power, and area earlier in the design process – Designers can create tools which automatically manipulate the design for verification, synthesis, optimization, etc. 6.884 – Spring 2005 02/04/05 L02 – Verilog 10
  • 11. A Tale of Two HDLs VHDL ADA-like verbose syntax, lots of redundancy Extensible types and simulation engine Design is composed of entities each of which can have multiple architectures Gate-level, dataflow, and behavioral modeling. Synthesizable subset. Harder to learn and use, DoD mandate Verilog C-like concise syntax Built-in types and logic representations Design is composed of modules which have just one implementation Gate-level, dataflow, and behavioral modeling. Synthesizable subset. Easy to learn and use, fast simulation 6.884 – Spring 2005 02/04/05 L02 – Verilog 11
  • 12. We will use Verilog … Advantages – Choice of many US design teams – Most of us are familiar with C-like syntax – Simple module/port syntax is familiar way to organize hierarchical building blocks and manage complexity – With care it is well-suited for both verification and synthesis Disadvantages – Some comma gotchas which catch beginners everytime – C syntax can cause beginners to assume C semantics – Easy to create very ugly code, good and consistent coding style is essential 6.884 – Spring 2005 02/04/05 L02 – Verilog 12
  • 13. An HDL is NOT a Software Programming Language Software Programming Language – Language which can be translated into machine instructions and then executed on a computer Hardware Description Language – Language with syntactic and semantic support for modeling the temporal behavior and spatial structure of hardware module foo(clk,xi,yi,done); input [15:0] xi,yi; output done; always @(posedge clk) begin: if (!done) begin if (x == y) cd <= x; else (x > y) x <= x - y; end end endmodule 6.884 – Spring 2005 02/04/05 L02 – Verilog 13
  • 14. Hierarchical Modeling with Verilog A Verilog module includes a module name and an interface in the form of a port list – Must specify direction and bitwidth for each port module input adder( A, B, cout, sum ); [3:0] A, B; adder A B output cout; output [3:0] sum; // HDL modeling of // adder functionality cout sum endmodule Don't forget the semicolon! 6.884 – Spring 2005 02/04/05 L02 – Verilog 14
  • 15. Hierarchical Modeling with Verilog A Verilog module includes a module name and an interface in the form of a port list – Must specify direction and bitwidth for each port – Verilog-2001 introduced a succinct ANSI C style portlist adder A B module adder( input [3:0] A, B, output cout, output [3:0] sum ); // HDL modeling of 4 bit // adder functionality cout sum endmodule 6.884 – Spring 2005 02/04/05 L02 – Verilog 15
  • 16. Hierarchical Modeling with Verilog A module can contain other modules through module instantiation creating a module hierarchy – Modules are connected together with nets – Ports are attached to nets either by position or by name FA ba c cin cout module FA( input a, b, cin output cout, sum ); // HDL modeling of 1 bit // adder functionality endmodule 6.884 – Spring 2005 02/04/05 L02 – Verilog 16
  • 17. Hierarchical Modeling with Verilog A module can contain other modules through module instantiation creating a module hierarchy – Modules are connected together with nets – Ports are attached to nets either by position or by name adder A B Scout FA FA FA FA module adder( input [3:0] A, B, output cout, output [3:0] S ); FA fa0( ... ); FA fa1( ... ); FA fa2( ... ); FA fa3( ... ); endmodule 6.884 – Spring 2005 02/04/05 L02 – Verilog 17
  • 18. Hierarchical Modeling with Verilog A module can contain other modules through module instantiation creating a module hierarchy – Modules are connected together with nets – Ports are attached to nets either by position adder A B module adder( input [3:0] A, B, output cout, output [3:0] S ); cout S wire c0, c1, c2; FA fa0( A[0], B[0], 0, c0, S[0] ); FA fa1( A[1], B[1], c0, c1, S[1] ); FA fa2( A[2], B[2], c1, c2, S[2] ); FA fa3( A[3], B[3], c2, cout, S[3] ); FA FA FA FA endmodule Carry Chain 6.884 – Spring 2005 02/04/05 L02 – Verilog 18
  • 19. Hierarchical Modeling with Verilog A module can contain other modules through module instantiation creating a module hierarchy – Modules are connected together with nets – Ports are attached to nets either by position or by name adder A B Scout FA FA FA FA module adder( input [3:0] A, B, output cout, output [3:0] S ); wire c0, c1, c2; FA fa0( .a(A[0]), .b(B[0]), .cin(0), .cout(c0), .sum(S[0] ); FA fa1( .a(A[1]), .b(B[1]), ... endmodule 6.884 – Spring 2005 02/04/05 L02 – Verilog 19
  • 20. Verilog Basics Data Values Numeric Literals 4’b10_11 0 1 Underscores are ignored X Z Base format (d,b,o,h) Decimal number representing size in bits 32’h8XXX_XXA3 6.884 – Spring 2005 02/04/05 L02 – Verilog 20
  • 21. 3 Common Abstraction Levels Behavioral Gate-Level Dataflow Module’s high-level algorithm is implemented with little concern for the actual hardware Module is implemented by specifying how data flows between registers Module is implemented in terms of concrete logic gates (AND, OR, NOT) and their interconnections 6.884 – Spring 2005 02/04/05 L02 – Verilog 21
  • 22. 3 Common Abstraction Levels Behavioral Gate-Level Dataflow Designers can create lower-level models from the higher-level models either manually or automatically The process of automatically generating a gate-level model from either a dataflow or a behavioral model is called Logic Synthesis 6.884 – Spring 2005 02/04/05 L02 – Verilog 22
  • 23. Gate-Level : 4-input Multiplexer module mux4( input a, b, c, d input [1:0] sel, output out ); wire [1:0] sel_b; not not0( sel_b[0], sel[0] ); not not1( sel_b[1], sel[1] ); Basic logic gates are built-in primitives meaning there is no need to define a module for these gates wire n0, n1, n2, n3; and and0( n0, c, sel[1] ); and and1( n1, a, sel_b[1] ); sel[0] and and2( n2, d, sel[1] ); and and3( n3, b, sel_b[1] ); sel[1] wire x0, x1; nor nor0( x0, n0, n1 ); c nor nor1( x1, n2, n3 ); a out wire y0, y1; d or or0( y0, x0, sel[0] ); bor or1( y1, x1, sel_b[0] ); nand nand0( out, y0, y1 ); endmodule 6.884 – Spring 2005 02/04/05 L02 – Verilog 23
  • 24. Dataflow : 4-input Multiplexer module mux4( input a, b, c, d input [1:0] sel, output out ); wire out, t0, t1; assign t0 = ~( (sel[1] & c) | (~sel[1] & a) ); assign t1 = ~( (sel[1] & d) | (~sel[1] & b) ); assign out = ~( (t0 | sel[0]) & (t1 | ~sel[0]) ); endmodule This is called a continuous assignment since the RHS is always being evaluated and the result is continuously being driven onto the net on the LHS 6.884 – Spring 2005 02/04/05 L02 – Verilog 24
  • 25. Dataflow : 4-input Multiplexer module mux4( input a, b, c, d input [1:0] sel, output out ); wire t0 = ~( (sel[1] & c) | (~sel[1] & a) ); wire t1 = ~( (sel[1] & d) | (~sel[1] & b) ); wire out = ~( (t0 | sel[0]) & (t1 | ~sel[0]) ); endmodule An implicit continuous assignment combines the net declaration with an assign statement and thus is more succinct 6.884 – Spring 2005 02/04/05 L02 – Verilog 25
  • 26. Dataflow : 4-input Mux and Adder // Four input muxltiplexor module mux4( input a, b, c, d Dataflow style Veriloginput [1:0] sel, output out ); enables descriptions which are more assign out = ( sel == 0 ) ? a : ( sel == 1 ) ? b : abstract than gate- ( sel == 2 ) ? c : level Verilog ( sel == 3 ) ? d : 1’bx; endmodule // Simple four bit adder module adder( input output [3:0] [3:0] op1, op2, sum ); assign sum = op1 + op2; endmodule 6.884 – Spring 2005 02/04/05 L02 – Verilog 26
  • 27. Dataflow : Key Points Dataflow modeling enables the designer to focus on where the state is in the design and how the data flows between these state elements without becoming bogged down in gate-level details – Continuous assignments are used to connect combinational logic to nets and ports – A wide variety of operators are available including: Arithmetic: + - * / % ** Logical: ! && || Avoid these Relational: > < >= <= operators since Equality: == != === !=== they usually Bitwise: ~ & | ^ ^~ synthesize poorly Reduction: & ~& | ~| ^ ^~ Shift: >> << >>> <<< Concatenation: { } Conditional: ?: 6.884 – Spring 2005 02/04/05 L02 – Verilog 27
  • 28. Dataflow : Key Points Dataflow modeling enables the designer to focus on where the state is in the design and how the data flows between these state elements without becoming bogged down in gate-level details – Continuous assignments are used to connect combinational logic to nets and ports – A wide variety of operators are available including: Arithmetic: + - * / % ** Logical: ! && || Relational: > < >= <= assign signal[3:0] Equality: ~ & | ^ ^~ & ~& | ~| ^ ^~ >> << >>> <<< ?: == != === !=== = { a, b, 2’b00 } Bitwise: Reduction: Shift: Concatenation: { } Conditional: 6.884 – Spring 2005 02/04/05 L02 – Verilog 28
  • 29. Behavioral : 4-input Multiplexer module mux4( input a, b, c, d input [1:0] sel, output out ); reg out; always @( a or b or c or d or sel ) begin if ( sel == 0 ) An always block is a behavioral out = a; block which contains a list of else if ( sel == 1 ) expressions which are (usually)out = b else if ( sel == 2 ) evaluated sequentially out = c The code in an always block canelse if ( sel == 3 ) out = d be very abstract (similar to C end code) – here we implement a mux with an if/else statement endmodule 6.884 – Spring 2005 02/04/05 L02 – Verilog 29
  • 30. Behavioral : 4-input Multiplexer module mux4( input a, b, c, d input [1:0] sel, output out ); else if ( sel == 2 ) out = c else if ( sel == 3 ) out = d if any of these signals change then the always block is executed reg out; ( a or b or c or d or begin if out = a; out = b An always block can include a sensitivity list – always @ sel ) ( sel == 0 ) else if ( sel == 1 ) end endmodule 6.884 – Spring 2005 02/04/05 L02 – Verilog 30
  • 31. Behavioral : 4-input Multiplexer module mux4( input a, b, c, d input [1:0] sel, output out ); reg out; begin if out = a; out = b always @( a, b, c, d, sel ) ( sel == 0 ) else if ( sel == 1 ) In Verilog-2001 we can use a else if ( sel == 2 ) comma instead of the or out = c else if ( sel == 3 ) out = d end endmodule 6.884 – Spring 2005 02/04/05 L02 – Verilog 31
  • 32. Behavioral : 4-input Multiplexer module mux4( input a, b, c, d input [1:0] sel, output out ); reg out; always @( a, b, c, d, sel ) begin if ( sel == 0 ) out = a; else if ( sel == 1 ) out = b else if ( sel == 2 ) out = c else if ( sel == 3 ) out = d end endmodule What happens if we accidentally leave off a signal on the sensitivity list? The always block will not execute if just d changes – so if sel == 3 and d changes then out will not be updated This will cause discrepancies between simulated and synthesized hardware – there are no sensitivity lists in real hardware so it would work fine! 6.884 – Spring 2005 02/04/05 L02 – Verilog 32
  • 33. Behavioral : 4-input Multiplexer module mux4( input a, b, c, d input [1:0] sel, output out ); reg out; begin ( * ) if always @ ( sel == 0 ) out = a; else if ( sel == 1 ) out = b else if ( sel == 2 ) out = c else if ( sel == 3 ) out = d end endmodule In Verilog-2001 we can use the @(*) construct which creates a sensitivity list for all signals read in the always block 6.884 – Spring 2005 02/04/05 L02 – Verilog 33
  • 34. Behavioral : 4-input Multiplexer module mux4( input a, b, c, d input [1:0] sel, output out ); reg out; always @( * ) begin case ( sel ) Always blocks can contain case0 : out = a; statements, for loops, while loops,1 : out = b; 2 : out = c; even functions – they enable 3 : out = d; high-level behavioral modeling endcase end endmodule 6.884 – Spring 2005 02/04/05 L02 – Verilog 34
  • 35. Behavioral : 4-input Multiplexer module mux4( input a, b, c, d input [1:0] sel, output out ); reg out; What about this funny No! and whoever reg statement? decided on the reg always @( * ) Is this how you create syntax really begin a register in Verilog? messed things up! case ( sel ) 0 : out = a; 1 : out = b; 2 : out = c; 3 : out = d; endcase end endmodule 35L02 – Verilog02/04/05 Figure by MIT OCW. 6.884 – Spring 2005
  • 36. Behavioral : 4-input Multiplexer module mux4( input a, b, c, d input [1:0] sel, output out ); reg out; In Verilog a reg is just a variable – always @( * ) when you see reg think variable not begin case ( sel ) hardware register! 0 : out = a; Any assignments in an always block 1 : out = b; 2 : out = c; must assign to a reg variable – the 3 : out = d; reg variable may or may not actually endcase represent a hardware register end If the always block assigns a value to endmodule the reg variable for all possible executions then the reg variable is not actually a hardware register 6.884 – Spring 2005 02/04/05 L02 – Verilog 36
  • 37. Behavioral : 4-input Multiplexer module mux4( input a, b, c, d input [1:0] sel, output out ); reg out; always @( * ) begin case ( sel ) 0 : out = a; 1 : out = b; 2 : out = c; 3 : out = d; endcase end endmodule What about in this situation? Will the generated hardware include a latch for out? Figure by MIT OCW. 6.884 – Spring 2005 02/04/05 L02 – Verilog 37
  • 38. Behavioral : 4-input Multiplexer module mux4( input a, b, c, d input [1:0] sel, output out ); reg out; always @( * ) begin case ( sel ) 0 : out = a; 1 : out = b; 2 : out = c; 3 : out = d; endcase end endmodule Maybe! What if sel == xx? Then out is unassigned and the hardware must maintain the previous value of out! Figure by MIT OCW. 6.884 – Spring 2005 02/04/05 L02 – Verilog 38
  • 39. Behavioral : 4-input Multiplexer module mux4( input a, b, c, d input [1:0] sel, output out ); Fix it with a default clause in the case statement –reg out; always @( * ) then no hardware latch is begin inferred case ( sel ) default : out = 1’bx; 0 : out = a; 1 : out = b; 2 : out = c; 3 : out = d; endcase end endmodule Figure by MIT OCW. 6.884 – Spring 2005 02/04/05 L02 – Verilog 39
  • 40. Behavioral Non-Blocking Assignments always @( posedge clk ) begin x = next_x; end next_x D Q X clk always @( posedge clk ) begin x = next_x; y = x; end next_x D Q clk X Y always @( posedge clk ) begin x <= next_x; end next_x D Q X clk always @( posedge clk ) begin x <= next_x; y <= x; end D Q X next_x D Q Y clk clk 6.884 – Spring 2005 02/04/05 L02 – Verilog 40
  • 41. Behavioral Non-Blocking Assignments always @( posedge clk ) begin y = x; x = y; end X Y Take Away Point - always ask yourself β€œDo I need blocking or non-blocking assignments for this always block?” Never mix and match! always @( posedge clk ) begin y <= x; x <= y; end D Q D Q X clk Y clk 6.884 – Spring 2005 02/04/05 L02 – Verilog 41
  • 42. Which abstraction is the right one? Designers usually use a mix of all three! Early on in the design process they might use mostly behavioral models. As the design is refined, the behavioral models begin to be replaced by dataflow models. Finally, the designers use automatic tools to synthesize a low-level gate-level model. Behavioral Dataflow Gate-Level 6.884 – Spring 2005 02/04/05 L02 – Verilog 42
  • 43. Revisiting Logic Synthesis Behavioral Gate-Level Dataflow Modern tools are able to synthesize more and more behavioral Verilog code directly to the gate-level The problem though, is that it is very hard to predict what the generated hardware will look like This makes it difficult to perform rational design space exploration 6.884 – Spring 2005 02/04/05 L02 – Verilog 43
  • 44. Revisiting Logic Synthesis Behavioral Gate-Level Dataflow In this course we will mostly stick to very predictable dataflow to gate-level synthesis – we want to have a good idea what kind of hardware we are generating! 6.884 – Spring 2005 02/04/05 L02 – Verilog 44
  • 45. Writing Parameterized Models module mux4 #( parameter width ) ( input [width-1:0] a, b, c, d input [1:0] sel, output [width-1:0] out ); ... endmodule // Specify parameters at instantiation time mux4 #( .width(32) ) alu_mux( .a(op1), .b(bypass), .c( .sel(alu_mux_sel), .out(alu_mux_out) ); 32’b0), .d(32’b1), Parameters enable static configuration of modules at instantiation time and can greatly increase the usefulness of your modules 6.884 – Spring 2005 02/04/05 L02 – Verilog 45
  • 46. Writing Parameterized Models module adder #( parameter width ) ( input [width-1:0] op1,op2, output cout, output [width-1:0] sum ); wire [width-1:0] carry; assign assign carry[0] = 0; cout = carry[width] genvar i; Generate blocks can generate for begin ( i = 0; i < width; i = i+1 ) : ripple use parameters to FA fa( op1[i], op2[i], carry[i], carry[i+1] ); end instantiate a variable number of sub-modules or to create a variable number of nets endgenerate endmodule 6.884 – Spring 2005 02/04/05 L02 – Verilog 46
  • 47. Static Elaboration Model Synthesis Gate-Level Elaborated Model Static Elaboration 6.884 – Spring 2005 02/04/05 L02 – Verilog 47
  • 48. Larger Examples Let’s briefly examine two larger digital designs and consider the best way to model these designs in Verilog GCD Beta 6.884 – Spring 2005 02/04/05 L02 – Verilog 48
  • 49. GCD Behavioral Example module gcd_behavioral #( parameter width = 16 ) ( input [width-1:0] A_in, B_in, output [width-1:0] Y ); reg [width-1:0] A, B, Y, swap; integer done; always @( A_in or B_in ) begin done = 0; A = A_in; B = B_in; while begin ( !done ) if ( A < B ) begin We write the generalswap = A; A = B; algorithm in an always block B = swap; using a very C-like syntaxend else if ( B != 0 ) A = A - B; else done = 1; end Y = A; end endmodule 6.884 – Spring 2005 02/04/05 L02 – Verilog 49
  • 50. module gcd_test; parameter width = 16; GCD Behavioral reg [width-1:0] A_in, B_in; wire [width-1:0] Y; Test Harness gcd_behavioral #( .width(width) ) gcd_unit( .A_in(A_in), .B_in(B_in), .Y(Y) ); initial begin // Default inputs if cmdline args // are not provided A_in = 27; B_in = 15; // Read in cmdline args $value$plusargs $value$plusargs ("a-in=%d",A_in); ("b-in=%d",B_in); // Let the simulation run #10; // Output the results $display(" a-in = %d", A_in ); $display(" b-in = %d", B_in ); $display(" gcd-out = %d", Y ); $finish; end endmodule We use a test harness to drive the GCD module. The test harness includes an initial block, which is similar to always block except it executes only once at time = 0. Special directives which begin with $ enable the test harness to read command line arguments, use file IO, print to the screen, and stop the simulation 6.884 – Spring 2005 02/04/05 L02 – Verilog 50
  • 51. Design Strategy Partition into control and datapath Keep all functional code in the leaf modules GCD RTL Example go done Control Unit zero? lt out A_in A sub B_in B Design Strategy Partition into control and datapath Keep all functional code in the leaf modules 6.884 – Spring 2005 02/04/05 L02 – Verilog 51
  • 52. GCD RTL Datapath module gcd_dpath #( parameter width = 16 ) ( input clock, input A_en, B_en, A_mux_sel, B_mux_sel, out_mux_sel, input [width-1:0] A_in, B_in, output B_zero, A_lt_B, output [width-1:0] Y ); reg [width-1:0] A, B; assign Y = A; // Datapath logic wire [width-1:0] out = ( out_mux_sel ) ? B : A - B; wire [width-1:0] wire [width-1:0] A_next = ( A_mux_sel ) ? out : A_in; B_next = ( B_mux_sel ) ? A : B_in; // Generate output control signals wire wire B_zero = ( B == 0 ); A_lt_B = ( A < B ); A mix of dataflow and behavioral // Edge-triggered flip-flops Edge-triggered always @( posedge clock ) flip-flops with begin if ( A_en ) enables A <= A_next; if ( B_en ) B <= B_next; end endmodule 6.884 – Spring 2005 02/04/05 L02 – Verilog 52
  • 53. GCD RTL Control Unit module gcd_ctrl ( input input clock, reset, go, B_zero, A_lt_B, output A_en, B_en, A_mux_sel, B_mux_sel, out_mux_sel, output done ); // The running bit is one after go goes high and until done goes high reg running = 0; always @( posedge clock ) begin if ( go ) running <= 1; else if ( done ) running <= 0; end // Combinational control logic - we group all the control signals // onto one bus to make the Verilog more concise reg [5:0] ctrl_sig; assign { A_en, B_en, A_mux_sel, B_mux_sel, out_mux_sel, done } = ctrl_sig; always @(*) begin if ( !running ) ctrl_sig = 6'b11_00x_0; // Latch in A and B values else if ( A_lt_B ) ctrl_sig = 6'b11_111_0; // A <= B and B <= A else if ( !B_zero ) ctrl_sig = 6'b10_1x0_0; // A <= A - B and B <= B else ctrl_sig = 6'b00_xxx_1; // Done end endmodule 6.884 – Spring 2005 02/04/05 L02 – Verilog 53
  • 54. GCD Testing We use the same test inputs to test both the behavioral and the RTL models. If both models have the exact same observable behavior then the RTL model has met the functional specification. Test Inputs Behavioral Model RTL Model Identical Outputs? 6.884 – Spring 2005 02/04/05 L02 – Verilog 54
  • 55. WA Beta Redux I thought I already did ILL XAdr OP JT 6.004 PCSEL 4 3 2 1 0 PC 00 A Instruction Memory +4 D Ra: <20:16> Rb: <15:11> Rc: <25:21> + 0 1 RA2SEL WASEL RA2XP RA1 Register Rc: <25:21> 1 WA File WD 0 RD1 RD2 WE WERF Z Figure by MIT OCW. JT PC+4+4*SXT(C) C: SXT(<15:0>) IRQ Z ASEL 1 0 1 0 BSEL Control Logic PCSEL RA2SEL A B ASEL ALUFN ALU WD R/W Wr BSEL WDSEL Data Memory ALUFN Adr RD Wr WERF WASEL PC+4 0 1 2 WDSEL 6.884 – Spring 2005 02/04/05 L02 – Verilog 55
  • 56. Goals for the Beta Verilog Description Readable, correct code that clearly captures the architecture diagram – β€œcorrect by inspection” Partition the design into regions appropriate for different implementation strategies. Big issue: wires are β€œbad” since they take up area and have capacitance (impacting speed and power). – Memories: very dense layouts, structured wires pretty much route themselves, just a few base cells to design & verify. – Datapaths: each cell contains necessary wiring, so replicating cells (for N bits of datapath) also replicates wiring. Data flows between columnar functional units on horizontal busses and control flows vertically. – Random Logic: interconnect is β€œrandom” but library of cells can be designed ahead of time and characterized. – Think about physical partition since wires that cross boundaries can take lots of area and blocks have to fit into the floorplan without wasteful gaps. 6.884 – Spring 2005 02/04/05 L02 – Verilog 56
  • 57. Hey! What happened to abstraction? Wasn’t the plan to abstract-away the physical details so we could concentrate on getting the functionality right? Why are we worrying about wires Because life is short! If you have the luxury of writing two models (the first to experiment with function, the second to describe the actual partition you want to have), by all means! But with a little experience you can tackle both problems at once. and floorplans at this stage? 6.884 – Spring 2005 02/04/05 Figure by MIT OCW. L02 – Verilog 57
  • 58. WA Divide and Conquer (C) 01 RD WD R/W 0 1 2 0 1XP PC JT +4 A D + Register File RA1 RD1 RD2 01 ) Z A B JT WA WD WE Control Logic Z Wr PC+4 0 1 Wr 01234 ILL OP IRQ 00 Step 1: identify memories 1 1 1 Step 2: identify datapaths 2 2 PC Main Datapath What’s left is random logic … PC+4+4*SXT ASEL Data Memory Adr WDSEL Rc: <25:21> Instruction Memory Rb: <15:11>Ra: <20:16> RA2SEL Rc: <25:21> RA2 BSEL C: SXT(<15:0> ALUALUFN ASEL BSEL PCSEL RA2SEL WDSEL ALUFN XAdr WASEL WASEL WERF WERF PCSEL 6.884 – Spring 2005 02/04/05 L02 – Verilog 58
  • 59. Take Away Points Hardware description languages are an essential part of modern digital design – HDLs can provide an executable functional specification – HDLs enable design space exploration early in design process – HDLs encourage the development of automated tools – HDLs help manage complexity inherent in modern designs Verilog is not a software programming language so always be aware of how your Verilog code will map into real hardware Carefully plan your module hierarchy since this will influence many other parts of your design 6.884 – Spring 2005 02/04/05 L02 – Verilog 59
  • 60. Laboratory 1 You will be building an RTL model of a two-stage MIPS processor 1. Read through the lab and the SMIPS processor spec which is posted on the labs section 2. Look over the Beta Verilog posted on the MIT server 3. Try out the GCD Verilog example (or on any MIT server/Linux machine) % setup 6.884 % cp –r /mit/6.884/examples/gcd . % cat gcd/README 4. Next week’s tutorial will review the Beta implementation and describe how to use Lab 1 toolchain (vcs, virsim, smips-gcc) 6.884 – Spring 2005 02/04/05 L02 – Verilog 60