Microprocessor (8086) Lab
Microprocessor (8086) Lab
org/content/m32857/latest/
Connexions
You are here: Home » Content » Microprocessor(8086) Lab
Microprocessor(8086) Lab
Module by: Rajeshwari Hegde.
Summary: This module contains the programs involving Data transfer instructions, Arithmetic and logical
instructions, string manipulation instructions etc
Program:
.model small
.data
Num dw 4321h
.code
Mov ax,@data
Mov ds,ax
Mov si,1000h
Mov bx,1000h
Mov ah,4ch
Int 21h
1 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
End
Output:
Ax=1234h
Bx=1234h
Ax=4321h…..
overlap
.model small
.data
d1 db 1,2,3,4,5
d2 db 10 dup(0)
.code
mov ds,ax
inc si ;Increment si
inc di ;Increment di
int 21h
end
d1 d2
2 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
01
02
03
04
05
TABLE
1
3 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
01
02
03
04
05
TABLE
2
.model small
.data
d1 db 1,2,3,4,5
d2 db 10 dup(0)
.code
mov ds,ax
inc si ;Increment si
inc di ;Increment di
4 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
INC di ;Increment di
inc si ;Increment si
int 21h
end
(with overlap)
01
02
03
04
05
TABLE
3
01
02
03
04
05
TABLE
4
01
02
01
02
03
04
05
TABLE
5
5 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
.model small
.data
d1 db 1,2,3,4,5
d2 db 22h,33h,44h,55h,66h
.code
mov ds,ax
mov[si],bl ;Move bl to d1
inc si ;Increment si
inc di ;Increment di
int 21h
end
01
02
03
04
05
TABLE
6
6 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
11
22
33
44
55
TABLE
7
d1 d2 d1 d2
01
02
03
04
05
TABLE
8
11
22
33
44
55
TABLE
9
.model small
.data
n1 dw 1111h,2222h,3333h,4444h,0ffffh
n2 dw 02 dup(0)
.code
7 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
mov ds,ax
int 21h
end
I/p:1111h,2222h,3333h,4444h,0ffffh
o/p:1aaa9h
numbers.
.model small
.data
d1 dd 0f2222222h
d2 dd 33333333h
d3 dd 10 dup(0)
.code
8 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
mov ds,ax
;by bx
inc si ;Increment si
inc di ;Increment di
dec bx ;decrement bx
dec cx ;Decrement cx
int 21h
end
Output:125555555h
.data
9 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
d1 dq 1234567812345678h
d2 dq 1234567812345678h
res db 09 dup(0)
.code
mov ds,ax
adc al,[di] ;Add with carry to the LS byte of the ;second number
dec bx ;Decrement bx
inc si ;Increment si
inc di ;Increment di
int 21h
end
Input: 1234567812345678h,1234567812345678h
Output:2468ACF02468ACF0H
.model small
10 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
.data
num dd 12345678h
num1 dw 2345h
res dw 02 dup(0)
.code
mov ds,ax
div bx ;dx:ax/bx
int 21h
end
Output:Quotient:8422h, Remainder:134Eh
.model small
.data
array dw 1111h,2222h,8567h,4589h,5555h
res dw 02 dup(0)
.code
mov ax,@data
11 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
jnc below ;if 1st number>2nd number compare 1st with ;3rd number and so on.
mov ax,[bx+2]
below:inc bx
inc bx
dec cx
int 21h
end
Input: 1111h,2222h,8567h,4589h,5555h
.model small
.data
n1 dw 0ffffh,5555h,3333h,7777h
count dw 04h
.code
mov ds,ax
dec bx
inc si
inc si
12 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
mov n1[si-2],ax
dec bx
mov ah,4ch
int 21h
end
.model small
.data
string db "bmscollege$"
enter db "j"
char db 02 dup(0)
.code
mov ds,ax
mov es,ax
13 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
dec cl
jnz up
mov ah,09h
int 21h
jmp end1
mov ah,09h
int 21h
int 21h
end
.model small
.data
no dw 08h
res dw 02 dup(0)
.code
mov ds,ax
mov bx,no
14 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
jmp up
down:mov res,dx
mov res+2,ax
int 21h
end
I/P=08h
O/P=9D80h
12. Program to check whether the given data byte is positive or negative
.model small
.data
n1 db 09H
.code
mov ds,ax
mov al,n1
mov dx,offset n3
mov ah,09h
int 21h
jmp end1
mov ah,09h
int 21h
end1:mov ah,4ch
int 21h
15 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
end
Input:09h
Input:0ffh
.model small
.data
n1 db 0feH
n4 db 04 dup(0)
.code
mov ds,ax
mov ah,00h
mov bl,02h
div bl ;divide by 2
lea dx,n2
int 21h
mov ah,09h
int 21h
int 21h
16 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
end
Input:0feh
Input:09h
.model small
.data
num dw 4421h
.code
mov ds,ax
mov ah,09h
int 21h
jmp last
pali:mov ah,09h
17 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
int 21h
int 21h
end
15. Program to check whether the given data word is a nibble wise palindrome
.model small
.data
num dw 8448h
.code
mov ds,ax
dec cl ;Decrement cl
mov ah,09h
lea dx,msg2
int 21h
lea dx,msg1
int 21h
18 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
int 21h
end
.model small
.data
;N1 db ‘9’
;N2 db ‘9’
N1 db ‘5’
N2 db ‘8’
N3 db 02 dup(0)
.code
Mov ds,ax
Push ax
Mov ah,02h
Int 21h
Pop ax
Mov ah,02h
Int 21h
Int 21h
End
19 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
Input : N1=’9’
N2=’9’
Output: 18
Input: N1 = ‘5’
N2 = ‘8’
Output: 13
.model small
.data
num db 35h
;num db 0AAh
res db 2 dup(0)
.code
Mov ax,@data
Mov cl,04h
Jc d1
D1:add al,30h
Mov [si],al
Mov al,num
20 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
D2:add al,30h
Int 21h
End
Input:35h
[si+1]
Input:0AAh
[si+1]
.model small
.data
D1 db 99h
;D1 db 85h
D2 db 02 dup(0)
.code
Mov ax,@data
Mov cl,04h
Mov bl,al
Mov al,0ah
21 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
Int 21h
End
Input : 99
Output: 63h
Input : 85
Output: 55h
.model small
.data
num db 0ffh
;num db 63h
res db 03 dup(0)
.code
Mov ax,@data
Mov bl,64h
Lea si,res
mov bl,0ah
div bl ;divide ax by bl
22 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
int 21h
end
Input :0ffh
Input :063h
.model small
.data
n3 db 0fh
.code
mov ax,@data
mov dl,00h
jnz invalid ;if 1st three MSBs are not zero jump to ;invalid
mov bl,05h
mov al, n3 ;if 1st three MSBs are non-zero, move the ;number to al
23 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
mov ah,09h
int 21h
int 21h
int 21h
end
Input:0fh
Input:09h
.stack 64
.data
;num dw 05h,02h
num dw 09h,2dh
lcm dw 2 dup(0)
.code
mov ax,@data
mov num,ax
mov num+2,bx
24 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
push dx
div bx ;divide ax by bx
je store
pop dx
pop ax
add ax,num
jnc no_increment
inc dx
pop lcm
mov ah,4ch
int 21h
end
Input:05h, 02h
Output:0ah
Input:
.model small
.data
num dw 1bh,09h
Gcd dw ?
.code
Mov ax,@data
Again:cmp ax,bx ;
25 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
Je exit
Jb down
Divaxbx:mov dx,0
Div bx
Cmp dx,0
Je exit
Mov ax,dx
Jmp again
Down:xchg ax,bx
Jmp divaxbx
Exit:mov gcd,bx
Mov gcd+2,ax
Mov ah,4ch
Int 21h
End
23. Program to divide a packed bcd number by an unpacked bcd number and display the quotient
and remainder on the screen
.model small
.data
N1 db 6
N2 db 7
N3 db 02 dup(0)
.code
Mov ax,@data
Mov ds,ax
Mov ah,n1
Mov al,n2
mov ch,09h
Aad
div ch
26 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
Or ax,3030h
Push ax
Mov dl,ah
Mov ah,02h
Int 21h
mov ah,02h
int 21h
pop ax
Mov dl,al
Mov ah,02h
Int 21h
Mov ah,4ch
Int 21h
End
Input:6 and 7
24.Program to multiply two unpacked BCD numbers and display the result
.model small
.data
N1 db 9
N2 db 5
N3 db 02 dup(0)
.code
Mov ax,@data
Mov ds,ax
Mov al,n1
Mov bl,n2
mul bl
Aam
27 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
Or ax,3030h
Push ax
Mov dl,ah
Mov ah,02h
Int 21h
pop ax
Mov dl,al
Mov ah,02h
Int 21h
Mov ah,4ch
Int 21h
End
.model small
.data
num1 dd 0ff0aff0h
num2 dd 03304002h
res dq 00h
.stack 100h
.code
Mov ax,@data
Mov ds,ax
Lea si,num1
Lea di,num2
Lea bx,res
clc
mov ax,[si]
28 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
mov[bx],ax
mov cx,dx
mov ax[si+2]
add ax,cx
adc dx,00h
push dx
push ax
mov ax,[si]
pop cx
add ax,cx
adc dx,00h
mov[bx+2],ax
mov cx,dx
mov ax,[si+2]
add ax,cx
adc dx,00h
pop cx
add ax,cx
adc dx,00h
mov[bx+4],ax
mov[bx+6],dx
mov ah,4ch
int 21h
end
Input:
Num1:0ff0aff0h
Num2:03304002h
29 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
Output:32d32d18dd5fe0h
.model small
.data
num db 0ffh
res db 04 dup(0)
.code
mov ax,@data
mov ds,ax
mov ah,00h
mov al,num
mov bl,al
mul bl
lea si,res
mov[si],ah
mov[si+1],al
mov ch,02
up:mov dl,[si]
and dl,0f0h
mov cl,04h
ror dl,cl
cmp dl,0ah
jb down
add dl,07h
down:add dl,30h
mov ah,02h
int 21h
mov dl,[si]
and dl,0fh
cmp dl,0ah
30 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
jc down1
add dl,07h
down1:add dl,30h
mov ah,02h
int 21h
inc si
dec ch
jnz up
mov ah,4ch
int 21h
end
Input:04h
Input:0ffh
.model small
.data
num dw 05h
;num dw 0ffh
cube dw 02 dup(0)
.code
Mov ax,@data
Mov ds,ax
Mov dx,0h
Mov ax,num
Mul num
Mov cx,dx
Mul num
Add ax,cx
31 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
Mov cube,ax
Jnc skip
Inc dx
Skip:mov cube+2,dx
Mov ah,4ch
Int 21h
End
Input:0ffh
Input:05h
28. Program to find number of ones in a given data word and display the count on the screen
.model small
.data
n1 dw 0fff0h
n3 db 04 dup(0)
.code
mov ax,@data
mov ds,ax
mov bx,00h
lea si,n3
clc
mov cl,10h
mov ax,n1
up:rcl ax,01
jnc d1
inc bl
d1:mov [si],bl
dec cx
32 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
jnz up
mov dl,[si]
and dl,0f0h
mov cl,04h
ror dl,cl
cmp dl,0ah
jc d11
add dl,07h
d11:add dl,30h
mov ah,02h
int 21h
mov dl,[si]
and dl,0fh
cmp dl,0ah
jc d12
add dl,07h
d12:add dl,30h
mov ah,02h
int 21h
mov ah,4ch
int 21h
end
Input:0fff0h
29.ascii multiplication
.model small
.data
N1 db 6
N2 db 7
N3 db 02 dup(0)
33 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
.code
Mov ax,@data
Mov ds,ax
Mov ah,n1
Mov al,n2
mov ch,09h
;Mov ah,00h
Aad
div ch
Or ax,3030h
Push ax
Mov dl,ah
Mov ah,02h
Int 21h
pop ax
Mov dl,al
Mov ah,02h
Int 21h
Mov ah,4ch
Int 21h
End
.model small
.data
string db 18 dup(0)
.code
mov ax,@data
mov ds,ax
34 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
mov es,ax
mov ah,09h
int 21h
add si,14h
mov dl,24h
mov [si],dl
cops:mov ah,01h
int 21h
cmp al,0dh
jz rev
dec si
mov [si],al
jmp cops
mov ah,09h
int 21h
mov ah,09h
mov dx,si
int 21h
mov ah,4ch
int 21h
end
.model small
.data
dst db 25 dup(0)
.code
35 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
mov ax,@data
mov ds,ax
mov es,ax
lea si,src
lea di,dst
cld
mov cx,0fh
rep movsb
mov ah,4ch
int 21h
end
data segment
mainstr db 80 dup(0)
subst db 80 dup(0)
cr db 0ah,0dh,"$"
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov es,ax
mov ah,09h
lea dx,mes1
int 21h
36 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
mov si,00
up:mov ah,01h
int 21h
cmp al,0dh
jz acc
mov mainstr[si],al
inc si
jmp up
acc:mov mainstr[si],al
lea dx,cr
mov ah,09h
int 21h
lea dx,mes2
int 21h
mov di,00
t3:mov ah,01h
int 21h
cmp al,0dh
jz out
mov subst[di],al
inc di
jmp t3
out:mov subst[di],al
lea dx,cr
mov ah,09h
int 21h
mov si,00
mov di,00
again:mov al,mainstr[si]
cmp al,null
37 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
jz t2
cmp al,subst[di]
jz down
mov di,00
inc si
jmp again
down:inc si
inc di
mov al,subst[di]
cmp al,null
jz found
jmp again
found:mov ah,09h
lea dx,sfound
int 21h
jmp quit
t2:mov ah,09h
lea dx,nfound
int 21h
quit:mov ah,4ch
int 21h
code ends
end start
3 2. Program to multiply two data words and display the answer by calling a far procedure
data segment
;mul1 db 12h
38 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
;mul2 db 24h
mul1 db 0ffh
mul2 db 0ffh
data ends
stack_seg segment
dw 40 dup(0)
stack_seg ends
extrn disp:far
sbrt ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,mul1
mul mul2
mov cx,ax
mov al,ah
call disp
mov al,cl
call disp
mov ah,4ch
int 21h
code ends
end start
public disp
39 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
assume cs:sbrt
push ax
push dx
push cx
mov dl,al
and dl,0f0h
mov cl,04h
ror dl,cl
cmp dl,0ah
jb down
add dl,07h
down:add dl,30h
push ax
mov ah,02h
int 21h
pop ax
mov dl,al
and dl,0fh
cmp dl,0ah
jc down1
add dl,07h
down1:add dl,30h
push ax
mov ah,02h
int 21h
pop ax
pop cx
pop dx
pop ax
40 of 41 2/19/2011 2:32 PM
Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/
ret
disp endp
sbrt ends
end
Input:12h 24h
This work is licensed by Rajeshwari Hegde under a Creative Commons Attribution License (CC-BY 3.0), and is an Open Educational Resource.
41 of 41 2/19/2011 2:32 PM