Btcs9301 MP Lab File

You might also like

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

Sr.

no experiments Date Teacher


Sing.

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.

EXPERIMENTAL SETUP DETAILS FOR THE COURSE

Software Requirements

8086 Emulator or 8086 assembler

Hardware Requirements

8086 SDK Kit or Any computer Hardware capable of running 8086 emulator can

be used for this course.


Experiment-1

ADDITION OF 2 8-BIT HEXADECIMAL NUMBERS

Aim: Write an Assembly Language Program (ALP) to add 2 8-bit hexadecimal numbers.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

;PROGRAM : ADDITION OF 2 8-BIT HEXADECIMAL NUMBERS


assume cs:code,

ds:data code

segment

start: mov ax,

data mov

ds, ax mov

ax,00h mov

al, num1

mov bl,

num2 add

al, bl mov

result, al

mov ah,

4ch int 21h

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

Conclusion/Result: The addition of two 8-bit hexadecimal numbers is

verified. Exercise:

1. What is an assembler directive?

2. What is a pseudo operation?

3. What does ORG 2000H imply?

4. AL register is used why not AX?

5. What is the purpose of INT3 in the program?

6. What is the purpose of MOV AH, 4CH, INT 21H in the program?
Experiment-2

ADDITION OF 2 16-BIT HEXADECIMAL NUMBERS

Aim: Write an Assembly Language Program (ALP) to add 2 16-bit hexadecimal numbers.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

;PROGRAM : ADDITION OF 2 16-BIT HEXADECIMAL NUMBERS

assume cs:code,

ds:data code

segment

start: mov ax,

data mov

ds, ax mov

ax, 00h mov

ax, num1

mov bx,

num2 add

ax, bx mov

result, ax

mov ah,

4ch int 21h

code ends

data segment

num1 dw

1234h num2

dw 4321h

result dw

0000h

data ends
end start

INPUT: num1 = 1234h

AX = 1234h

num2 =

4321h BX

4321h

OUTPUT:

result =

5555h AX =

5555h

Conclusion/Result: The addition of two 16-bit hexadecimal numbers is verified.

Exercise:

1. Can ORG have other numbers instead of 2000h?

2. What is the purpose of MOV DS, AX?

3. Why AX register is used and not AL?

4. What is the purpose of DW?

5. What happens if the result is greater than 16bit when result is declared as DW?
Experiment-3

SUBTRACTION OF 2 8-BIT HEXADECIMAL NUMBERS

Aim: Write an Assembly Language Program(ALP) to subtract 2 8-bit hexadecimal numbers.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

;PROGRAM : SUBTRACTION OF 2 8-BIT HEXADECIMAL NUMBERS

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,

4ch int 21h

code ends

data segment

num1 db

4AH num2

db 3FH

result db

00H
data ends

end start

INPUT: num1 = 4Ah

AL = 4Ah

num2 =

3Fh BL =

3Fh

OUTPUT:

result =

0Bh AL =

0Bh

Conclusion/Result: The subtraction of two 8-bit hexadecimal numbers is verified.


Experiment-4
SUBTRACTION OF 2 16-BIT HEXADECIMAL NUMBERS
Aim: Write an Assembly Language Program (ALP) to subtract 2 16-bit hexadecimal numbers.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

;PROGRAM :SUBTRACTION OF 2 16-BIT HEXADECIMAL NUMBERS

assume cs:code,

ds:data code

segment

start: mov ax,

data mov

ds, ax mov

ax, 00h 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

INPUT: num1 = 5678h

AX = 5678h

num2=432

1h

BX = 4321h

OUTPUT:

result =

1357h AX =

1357h

Conclusion/Result: The subtraction of two 16-bit hexadecimal numbers is verified


Experiment-5
MULTIPLICATION OF 2 8-BIT HEXADECIMAL NUMBERS
Aim: Write an Assembly Language Program(ALP) to multiply 2 8-bit hexadecimal numbers.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

;PROGRAM :MULTIPLICATION OF 2 8-BIT HEXADECIMAL NUMBERS

assume cs:code,

ds:data code

segment

start: mov ax,

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

INPUT: num1 = 4Fh

AL = 4Fh

num2 =

8Ch BL =

8Ch

OUTPUT:

result =

34h result1

= 2Bh AX =

