Computer Organization and Assembly Language Lab Manual
Computer Organization and Assembly Language Lab Manual
The Digital Logic Design Lab (DLD Lab) is one of the most important and well equipped lab of
the Department of Computer Science at SZABIST , Islamabad. This lab is conducted at the
Computer Interfacing Lab situated at the 2nd floor of the Computer Science Department.
Objectives & Courses
The DLD Lab is for undergraduate coursework related to the course Computer Architecture. It is
one of the core modules of BSCS Computer Science therefore the lab has a significant
importance in the department.
Related Courses
This lab is designed such that the students get a hands on familiarity with the concepts they
come across in the course Computer Architecture that is the Digital Systems course. This is an
undergraduate course which deals with the basics of digital systems design and is a core
module of the BSCS . Computer Science coursework as it provides the prerequisites for
advance courses in digital Computer. Because of the significance of this course the DLD Lab
has been carefully designed to meet the course requirement.
The Lab is well equipped with both hardware and software facilities required by the students to
perform the necessary experiments designed for this lab. Details of the lab equipment has been
discussed in a proceeding section. Experiments are designed in such a way that the students
become well aware of the concepts they learn in the theory sessions. A list of experiments that
are conducted in this lab has also been mentioned in a proceeding section.
Lab Description & Experiments
Lab Description
Hardware Labs have been designed to familiarize students with the Combinational Digital Logic Design
and Sequential Digital Logic Design through the implementation of Digital Logic Circuits using ICs of basic
logic gates and some simple digital logic circuits. Tools have been used in these labs. Finally, the skills
learnt in the implement some digital logic circuits on, using Kit Portable Advanced Laboratory Board.
Expected Outcomes
Students will learn the fundamentals of computer organization and its relevance to classical and modern
problems of computer design. 2. Students will be able to identify where, when and how enhancements
of computer performance can be accomplished. 3. Student will see how to use concepts of computer
organization in real-life settings using various PC performance improvements. 4. Students will also be
introduced to more recent applications of computer organization in advanced digital systems.
This is an introductory course in Computer Organization designed for students to become familiar with
the fundamentals of computer organization techniques and their application to computer engineering
problems. It provides essential tools that are needed from engineering professionals to measure a
simple PC performance.
Course Outline
SN# Contents
1) INTRO. TO MASM & LINK SIMULATOR
2) INTRO. TO QTSPIM SIMULATOR
3) EXECUTION OF THREE INSRUCTION PROGRAM
4) ASSEMBLY LANGUAGE PROGRAM
a) ASSEMBLY LANGUAGE PROGRAM STATEMENT FORMAT
b) ASSEMBLER DIRECTIVES > ASSUME
* *DEFINED BYTE
* *DEFINED DOUBLE WORD
* *DEFINED QUED WORD
* *DEFINED TEN WORD
* *DEFINED WORD
5) 8086 MICROPROCESSOR
a) PIN DIAGRAM
b) ARCHITECTURE
c) INSTRUCTION SETS
d) ADDRESSING MODES
e) ADDRESSING MODES
f) MIPS INSTRUCTION SETS
g) MIPS ASSEMBLY PROGRAMMING
6) a) Introduction , Print Screen and Commands of Qtspim.
b) Write a program that print hello world
7) a) Add and subtract two number
b) Implementation of IF Else Program in MIPS
8) Implementation of While Loop Program
9) Implementation of Sorting Algorithm
10) Write a program in which user Input data and print output on console
11) Write a program to demonstrate call a subroutine (Function)
12) Implementation of fibonacci series program In MIPS
Introduction of COAL
Assembly language is a low-level programming language for a computer or
other programmable device specific to a particular computer architecture in
contrast to most high-level programming languages, which are generally
portable across multiple systems.
Tools:
1): Microsoft Macro Assembler (MASM) is x86 assembler that uses the Intel syntax
for MS-DOS and Microsoft Windows.
2): Linker is a computer program that takes one or more object files generated
by a compiler and combines them into a single executable file, library file, or
another object file.
A simpler version that writes its output directly to memory is called the loader,
though loading is typically considered a separate process.
3): Spim is a self-contained simulator that runs MIPS32 programs. It reads and
executes assembly language programs written for this processor. Spim also
provides a simple debugger and minimal set of operating system services.
Spim does not execute binary (compiled) programs.
Lab Experiment #1
Task : Make Assembly language program to multiply
two numbers.
Introduction :
In following experiment we will use MASM and LINK program to produce
assembly language program to do the multiplication. .asm file is
converted through masm to obj file then linker is used to link code
together. debug is used to create exe file and register commands are
used to move, store and execute arithmetic functions in register.
Link TEST12.obj
Debug TEST12.exe
l100
d100
g100
d100
Program :
DATA_HERE SEGMENT
NUM1 DW 204AH
NUM2 DW 3B6AH
PROD DW 2 DUP(0)
DATA_HERE ENDS
CODE_HERE SEGMENT
ASSUME CS:CODE_HERE, DS:DATA_HERE
MOV DS, AX
MUL NUM2
MOV PROD, AX
MOV PROD+2, DX
mov AH,4CH
INT 21H
CODE_HERE ENDS
END START
RESULT
Lab Experiment #2
Task : Make Assembly language program to subtract
two numbers.
Introduction :
In following experiment we will use MASM and LINK program to produce
assembly language program to do the multiplication. .asm file is
converted through masm to obj file then linker is used to link code
together. debug is used to create exe file and register commands are
used to move, store and execute arithmetic functions in register.
Link sub.obj
Debug sub.exe
l100
d100
g100
d100
Program :
DATA SEGMENT
SUB DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
MOV DS,AX
MOV AX,NUM ; First number loaded into AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
Lab Experiment #3
Task : Make Assembly language program to divide
two numbers.
Introduction :
In following experiment we will use MASM and LINK program to produce
assembly language program to do the division .asm file is converted
through masm to obj file then linker is used to link code together. debug is
used to create exe file and register commands are used to move, store
and execute arithmetic functions in register.
Link divi.obj
Debug divi.exe
l100
d100
g100
d100
Program :
DATA SEGMENT
NUM1 DB 72H
NUM2 DB 2H
DATA ENDS
CODE SEGMENT
MOV AX ,Data
MOV DS ,AX
MOV AL , NUM1
MOV AH, 0H
DIV NUM2
MOV QUO, AL
MOV AH,4CH
INT 21H
CODE ENDS
END START
EXPERIMENT # 4
Statement:
Using the command prompt generate masm and link files and also check if a number is positive or
negative?
Step 1:
Open the notepad to write the code which is given below and later save it as pn.asm in the same folder
i.e. D drive where masm and link are installed.
DATA SEGMENT
NUM DB 12H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV AL,NUM
ROL AL,1
JC NEGA
MOV AH,4CH
INT 21H
CODE ENDS
END START
Step 2:
d: masm.pn.asm // this is used to generate the masm file and enter thrice until no
error is to be found
Step 3:
Now generate the object file using the link command. Commands are as follows:
Step 4:
Debug pn.exe
L100
D100
The number that have been mentioned in the data will be shown on the screen as
shown in the result 1 below:
Step 5:
D100
The output of the pn will be shown which will tell that the data is positive number
EXPERIMENT # 5
Statement:
Using the command prompt generate masm and link files and also check if a number is positive or
negative?
Step 1:
Open the notepad to write the code which is given below and later save it as pn-ve.asm in the same
folder i.e. D drive where masm and link are installed.
DATA SEGMENT
NUM DB -12H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV AL,NUM
ROL AL,1
JC NEGA
MOV AH,4CH
INT 21H
CODE ENDS
END START
Step 2:
d: masm.pn-ve.asm // this is used to generate the masm file and enter thrice until
no error is to be found
Step 3:
Now generate the object file using the link command. Commands are as follows:
Step 4:
Debug pn-ve.exe
L100
D100
The number that have been mentioned in the data will be shown on the screen as
shown in the result 1 below:
Step 5:
D100
The output of the pn-ve.asm file will be shown which will tell that the data is
negative number
Lab-6 :
Task-1:
QTSpim:
SPIM is an emulator for MIPS RISC computers written by James Larus at the University
of Wisconsin. It allows users to run programs written in MIPS RISC assembly language without
having access to a computer running a MIPS RISC chip.
There are two versions of SPIM (each is available both for Unix and for PCs). The simplest is a
command line version in which you type commands in response to a user prompt (this is the
version available here on osf1). The PC version of this can be run in a DOS window. The more
elaborate, and much more useful, version of SPIM has a graphical user interface and can be
used as a visual debugger as well as for running MIPS programs. Under Unix the graphical user
interface version requires X-Windows. The PC version runs under MS Windows.
Load A file:
Consol Result:
Task-2:
Code:
.data
.extern foobar 4
.text
.globl main
lw $t1, foobar
Output:
“Hello World”
******************-*-*-*-*-******************
Lab # 02 Task-1:
Code:
.globl main
.text #empty
main:
Subtraction Result:
Lab # 07
Task-2:
Code:
globl main
.text #empty
main:
j Exit
ELSE:
Exit:
Code:
.globl main
.text #empty
main:
ori $t5,$0,1
LOOP:
beq $t3,$t1,EXIT
add $t3,$t3,$t5
j LOOP
EXIT:
Output in registers :
Final output:
Lab # 09
Code:
.text
.globl main
main:
loop:
blt $t1, $t0, swap # if the following value is greater, swap them
addi $a0, $a0, # advance the array to start at the next location
j loop
swap:
.data
Input:
Values In Registers:
Final Output:
Lab # 10
Task:
Write a program in which user Input data and print out on console
Code:
.globl main
.data
f: .word 0
.text
main:
lw $t0, f
li $t1, 5
sw $t1, f
li $v0, 5
syscall
sw $v0, f
lw $t3, f
li $v0, 1
syscall
syscall
Output Print Screen:
Input:
Final Output:
Lab # 11
Task:
Code:
.data
x: .word 3
y: .word 5
.text
.globl main
.ent main
main:
lw $a0,x
lw $a1,y
jal power
sw $s1,power
li $v0,10
syscall
.end main
.globl power
.ent power
power:
li $s1, 1
li $t0, 0
powloop:
mul $s1,$s1,$a0
add $t0,$t0,1
blt $t0,$a1,powloop
jr $ra
.end power
Input:
Values In registers :
Final Output:
Lab # 12
Task:
Assembly Code :
sw $ra, 0($sp)
jal fibo;
lw $ra, 0($sp)
sw $s0, 0($sp)
sw $s1, 4($sp)
sw $ra, 8($sp)
jr $ra
jal fibo;
addi $s1, $v0, 0
jal fibo
j EXIT
lw $s1, 4($sp)
lw $ra, 8($sp)
jr $ra
INput:
Values In registers:
Values In registers:
Final Output: