St. Thomas' College of Engineering and Technology: Laboratory Manual Computer Architecture PCC-CS492
St. Thomas' College of Engineering and Technology: Laboratory Manual Computer Architecture PCC-CS492
DEPARTMENT OF
INFORMATION TECHNOLOGY
Laboratory Manual
Computer Architecture
PCC-CS492
Name: ____________________________
University Roll No: _____________________
College Roll No: _______________________
Year:___________ Semester: _________
Session: _____________________________
General Information
Computer Architecture
Course Name Semester IV
Lab
Course Code PCC-CS492 Year with stream 2ndyear IT
Course Credit 2 Session 2020-2021
Faculty Class hours and
4 hrs.
Instructor/s total class load
Technical
Laboratory
assistant/s
CO 1 Apply the knowledge of hardware simulation for both structural and Apply
behavioral approach.
CO 2 Choose proper combinational modules, such as multiplexers, Apply
decoders etc. to develop a complex combinational system
CO 3 Build sequential systems composed of standard sequential modules, Apply
such as counters and registers.
CO 4 Analyze complex circuit and break them into smaller module and Analyzing
implement.
CO 5 Understand interfacing of peripheral devices with controller. Understanding
CO 6 Design & Develop any digital design interface using HDL Create
1
Computer Architecture Laboratory (PCC-CS492)
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
CO1
CO2
CO3
CO4
CO5
CO6
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
List of Experiments
4 Combinatorial circuit I
5 Combinatorial circuit II
8 Arithmetic operations II
10 Counters
13 Design of ALU
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
LAB SESSION 01
Net data types are used to model connections in structural descriptions. They do not store values
(except trireg). The net data types have the value of their drivers.
Example:
wire [7:0] Data; // Array declaration
wire [7:0] data [0:7] // Two dimensional array
wire [7:0] Array [0:255][0:255][0:255]; // Multidimensional array
Notes:
• supply1 and supply0 are used to declare power and ground nets only.
Syntax:
• register_type [ size ]variable_name, variable_name, ...;
• register_type [ size ]variable_name = initial_value;
• register_type [ size ]memory_name [ array_size ];
• register_type [ size ]memory_name [ array_size ] [ array_size ] ...; //
Multi-dimensional array
Description:
• Register data types are used as variables in procedural blocks. They store logic values only (no
logic strength).
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
• A register data type must be used when the signal is on the left-hand side of a procedural
assignment.
• Verilog-2001 adds the ability to initialize variables at the time they are declared. The initial value
assigned to the variable takes effect at simulation time zero, just as if the value had been assigned
within an initial block.
Example:
• reg [7:0] Data;
• integer Int;
• time Now;
• reg [15:0] Memory [0:1023];
• reg [7:0] A = 8'h3C;
• reg [7:0] Array [0:255][0:255][0:255];
Use reg for describing logic, integer for loop variables and calculations, real in system modules,
and time and realtime for storing simulation times in testbenches.
Verilog Operators:
Continuous Assignment
A continuous assignment drives a value into a net.
Syntax:
net_data_type [ strength ] [ delay ] [ size ] net_name = expression; // implicit
assign [ strength ] [ #( delay ) ] net_name = expression; // explicit
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Description:
Continuous assignments model combinational logic. Each time the expression changes on the right-hand side, the
right-hand side is re-evaluated, and the result is assigned to the net on the left-hand side.
The implicit continuous assignment combines the net declaration (see Net data type) and continuous assignment into
one statement. The explicit assignment require two statements: one to declare the net (see Net data type), and one to
continuously assign a value to it.
Continuous assignments are not the same as procedural continuous assignments. Continuous assignments are
declared outside of procedural blocks. They automatically become active at time zero, and are evaluated concurrently
with procedural blocks, module instances, and primitive instances.
Example:
wire Q = A || B; // continuous assignment
wire Out;
assign Out = A & B;
assign {COut, Sum} = A + B + CIn;
wire #50 Out = A & B;
Problem statement:
Write verilog programs to design, simulate and test the following circuits:
a) Basic gates
b) Universal gates
c) Exclusive gates
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Questionnaires:
1.1. What is the difference between wire and reg?
1.2. Which of the following statements is true for Verilog modules?
a. A module can contain definitions of other modules.
b. When a module X is called multiple numbers of times from some other module, only one copy
of module X is included in the hardware after synthesis.
c. More than one module can be instantiated within another module.
d. If a module X is instantiated 4 times within another module, 4 copies of X are created.
1.3. For the following Verilog code segment, what will be the number of bits in C as deduced during
synthesis?
wire [9:0] A, B;
integer C;
C = A + B + 1;
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
LAB SESSION 02
Title: TERNARY OPERATOR
Objective: Introduction to ternary operator
Theory:
Procedural Assignment
A procedural assignment updates the value of register data types.
Syntax:
[ delay ]register_name = [ delay ] expression; // blocking
[ delay ]register_name<= [ delay ] expression; // non-blocking
Description:
Procedural assignments are used for updating register data types and memory data types.
The expression in a blocking procedural assignment is evaluated and assigned when the statement is encountered. In
a begin-end sequential statement group, execution of the next statement is blocked until the assignment is complete.
In a non-blocking procedural assignment, the expression is evaluated when the statement is encountered, and
assignment is postponed until the end of the time-step. In a begin-end sequential statement group, execution of the
next statement is not blocked and may be evaluated before the assignment is complete. A group of statements with a
non-blocking assignment has similar functionality as a group of statements within a fork-join block.
The left-hand side of a procedural assignment should be one of the following:
When the right-hand side evaluates to a fewer bits than the left-hand side, the assignment to a reg does not
sign-extend.
The evaluation of the assignment is delayed by the delay when the delay is specified before the register name. When
the delay is specified before the expression, the expression is evaluated when the statement is encountered, and
assigned in the time-step specified by the delay.
Example:
begin
a = 0;
#10 a = 1;
#5 a = 2;
end // time 0: a=0; time 10: a=1; time 15 (#10+#5): a=2;
begin
a <= 0;
#10 a <= 1;
#5 a <= 2;
end // time 0: a=0; time 5: a=2; time 10: a=1;
begin
a <= b;
b <= a;
end // both assignments are evaluated before a or b changes
Useful statement: assign out = sel ? 0:1;assigns the value of out as 0 if selis 1 and the value of out as 1 when selis 0.
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Statement: Write a Verilog program to design, simulate and test a circuit ofa tri-state buffer having following
properties:
• Take 1-bit Input as I
• Control Input (CNT’)
• Output is Z
------------------------------------------------------------------------------------------------------------------------------
2.24-bit Unidirectional Bus
Statement: Write a Verilog program to design, simulate and test a circuit ofa 4-bit unidirectional bus circuithaving
following properties: [Hint: use 2.1 module initiation in the coding]
• Take 4-bit Input as I
• Control Input (CNT’)
• Output is Z (4-bit)
------------------------------------------------------------------------------------------------------------------------------
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Questionnaires:
1.1. What are the differences between blocking and non-blocking assignments?
1.2. Write averilogcode to swap contents of two registers with and without atemporary register?
1.3. What is the difference between === and == ?
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
LAB SESSION 03
Title: MINIMIZATION TECHNIQUES
Objective: Implementation of Boolean function and Logic Equations
Problem statement:
3.1 Majority Circuit
A majority circuit is a combinatorial circuit whose output is equal to 1 if the input variables have more
1’s than 0’s. Design a 3-input majority circuit.
Statement: Write a Verilog program to design, simulate and test a circuit of3-input majority circuit
having following properties:
• Take 3-bit Input as A2A1A0
• Output as Z
---------------------------------------------------------------------------------------------------------------------------
3.2 Two’s complementer
Design a 4-bit combinational circuit for implementing 2’s complement. Show that the circuit can be
constructed using exclusive-OR gates.
Statement: Write a Verilog program to design, simulate and test a circuit of4-bit 2’s complement circuit
having following properties:
• Consider 4-bit input as (A3A2A1A0) and 4-bit output as (B3B2B1B0).
• Form the truth table for 4-bit 2’s complementer circuit.
• Use the minimal sum-of-products(SOP) method to derive the logic for the 4-bit output
(B3B2B1B0).
---------------------------------------------------------------------------------------------------------------------------
3.3 Function minimization
A) Statement:Implement the Boolean function: F(A, B, C, D)= Σ (0, 1, 3, 4, 8, 9,15) using a Verilog
program and test the above circuit.
B) Statement: Write a Verilog program to design, simulate and test a combinatorial circuit with 3-bit
input as A2A1A0 and 3-bit output as B2B1B0. When the binary input is 0, 1, 2, or 3, the binary output
is one greater than the input. When the binary input is 4, 5, 6, or 7, the binary output is one less than
the input.
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Questionnaire:
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
LAB SESSION 04
Title: COMBINATIONAL CIRCUITS
Objective: Implementation of combinational circuits.
Problem statement:
4.1 Multiplexer (4 to 1)
Statement:Write a Verilog program that implements Multiplexer module (4x1 MUX).
---------------------------------------------------------------------------------------------------------------------------
4.2 8-to-1 multiplexer
Statement: Write a Verilog program that includes above module (4x1 MUX) to describe the functionality
of 8-1 multiplexer circuit.
---------------------------------------------------------------------------------------------------------------------------
4.3 Decoder (3 to 8)
Statement: Write a verilog code to design, simulate and test a circuit of 3 to 8 decoder.
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Questionnaires:
4.1. What is the difference between the following two lines of verilog code?
#5 a = b;
a = #5 b;
4.2. What do we mean by continuous assignment?
4.3. For the following Verilog code segment:
wire [7:0] A;
wire B;
assign B = ^A;
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
LAB SESSION 05
-------------------------------------------------------------------------------------------------------------------------
Truth Table/ Functional Table/ Circuit/Block Diagram:
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Questionnaires:
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Problem statement:
6.1 Code conversion
A) Binary-to-BCD Converter
B) Binary to gray code converter
C) Gray code to binary converter
D) Binary to Excess-3 code converter
E) Excess-3 code to binary converter
Statement: Write a verilog code to design ,simulate and test the circuits of the above Converters (4 bit).
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Questionnaires:
6.1. For the following code segment, the final value of variable “Z” will be ……. Justify your answer.
Integer X, Y, Z;
Initial
Begin
X=33; Y=27; Z= 16;
Y <= #10 X- Z;
X<= #10 Y * 5;
Z<= #10 X + Y
End
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
LAB SESSION 07
Problem statement:
7.1Half Adder
Statement:Write a Verilog program to design, simulate and test the functionality of a half adder circuit.
---------------------------------------------------------------------------------------------------------------------------
Statement:Write a Verilog program to design, simulate and test the functionality of a full adder circuit.
---------------------------------------------------------------------------------------------------------------------------
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Questionnaires:
7.1. If the 8-bit variable “x” declared as “reg [7:0] x” is initialized to 8’b 10101101, what will be its value
after executing the following code segment?
always @(posedge clock)
begin
x <= x << 1;
x[0] <= x[7];
end
LAB SESSION 08
Title: ARITHMETIC OPERATION
Objective: Implementation of Arithmetic operations
Problem statement:
8.1 Incrementer Circuit (4-bit)
Statement:Write a verilog program to design, simulate and test the functionality of the 4-bit incrementer
circuit.
------------------------------------------------------------------------------------------------------------------------
8.2 Decrementer Circuit (4-bit)
Statement:Write a verilog program to design, simulate and test the functionality of the 4-bit decrementer
circuit.
------------------------------------------------------------------------------------------------------------------------
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Questionnaires:
LAB SESSION 09
Title: SEQUENTIAL LOGIC
Objective: Implementation of Sequential logic
Problem statement:
9. Flip Flops
Statement: Write a Verilog program to design, simulate and test the circuits of the following flip-flops
A) D Flip Flop
B) S-R Flip Flop
C) J-K Flip Flop
D) T Flip Flop
-------------------------------------------------------------------------------------------------------------------------
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Questionnaires:
LAB SESSION 10
Title: COUNTERS
Objective: Implementation of Counters
Problem statement:
10.Statement: Write a Verilog program to design, simulate and test the following counters.
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Questionnaires:
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
LAB SESSION 11
Title:Shift Register
Objective: Implementation of Shift Registers and GPR
Problem statement:
11.Statement: Write a verilog program to design, simulate and test the following registers.
A) SISO
B) SIPO
C) PISO
D) PIPO
E) GPR
--------------------------------------------------------------------------------------------------------------------
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Questionnaires:
LAB SESSION 12
Title:Main Memory
Objective: Implementation of Main Memory
Problem statement:
12.1 RAM Realization
Statement: Write a Verilog program to model a RAM memory cell with all the following considerations.
Statement: Write a Verilog program to model a ROM memory cell with all the following considerations.
• Read signal(RD’)
• Address line (A)
• Select line (EN’ active low)
• Data I/P (DI)
• Data O/P (DO)
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Questionnaires:
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
LAB SESSION 13
Title:Arithmetic and Logical Unit (ALU)
Problem statement:
13.Statement:Write a verilog program to implement an 8-bit ALU which will perform the following
functional table.
Functional Table:
Sl no. Operation Remarks
0 A-B Without carry
1 A+B
2 A+B+Cin
3 A-B+(~Cin) With carry
4 A^B A xorB
5 ~B B’
6 A|B AOR B
7 A&B A AND B
-------------------------------------------------------------------------------------------------------------------------
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Questionnaires:
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
LAB SESSION 14
Title:Moore FSM Sequence Detector
Problem statement:
The Moore FSM keeps detecting a binary sequence from a digital input and the output of the FSM goes
high only when a "1011" sequence is detected. The state diagram of the Moore FSM for the sequence
detector is shown in the following figure.
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Questionnaires:
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
Loops in Verilog
1. While loop
A while statement executes the code within it repeatedly if the condition it is assigned to check returns true.
While loops are normally not used for models in real life, but they are used in test benches. As with other
statement blocks, they are delimited by begin and end.
always @ (posedgeclk or posedgerst)
if (rst) begin
count <= 0;
end
else begin
while (enable) begin
count <= count + 1;
end
end
---------------------------------------------------------------------------------------------------------------------------
2. For loop
For loops in Verilog are almost exactly like for loops in C or C++. The only difference is that the ++ and --
operators are not supported in Verilog. Instead of writing i++ as you would in C, you need to write out its
full operational equivalent, i = i + 1.
We need to test it to see if it works according to specifications. Let's look at the Module Under Test (MUT)
testbench.
module MUT (
clock,
reset,
req_0,
req_1,
gnt_0,
gnt_1
);
module MUT_tb;
initial begin
$monitor ("req0=%b,req1=%b,gnt0=%b,gnt1=%b", req0,req1,gnt0,gnt1);
clock = 0;
reset = 0;
req0 = 0;
req1 = 0;
#5 reset = 1;
#15 reset = 0;
#10 req0 = 1;
#10 req0 = 0;
#10 req1 = 1;
#10 req1 = 0;
#10 {req0,req1} = 2'b11;
#10 {req0,req1} = 2'b00;
#10 $finish;
end
always begin
#5 clock = ! clock;
end
MUT U0 (
.clock (clock),
.reset (reset),
.req_0 (req0),
.req_1 (req1),
Page No.___________
Computer Architecture Laboratory (PCC-CS492)
.gnt_0 (gnt0),
.gnt_1 (gnt1)
);
endmodule
Page No.___________