2B34h

Conclusion/Result: The multiplication of two 8-bit hexadecimal numbers is verified.


Experiment-6

MULTIPLICATION OF 2 16-BIT HEXADECIMAL NUMBERS

Aim: Write an Assembly Language Program (ALP) to multiply two 16-bit hexadecimal numbers.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

;PROGRAM :MULTIPLICATION OF 2 16-BIT HEXADECIMAL NUMBERS

assume cs:code,

ds:data code

segment

start: mov ax,

data mov

ds, ax

mov ax, 00

mov ax,

num1 mov

bx, num2

mul bx

mov result1,

ax mov

result2, dx int

03h

mov ah, 4ch

code ends

data

segment

num1 dw

3A6Bh num2

dw 8ECDh

result1 dw
0000h

result2

dw 0000h

data ends
OUTPUT:

end start

INPUT: num1 = 3A6Bh

AX = 3A6Bh

num2 =

8ECDh BX

8ECDh

result1 =

21AFh result2

= 2096h DX =

2096h

AX = 21AFh

Conclusion/Result: The multiplication of two 16-bit hexadecimal numbers is verified.


Experiment-7
DIVISION OF 2 8-BIT HEXADECIMAL NUMBERS
Aim: Write an Assembly Language Program (ALP) to divide 2 8-bit hexadecimal numbers.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

;PROGRAM :DIVISION OF 2 8-BIT HEXADECIMAL NUMBERS

assume cs:code,

ds:data code

segment

start: mov ax,

data mov

ds, ax mov

ax, 00h

mov dx,

00h mov al,

num1 mov

bl, num2 div

bl

mov quotient, al

mov

remainder,ah

mov ah, 4ch

int 21h

code ends

data

segment

num1 db 8fh

num2 db 1ah

quotient db 00h

remainder db
00h

data ends

end start

INPUT: num1 = 8Fh

AL = 8Fh

num2 =

1Ah BL =

1Ah

OUTPUT: quotient = 05h

remainder =

0Dh AL = 05h

AH = 0Dh

Conclusion/Result: The division of two 8-bit hexadecimal numbers is verified.


Experiment-8
DIVISION OF 2 16-BIT HEXADECIMAL NUMBERS
Aim: Write an Assembly Language Program(ALP) to divide 2 8-bit hexadecimal numbers.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

; PROGRAM : DIVISION OF TWO 16-BIT HEXADECIMAL NUMBERS

assume cs:code,

ds:data code

segment

start: mov ax,

data mov

ds, ax mov

ax, 00h 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

INPUT: num1 = 9FFFh

AX = 9FFFh

num2 =

1A3Eh BX =

1A3Eh

OUTPUT:

quotient =

0006h AX =

0006h

remainder =

028Bh DX =

028Bh

Conclusion/Result: The division of two 16-bit hexadecimal numbers is verified.


Experiment-9

ASCII ADDITION OF 2 DECIMAL NUMBERS

Aim: Write an Assembly Language Program(ALP) to perform ASCII addition of two


decimal numbers.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

; PROGRAM : ASCII ADDITION OF 2 DECIMAL NUMBERS

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,

ip2 add al,

bl

aaa

mov res1,

al mov

res2, bl

mov ah,

4ch int
21h

code ends

end start
INPUT: ip1 = 9

AL = 39h ; ASCII value

of decimal 9 ip2 = 6

BL = 36h ; ASCII value of decimal 6.

; Result is 15d

OUTPUT:

res2 =

01h res1

= 05h

Conclusion/Result: The ASCII addition of two decimal numbers is performed and


the result is verified.
Experiment- 10
ASCII SUBTRACTION OF 2 DECIMAL NUMBERS
Aim: Write an Assembly Language Program(ALP) to perform ASCII subtraction of two
decimal numbers.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

; PROGRAM : ASCII SUBTRACTION OF 2 DECIMAL NUMBERS

assume cs:code, ds:data

data segment

ip1 db

'8',0dh,0ah ip2

db '2',0dh,0ah

res db 00h

data ends

code segment

start: mov ax,

data mov

ds, ax xor

ax, ax mov

al, ip1

mov bl,

ip2 sub al,

bl

aas

mov res1,

al mov ah,

4ch int

21h

code ends
end start

INPUT: ip1 = 08h

AL = 38h ; ASCII value

of decimal 8 ip2 = 02h

BL = 32h ; ASCII value of decimal 2.

; Result is 6 decimal

OUTPUT:

res = 06h

Conclusion/Result: The ASCII subtraction of two decimal numbers is performed and


the result is verified.
Experiment-

11 ASCII MULTIPLICATION OF 2 DECIMAL

NUMBERS

Aim: Write an Assembly Language Program (ALP) to perform ASCII multiplication of two
decimal numbers.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

;PROGRAM : ASCII MULTIPLICATION OF 2 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

mul bl ; 05h x 09h =

2Dh aam

mov res, ax ; AH = 04h and AL =

05h mov ah, 4ch

int 21h

code ends
end start
INPUT: ip1 = 5

AL = 05h

ip2 = 9

BL = 09h

OUTPUT:

res = 0405h ; unpacked BCD for 45 decimal

Conclusion/Result: The ASCII multiplication of two decimal numbers is performed and


the result is verified.

EXERCISE:

1. What is the purpose of XCHG instruction in ASCII adjust after multiplication?

2. Why is ASCII adjust after multiply can be called as 1 byte binary to BCD conversion?

3. What does AL & AH contains?


Experiment-12

ASCII DIVISION OF 2 DECIMAL NUMBERS

Aim: Write an Assembly Langu ge Program(ALP) to perform ASCII multiplication of two


decimal numb rs.

Apparatus: EMU8086 softwar package, Computer, Keyboard, Power Supply.

; PROGRAM : ASCII DIVISION OF 2 DECIMAL NUMBERS

assume cs:c de, ds:data

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

mov al, ip1 ; AL = 07h

mov ah, ip2 ; AH = 06H i.e., unpacked BCD for


67decimal
aad ; AX = 67 decimal = 0043h equivalent of
67decimal
mov cl, ip3

div cl

mov quo, ah ; 43/9= 4 with remainder 7

mov rem, al ; AL = 07 unpacked BCD, AH= 04 unpacked


BCD
mov ah, 4ch

int 21h
code ends

end start

INPUT: ip1 = 07h

ip2 = 06h ; AX= 0607h unpacked BCD for

67 decimal ip3 = 09h

OUTPUT:

quo =

07h AL =

07h

rem =

04h AH

= 04h

Conclusion/Result: The ASCII division of two decimal numbers is performed and


the result is verified.

EXERCISE:

1. What is the ASCII instruction, which is used before the arithmetic operation?

2. Why is ASCII adjust before division is done before actual division?

3. What does AL & AH contains?


PROGRAMS

ON

LOGICAL
OPERATIONS
Experiment-13

CONVERSION OF PACKED BCD TO UNPACKED

BCD NUMBER

Aim: Write an Assembly Language Program (ALP) to convert a packed BCD number to
unpacked BCD number.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

; PROGRAM : CONVERSION OF PACKED BCD TO UNPACKED BCD

assume cs:code,

ds:data data

segment

packbcd db

5Ah

unpackbcd

dw 0

data ends

code segment

start: mov ax, data

mov ds,

ax xor

ax, ax ; AL = 5Ah

mov al, packbcd


mov dl, al ; DL = 5Ah

and al, 0f0h ; AL = 50h

mov cl, 4 ; CL = 04h

ror al, cl ; AL = 05h

mov bh, al ; BH = 05h


and dl, 0fh ; DL = 06h
mov bl, dl ; BL = 06h

mov unpackbcd, bx ; BX =
0506h
mov ah, 4ch
int 21h

code ends

end start

INPUT: packbcd = 5Ah

AL = 5Ah

OUTPUT:

BX = 050Ah i.e., BH = 05h , BL = 0Ah

unpackbcd = 050Ah

Conclusion/Result: The given packed BCD number is converted to equivalent


unpacked number and the result is verified.

EXERCISE:

1. What is the purpose of the instruction ROR AL, CL?

2. What is the purpose of the instruction AND AL, 0FH & AND
AL, 0F0H in the program?

3. What is the expansion of UPBCD?

4. What is the use of DAA instruction?

5. What is the reason for packing unpacked BCD?

6. What is common between unpacked BCD and ASCII?


Experiment-14

CONVERSION OF BCD NUMBER TO EQUIVALENT ASCII NUMBER

