Computer Organization and Architecture Lab 2014
Computer Organization and Architecture Lab 2014
EE-227L
Computer Organization and
Architecture Lab
School of Engineering
University of Management and Technology
CII, Johar Town Lahore
http:/www.umt.edu.pk
University of Management & Technology
School of Engineering
List Of Experiments
Week Experiments
5 MIPS Linking
6 Introduction to Basic Syntax of Verilog and Gate-level-Modeling Using Xilinx ISE tools
7 Simulation of Full and 4-Bit Ripple Carry Adder in Gate Level Abstraction
13 To Understand the codes of Data Memory, Instruction Memory, Register file, ALU and
Address Generator of The Single Cycle MIPS Machine
14 Complete Data path and Control of The Single Cycle MIPS Machine
Roll #:_____________________________
1.1 Introduction
PCSpim is a personal computer simulator for MIPS. It helps in learning the
language without having to buy a MIPS-based computer. It also provides
debugging features such as setting breakpoints, executing instructions in steps
and viewing register and memory contents during the execution of the
program. PCSpim does not come with an editor or a word processor, so, we
shall be using Notepad for writing the programs.
This window is called the registers window. It contains information about the
Program Counter (PC) and General, Single and Double Floating Point Registers.
Each of these is thirty-two in number.
This window displays the contents of the text segment. Recall that the text
segment is the portion of the memory that contains the instructions to be executed.
Page | 1
Computer Organization And Architecture LAB 1
The first column contains the address of the instruction. The second one is the
instruction expressed in Hex form (a topic for next class on Monday); the third is
the actual machine language instruction to be executed while the last contains the
original instruction.
This window displays the contents of the data segment. Data segment
reserves the space for declarations (int, char etc)) that you do while writing the
program. It also shows the contents of the stack.
1.3 EXAMPLE # 1
Open Notepad and type in the following code: (Note that .data portion is optional
and not needed here)
Note that it is case sensitive, all program in lower case except labels.
main:
addi $s0, $zero, 100
addi $s1, $zero, 200
addi $s2, $zero, -300
To run the program in single steps press F10 for each instruction. Keep pressing
F10 till you reach the instruction at address 0x00400024 (shown on left side in test
window). This is where you program starts and here you will be able to see your
program in widow as mentioned above. These instruction corresponds to the
instructions of your program. All the instructions before this address are added by
PCSPIM.
Note that at this point notice that all register contain 0000 0000 (they are displayed
in HEX by default.)
You shall be required to provide all the answers in hex form. However, you should
view registers in decimal form to confirm your answers. For $t3, $t4, do the
calculations in 32-bit binary (by directly converting hex values of s0 and s1
given above) on the back of this page to verify your answer.
1.4 Exercise # 1: Summing the First Ten Integers using Control Instruction
The following code sums the first ten positive integers. Figure out the missing parts
and run the program.
main:
addi $s0, $zero, 10 #counter
addi $t0, $zero, 0 #sum/accumulator initialized to 0
loop1: # fill missing values
add ______, ______, ______
addi ______, ______, -1
bnez ______, ______
nop
nop
After executing the last instruction in the loop and before executing the nop (No
Operation) instruction, what is the value of $t0? _______. Show the program to
your Teacher _______
1.5.2.1 Exercise # 1
Write a program to load the value 223 in $t0 register. Shift it left by 5, then shift it
right by 7 and then shift it left by 2.
Show your program to Teacher: _____________ Run the program.
What is the Hex value of 223 load in $t0:___________
What is value of $t0 after it is shifted left by 5? ___________. Why?
___________________
What is value of $t0 after it is shifted right by 7? ___________.
Why?__________________
What is value of $t0 after it is shifted left by 2? ___________. Why?
____________________
Is the final result different from 223: Why?
__________________________________________
1.5.2.2 Exercise # 2
Write a program to load 220 in $s0. Mask $s0 using and operation to obtain least
significant five bits of $s0 and store them in $s1. Find the sum of 8*$s1 and $s1/8
using shift operations. Show your program to Teacher. _____________
What is the sum? _________
1.5.2.3 Exercise # 3
Recall that immediate field in addi can hold 16 bits. We learned how to load a 32-
bit value in a register. Let us try that.
Remember the method is: 1. Load upper (most significant) 16 bits in a register. 2.
Shift it left by 16 places. 3. Add lower (least significant) 16 bits.
Using the abovementioned method, load the value 0x12345678 in $t0. You can
load hex values using 0x notation,
e.g. addi $t0, $zero, 0x1234. Show your code to the Teacher _______.
Page | 4
Computer Organization And Architecture LAB 1
Assembler directives give a programmer the ability to establish some initial data
structures that will be accessed by the computer at “run time”. Some directives
we have learned in the class are:
.data All the items following this directive are stored in the data segment.
.globl main Declare that the label main is global so it can be referenced by operating
system.
.text All the items following this directive are stored in the text segment or the code of the
program.
.word w1,…,wn Store the n 32-bit quantities in successive memory words.
.data
myData: .word 2, 12, -5, 7, 4, -2, 3, -7, 89, 4
sum: .word 0 # this will contain the sum
.globl main
.text
main:
la $s0, myData #load address of myData
add $t2, $zero, $zero #initialize to save the sum
<Write you code here to do sum of myData array. Do not use any branch instruction but
hard code for each element.
Page | 5
Computer Organization And Architecture LAB 1
la $s0, sum
sw $t2, 0($s0)
You need to show the program and its working to the Teacher. What is value of sum:
_______
What is the address of first element of array in data segment: _______________. Check this
after you run first instruction of the program that $s0 is indeed loaded with that correct
address using special assembler generated instruction. We will not discuss la (load
address instruction) any further.
What address is loaded for sum _____________ and why ___________________. (How can you
calculate this address)
What value is stored at the address of sum __________ (see data memory to answer this,
before and after stepping through the last instruction)
Repeat exercise 5 but this time using branch instruction and for 15 values
.data
myData: .word 200, -1299, -5000, 7123, 4, -2, 3, -7, 89, 4, -1000, 11, 0, 14, -1
sum: .word 0 # this will contain the sum
.globl main
.text
main:
la $s0, myData #load address of myData
li $t1, 9 #counter , you may initialize to 10 not 9
add $t2, $zero, $zero #initialize to save the sum
loop:
<Write you code here to do sum of myData array using beq or bneq instruction>
exit:
la $s0, sum
Page | 6
Computer Organization And Architecture LAB 1
sw $t2, 0($s0)
0x10010000: _____________
0x10010004: _____________0x10010008: _____________
0x1001000C: _____________
0x10010010:_____________
0x10010014:_____________0x10010018:_____________
0x1001001C:_____________
0x10010020:_____________
0x10010024:_____________0x10010028:_____________
0x1001002C:_____________
0x10010030:_____________
0x10010034:_____________0x10010038:_____________
0x1001003C:_____________
Page | 7
Computer Organization And Architecture LAB 1
Observations/Comments/Explanation of Results
Page | 8
Computer Organization And Architecture LAB 1
Page | 9
Computer Organization And Architecture LAB 2
Roll #:_____________________________
Following is the last exercise from the last lab. It finds sum of 10 numbers stored in an array
myData[10]. Remember index goes from 0 to 9 in C.
.data
.globl main
.text
main:
assigned to sum
loop:
sw $t2, 0($s1) # store the sum, could’ve stored once outside the loop
exit:
nop
Type and run this program and show its working to the Teacher.
Exercise 2.
Page | 11
Computer Organization And Architecture LAB 2
Exercise 3. We have seen the C code and Assembly code. Now let us create a processor
picture for the above code.
Fill the missing boxes (*) in the following Memory Map and write values in SUM data
memory AFTER the sum is stored.
data
●●●
●●●
●●●
[0x1001002c]
[0x10010024] * *
[0x10010020] * *
[0x1001001c] * *
[0x10010018] * *
[0x10010014] * *
[0x10010010] 0x00000004 *
[0x1001000c] 0x00001bd3 *
[0x10010008] 0xffffec78 *
Page | 12
Computer Organization And Architecture LAB 2
[0x10010004] 0xfffffaed -1299 Use calculator to confirm
that
●●●
●●●
●●●
[0x0040004c] * * * ***
[0x00400048] * * *
[0x00400044] * * * **
[0x00400040] * * *
[0x0040003c] * * * **
[0x00400038] * * *
[0x00400034] 0x00005020 add $10, $0, $0 add $t2, $zero, $zero **
[0x0040002c] 0x3431003c ori $17, $1, 60[sum] Here confirm that $s0 and
[0x00400024] 0x3c101001 lui $16, 4097 [myData]la $s0, myData Your program code starts
here
Page | 13
Computer Organization And Architecture LAB 2
** On back of the page use 32-bit hex code to prove that this the right instruction in
assembly.
Why____________________
Page | 14
Computer Organization And Architecture LAB 2
Observations/Comments/Explanation of Results
Page | 15
Computer Organization And Architecture LAB 2
Page | 16
Computer Organization And Architecture LAB 3
Roll #:_____________________________
System call is used to communicate with the system for reading from
keyboard or writing to screen. System call require some parameter to be
passed in a particular register and a request number (or service code) to be
passed in another register $v0.
1. Load system call code into Register $v0. Codes (Value of $V0 to be
loaded) are given in the table below.
2. Load arguments (if any) into registers $a0, $a1
3. use syscall
4. Results are returned in registers $v0.
.data
Page | 17
Computer Organization And Architecture LAB 3
mesg1: .asciiz “My Name is ………. \n“
.text
.globl main
main:
syscall
syscall
Type the code given on the last page to find the sum of N integers and run for N =
100, N= 200, N= 1000.
Page | 18
Computer Organization And Architecture LAB 3
___________, _______________, _______________, _____________
Now for what value of N you start getting wrong answers, can you explain the wrong
answer.
What happens if you give a very large N, say 100000. Can you explain the answer
now _____________.
Let say we have the following function that returns 0 if the value passed is greater
than 255, 0 otherwise. Convert the following C program to MIPS assembly.
int check255(int x)
int result;
if (x > 255) {
result = 0;
else {
result = 1;
return result;
Page | 19
Computer Organization And Architecture LAB 3
Here is a template for the program that uses check255 function. The template
shows how to call a function. In addition, it shows how to read from the keyboard
and write answer to the screen using SPIM system calls.
.text
.globl main
main:
# get input
add $a0, $zero, $v0 # put int into $a0, the argument register for
parameter passing
# print output
check255:
Page | 20
Computer Organization And Architecture LAB 3
What is value stored in $ra when jal check255 is executed ________, Why
________________
.data
.globl main
.text
main:
jal sum # call sum function.On return v0 will have some of pos nos
syscall
syscall
syscall
syscall
sum:
li $v0,0
li $v1,0
Loop:
blez $a1, Return #a1 has N, if N is less than 0 return from function
Negative:
b Loop
Return:
jr $ra
######################################################
#######################################################
# Functional Description:
# cin >> v0
# If ( v0 > 0 )
# {t0 = 0;
# {t0 = t0 + v0;
# v0 = v0 – 1}
# }
# else /*User can input any negative number to terminate this program */
# cout << “\n **** Bye Bye – Have good day ****”
####################################################################
##
# Cross References:
####################################################################
#### .data
.glob1 main
.text
main:
Loop:
Page | 24
Computer Organization And Architecture LAB 3
addi $v0, $v0, -1 # summing integers in reverse order
b # branch to main
Page | 25
[ Computer Organization And Architecture] [lab 3]
Observations/Comments/Explanation of Results
Page | 26
Computer Organization And Architecture LAB 4
Roll #:_____________________________
Experiment 1:
using loop perform the following task
(the compute should ask the user to enter digits as shown and should
display the sum
Enter digit 1
Enter digit 2
Enter digit 3
Enter digit 4
Enter digit 5
The sum is _____
Note: it should not just ask you to enter digit,it should ask you to give
1st,2nd,3rd,4th,5th digit as shown above and use onlyi loop.
Bonus:(you can try this at the end of lab session,you can submit it till next
lab for bonus marks)
Experiment 2:
What does the following program calculates ?
.text
.globl main
main:
li $v0,5
syscall
add $a0,$zero,$v0
li $v0,5
syscall
add $a1,$zero,$v0
li $v0,5
syscall
add $a2,$zero,$v0
Page | 27
Computer Organization And Architecture LAB 4
li $v0,5
syscall
add $a3,$zero,$v0
jal abc
li $v0,1
add $a0,$zero,$s2
syscall
li $v0,10
syscall
abc:
add $s0,$a0,$a1
add $s1,$a2,$a3
sub $s2,$s0,$s1
jr $ra
Experiment3:
why is the given program not giving the correct value. Debug !
.text
.globl main
main:
li $v0,5
syscall
add $a0,$zero,$v0
li $v0,5
syscall
add $a1,$zero,$v0
li $v0,5
syscall
add $a2,$zero,$v0
Page | 28
Computer Organization And Architecture LAB 4
li $v0,5
syscall
add $a3,$zero,$v0
jal sum
li $v0,1
add $a0,$zero,$s0
syscall
li $v0,10
syscall
sum:
addi $sp,$sp,-12
sw $t0,8($sp)
sw $t1,4($sp)
sw $s0,0($sp)
add $t0,$a0,$a1
add $t1,$a2,$a3
sub $s0,$t0,$t1
lw $t0,8($sp)
lw $t1,4($sp)
lw $s0,0($sp)
addi $sp,$sp,12
jr $ra
Experiment4:
following function opens the console ,user enters the digit and by running
the program all the way through, calculates its factorial.
Page | 29
Computer Organization And Architecture LAB 4
main:
li $v0,5
syscall
add $a0,$zero,$v0
jal fact
add $a0,$zero,$v0
li $v0,1
syscall
li $v0,10
syscall
fact:
addi $sp,$sp,-8
sw $ra,4($sp)
sw $a0,0($sp)
slti $t0,$a0,1
beq $t0,$zero,l1
addi $v0,$zero,1
addi $sp,$sp,8
jr $ra
lw $a0,0($sp)
lw $ra,4($sp)
addi $sp,$sp,8
mul $v0,$a0,$v0
jr $ra
lab tasks:
make the program more refined
Page | 30
Computer Organization And Architecture LAB 4
>display on console, the system should ask you to enter the digit whose
factorial you want to find.
Lab Assignment:
Page | 31
Computer Organization And Architecture LAB 4
Observations/Comments/Explanation of Results
Page | 32
Computer Organization And Architecture LAB 5
Roll #:_____________________________
Page | 33
Computer Organization And Architecture LAB 5
2.
Page | 34
Computer Organization And Architecture LAB 5
Page | 35
Computer Organization And Architecture LAB 5
3. Load Lab5-part1.s into QTSPIM. Use “Reinitialize and Load Program”. Then use “Load File” to
load lab5-part2.s
Page | 36
Computer Organization And Architecture LAB 5
Observations/Comments/Explanation of Results
Page | 37
Computer Organization And Architecture LAB 6
Roll #:_____________________________
Objectives:
Understanding how to define the port list for a module and declare it in
Verilog.
Reference:
Chapter 4
Procedure:
Page | 38
Computer Organization And Architecture LAB 6
Start >> Programs >> Xilinx ISE 7.1 >> Project Navigator
Page | 39
Computer Organization And Architecture LAB 6
Page | 40
Computer Organization And Architecture LAB 6
C:\COMParch\Your ID
4. Click Next.
5. In the next window of ‘Select Device and Design Flow for the Project’:
Page | 41
Computer Organization And Architecture LAB 6
Select the simulator as : ISE simulator and don’t worry about the rest of the options for
the time being. We shall look at them in greater detail afterwards.
6. Click Next.
Page | 42
Computer Organization And Architecture LAB 6
Page | 43
Computer Organization And Architecture LAB 6
Page | 44
Computer Organization And Architecture LAB 6
Page | 45
Computer Organization And Architecture LAB 6
Page | 46
Computer Organization And Architecture LAB 6
Page | 47
Computer Organization And Architecture LAB 6
Page | 48
Computer Organization And Architecture LAB 6
Page | 49
Computer Organization And Architecture LAB 6
15. Enter the following Verilog Code in half_adder.v file and save the file:
output sum;
output carry;
input in1;
Page | 50
Computer Organization And Architecture LAB 6
input in2;
endmodule
In the ‘Processes Window’, located 2nd from the top on the left hand side, locate
the “Synthesize-XST” process and expand it by clicking on the small box
containing + sign alongside it. Now, in the options available inside the
“Synthesize-XST” process, locate the “Check Syntax” step and click on it.
Page | 51
Computer Organization And Architecture LAB 6
16. Make the Gate-level Diagram of the half and full adder. Show proper working and table.
Page | 52
Computer Organization And Architecture LAB 6
17. Make sure that your Verilog Code is free of any Syntax errors and the Check Syntax process
does not give any error.( of course we are talking about half-adder you just made. )
19. In the New Source Window, select the ‘Test Bench Waveform’ out of different options available
in the left hand column and give the file name as “half_adder_tb”.
Page | 53
Computer Organization And Architecture LAB 6
21. In the next window, you have to associate this testbench waveform with a particular verilog
module of your design to which you want to apply this waveform and check the results. As we
have only one module, half_adder, in our design, select half_adder and then click Next.
Page | 54
Computer Organization And Architecture LAB 6
22. In the next ‘New Source Information’ window, simply click Finish.
Page | 55
Computer Organization And Architecture LAB 6
Page | 56
Computer Organization And Architecture LAB 6
24. In the right hand side portion named ‘Clock Information’, select ‘Combinational (or Internal
Clock)’ option.
Page | 57
Computer Organization And Architecture LAB 6
Page | 58
Computer Organization And Architecture LAB 6
27. In this Waveform window, you can see that outputs are indicated with yellow colour and
inputs are indicated with light green colour.
28. You can click the input signal waveform area to decide what waveform you want to apply to
the inputs of your module and then in the next step, you will be able to simulate and see the
results of applying that particular input in the form of output waveforms.
Page | 59
Computer Organization And Architecture LAB 6
29. Click the save icon in order to save this TestBenchWaveform file named half_adder_tb.tbw.
30. In the ‘Sources in the Project’ window on the top left hand side, select the Test Bench
Waveform file named ‘half_adder_tb’. Then, click on the ‘Process View’ tab, located at the
bottom of the 2nd window from the top on the left hand side.
Page | 60
Computer Organization And Architecture LAB 6
31. Clicking the ‘Process View’ for half_adder_tb file will result in the screen as shown below:
Page | 61
Computer Organization And Architecture LAB 6
32. Expand the “Xilinx ISE Simulator” options in the Processes Window and double click on the
“Simulate Behavioral Model” option.
33. This will start the simulation process and you will end up with something like this:
Page | 62
Computer Organization And Architecture LAB 6
34. Out of the four tabs available at the bottom of the main window, select the second from the
right hand side named half_adder_tb_isim. This will show you the results of simulating the
Verilog module half_adder.v by applying it the input waveform mentioned in the file
half_adder_tb.tbw.
Page | 63
Computer Organization And Architecture LAB 6
35. Assignment:
Page | 64
Computer Organization And Architecture LAB 6
36.
Write down the module statement and port list for the following Block diagram:
( You are not expected to write the whole programme just the first couple of statements )
Page | 65
Computer Organization And Architecture LAB 6
Observations/Comments/Explanation of Results
Roll #:_____________________________
Page | 66
Computer Organization And Architecture LAB 7
Objective:
Full Adder:
Following the steps described in the manual 5 simulate full adder . ( I mean the so many
steps you just did , do them again and get used to them . They are your friends!!! )
Gate level code for the full adder module:
output sum;
output carry_out;
input in1;
input in2;
input carry_in;
wire c, d, e;
xor x1(c,in1,in2);
or o1(carry_out, d, e);
endmodule
Page | 67
Computer Organization And Architecture LAB 7
Note the difference of Verilog code for the full adder and the code of half adder employed in
the last couple of steps . Note the use of “wire c,d,e;” in order to handle the intermediate
connections between the gates.
1. Enter this code and then, simulate it using the steps described above
The use of the smaller blocks to design a larger block is known as “Hierarchical Design”.
This sort of hierarchical design can be implemented in Verilog as well through the concept
of “Instantiating” a smaller module in some larger module .Following is the Verilog Code for
the full adder using this hierarchical approach, by “Instantiating” the half_adder module
Page | 68
Computer Organization And Architecture LAB 7
module full_adder (sum ,carry_out, in1, in2, carry_in);
output sum;
output carry_out;
input in1;
input in2;
input carry_in;
wire c, d, e;
half_adder h1(s1,c1,in1,in2);
endmodule
3. Enter this code and then, simulate it using the steps described above.
Previously you had been asked to write the Verilog Code of a 4 bit Ripple Carry Adder
which consisted of 4 full adders that you had previously designed. Now, you will again
write the Verilog Code for this Ripple Carry Adder but this time the inputs and outputs
will be handled differently using the concept of “Vectors” in Verilog.
1. Following is the Diagram for that Ripple Carry Adder using this new approach.
Page | 69
Computer Organization And Architecture LAB 7
2. Following is the Verilog code for the Ripple Carry Adder defining the inputs and
outputs as Vectors.
output carry_out;
input carry_in;
endmodule
Page | 70
Computer Organization And Architecture LAB 7
Roll #:_____________________________
Objectives:
As it had been mentioned in the first lab that in Verilog we have different levels of
abstraction available to us like:
a. Gate level
b. Dataflow level
c. Behavioral level
In the first few labs, we have looked at the Gate level coding.
In the manual techniques of designing any digital logic circuit, we start from the truth
table, generate a separate Boolean Equation for each output column of the truth table,
then these Boolean equations are simplified using different techniques and finally, these
simplified Boolean equations are translated into gate level diagram.
In Gate level coding, we basically translate the gate level diagram of a circuit into
statements
While in Dataflow level coding, we can directly translate the Boolean equations of a circuit into
statements. So, you can easily see that Dataflow level coding is at a higher level of abstraction
Page | 71
Computer Organization And Architecture LAB 7
as compared to Gate level coding. While describing Boolean equations in the form of Dataflow
statements, we use logical operators like negation (~), and (&), or(|), xor(^), xnor(^~),etc.
Besides describing Boolean equations at Dataflow level, we can even move on to a higher level
of abstraction and use other type of operators as well like arithmetic operators(+,-)
Dataflow Operators:
Page | 72
Computer Organization And Architecture LAB 7
wire[3:0] x, y;
wire[7:0] z, q, w, t;
wire[31:0] m, n;
assign x = 4’b1100;
assign y = 4’b0101;
// m is 32’b11001100110011001100010111000101
input sel, a, b;
output q;
endmodule
input sel, a, b;
Page | 73
Computer Organization And Architecture LAB 7
output q;
assign q = sel ? b : a;
endmodule
output sum;
output carry;
input X;
input Y;
assign sum = X ^ Y;
endmodule
2:4 Decoder:
Page | 74
Computer Organization And Architecture LAB 7
module decode24(q, a);
output[3:0] q;
input[1:0] a;
endmodule
input sel;
input[15:0] a, b;
output[15:0] q;
assign q = sel ? b : a;
endmodule
input sel;
input[WID-1:0] a, b;
output[WID-1:0] q;
assign q = sel ? b : a;
endmodule
Page | 75
Computer Organization And Architecture LAB 7
module mux41n(q, sel, a, b, c, d);
parameter WID=16;
input[1:0] sel;
input[WID-1:0] a, b, c, d;
output[WID-1:0] q;
endmodule
Assignment:
Write down the code for 8to 1 Multiplexer in data flow level coding.
Page | 76
Computer Organization And Architecture LAB 7
Observations/Comments/Explanation of Results
Page | 77
Computer Organization And Architecture LAB 8
Roll #:_____________________________
Objectives:
After this lab you’ll be able to
Half Adder:
output sum;
output carry;
input X;
input Y;
assign sum = X ^ Y;
endmodule
Page | 78
Computer Organization And Architecture LAB 8
output sum;
output carry;
input X,Y,Z;
assign sum = X ^ Y ^ Z;
endmodule
Page | 79
Computer Organization And Architecture LAB 8
Assignment:
Write the code for a 4 bit adder using data flow modelling.
Page | 80
Computer Organization And Architecture LAB 8
Observations/Comments/Explanation of Results
Page | 81
Computer Organization And Architecture LAB 9
Roll #:_____________________________
Objectives
After this lab you’ll be able to
Introduction
A number of standard combinational logic functions have been developed for digital circuits that
represent many of the useful tasks that can be performed with digital circuits.
Decoders detect the presence of particular binary states and can activate other circuits based on their
input values or can convert an input code to a different output code.
Encoders generate a binary or binary coded decimal (BCD) code corresponding to an active input.
Multiplexers and de-multiplexers are used for data routing. They select a transmission path for
incoming or outgoing data, based on a selection made by a set of binary-related inputs.
Decoders
The general function of a decoder is to activate one or more circuit outputs upon detection of a
particular digital state. The simplest decoder is a single logic gate, such as a NAND or AND, hose
output activates when all its inputs are HIGH. When combined with one or more inverters, a NAND or
AND can detect any unique combination of binary input values. An extension of this type of decoder
is a device containing several such gates, each of which responds to a different input state. Usually, for
an n-bit input, there are 2n logic gates, each of which decodes a different combination of input
variables. Some types of decoders translate binary inputs to other forms, such as the decoders that
Page | 82
Computer Organization And Architecture LAB 9
drive seven-segment numerical displays. The decoder has one output for every segment in the display.
These segments illuminate in unique combinations for each input code
Figure 1 shows the logic circuit of a 2-line-to-4-line decoder. The circuit detects the presence of a
particular state of the 2-bit input D1D0, as shown by the truth table in Table 1. One and only one
output is HIGH for any input combination, provided the enable input G is LOW.
G(activelow) D0 D1 Y0 Y1 Y2 Y3
0 0 0 1 0 0 0
0 0 1 0 1 0 0
0 1 0 0 0 1 0
0 1 1 0 0 0 1
1 X X 0 0 0 0
Page | 83
Computer Organization And Architecture LAB 9
Task1:
A verilog module is shown below. Create a new project using Xilinx ISE.Add this module to
project and verify it by simulating its behavior .
begin
case (sel)
endcase
end
endmodule
Page | 84
Computer Organization And Architecture LAB 9
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Draw results from Test bench for 3 to 8 decoder? Indicate Input & Output signals?
Page | 85
Computer Organization And Architecture LAB 9
Task2:
A verilog module is shown below. Create a new project using Xilinx ISE.Add this module to
project and verify it by simulating its behavior.
always @(sel)
begin
case (sel)
endcase
end
endmodule
______________________________________________________________________________
Page | 86
Computer Organization And Architecture LAB 9
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Explain and record results for above verilog module? How this module will be
implemented at hardware level?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Draw results from Test bench for 3 to 8 decoder? Indicate Input & Output signals?
Page | 87
Computer Organization And Architecture LAB 9
Observations/Comments/Explanation of Results
Page | 88
Computer Organization And Architecture LAB 10
Roll #:_____________________________
Introduction
The arithmetic logic unit (ALU) carries out the logic operations (such as comparisons) and arithmetic
operations (such as add or subtract) required during the program execution. Generally
an ALU has two data inputs and one data output. Operations performed in the ALU often affect bits in
the status register (bits are set to indicate actions such as whether an overflow has occurred). The ALU
knows which operations to perform because it is controlled by signals from the control unit.
op_a; Input 4
op_b; Input 4
Func Input 2
alu_out Output 4
Page | 89
Computer Organization And Architecture LAB 10
begin
case(func)
endcase
end
endmodule
Page | 90
Computer Organization And Architecture LAB 10
Task1:
Create a project in Xilinx ISE .Add this file to the project .Now simulate this file using ISE Simulator.
Next synthesize this file using XST.
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Draw results from Test bench for ALU IN FIGURE 2? Indicate Input & Output
signals?
Page | 91
Computer Organization And Architecture LAB 10
op_a; Input 4
op_b; Input 4
Func Input 3
alu_out Output 4
Objective of this task is to write a verilog module for a complex ALU which can add,subtract ,compare
and shift and rotate operands.
Before writing module for complex ALU first answer following questions
Page | 92
Computer Organization And Architecture LAB 10
Write statements in Verilog HDL that can compare two operands each of 4 bits?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Read verilog module for complex ALU called alu_cmplx .Explain its operation
without using Xilinx ISE?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Page | 93
Computer Organization And Architecture LAB 10
Observations/Comments/Explanation of Results
Page | 94
Computer Organization And Architecture LAB 11
Roll #:_____________________________
Without using synthesizer tool draw hardware diagram for complex ALU from
module given below?
begin
casex({func, op_b})
//Logic operations:
//Aritmetic operations:
//Comparator
//alu_out[3] = 0, alu_out[2] = G;
//alu_out[1] = E, alu_out[0] = L;
7'b110_xxxx: begin
alu_out = 4'b0100;
if (op_a == op_b)
alu_out = 4'b0010;
Page | 96
Computer Organization And Architecture LAB 11
alu_out = 4'b0001;
end
//Shifter Rotator
endcase
Page | 97
Computer Organization And Architecture LAB 11
end
endmodule
Draw results from Test bench for ALU IN Figure 3? Indicate Input & Output
signals? Verify that each function of ALU is being performed.
Page | 98
Computer Organization And Architecture LAB 11
Observations/Comments/Explanation of Results
Page | 99
Computer Organization And Architecture LAB 12
Roll #:_____________________________
Objectives
The target of today's experiment in to develop a Verilog module which will serve as the interconnect
module for all the elements present in Single Cycle MIPS machine proposed by Hennessey and
Patterson in your textbook.
Page | 100
Computer Organization And Architecture LAB 12
Code Listing
if (read == 1'b1)
data_out = data_mem[address];
if (write == 1'b1)
data_mem[address] = data_in;
endmodule
Page | 101
Computer Organization And Architecture LAB 12
mem[address + 3]};
endmodule
if(write==1'b1)
rf[add_write] = data_in;
endmodule
Page | 102
Computer Organization And Architecture LAB 12
output zero_flag;
reg zero_flag;
always @ (alu_out)
if (alu_out == 32'd0)
zero_flag = 1'b1;
else
zero_flag = 1'b0;
case(alu_control)
alu_out = 32'd1;
else
alu_out = 32'd0;
Page | 103
Computer Organization And Architecture LAB 12
endcase
endmodule
initial
pc = 0;
if (branch_sel == 1'b0)
pc = pc + 4;
else
pc = pc + 4 + {offset[29:0], 2'b0};
endmodule
Page | 104
Computer Organization And Architecture LAB 12
Observations/Comments/Explanation of Results
Page | 105
Computer Organization And Architecture LAB 13
Roll #:_____________________________
Complete Data path and Control of The Single Cycle MIPS Machine
Objectives
The target of today's experiment in to develop a Verilog module which will serve as the interconnect
module for all the elements present in Single Cycle MIPS machine proposed by Hennessey and
Patterson in your textbook.
Code Listings:
jump_address, shifted_offset;
assign pc = pc_out;
endmodule
Page | 107
Computer Organization And Architecture LAB 13
endmodule
assign out = in + 4;
endmod-ule
endmodule
Page | 108
Computer Organization And Architecture LAB 13
out = in;
endmodule
in};
endmodule
input sel;
Page | 109
Computer Organization And Architecture LAB 13
case(sel)
endcase
endmodule
input sel;
case(sel)
endcase
endmodule
Page | 110
Computer Organization And Architecture LAB 13
initial
cont = 9'd0;
always @ (opcode)
case(opcode)
Page | 111
Computer Organization And Architecture LAB 13
endcase
endmodule
casex({func_field, alu_op})
endcase
endmodule
Page | 112
Computer Organization And Architecture LAB 13
Task:
Create a project in Xilinx ISE .Add all of the modules written above to the project.
Develop a Verilog module which will serve as the interconnect module for all the elements present in
Single Cycle MIPS machine proposed by Hennessey and Patterson in your textbook.
Page | 113
Computer Organization And Architecture LAB 13
Observations/Comments/Explanation of Results
Page | 114
Computer Organization And Architecture LAB 14
Roll #:_____________________________
Objectives
The target of today's experiment in to verify the data path of single machine that was implemented
in previous lab.
Page | 115
Computer Organization And Architecture LAB 14
Code:
module processor(clk,result);
input clk;
output[5:0] result;
wire branch_signal;
wire zero_flag;
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
Page | 116
Computer Organization And Architecture LAB 14
////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
endmodule
Page | 117
Computer Organization And Architecture LAB 14
initial
begin
data_mem[4] = 7;
data_mem[65] = 56;
data_mem[67] = 43;
end
if (read == 1'b1)
data_out = data_mem[address];
if (write == 1'b1)
data_mem[address] = data_in;
endmodule
Page | 118
Computer Organization And Architecture LAB 14
initial
begin
//r-format addition
mem[0] = 8'h00;
mem[1] = 8'h01;
mem[2] = 8'h10;
mem[3] = 8'h20;
//r-format subtraction
mem[4] = 8'h00;
mem[5] = 8'h82;
mem[6] = 8'h10;
mem[7] = 8'h22;
//r-format addition-----accumulation
mem[8] = 8'h00;
mem[9] = 8'h44;
mem[10] = 8'h10;
mem[11] = 8'h10;
mem[12] = 8'h00;
mem[13] = 8'h44;
mem[14] = 8'h10;
mem[15] = 8'h10;
mem[16] = 8'h00;
mem[17] = 8'h44;
Page | 119
Computer Organization And Architecture LAB 14
mem[18] = 8'h10;
mem[19] = 8'h10;
mem[20] = 8'h00;
mem[21] = 8'h44;
mem[22] = 8'h10;
mem[23] = 8'h10;
//sw
mem[24] = 8'hAC;
mem[25] = 8'h20;
mem[26] = 8'h00;
mem[27] = 8'h00;
mem[28] = 8'hAC;
mem[29] = 8'h22;
mem[30] = 8'h00;
mem[31] = 8'h41;
mem[32] = 8'h8C;
mem[33] = 8'h24;
mem[34] = 8'h00;
mem[35] = 8'h41;
end
Page | 120
Computer Organization And Architecture LAB 14
endmodule
initial
begin
rf[0] = 2;
rf[1] = 4;
rf[2] = 65;
rf[3] = 3;
rf[4] = 21;
rf[5] = 5;
rf[6] = 78;
rf[7] = 5;
rf[8] = 3;
rf[9] = 11;
end
Page | 121
Computer Organization And Architecture LAB 14
if(write==1'b1)
rf[add_write] = data_in;
endmodule
input sel;
case(sel)
endcase
endmodule
Page | 122
Computer Organization And Architecture LAB 14
input sel;
case(sel)
endcase
endmodule
initial
cont = 9'd0;
Page | 123
Computer Organization And Architecture LAB 14
always @ (opcode)
case(opcode)
endcase
endmodule
Page | 124
Computer Organization And Architecture LAB 14
casex({func_field, alu_op})
endcase
endmodule
output zero_flag;
reg zero_flag;
always @ (alu_out)
if (alu_out == 32'd0)
Page | 125
Computer Organization And Architecture LAB 14
zero_flag = 1'b1;
else
zero_flag = 1'b0;
case(alu_control)
alu_out = 32'd1;
else
alu_out = 32'd0;
endcase
endmodule
Page | 126
Computer Organization And Architecture LAB 14
initial
pc = 32'h00000000;
//pc = pc + 4;
//else
endmodule
Task:
1. Create a project in Xilinx ISE .Add the above code in it. Make the testbench of it and determine
what the code is doing.
Page | 127
Observations/Comments/Explanation of Results
The End
Page | 128