Professional Documents
Culture Documents
Btcs9301 MP Lab File
Btcs9301 MP Lab File
10
Sr. No. Title of Lab Experiment
PROGRAMS ON ARITHMETIC OPERATIONS
1. ADDITION OF 2 8-BIT HEXADECIMAL NUMBERS.
2. ADDITION OF 2 16-BIT HEXADECIMAL NUMBERS.
3. SUBTRACTION OF 2 8-BIT HEXADECIMAL NUMBERS.
4. SUBTRACTION OF 2 16-BIT HEXADECIMAL NUMBERS.
5. MULTIPLICATION OF 2 8-BIT HEXADECIMAL NUMBERS.
6. MULTIPLICATION OF 2 16-BIT HEXADECIMAL NUMBERS.
7. DIVISION OF 2 8-BIT HEXADECIMAL NUMBERS.
8. DIVISION OF 2 16-BIT HEXADECIMAL NUMBERS.
9. ASCII ADDITION OF 2 DECIMAL NUMBERS.
10. ASCII SUBTRACTION OF 2 DECIMAL NUMBERS.
11. ASCII MULTIPLICATION OF 2 DECIMAL NUMBERS.
12. ASCII DIVISION OF 2 DECIMAL NUMBERS.
PROGRAMS ON LOGICAL OPERATIONS
13. CONVERSION OF PACKED BCD TO UNPACKED BCD NUMBER.
14. CONVERSION OF BCD NUMBER TO EQUIVALENT ASCII NUMBER.
15. TO SORT ARRAY ELEMENTS IN AN ASCENDING ORDER.
16. ADDITION OF ALL THE 8 – BIT ELEMENTS OF A GIVEN ARRAY.
PROGRAMS ON STRING OPERATIONS
17. TRANSFER OF BLOCK OF DATA FROM ONE LOCATION TO ANOTHER.
18. TO COMPARE TWO GIVEN STRINGS AND FIND OUT IF THEY ARE EQUAL OR NOT.
Software Requirements
Hardware Requirements
8086 SDK Kit or Any computer Hardware capable of running 8086 emulator can
Aim: Write an Assembly Language Program (ALP) to add 2 8-bit hexadecimal numbers.
ds:data code
segment
data mov
ds, ax mov
ax,00h mov
al, num1
mov bl,
num2 add
al, bl mov
result, al
mov ah,
code ends
data segment
num1 db
03h num2
db 08h
result db
00h
data ends
end start
INPUT: num1 = 03h
AL = 03h
num2 =
08h BL =
08h
OUTPUT:
result =
0Bh AL =
0Bh
verified. Exercise:
6. What is the purpose of MOV AH, 4CH, INT 21H in the program?
Experiment-2
Aim: Write an Assembly Language Program (ALP) to add 2 16-bit hexadecimal numbers.
assume cs:code,
ds:data code
segment
data mov
ds, ax mov
ax, num1
mov bx,
num2 add
ax, bx mov
result, ax
mov ah,
code ends
data segment
num1 dw
1234h num2
dw 4321h
result dw
0000h
data ends
end start
AX = 1234h
num2 =
4321h BX
4321h
OUTPUT:
result =
5555h AX =
5555h
Exercise:
5. What happens if the result is greater than 16bit when result is declared as DW?
Experiment-3
assume cs:code,
ds:data code
segment
start: mov
ax,data
mov ds,ax
mov ax,00h
mov
al,num1
mov
bl,num2
sub al, bl
mov result,
al mov ah,
code ends
data segment
num1 db
4AH num2
db 3FH
result db
00H
data ends
end start
AL = 4Ah
num2 =
3Fh BL =
3Fh
OUTPUT:
result =
0Bh AL =
0Bh
assume cs:code,
ds:data code
segment
data mov
ds, ax mov
ax, num1
mov bx,
num2 sub
ax, bx mov
result, ax
int 03h
mov ah,4ch
int 21h
code ends
data segment
num1 dw
5678h num2
dw 4321h
result dw
0000h
data ends
end start
AX = 5678h
num2=432
1h
BX = 4321h
OUTPUT:
result =
1357h AX =
1357h
assume cs:code,
ds:data code
segment
data mov
ds, ax
mov ax, 00
mov al,
num1 mov
bl, num2
mul bl
mov result1,
al mov
result2,
ah mov ah,
4ch
code ends
data segment
num1 db
4Fh num2
db 8Ch
result1 db
00
result2 db 00
data ends
end start
AL = 4Fh
num2 =
8Ch BL =
8Ch
OUTPUT:
result =
34h result1
= 2Bh AX =
2B34h
Aim: Write an Assembly Language Program (ALP) to multiply two 16-bit hexadecimal numbers.
assume cs:code,
ds:data code
segment
data mov
ds, ax
mov ax, 00
mov ax,
num1 mov
bx, num2
mul bx
mov result1,
ax mov
result2, dx int
03h
code ends
data
segment
num1 dw
3A6Bh num2
dw 8ECDh
result1 dw
0000h
result2
dw 0000h
data ends
OUTPUT:
end start
AX = 3A6Bh
num2 =
8ECDh BX
8ECDh
result1 =
21AFh result2
= 2096h DX =
2096h
AX = 21AFh
assume cs:code,
ds:data code
segment
data mov
ds, ax mov
ax, 00h
mov dx,
num1 mov
bl
mov quotient, al
mov
remainder,ah
int 21h
code ends
data
segment
num1 db 8fh
num2 db 1ah
quotient db 00h
remainder db
00h
data ends
end start
AL = 8Fh
num2 =
1Ah BL =
1Ah
remainder =
0Dh AL = 05h
AH = 0Dh
assume cs:code,
ds:data code
segment
data mov
ds, ax mov
dx, 00h
mov ax,
num1 mov
bx, num2
div bx
mov quotient,
ax mov
remainder, dx
int 03h
mov ah,4ch
int 21h
code ends
data segment
num1 dw 9FFFh
num2 dw 1A3Eh
quotient dw 0000h
remainder dw
0000h
data
ends
end
start
AX = 9FFFh
num2 =
1A3Eh BX =
1A3Eh
OUTPUT:
quotient =
0006h AX =
0006h
remainder =
028Bh DX =
028Bh
assume cs:code,
ds:data data
segment
ip1 db
'9',0dh,0ah ip2
db '6',0dh,0ah
res1 db 0
res2 db 0
data ends
code
segment
start: mov ax,
data mov
ds, ax xor
ax, ax mov
al, ip1
mov bl,
bl
aaa
mov res1,
al mov
res2, bl
mov ah,
4ch int
21h
code ends
end start
INPUT: ip1 = 9
of decimal 9 ip2 = 6
; Result is 15d
OUTPUT:
res2 =
01h res1
= 05h
data segment
ip1 db
'8',0dh,0ah ip2
db '2',0dh,0ah
res db 00h
data ends
code segment
data mov
ds, ax xor
ax, ax mov
al, ip1
mov bl,
bl
aas
mov res1,
al mov ah,
4ch int
21h
code ends
end start
; Result is 6 decimal
OUTPUT:
res = 06h
NUMBERS
Aim: Write an Assembly Language Program (ALP) to perform ASCII multiplication of two
decimal numbers.
assume cs:code,
ds:data data
segment
ip1 db 5
ip2 db 9
res dw 0000h
data ends
code
segment
start: mov ax,
data mov
ds, ax xor
ax, ax mov
al, ip1
mov bl,
ip2
2Dh aam
int 21h
code ends
end start
INPUT: ip1 = 5
AL = 05h
ip2 = 9
BL = 09h
OUTPUT:
EXERCISE:
2. Why is ASCII adjust after multiply can be called as 1 byte binary to BCD conversion?
data
segment
ip1 db 07d
ip2 db 06d
ip3 db 09d
quo db 00h
rem db 00h
data ends
code
segment
start: mov ax, data
mov ds, ax
xor ax, ax
xor cx, cx
div cl
int 21h
code ends
end start
OUTPUT:
quo =
07h AL =
07h
rem =
04h AH
= 04h
EXERCISE:
1. What is the ASCII instruction, which is used before the arithmetic operation?
ON
LOGICAL
OPERATIONS
Experiment-13
BCD NUMBER
Aim: Write an Assembly Language Program (ALP) to convert a packed BCD number to
unpacked BCD number.
assume cs:code,
ds:data data
segment
packbcd db
5Ah
unpackbcd
dw 0
data ends
code segment
mov ds,
ax xor
ax, ax ; AL = 5Ah
mov unpackbcd, bx ; BX =
0506h
mov ah, 4ch
int 21h
code ends
end start
AL = 5Ah
OUTPUT:
unpackbcd = 050Ah
EXERCISE:
2. What is the purpose of the instruction AND AL, 0FH & AND
AL, 0F0H in the program?
Aim: Write an Assembly Language Program (ALP) to convert a given BCD number to its
equivalent ASCII number.
assume cs:code,
ds:data data
segment
bcdnum db 85h
asciiequ dw
0000h
data ends
code
segment
data mov
ds, ax
xor ax, ax
4ch int
21h
code ends
end start
OUTPUT:
asciiequ =
0805h BX =
3835h
Conclusion/Result: The given BCD number is converted to its equivalent ASCII number and
the result is verified.
EXCERCISE:
1. What is the difference between adding 30h and OR 30H to a BCD number to conversion toASCII?
ASCENDING ORDER
Aim: Write an Assembly Language Program (ALP) to sort the elements in an array in
ascending order.
assume cs:code,
ds:data data
segment
array db 53h,19h,25h,02h,
data ends
code
segment
data mov
ds, ax
cmp al,
[si+1] jl
back
xchg
[si+1],al
xchg [si],al
back: add si,
01 loop
again1
dec dx
jnz again0
mov ah,
4Ch int
21h
code ends
end start
INPUT:
53h,19h,25h,02h,4Ah
OUTPUT:
Conclusion/Result: The given array elements are arranged in ascending order and the result
is verified.
Experiment-16
Aim: Write an Assembly Language Program (ALP) to add all the 8-bit elements of a given array.
assume cs:code,
ds:data data
segment
arr1 db 4ah,12h,52h,19h,07h,04h,31h,3bh,10h,1fh
data ends
code segment
data mov
ds, ax
mov cl, 10
xor di, di
[bx+di] mov
sum, ax inc
di
dec cl
jnz
back
hlt
code
ends
end start
Sample Output:
Output:AX= 016dh
Conclusion/Result: The given array elements are added together and the sum of all the
given array elements is obtained and the result is verified.
PROGRAMS
ON
STRING
OPERATIONS
Experiment-17
Aim: Write an Assembly Language Program (ALP) to transfer a block of data from one
location to another.
data ends
extra segment
dstdata db 12 dup(0)
extra ends
code segment
data mov
ds, ax
mov ax,
extra mov
es, ax
mov cx,
29 rep
movsb
nop
mov ah, 4ch
int 21h
code ends
end start
INPUT:
OUTPUT:
Conclusion/Result: The given block of data is transferred from the source location to the
destination location and the result is verified.
EXERCISE:
TO COMPARE TWO GIVEN STRINGS AND FIND OUT IF THEY ARE EQUAL OR NOT
Aim: Write an Assembly Language Program (ALP) to compare two given strings and find out if
they are equal or not.
; PROGRAM: TO COMPARE TWO GIVEN STRINGS AND FIND OUT IF THEY ARE ;EQUAL OR NOT
str1 db
'Sphoorthy'
str1) str2 db
‘Sphoorthy’ res
dw ?
data ends
code
segment
data mov
ds, ax
mov es, ax
cl, strlen
cld
rep
cmpsb
jne fwd
mov ax,
0000h mov
res, ax jmp
next
fwd: mov ax,
1111h mov
res, ax
next: hlt
mov ah,
4ch int
21h
code ends
end start
OUTPUT: AX = 0000h
res = 0000h
OUTPUT: AX = 1111h
res = 1111h
Result/Conclusion: If the AX register contains 0000h, then the strings being compared are equal.
If the AX register contains 1111h, then the strings being compared are not equal.
Thus, two given strings are compared and the result is verified.
EXERCISE: