Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Lab Session 05

Object
To understand the concept how to perform arithmetic operations in assembly
language.

Theory
mov ah,01h
int 21h
sub al,30h
mov bl,al

The above Four line code is used to Read a Character from Console and save the value entered in
BL in its BCD form. This can be done by subtracting 30H i.e. SUB AL,30H. The value coming
from Console is Basically in ASCII form. eg. When you enter 5 we see 35H,So by subtracting 30H
we get back to value as 5.

Standard Input and Standard Output related Interupts are found in INT 21H which is also called
as DOS interrupt. It works with the value of AH register, If the Value is 1 or 1h, That means READ
a Character from Console, Echo it on screen and save the value entered in AL register.

ADD BL,30H

Since the Result of addition is in BL register in BCD form After addition. Now we want to print
the result on screen or console. the BCD form value will not show us the Result But will print the
Corresponding Ascii Codes of the number, Hence By adding 30H to BCD will Convert it to ASCII
code which will print the digit (number) on screen.
Sample Code
.model small
.stack 100h
.code
main proc
mov ah,01h
int 21h
sub al,30h
mov bl,al
mov ah,01h
int 21h
sub al,30h
add bl,al
add bl,30h
mov ah,02h
mov dl,bl
int 21h
mov ah,4ch
int 21h
main endp
end main
Lab Task
Write a program that take two integers as input and display sum of the integers.
Output will look like as follows:
Input First Integer: 3
Input Second Integer: 2
Sum of Integers: 5
.model small

.stack 100h

.data

Msg db "Enter first integer$"

msg1 db 10,13,"Enter second integer$"

msg2 db 10,13,"Sum of integer$"

.code

Main proc

Mov ax,@data

Mov ds,ax

Mov ah,09h

Mov dx,offset msg

int 21h

mov ah,01h

int 21h

sub al,30h

mov bl,al

mov ah,09h

mov dx,offset msg1

int 21h

mov ah,01h
int 21h

sub al,30h

add bl,al

add bl,30h

mov dl,al

mov ah,09h

mov dx,offset msg2

int 21h

mov dl,bl

mov ah,02h

int 21h

mov ah,4ch

int 21h

main endp

end main
Write a program that take three integers as input and display sum of the integers.
Output will look like as follows:
Input First Integer: 3
Input Second Integer: 2
Input Third Integer: 2
Sum of Integers: 7

.model small
.stack 100h
.data
msg db "Enter first integer : $"
msg1 db 10,13,"Enter second integer : $"
msg2 db 10,13,"Enter third integer : $ "
msg3 db 10,13,"Sum of integer = $"

.code
main proc
Mov ax,@data
Mov ds,ax
mov ah,09h
mov dx,offset msg
int 21h
mov ah,01h
int 21h
sub al,30h
mov bl,al
mov ah,09h
mov dx,offset msg1
int 21h
mov ah,01h
int 21h
sub al,30h
add bl,al
mov ah,09h
mov dx,offset msg2
int 21h
mov ah,01h
int 21h
sub al,30h
add bl,al
add bl,30h
mov ah,09h
mov dx,offset msg3
int 21h
mov dl,bl
mov ah,02h
int 21h
mov ah,4ch
int 21h

main endp
end main
Write a program that take three integers as input and display sum of the integers.
Output will look like as follows:
2+2+2+3=9
.model small
.stack 100h
.data
msg db "+$"
msg1 db "=$"

.code
main proc
Mov ax,@data
Mov ds,ax
mov ah,01h
int 21h
sub al,30h
mov bl,al
mov ah,09h
mov dx,offset msg
int 21h
mov ah,01h
int 21h

sub al,30h
add bl,al
mov ah,09h
mov dx,offset msg
int 21h
mov ah,01h
int 21h
sub al,30h
add bl,al
add bl,30h
mov ah,09h
mov dx,offset msg1
int 21h
mov dl,bl
mov ah,02h
int 21h
mov ah,4ch
int 21h
main endp
end main
Write a program that take two integers as input and perform subtraction.
Output will look like as follows:
Input First Integer: 3
Input Second Integer: 2
After subtraction of Integers: 1
.model small
.stack 100h
.data
msg db "Enter first integer$"
msg1 db 10,13,"Enter second integer$"
msg2 db 10,13,"After subtraction of Integers$"

.code
main proc
Mov ax,@data
Mov ds,ax
mov ah,09h
mov dx,offset msg
int 21h
mov ah,01h
int 21h
sub al,30h
mov bl,al
mov ah,09h
mov dx,offset msg1
int 21h
mov ah,01h
int 21h
sub al,30h
sub bl,al
add bl,30h
mov ah,09h
mov dx,offset msg2
int 21h
mov dl,bl
mov ah,02h
int 21h
mov ah,4ch
int 21h

main endp
end main

You might also like