Professional Documents
Culture Documents
Version-2.1
PREPARED BY
Lab manual is prepared by Lecturer Rabia Khan and Demonstrator Kabeer Ahmed, updated by Mehreen Ahmed
under the supervision of Head of Department Dr. Adil Masood Siddiqi in year 2016.
GENERAL INSTRUCTIONS
a. Students are required to maintain the lab manual with them till the end of the semester.
b. All readings, answers to questions and illustrations must be solved on the place provided. If more space is
required then additional sheets may be attached. You may add screen print to the report by using the ‘Print
Screen’ command on your keyboard to get a snapshot of the displayed output.
c. It is the responsibility of the student to have the manual graded before deadlines as given by the instructor
d. Loss of manual will result in re submission of the complete manual.
e. Students are required to go through the experiment before coming to the lab session. Lab session details will
be given in training schedule.
f. Students must bring the manual in each lab.
g. Keep the manual neat clean and presentable.
h. Plagiarism is strictly forbidden. No credit will be given if a lab session is plagiarised and no re submission
will be entertained.
i. Marks will be deducted for late submission.
j. In the exercises, you have to put the output in your Lab report.
k. Name your reports using the following convention:
Lab#_Rank_YourFullName
(1) ‘#’ replaces the lab number.
(2) ‘Rank’ replaces Maj/Capt/TC/NC/PC
(3) ‘YourFullName’ replaces your complete name.
l. You need to submit the report even if you have demonstrated the exercises to the lab engineer/instructor or
shown them the lab report during the lab session.
VERSION HISTORY
Date Update By Details
July 2013 Demo Kabeer Ahmed First Version Created
Feb 2014 Demo Kabeer Ahmed Second Version Created
Feb 2016 TA Mehreen Ahmed 2.1 Version Created
Exercise 2.1
Write a program that input a character from user is in lowercase, the program will
convert it to uppercase and will display it on console after conversion.
Hint: - The ASCII codes for lowercase letters (a-z) are 97-122. In order to convert a lowercase
letter to
Code:
org 100h
.data
newline db 0dh,0ah,'$'
.code
mov ds, ax
mov ah, 9
INT 21H
mov bl, al
sub bl, 32
mov ds, ax
mov ah, 9
mov ds, ax
mov ah, 9
mov dl, bl
mov ah,2h
INT 21H
mov ax,4C00h
INT 21H
main endp
end main
Output:
Exercise 2.2 Write a program that input a character from user. The program will display it ten
times on screen in newline.
Code:
org 100h
.data
newline db 0dh,0ah,'$'
.code
mov ds, ax
mov ah, 9
mov ah,1h
INT 21H
mov bl, al
mov cx, 10
repitition:
mov ds, ax
mov dx, offset newline
mov ah, 9
mov ds, ax
mov ah, 9
mov dl, bl
mov ah,2h
INT 21H
loop repitition
mov ax,4C00h
INT 21H
main endp
end main
Output:
Exercise 2.3 Write a program that will display uppercase letters (A-Z), using loop on new line.
Code:
org 100h
.data
newline db 0dh,0ah,'$'
.code
main proc
mov cx, 26
repitition:
mov ds, ax
mov ah, 9
mov ds, ax
mov ah, 9
mov dl, bl
mov ah,2h
INT 21H
add bl, 1
loop repitition
mov ax,4C00h
INT 21H
main endp
end main
Output:
Lab 03
Exercise 3.1
Code:
include emu8086.inc
.data
num1 dw 0
num2 dw 0
call scan_num
mov num1,cx
printn
call scan_num
mov num2,cx
mov ax,num1
add num2
printn
call print_num
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
DEFINE_SCAN_NUM
proc END
ret
Output:
Exercise 3.2:
Code:
include emu8086.inc
.data
num1 dw 0
num2 dw 0
num3 dw 0
num4 dw 0
num5 dw 0
call scan_num
mov num1,cx
mov ax,num1
printn
call scan_num
mov num2,cx
add ax,num2
;----
printn
call scan_num
mov num3,cx
add ax,num3
printn
call scan_num
mov num4,cx
add ax,num4
printn
call scan_num
mov num5,cx
add ax,num5
printn
call print_num
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
DEFINE_SCAN_NUM
proc END
ret
Output:
Lab 04
Exercise 4.1
Code:
include emu8086.inc
.data
num1 dw 0
num2 dw 0
mov num1,cx
printn
call scan_num
mov num2,cx
mov ax,num1
mul num2
printn
call print_num
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
DEFINE_SCAN_NUM
proc END
ret
Output:
Exercise 4.2
Code:
;x+2z-y-1
include emu8086.inc
.data
x dw 0
y dw 0
z dw 0
m dw 2
;================
printn
printn
printn
printn
print 'Enter value of x: '
call scan_num
mov x,cx
printn
call scan_num
mov y,cx
printn
call scan_num
mov z,cx
;================
mov ax,z
mul m
sub ax,y
sub ax,1
add ax,x
printn
call print_num
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
DEFINE_SCAN_NUM
proc END
ret
Output:
Exercise 4.3:
Code:
include emu8086.inc
.data
h dw 0
w dw 0
l dw 0
a dw 0
b dw 0
c dw 0
num dw 2
;================
print 'Enter value of height, width & length of box to calculate its surface area from
formula as, '
printn
printn
print '" surface area = 2 * (length * width + length * height + width * height) "'
printn
printn
call scan_num
mov h,cx
printn
call scan_num
mov w,cx
printn
call scan_num
mov l,cx
;================
mov ax,l
mul w
mov a,ax
mov ax,l
mul h
mov b,ax
mov ax,w
mul h
mov c,ax
mov ax,a
add ax,b
add ax,c
mul num
printn
call print_num
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
DEFINE_SCAN_NUM
proc END
ret
Output:
Lab 05
Exercise 5.1: [5]
Write a program that Divide two word variables Var1=-500 and Var2=2 and stores the
result in memory.
Solution:
Code:
org 100h
include emu8086.inc
.data
var1 dw 500
var2 db 2
.code
mov ax, var1
mov bl, var2
div bl
call PRINT_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
ret
Output:
Solution:
Code:
org 100h
include emu8086.inc
.data
sum dw 0
avg dw 0
.code
print "Enter marks for M1: "
call SCAN_NUM
printn ""
add ax, cx
mov sum, ax
mov bl, 5
div bl
mov avg, ax
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
DEFINE_SCAN_NUM
ret
Output:
Solution:
Code:
org 100h
include emu8086.inc
.code
print "Enter temperature in C: "
call SCAN_NUM
printn ""
mov ax, 9h
mov bl, 5h
div bl
mov dl, al
mov dh, 0
mov ax, 0
add ax, dx
mul cx
add ax, 32
print "Temperature in F is : "
call PRINT_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
DEFINE_SCAN_NUM
ret
Output:
Lab 06
Exercise:
Write a single instruction that clears the high 8 bits of AX and does not change the
low 8 bits.
Solution:
Code:
org 100h
include emu8086.inc
.code
mov ax, 1111111111111111b
and ax, 0000000011111111b
ret
Output:
Exercise: [6]
Write a single instruction that sets the high 8 bits of AX and does not change the
low 8 bits.
Solution:
Code:
org 100h
include emu8086.inc
.code
mov ax, 0000000000000000b
or ax, 1111111100000000b
ret
Output:
Lab 07
Exercise 8.1:
Write a program to print the sum of series 1+3+6+ … n and also print the value of
ax and bx after each step.
Note:- ax contains the sum of series and bx used as counter.
Code:
include emu8086.inc
.DATA
.CODE
main PROC
mov bx,0 ; number := 0
mov ax,0 ; sum := 0
forever: inc bx ; add 1 to number
add ax, bx ; add number to sum
call print_num
print ','
jmp forever ; repeat
main ENDP
DEFINE_PRINT_NUM ; used by print_num proc
DEFINE_PRINT_NUM_UNS ; used by print_num proc END main
Output:
Exercise 8.2:
Write a program to print the smallest number from three integers.
Code:
include emu8086.inc
.DATA
.CODE
main PROC
mov bx,2 ; number := 0
mov ax,11 ; sum := 0
mov cx,7
mov dx, ax ; assume ax is larger
cmp ax, bx ; if AX >= BX then
jle L1 ; jump to L1
mov dx, bx ; else move bx to dx because it is larger than ax
L1: print "The smallest number is= "
cmp dx, cx
jle l2
mov dx, cx
l2:
mov ax, dx
call print_num
main ENDP
DEFINE_PRINT_NUM ; used by print_num proc
DEFINE_PRINT_NUM_UNS ; used by print_num proc END main
Output:
Lab 09
Code:
include emu8086.inc
.data
.code
main PROC
mov dl, 0 ; num
mov bl, 0 ; sum
for:
inc dl
add bl, dl
cmp dl, 10
jl for
mov ax, bx
print 'Sum is: '
call print_num
main ENDP
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
Output:
Code:
include emu8086.inc
.data
.code
main PROC
DEFINE_PRINT_NUM
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM_UNS
Output:
Lab 10
Code:
include emu8086.inc
.data
.code
main PROC
mov bx, 6 ; N
mov cx, 3 ; K
mov si, bx
sub si, cx
mov ax, 1
for1:
mul bx
sub bx, 1
cmp bx, 1
jnle for1
mov bx, ax ; N!
mov ax, 1
for2:
mul cx
sub cx, 1
cmp cx, 1
jnle for2
mov cx, ax ; K!
mov ax, 1
for3:
mul si
sub si, 1
cmp si, 1
jnle for3
mov si, ax ; N-K!
mov ax, si
mov ax, si
mul cx
mov si, ax ; K!(N-K)!
mov ax, bx
mov bx, si
div bx
mov ah, 0
print 'binomial coefficient is :'
call print_num
main ENDP
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
Output:
Code:
include emu8086.inc
.data
.code
main PROC
print 'Enter a number n: '
call scan_num
printn ''
mov si, 0 ; sum of squares
for:
mov ax, 1
mul cx
mul cx
add si, ax
sub cx, 1
cmp cx, 0
jnle for
print 'Sum of sqaures upto number is: '
mov ax, si
call print_num
main ENDP
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
Output:
Code:
include emu8086.inc
org 100h
.data
var1 dw 11h
var2 dw 23h
.code
main PROC
mov ax, var1
print 'var1 before sawpping : '
call print_num
printn ''
mov ax, var2
print 'var2 before sawpping : '
call print_num
printn ''
mov ax, var1
mov bx, var2
mov var1, bx
mov var2, ax
mov ax, var1
print 'var1 after sawpping : '
call print_num
printn ''
mov ax, var2
print 'var2 after sawpping : '
call print_num
printn ''
main ENDP
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
Output:
Lab 11
Code:
include emu8086.inc
org 100h
.data
arr dw 10 dup (?)
.code
main PROC
mov bx, 10
lea si, arr
l1:
print 'Enter number : '
call scan_num
printn ''
mov word ptr[si], cx
add si, 2
sub bx, 1
cmp bx, 1
jge l1
mov bx, 10
mov ax, 0 ; sum of numbers
lea si, arr
l2:
mov di, ax
mov bx, 10
mov cx, 0 ; number of numbers
lea si, arr
l3:
mov ax, di
div cx
mov ah, 0
print 'Average of the numbers is: '
call print_num
printn ''
;;;;;;
mov bx, 10
mov cx, 0 ; number of numbers greater than or equal to avg
lea si, arr
l4:
mov ax, cx
print 'Number of the numbers greater than or equal to avg is: '
call print_num
printn ''
main ENDP
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
Output:
Code:
include emu8086.inc
org 100h
.data
arr dw 5 dup (?)
.code
main PROC
mov bx, 5
lea si, arr
l1:
print 'Enter number : '
call scan_num
printn ''
mov word ptr[si], cx
add si, 2
sub bx, 1
cmp bx, 1
jge l1
mov bx, 5
lea si, arr
l2:
cmp cx, word ptr[si], cx
jne n
mov sp, 1
n:
add si, 2
sub bx, 1
cmp bx, 1
jge l2
cmp sp, 1
jne notfound
print 'Number found'
jmp e
notfound:
print 'Number not found'
e:
main ENDP
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
Output: