Computer Organization Lab Manual Department of Computer Science
By: Engr. Naveed Alam and Arshad Beg
Lab Venue 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 2 nd floor of the Computer Science Department.
Objectives & Courses Scope of the Lab
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. Brief Overview of the Lab
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 Venue 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 2 nd floor of the Computer Science Department.
Objectives & Courses Scope of the Lab
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. Brief Overview of the Lab
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 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) 3) 4) a) b) * * * * * 5) a) b) c) d) e) f) g) 6)
INTRO. TO QTSPIM SIMULATOR EXECUTION OF THREE INSRUCTION PROGRAM ASSEMBLY LANGUAGE PROGRAM ASSEMBLY LANGUAGE PROGRAM STATEMENT FORMAT ASSEMBLER DIRECTIVES > ASSUME *DEFINED BYTE *DEFINED DOUBLE WORD *DEFINED QUED WORD *DEFINED TEN WORD *DEFINED WORD 8086 MICROPROCESSOR PIN DIAGRAM ARCHITECTURE INSTRUCTION SETS ADDRESSING MODES ADDRESSING MODES MIPS INSTRUCTION SETS MIPS ASSEMBLY PROGRAMMING a) Introduction , Print Screen and Commands of Qtspim. b) Write a program that print hello world a) Add and subtract two number b) Implementation of IF Else Program in MIPS Implementation of While Loop Program Implementation of Sorting Algorithm Write a program in which user Input data and print output on console Write a program to demonstrate call a subroutine (Function) Implementation of fibonacci series program In MIPS
7) 8) 9) 10) 11) 12)
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. A processor understands only machine language instructions, which are strings of 1's and 0's. However, machine language is too obscure and complex for using in software development. So, the low-level assembly language is designed for a specific family of processors that represents various instructions in symbolic code and a more understandable form. An assembler program creates object code by translating combinations of mnemonics and syntax for operations and addressing modes into their numerical equivalents. This representation typically includes an operation code ("opcode”) as well as other control bits. The assembler also calculates constant expressions and resolves symbolic names for memory locations and other entities. The use of symbolic references is a key feature of assemblers, saving tedious calculations and manual address updates after program modifications. Most assemblers also include macro facilities for performing textual substitution – e.g., to generate common short sequences of instructions as inline, instead of called subroutines. In electronics engineering and computer engineering, micro-architecture, also called computer organization and sometimes abbreviated as µarch or uarch, is the way a given instruction set architecture (ISA) is implemented in a particular processor . A given ISA may be implemented with different microarchitectures; implementations may vary due to different goals of a given design or due to shifts in technology.
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.
Commands:
masm TEST12.asm
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
CODE_HERE
ENDS
SEGMENT
ASSUME CS:CODE_HERE, DS:DATA_HERE START:
MOV AX, DATA_HERE MOV DS, AX MOV AX, NUM1 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.
Commands:
masm sub.asm
Link sub.obj Debug sub.exe l100 d100 g100 d100
Program : DATA SEGMENT NUM DW 6235H, 0F325H SUB DW 2 DUP(0) DATA ENDS CODE SEGMENT ASSUME CS: CODE, DS:DATA START: MOV AX,DATA MOV DS,AX
MOV AX,NUM ; First number loaded into AX SUB AX,NUM+2 ; Second number added with AX DOWN: MOV SUB,AX ; Storing the sum value 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.
Commands:
masm divi.asm
Link divi.obj Debug divi.exe l100 d100 g100 d100
Program : DATA SEGMENT NUM1 DB 72H NUM2 DB 2H QUO DB 1 DUP (0) REM DB 1 DUP (0) DATA ENDS CODE SEGMENT ASSUME CS: CODE, DS:DATA
START: MOV AX,DATA MOV AX ,Data MOV DS ,AX MOV AL , NUM1 MOV AH, 0H DIV NUM2 MOV QUO, AL MOV REM ,AH 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 MES1 DB 10,13,'DATA IS POSITIVE $' MES2 DB 10,13,'DATA IS NEGATIVE $' DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX MOV AL,NUM ROL AL,1 JC NEGA ;Move the Number to AL. ;Perform the rotate left side for 1 bit position. ;Check for the negative number. MOV DX,OFFSET MES1 ;Declare it positive. JMP EXIT ;Exit program. NEGA: MOV DX,OFFSET MES2;Declare it negative. EXIT: MOV AH,09H
INT 21H MOV AH,4CH INT 21H CODE ENDS END START
Step 2: Open the command prompt and enter the first command: d: //this tells the location of masm and link 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: Link pn.obj // enter thrice until no error is to be found. Step 4: Use the debug command to create the exe file 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: Enter the following commands G100 //the program terminates 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 MES1 DB 10,13,'DATA IS POSITIVE $' MES2 DB 10,13,'DATA IS NEGATIVE $' DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX MOV AL,NUM ROL AL,1 JC NEGA ;Move the Number to AL. ;Perform the rotate left side for 1 bit position. ;Check for the negative number. MOV DX,OFFSET MES1 ;Declare it positive. JMP EXIT ;Exit program. NEGA: MOV DX,OFFSET MES2;Declare it negative. EXIT: MOV AH,09H
INT 21H MOV AH,4CH INT 21H CODE ENDS END START
Step 2: Open the command prompt and enter the first command: d: //this tells the location of masm and link 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: Link pn-ve.obj // enter thrice until no error is to be found. Step 4: Use the debug command to create the exe file 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: Enter the following commands G100 //the program terminates 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: Introduction to QTSpim Tool - A simulator of MIPS architecture. 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. Commands for Dos version:
The spim terminal interface provides the following commands:
Exit the simulator .
exit
read “file”
load “file”
Read file of assembly language into SPIM. If the file has already been read into SPIM, the system must be cleared (see reinitialize, below) or global labels will be multiply defined. Synonym for read.
execute “a.out”
Read the MIPS executable file a.out into SPIM. This command is only available when SPIM runs on a sys- tem containing a MIPS processor.
run
Start running a program. If the optional address addr is provided, the program starts at that address. Otherwise, the program starts at the global label
_ _start, which is usually the default start-up code that calls the routine at the global label main. step
Step the program for
N
(default: 1) instr uctions.
Print instructions as they execute.
continue
Continue program execution without stepping.
print $N
Print register N .
print $fN
Print floating-point
register N . print_all_regs registers. print_all_regs
Print all hex Print all
registers in hexadecimal. print addr
print_sym
reinitialize
breakpoint addr
delete addr
list
Print the contents of memory at address addr.
Print the names and addresses of the global labels known to SPIM. Labels are local by default and become global only when declared in a .globl assembler directive (see "Assember Syntax" section on page A-47). Clear the memory and registers.
Set a breakpoint at address memory address or symbolic label.
addr . addr
can be either a
Delete all breakpoints at address addr .
List all br eakpoints.
Rest of line is an assembly instruction that is stor ed in memor y.
A newline reexecutes previous command.
Print a help message.
?
Most commands can be abbreviated to their unique prefix (e.g., ex,
re, l, ru, s,
p). More dangerous commands, such as reinitialize , require a longer prefix.
Print Screens of GUI Version of QTSpim
Load A file:
Consol Result:
Task-2:
Writhe a program that print “Hello World” ?
Code:
.data msg: .asciiz "Hello World" .extern foobar 4
.text .globl main main: li $v0, 4
# syscall 4 (print_str)
la $a0, msg
# argument: string
syscall
# print the string
lw $t1, foobar
jr $ra
Output:
“Hello World”
# retrun to caller
******************-*-*-*-*-******************
Lab # 02
Task-1:
Write a program that Add and Subtract Numbers?
Code:
.globl main .text #empty main: ori $t1,$0,25
#loading 25 in t1 register
ori $t2,$0,12
#loading 12 in t2 register
add $s1,$t1,$t2
#adding t1 and t2 in s1 register
sub $s2,$t1,$t2
#Sub t1 and t2 in s2 register
ori $v0,$0,10
#loading value 10 in v0 register for ending program
syscall
#System call
Output Print Screen:
Add Result :
Subtraction Result:
Lab # 07 Task-2:
Writhe a program that implements IF Else Statement In MIPS?
Code:
globl main .text #empty main: ori $t1,$0,25
#loading 25 in t1 register
ori $t2,$0,12
#loading 12 in t2 register
bne $t1,$t2, ELSE add $s1,$t1,$t2
#adding t1 and t2 in s1 register
j Exit ELSE: sub $s2,$t1,$t2
#Sub t1 and t2 in s2 register
Exit: ori $v0,$0,10
#loading value 10 in v0 register for ending program
syscall
#System call
Output Print Screen:
Loading The program:
Insert value in a0 register:
Result of the statement in Register t1:
Lab # 08 Write a program that implements While Loop In MIPS?
Code:
.globl main .text #empty main:
ori $t1,$0,6
#loading 25 in t1 register
j
ori $t2,$0,2
#loading 2 in t2 register
k
ori $t3,$0,1
#loading 1 in t3 register
i
ori $t4,$0,2
#loading 5 in t4 register
result
ori $t5,$0,1
LOOP: beq $t3,$t1,EXIT add $t4,$t4,$t2
#adding t1 and t2 in s1 register
add $t3,$t3,$t5 j LOOP EXIT:
ori $v0,$0,10
#loading value 10 in v0 register for ending program
syscall
#System call
Output Print Screen:
First Input in register a0:
Inputs in Register a0 and v0:
Output in registers :
Final output:
Lab # 09 Write a program that implements Sorting Algorithm In MIPS?
Code:
.text .globl main main: la
$a0, Array
# sets the base address of the array to $a0
loop: lw
$t0, 0($a0)
# sets $t0 to the current element in array
lw
$t1, 4($a0)
# sets $t1 to the next element in array
blt $t1, $t0, swap addi
$a0, $a0,
# if the following value is greater, swap them # advance the array to start at the next location #from last time
j
loop # jump back to loop so we can compare next two elements
swap: sw
$t0, 4($a0)
# store the greater numbers contents in the higher
#position in array (swap) sw
$t1, 0($a0)
# store the lesser numbers contents in the lower
#position in array (swap) li
$a0, 0
# resets the value of $a0 back to zero so we can
#start from beginning of array
j
loop
# jump back to the loop so we can go through and
#find next swap
.data
Array:
.word
Output Print Screen:
Input:
Values In Registers:
14, 12, 13, 5, 9, 11, 3, 6, 7, 10, 2, 4, 8, 1
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
lw
$t0, f
li
$t1, 5
sw
$t1, f
li
$v0, 5
.text main:
syscall sw
$v0, f
lw $t3, f
li
$v0, 1
move $a0, $t3 syscall
ori $v0, $0, 10 syscall
Output Print Screen:
Input:
Final Output:
Lab # 11 Task: Write a program to demonstrate call a subroutine (Function).
Code:
# a program to demonstrate calling a subroutine. # functions/subroutine computers power
.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
Output Print Screen:
Input:
Values In registers :
Final Output:
Lab # 12 Task: Implementation of fibonacci series program In MIPS: Assembly Code :
main: addi $sp, $sp, -4 sw $ra, 0($sp)
addi $a0, $zero, 5 jal fibo;
lw $ra, 0($sp) addi $sp, $sp, 4
fibo: addi $sp, $sp, -12 sw $s0, 0($sp) sw $s1, 4($sp) sw $ra, 8($sp)
slti $t0, $a0, 2 beq $t0, $zero, ELSE
addi $v0, $zero, 1 jr $ra
ELSE: addi $s0, $a0, 0 addi $a0, $a0, -1 jal fibo;
addi $s1, $v0, 0 addi $a0, $s0, -2 jal fibo
add $s1, $s1, $v0 j EXIT
EXIT: lw $s0, 0($sp) lw $s1, 4($sp) lw $ra, 8($sp) addi $sp, $sp, 12
jr $ra
Output Print Screen: INput:
Values In registers:
Values In registers: