8086 Solution
8086 Solution
1. Write an assembly language program to transfer block of 8-bit data from one memory
location to another.
Solution:
.model small
.stack 100h
.data
list1 db 10h,20h,30h,40h,50h
list2 db 5 dup(?)
.code
main proc far
mov ax,@data
mov ds,ax
again:
mov al,[si] ;mov the first element of list1 to al i.e content of ds:si
mov [di],al ;transfer the first element of list1 to list2
inc si
inc di
loop again ;auto decrements cx and the loop continues till cx=0000h
mov ax,4c00h
int 21h
main endp
end main
2. Write an assembly language program to add all the elements of list1 and store in
variable.
Solution:
.model small
.stack 100h
.data
list1 db 10h,20h,30h,40h,50h
list2 db 5 dup(?)
.code
main proc far
mov ax,@data
mov ds,ax
mov al,[si]
again:
inc si
add al,[si]
mov list2,al
loop again ;auto decrements cx and the loop continues till cx=0000h
mov ax,4c00h
int 21h
main endp
end main
3. There are two tables having ten 16-bit data in each. Write an assembly language
program to generate the third table which contains the sum of corresponding element
of 1st and 2nd table.
Solution:
title addition of two table
.model small
.stack 100h
.data
array1 dw 1111h,2222h,3333h,4444h,5555h,11h,22h,33h,44h,55h
array2 dw 1111h,2222h,3333h,4444h,5555h,55h,44h,33h,22h,11h
arraysum dw 10 dup(?)
.code
main proc
mov ax,@data
mov ds,ax
mov cx,000ah
mov bx,0000h
start:
mov ax,array1[bx]
add ax,array2[bx]
mov arraysum[bx],ax
inc bx
inc bx
loop start
mov ax,4c00h
int 21h
main endp
end main
4. Two tables contain ten 16-bit data each. Write an assembly language program to
generate the 3rd table which contains 1FFFh if the corresponding data in the 1st table is
less than that of 2nd table, else store 0000h.
Solution:
.model small
.stack 100h
.data
array1 dw 0111h,0222h,0333h,0444h,0555h,732h,22h,33h,0aaah,0bbbh
array2 dw 0222h,0111h,0132h,4444h,5555h,55h,44h,33h,22h,11h
arraysum dw 10 dup(?)
.code
main proc far
mov ax,@data
mov ds,ax
mov cx,0ah
mov bx,00h
start:
mov dx,0000h
mov ax,array1[bx]
cmp ax,array2[bx]
jae condition ;jump if above or equal
mov dx,1fffh
condition:
mov arraysum[bx],dx
inc bx
inc bx
loop start
mov ax,4c00h
int 21h
main endp
end main
5. Write an assembly language program to find the largest number in the list of array of 5
elements.
Solution:
title find largest number
.model small
.stack 100h
.data
list db 10h,20h,30h,40h,09h,60h
large db 00h
.code
cmp bl,[si]
jnc nochange
mov bl,[si]
nochange:
inc si
loop again
mov large,bl
mov ax,4c00h
int 21h
main endp
end main
6. Write an assembly language program to find the smallest number in the list of array of
5 elements.
Solution:
title find smallest number
.model small
.stack 100h
.data
list db 10h,20h,30h,40h,09h,60h
small db 00h
.code
main proc
mov ax,@data
mov ds,ax
cmp bl,[si]
jc nochange
nochange:
inc si
loop again
mov small,bl
mov ax,4c00h
int 21h
main endp
end main
mov al,num
mov bl,al
mov dl,01h
back:
mul dl
mov [si],al
inc si
inc dl
mov al,bl
loop back
mov ax,4c00h
int 21h
main endp
end main
mov ax,4c00h
int 21h
main endp
end main
again:
mov [si],bh
add bh,bl
mov dh,bh
mov bh,bl
mov bl,dh
inc si
loop again
mov ax,4c00h
int 21h
main endp
end main
10. Write a program to generate the multiplication table of a number given by the user.
Solution:
.model small
.stack 100h
.data
.code
main proc
mov ax,@data
mov ds,ax
label:
mov al,bh
add al,30h
mov dl,al
mov ah,02h
int 21h
mov dl,20h
mov ah,02h
int 21h
inc bl
loop again
mov ax,4c00h
int 21h
main endp
end main
11. Write an assembly language program to arrange the given set of data in descending
order.
Solution:
title sorting numbers
.model small
.stack 100h
.data
list db 10h,42h,11h,05h,01h,79h,34h,67h,02h,12h
.code
main proc far
mov ax,@data
mov ds,ax
sort:
mov si,offset list
mov bl,00h
mov cx,000ah
back:
mov al,[si] ;get kth element
inc si
mov ax,4c00h
int 21h
main endp
end main
12. Write a program to generate multiplication table of five numbers stored in memory as
array, store the result and display in following format
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
Solution:
.model small
.stack 100h
.data
array db 02h,03h,04h,05h,06h
.code
main proc
mov ax,@data
mov ds,ax
mov bx,0000h
mov cx,0005h
push cx
push bx
No_of_table:
push cx
mov al,array[bx]
and al,0fh ;taking only LSB
mov dh,al
mov bl, 01h
label:
mov al,bh
add al,30h
mov dl,al
mov ah,02h
int 21h
mov dl,20h
mov ah,02h
int 21h
inc bl
loop again
pop cx
pop bx
inc bx
push bx
loop No_of_table
mov ax,4c00h
int 21h
main endp
end main
mov cx,0ah
mov ah,00h
mov dx,00h
mov bl,03h
mov bh,02h
again:
mov al,bh
mul bl
add dx,ax
add bl,02
add bh,02
loop again
mov sum,dx
mov ax,4c00h
int 21h
main endp
end main
14. Write an Assembly language program to print the given line word wise into next line.
Solution:
.model small
.stack 100h
.data
lea si,string
again:
mov dl,[si]
cmp dl,'$'
jz finish
cmp dl,32
jz nextline
jmp print
nextline:
mov dl,0dh
mov ah,02h
int 21h
mov dl,0ah
mov ah,02h
int 21h
print:
inc si
mov ah,02h
int 21h
jmp again
finish:
mov ah,4ch
int 21h
main endp
end main
15. Write a program to convert from lowercase to uppercase entered by the user.
Solution:
.model small
.stack 100h
.data
string db ''
.code
main proc
mov ax,@data
mov ds,ax
mov di,offset string
a1:
mov ax,4c00h
int 21h
main endp
end main
17. Write a program in 8086 to read a string and count the number of vowels, consonants,
numerals and other characters and display the count.
Solution:
title counting different elements in a sentence
.model small
.stack 100h
.data
vowels db 00h
consonents db 00h
.code
main proc far
mov ax,@data ;initializing data segment
mov ds,ax
mov ch,00h
mov cl,len ;count of the input string
mov si,offset msg
again:
cmp [si],'A' ;compare input character with 'A'
jb number ;if it is below A, jump to number
number:
cmp [si],'0' ;check if it is a number, if not jump to
inc_others
jb inc_others
cmp [si],'9'
ja inc_others
inc_others:
inc others ;increment other counter
update:
inc si
loop again
mov ax,4c00h
int 21h
main endp
end main
mov ax,@data
mov ds,ax
mov ah,00 ;defining vedio mode
mov al,03 ;80*25
int 10h
dec bl
mov bh,00h
mov ah,06h ;clearing the window
mov al,00
int 10h
loop again
mov ax,4c00h
int 21h
main endp
end main
19. Write an assembly language program to take name and address from the user and
display at the center of the screen.
Solution:
.model small
.stack 100h
mov ah,02h
mov dl,0dh
int 21h
endm
.data
paralist1 label byte ;Giving 1st byte the Label 'paralist1'
mov ax,@data
mov ds,ax
mov ah,0ah
lea dx, paralist1
int 21h
new_line ;macro
mov ah,0ah
lea dx, paralist2
int 21h
mov ah,02
mov dh,12
mov dl,40
int 10h
mov ah,09
mov dx,offset name1
int 21h
mov ah,02
mov dh,13
mov dl,40
int 10h
mov ah,09
lea dx,address
int 21h
main endp
end main
mov ah,0ah
lea dx, paralist1
int 21h
lea si,name1
mov ah,02
mov dh,12
mov dl,40
int 10h
again:
mov ah,02
int 10h
mov ah,09
mov al,[si]
cmp al,0dh ;comparing the character with 'enter' key.
je finish
mov bl,2ch ;green background and red foreground
inc si ;getting next character
inc dx ;next colum of screen
mov cx,1h ;number of times the character is to display
int 10h
jmp again
finish:
mov ah,4ch
int 21h
main endp
end main