Aim: Write an Assembly Language Program (ALP) to convert a given BCD number to its
equivalent ASCII number.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

; PROGRAM: CONVERSION OF BCD NUMBER TO EQUIVALENT ASCII NUMBER

assume cs:code,

ds:data data

segment

bcdnum db 85h

asciiequ dw

0000h

data ends

code

segment

start: mov ax,

data mov

ds, ax

xor ax, ax

mov al, bcdnum ; AL = 85h

mov dl, al ; DL = 85h

and al, 0f0h ; AL = 80h

mov cl, 4 ; CL = 04h

ror al, cl ; AL = 08h

mov bh, al ; BH = 08h

and dl, 0fh ; DL = 05h

mov bl, dl ; BL = 05h BX = 0805h


mov asciiequ, bx ; asciiequ = 0805h

add bx, 3030h ; BX = 3835h


mov ah,

4ch int

21h

code ends

end start

INPUT: bcdnum = 85h

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?

2. Why unpacking is necessary during the conversion?

3. What is the ASCII character for symbol A?

4. What is the ASCII character for symbol zero ‘0’?


Experiment-

15 TO SORT ARRAY ELEMENTS IN AN

ASCENDING ORDER

Aim: Write an Assembly Language Program (ALP) to sort the elements in an array in
ascending order.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

; PROGRAM : SORT ARRAY ELEMENTS IN AN ASCENDING ORDER

assume cs:code,

ds:data data

segment

array db 53h,19h,25h,02h,

4Ah count equ 05

data ends

code

segment

start: mov ax,

data mov

ds, ax

mov dx, count-1

again0: mov cx, dx

mov si, offset array

again1: mov al, [si]

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:

02h, 19h, 25h, 4Ah, 53h

Conclusion/Result: The given array elements are arranged in ascending order and the result
is verified.
Experiment-16

ADDITION OF ALL THE 8 – BIT ELEMENTS OF A GIVEN ARRAY

Aim: Write an Assembly Language Program (ALP) to add all the 8-bit elements of a given array.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

; PROGRAM: ADDITION OF 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

start: mov ax,

data mov

ds, ax

mov cl, 10

xor di, di

lea bx, arr1

back: mov al,

[bx+di] mov

ah, 00h add

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

TRANSFER OF BLOCK OF DATA FROM ONE LOCATION TO ANOTHER

Aim: Write an Assembly Language Program (ALP) to transfer a block of data from one
location to another.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

;PROGRAM: TO TRANSFER A BLOCK OF DATA FROM ONE LOCATION TO ;ANOTHER

assume cs:code, ds:data,

es:extra data segment

srcdata db 'Empty vessels make much noise',24h

data ends

extra segment

dstdata db 12 dup(0)

extra ends

code segment

start: mov ax,

data mov

ds, ax

mov ax,

extra mov

es, ax

mov si, offset

srcdata mov di,

offset dstdata cld

mov cx,

29 rep

movsb

nop
mov ah, 4ch
int 21h

code ends

end start

INPUT:

'Empty vessels make much noise'

OUTPUT:

'Empty vessels make much noise'

Conclusion/Result: The given block of data is transferred from the source location to the
destination location and the result is verified.

EXERCISE:

1. If the DF=1, will the SI and DI register decremented?

2. The destination memory is pointed by which register combination?

3. The source is pointed to by which register combination?


Experiment-18

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.

Apparatus: EMU8086 software package, Computer, Keyboard, Power Supply.

; PROGRAM: TO COMPARE TWO GIVEN STRINGS AND FIND OUT IF THEY ARE ;EQUAL OR NOT

assume cs:code, ds:data,

es:extra data segment

str1 db

'Sphoorthy'

strlen equ ($-

str1) str2 db

‘Sphoorthy’ res

dw ?

data ends

code

segment

start: mov ax,

data mov

ds, ax

mov es, ax

mov si, offset

str1 mov di,

offset str2 mov

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

I. INPUT: str1 = ‘Sphoorthy’


str2 = ‘Sphoorthy’

OUTPUT: AX = 0000h

res = 0000h

II. INPUT: str1 = ‘Sheep’


str2 = ‘Ship’

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:

1. What is the significance of CLD?

2. How does CMPSB perform the comparison?

You might also like