Coal Lab Assignment 2 - v5 - f2019266302
Coal Lab Assignment 2 - v5 - f2019266302
2
Name: Talha Ahmad Bin Shafqat
ID: F2019266302
Section: V5
Lab Instructor: Maham Saleem
Lab 10 & 11 – Using Basic Instruction: A programming exercise
II
Objectives
In this lab, students are assigned a programming exercise related to what they have learned in
previous labs. Also, viva will be conducted from each student.
Lab Tasks
Task 1: Write a program to (a) display a “?”, (b) read two decimal digits whose sum is less
than 10, (c) display them and their sum on the next line, with an appropriate message.
Sample Execution:
?27
THE SUM OF 2 AND 7 is 9.
ANSWER:
.model small
.stack 100h
.data
output db 0Ah,0Dh,'THE SUM OF ','$'
output1 db ' AND ','$'
output2 db ' is ','$'
.code
main proc
mov dl,'?'
mov ah,02h
int 21h
Mov ah,01h
; Taking Input
Int 21h
int 21h
mov ah,09h
lea dx,output
int 21h
mov ah,02h
mov dl,bl
int 21h
mov ah,09h
lea dx,output1
int 21h
mov ah,02h
mov dl,bh
int 21h
mov ah,09h
lea dx,output2
int 21h
add bl,bh
sub bl,30h ; Adding using ascii
mov dl,bl
mov ah,02h
Int 21h ; Printing the Sum
main endp
end main
SCREENSHOT:
Task 2: Write a program to (a) prompt the user, (b) read first, middle, and last initials of a
person’s name, and (c) display them down the left margin.
Sample Execution:
Enter three initials: JFK
J
K
F
ANSWER:
.model small
.stack 100h
.data
start db 'Enter three initials:','$'
.code
main proc
mov ah,09h
lea dx,start
Int 21h
Mov ah,01h
Mov ah,02h
mov dl,0Ah
Int 21h ; Moving to Next Line
mov dl,0Dh
Int 21h ; Moving to Start of Line
mov dl,0Ah
Int 21h ; Moving to Next Line
mov dl,0Dh
Int 21h ; Moving to Start of Line
mov dl,bh
Int 21h ; Moving the result 2 to print
mov dl,0Ah
Int 21h ; Moving to Next Line
mov dl,0Dh
Int 21h ; Moving to Start of Line
main endp
end main
SCREENSHOT:
Task 3: Write a program to read one of the hex digits A-F, and display it on the next line in
decimal.
Sample Execution:
Enter a hex digit: C
In decimal it is 12
ANSWER:
.model small
.stack 100h
.data
hex db 'Enter a hex digit:','$'
decimal db 0Ah,0Dh,'In decimal it is ','$'
.code
main proc
mov ah,09h
lea dx,hex
Int 21h
Mov ah,01h
mov ah,09h
lea dx,decimal
Int 21h
mov ah,02h
mov dl,31h ; Moving 31 in hexa to print one
int 21h
mov dl,bl
int 21h
main endp
end main
SCREENSHOT:
Task 4: Write a program to display a 10*10 solid box of asterisk. Hint: Declare a string in
the data segment that specifies the box, and display it with INT 21h, function 9h?
ANSWER:
CODE 1
.model small
.stack 100h
.data
Steric db '**********',0Ah,0Dh ,'$' ;Create Character Array of 10
.code
main proc
Mov ah,09h
; For Displaying String
lea dx,Steric
Int 21h
Int 21h
Int 21h
Int 21h
Int 21h ; Printing 10 X 10 Sterics
Int 21h
Int 21h
Int 21h
Int 21h
Int 21h
main endp
end main
SCREENSHOT:
CODE 2
To make Empty box of 10 X 10
.model small
.stack 100h
.data
Steric db '**********',0Ah,0Dh ,'$'
Steric1 db '* *',0Ah,0Dh ,'$'
.code
main proc
Mov ah,09h
; For Displaying String
lea dx,Steric
Int 21h
lea dx,Steric1
Int 21h
Int 21h
Int 21h
Int 21h
Int 21h
Int 21h
Int 21h
Int 21h
lea dx,Steric
Int 21h
main endp
end main
SCREENSHOT: