Midterm-Verilog-19ECE349-RISC Processor Design Using HDL
Midterm-Verilog-19ECE349-RISC Processor Design Using HDL
• CO2: Able to design circuits using Verilog and understand concept of timing analysis
• Unit I:
• Fundamental techniques of computer design – RISC and CISC architectures - computer arithmetic, - comparison
of RISC and CISC architectures - Introduction to superscalar and super pipelined architectures - Verilog
Introduction and review of basic designs using Verilog - Static timing analysis – Introduction - setup and hold
time constraints - processor timing issues - design examples.
• Unit II:
• MIPS Processor- Introduction to MIPS features and MIPS instruction set, logical design of MIPS datapath -
control unit and instruction decode - Design of single cycle - multi-cycle and pipelined architectures of MIPS -
Hazards- data and control hazards - Verilog designs of single cycle and multi-cycle MIPS processor.
• Unit III:
• Verilog design of pipelined MIPS processor - Introduction to memory hierarchy cache memory fundamentals -
memory systems for superscalar processors.
Textbook(s) and References:
Textbook(s):
• 1.Patterson, David A., and John L. Hennessy, “Computer Organization and Design: The Hardware Software
Interface”, Morgan kaufmann, First edition 2005.
• 2. Sarah L Harris, David Money Harris “, Digital Design and Computer Architecture RISC-V Edition
• 2. Palnitkar, Samir. “Verilog HDL: a guide to digital design and synthesis”, Edition 1, Prentice Hall
Professional, 2003.
Reference(s)
• 1.Hamacher, V. Carl, et al. “Computer organization”, Fifth edition. New York et al. McGraw-Hill, 1984.
• 2.Dandamudi, Sivarama P, “Guide to RISC processors: for programmers and engineers”, First edition, Springer
Science & Business Media, 2005.
Verilog HDL
Hardware description languages
• Verilog HDL
• VHDL
• In a top-down design methodology, we define the top-level block and identify the
sub-blocks necessary to build the top-level block.
• We further subdivide the sub-blocks until we come to leaf cells, which are the
cells that cannot further be divided.
A top-down design methodology
bottom-up design methodology.
• Gate level
• Dataflow level
• Behavioral or algorithmic level
• Switch level
Gate level Modeling
Primary I/P
Internal Nets
Primary o/p
endmodule
Stimulus Block
module stimulus;
reg clk;
reg reset;
wire[3:0] q;
// instantiate the design block
ripple-carry-counter rl(q, clk, reset);
// Control the clk signal that drives the design block.Cycle time = 10ns
initial
clk = 1'b0; //set clk to 0
always
#5 clk = -clk; //toggle clk every 5 time units
Stimulus Block
// Control the reset signal that drives the design block
initial
begin
reset = 1'b1;
#15 reset = 1'b0;
#180 reset = 1'b1;
#10 reset = 1'b0;
#20 $finish; //terminate the simulation
end
// Monitor the outputs
initial
$monitor ($time, " Output q = %d" , q) ;
endmodule
initial
begin
reset = 1'b1;
#15 reset = 1'b0;
#180 reset = 1'b1;
#10 reset = 1'b0;
#20 $finish; //terminate the simulation
end
// Monitor the outputs
initial
$monitor ($time, " Output q = %d" , q) ;
endmodule
initial
begin
reset = 1'b1;
#15 reset = 1'b0;
#180 reset = 1'b1;
#10 reset = 1'b0;
#20
$finish; //terminate the simulation
end
// Monitor the outputs
initial
$monitor ($time, " Output q = %d" , q) ;
endmodule
l-bit Full Adder design using gate-level modeling
• module D-FF(q, d, clk, reset) ; // Control the reset signal that drives the design block
initial
• output q; begin
• input d, clk, reset; reset = 1'b1;
#15 reset = 1’b0;
• reg q;
#20 D=1’b1;
• always @(posedge reset or #180 reset = 1'b1;
negedge clk) #10 reset = 1’b0;
#10 D=1’b1;
• if (reset)
#20 $finish; //terminate the simulation
• q = 1'bO; end
• else // Monitor the outputs
initial
• q = d; $monitor ($time, " Output q = %d" , q) ;
• endmodule endmodule
Logic Diagram for Multiplexer- Gate level modeling
0 A= 0000, B=0000, C_IN= 0, --- C_OUT= 0, SUM= 0000 A = 4'd0; B = 4'd0; C_IN = 1'b0;
5 A= 0011, B=0100, C_IN= 0, --- C_OUT= 0, SUM= 0111 #5 A = 4'd3; B = 4'd4;
10 A= 0010, B=0101, C_IN= 0, --- C_OUT= 0, SUM= 0111 #5 A = 4'd2; B = 4'd5;
15 A= 1001, B=1001, C_IN= 0, --- C_OUT= 1, SUM= 0010 #5 A = 4'd9; B = 4'd9;
20 A= 1010, B=1111, C_IN= 0, --- C_OUT= 1, SUM= 1001
#5 A = 4'd10; B = 4'd15;
25 A= 1010, B=0101, C_IN= 1 --- C_OUT= 1, SUM= 0000
#5 A = 4'd10; B = 4'd5; C_IN = 1'b1;
Behavioral 4-bit Counter Description
//4-bit Binary counter
module counter(Q , clock, clear);
output [3:0] Q;
input clock, clear;
reg [3:0] Q;
always @( posedge clear or negedge clock)
begin
if (clear)
Q <= 4'd0; //Nonblocking assignments are recommended
//for creating sequential logic such as flipflops
else
Q <= Q + 1;// Modulo 16 is not necessary because Q is a
// 4-bit value and wraps around.
end
endmodule
3. Basic Concepts
Basic Concepts
module stimulus;
• Verilog Conventions reg clk;
• The basic conventions used by reg reset;
Verilog HDL are similar to those in wire[3:0] q;
the C programming language. // instantiate the design block
• Verilog contains a stream of tokens. ripple-carry-counter rl(q, clk, reset);
• Tokens can be comments, numbers, // Control the clk signal that drives the design
block.Cycle time = 10ns
strings, identifiers, and keywords.
initial
• Verilog HDL is a case-sensitive clk = 1'b0; //set clk to 0
language. All keywords are in always
lowercase. #5 clk = -clk; //toggle clk every 5 time units
Whitespace
notation
delta = 2.13; // delta is assigned a value 2.13
end
integer i; // Define an integer i
initial
i = delta; // i gets the value 2 (rounded value of 2.13)
Time
• Verilog simulation is done with respect to simulation time. A
special time register data type is used in Verilog to store
simulation time.
• A time variable is declared with the keyword time.
• The width for time register data types is implementation specific
but is at least 64 bits.
• The system function $time is invoked to get the current simulation
time.
Time
time save-sim-time; // Define a time variable save-sim-time
initial
save-sim-time = $time; // Save the current simulation time
Stimulus Block
// Control the reset signal that drives the design block
// reset is asserted from 0 to 20 and from 195 to 205.
initial
begin
reset = 1'b1;
#15 reset = 1'b0;
#180 reset = 1'b1;
#10 reset = 1'b0;
#20 $finish; //terminate the simulation
end
// Monitor the outputs
initial
$monitor ($time, " Output q = %d" , q) ;
endmodule
One dimensional Arrays wire [7:0] bus; // 8-bit bus
Two dimensional Arrays
Vector Vs Arrays
Vector: Arrays:
• A vector is a single
• arrays are multiple elements
element that is n-bits
wide. that are 1-bit or n-bits wide.
Arrays
• Arrays are allowed in Verilog for net, reg, integer, time, real and vector
register data types.
• Multi-dimensional arrays can also be declared with any
number of dimensions.
integer count[0:7]; // An array of 8 count variables
reg bool[31:0]; // Array of 32 one-bit boolean register variables
time chk_point[1:100]; // Array of 100 time checkpoint variables
Arrays
wire [7:0] w_array2 [5:0]; // Declare an array of 8 bit vector wire
reg [4:0] port_id[0:7]; // Array of 8 port_ids; each
port_id is 5 bits wide
Inputs
• Internally, input ports must always
be of the type net.
• Externally, the inputs can be
connected to a variable which is a
reg or a net.
Outputs
• Internally, outputs ports can be of
the type reg or net.
• Externally, outputs must always
be connected to a net. They
cannot be connected to a reg.
Stimulus Block
module stimulus;
reg clk;
reg reset;
wire[3:0] q;
// instantiate the design block
ripple-carry-counter rl(q, clk, reset);
// Control the clk signal that drives the design block.Cycle time = 10ns
initial
clk = 1'b0; //set clk to 0
always
Port Connection Rules
inouts
• Internally, inout ports
must always be of the
type net.
• Externally, inout ports
must always be connected
to a net.
Port Connection Rules
Width matching
• It is legal to connect internal and external items of
different sizes when making inter-module port
connections.
• However, a warning is typically issued that the widths
do not match.
Unconnected ports
• Verilog allows ports to remain unconnected.
fulladd4 fa0(SUM, , A, B, C_IN); // Output port c_out is unconnected
Example of illegal port connection
module Top;
• //Declare connection variables
reg [3:0]A,B;
reg C_IN;
reg [3:0] SUM;
wire C_OUT;
//Instantiate fulladd4, call it fa0
fulladd4 fa0(SUM, C_OUT, A, B, C_IN);
//Illegal connection because output port sum in module fulladd4
//is connected to a register variable SUM in module Top.
<stimulus>
• endmodule
Example of illegal port connection
This problem is rectified if the variable SUM is declared as a net (wire).
Connecting Ports to External Signals
0 A= 0000, B=0000, C_IN= 0, --- C_OUT= 0, SUM= 0000 A = 4'd0; B = 4'd0; C_IN = 1'b0;
5 A= 0011, B=0100, C_IN= 0, --- C_OUT= 0, SUM= 0111 #5 A = 4'd3; B = 4'd4;
10 A= 0010, B=0101, C_IN= 0, --- C_OUT= 0, SUM= 0111 #5 A = 4'd2; B = 4'd5;
15 A= 1001, B=1001, C_IN= 0, --- C_OUT= 1, SUM= 0010 #5 A = 4'd9; B = 4'd9;
20 A= 1010, B=1111, C_IN= 0, --- C_OUT= 1, SUM= 1001
#5 A = 4'd10; B = 4'd15;
25 A= 1010, B=0101, C_IN= 1 --- C_OUT= 1, SUM= 0000
#5 A = 4'd10; B = 4'd5; C_IN = 1'b1;
4-bit Ripple Carry Counter
module counter(Q , clock, clear);
output [3:0] Q;
input clock, clear;
// Instantiate the T flipflops
T_FF tff0(Q[0], clock, clear);
T_FF tff1(Q[1], Q[0], clear);
T_FF tff2(Q[2], Q[1], clear);
T_FF tff3(Q[3], Q[2], clear);
endmodule
Variables
Thank You