solution assembly 8086
TRANSCRIPT
// 1//
SOLUTION OF THE PROGRAMS USING 8086 ASSEMBLY LANGUAGE (USING EMU 8086 SIMULATOR)
1. Write an assembly language programming in 8086 to print the message.
include emu8086.inc
ORG 100h
PRINT 'My Name is Sachidananda!' ;Message is printed to the Output Screen
INT 16h ;Interrupt to the Operating System
RET ; return to operating system.
END ; directive to stop the compiler
2. Write an assembly language programming in 8086 to print the message of multiple lines.
include emu8086.inc
ORG 100h
PRINT 'My Name is Sachidananda!' ;Message is printed to the Output Screen
INT 16h ;Interrupt to the Operating System
GOTOXY 0, 1
PRINT 'From Berhampur'
INT 16h
GOTOXY 0, 2
PRINT 'Ganjam'
INT 16h
RET ; return to operating system.
END ; directive to stop the compiler
3. Write an assembly program to print information by using emu8086.inc and function.
include emu8086.inc
ORG 100h
PRINT 'My Name is Sachidananda!' ;Message is printed to the Output Screen
INT 16h ;Interrupt to the Operating System
GOTOXY 0, 1
PRINT 'From Berhampur'
INT 16h
GOTOXY 0, 2
PRINT 'Ganjam'
INT 16h
RET ; return to operating system.
END ; directive to stop the compiler
4. Write an assembly program using 8086mu to print some sequence of texts.
;name "Sachidananda"
org 100h
jmp start ; start is the lebel and jmp is the jump instruction
nam: db "Name: Sachidananda", 0dh,0ah,24h ; Define byte with space allocation in hexadecimal
// 2//
ad: db "Berhampur",0dh,0ah,24h
ph: db "9861329499",0dh,0ah,24h
start: mov dx, nam
mov ah,09h
int 21h ; Halt the program till press any key
mov ah,0
mov dx,ad
mov ah,09h
int 21h
mov ah,0
mov dx,ph
mov ah,09h
int 21h
mov ah,0
int 16h
ret ; Return to the Operating System
5. Write an assembly language program to display a character with its background color.
6. Write a program in 8086 Microprocessor of 8-bit register to find the sum of two integers.
ORG 100h ; Pre directive to control the program
include 'emu8086.inc' ; Include emu8086 header file for functions / procedures
LEA SI, msg1 ; Load data to source index
CALL PRINT_STRING ; calling of print_string procedure to print message
CALL scan_num ; calling of scan_num procedure for input value
mov ax, cx
putc 10 ; Put character to print in next line
LEA SI, msg2
CALL PRINT_STRING
CALL scan_num
mov bx, cx
putc 10
JMP calc
back: JMP stop
calc:
ADD ax, bx
Print "The sum is: "
CALL print_num
putc 10
putc 13
// 3//
JMP back
stop:
RET
msg1 DB 'Enter the first number: ',0
msg2 DB 'Enter the second number: ',0
DEFINE_SCAN_NUM
DEFINE_PRINT_STRING
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
END
6. Write a program 8086 Mp to enter two numbers and find the difference.
ORG 100h
include 'emu8086.inc'
LEA SI,msg1 ; Load effective address to Source Index
CALL PRINT_STRING ; Pre defined function/module
CALL scan_num
mov ax,cx
putc 10 ; Put charecter at line 1
LEA SI,msg2
CALL PRINT_STRING
CALL scan_num
mov bx,cx
putc 10
JMP calc
back: JMP stop
calc:
SUB ax, bx
Print "The sum is: "
CALL print_num
putc 10
putc 13
JMP back
stop:
RET
msg1 DB 'Enter the first number: ',0
msg2 DB 'Enter the second number: ',0
// 4//
DEFINE_SCAN_NUM
DEFINE_PRINT_STRING
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
END
7. Write a program 8086 Mp to find the sum of the two numbers, print in binary format
8. Write a program in 8086 Mp to find the product or multiplication of the two numbers.
include 'emu8086.inc'
data segment ; This is a segment used for data declarations
input1 db "ENTER NO. 1 : $"
input2 db 13,10,"ENTER NO. 2 : $" ; line number to display text in the next line
oper db 13,10,"PRODUCT : $"
line db 10,13
ends ; Data Segment ends
code segment
start:
mov ax,@data
mov ds,ax
lea dx,input1
mov ah,09h
int 21h
call scan_num
push cx
lea dx,input2
mov ah,09h
int 21h
call scan_num
push cx
pop ax
pop bx
jb multi
multi:
push ax
lea dx,oper
mov ah,09h
int 21h
pop ax
// 5//
mul bx
call print_num
jmp z
z: mov ax, 4c00h
int 21h
ends
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
END STAT
9. Write a program in 8086 Mp assembly language to find the division of the two numbers.
include 'emu8086.inc'
DATA SEGMENT
input1 db "ENTER NO. 1 : $"
input2 db 13,10,"ENTER NO. 2 : $"
oper db 13,10,"DIVISION = : $"
line db 10,13
ENDS
CODE SEGMENT
start:
mov ax,@data
Mov ds,ax
lea dx,input1
mov ah,09h
int 21h
call scan_num
push cx
lea dx,input2
mov ah,09h
int 21h
call scan_num
push cx
pop ax
pop bx
push ax
lea dx,oper
mov ah,09h
int 21h
jb division
division:
mov dl,0
xchg bx,ax
// 6//
div bx
call print_num
jmp z
z:
mov ax, 4c00h
int 21h
ends
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
END START
10. Write a program in 8086 MP to find the smallest number among two-inputted number.
include 'emu8086.inc'
org 100h ; set location counter to 100h
jmp CodeStart
DataStart:
promptMsg db "Enter first number: ", 0
minMsg db "Largest number = ", 0
promptMsgtwo db "Enter second number : ", 0
newline db 13, 10, 0
num1 dw ?
num2 dw ?
numSmall dw ?
CodeStart:
mov si, offset promptMsg
call print_string
call scan_num
mov num1, cx
mov si, offset newline
call print_string
mov si, offset promptMsgtwo
call print_string
call scan_num
mov num2, cx
mov si, offset newline
call print_string
mov si, offset minMsg
call print_string
mov bx, num2
// 7//
;compare values
CMP bx, num1
JB large
mov ax, num2
JMP printnum
large:
mov ax, num1 ; it is here because num1 is smaller than num2
printnum:
call print_num
EndLabel:
ret
DEFINE_PRINT_STRING
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
11. Write a program in 8086 MP to find the largest no. among two inputted no
include 'emu8086.inc'
org 100h ; set location counter to 100h
jmp CodeStart
DataStart:
promptMsg db "Enter first number: ", 0
minMsg db "Largest number = ", 0
promptMsgtwo db "Enter second number : ", 0
newline db 13, 10, 0
num1 dw ?
num2 dw ?
numSmall dw ?
CodeStart:
mov si, offset promptMsg
call print_string
call scan_num
mov num1, cx
mov si, offset newline
call print_string
mov si, offset promptMsgtwo
call print_string
call scan_num
mov num2, cx
mov si, offset newline
call print_string
mov si, offset minMsg
// 8//
call print_string
mov bx, num2
;compare values
CMP bx, num1
JB large
mov ax, num2
JMP printnum
large:
mov ax, num1 ;it is here because num1 is smaller than num2
printnum:
call print_num
EndLabel:
ret
DEFINE_PRINT_STRING
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
12. Write a program in 8086 Mp having 16-bits to enter any two numbers and perform arithmetic
Operations (+, -, *, /)
include 'emu8086.inc'
data segment
input1 db "ENTER NO. 1 : $"
input2 db 13,10,"ENTER NO. 2 : $"
oper db 13,10,"ENTER NO (1 to add,2 to sub, 3 to mul and 4 to div) : $"
total db 13,10,"ANSWERS IS : $"
nega db "-$"
line db 13,10
ends
code segment
start:
mov ax,@data
mov ds,ax
lea dx,input1
mov ah,09h
int 21h
call scan_num
push cx
lea dx,input2
mov ah,09h
// 9//
int 21h
call scan_num
push cx
lea dx,oper
mov ah,09h
int 21h
call scan_num
lea dx,total
mov ah,09h
int 21h
pop ax
pop bx
cmp cl,1
je a
jne s1
s1:cmp cl,2
je b
jne m1
m1:cmp cl,3
je c
jne d1
d1:cmp cl,4
je d
jne z
a:
add ax,bx
call print_num
jmp z
b:
cmp ax,bx
ja sa
jb sb
sa: sub ax,bx
push ax
lea dx,nega
mov ah,09h
int 21h
pop ax
jmp sc
// 10//
sb: sub bx,ax
mov ax,bx
sc:call print_num
jmp z
c:
mul bx
call print_num
jmp z
d: mov dl,0
xchg bx,ax
div bx
call print_num
z: mov ax, 4c00h
int 21h
ends
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
end start
13. Write a program to enter any character in uppercase and convert it into lowercase using 8086 MP having 16 bits.
include 'emu8086.inc'
.data
msg1 db "Input character in lowercase: ","$"
msg2 db 13,10,"The character in uppercase: ","$"
charac label byte
maxcharaclen db 2
curcharaclen db ?
characfield db 2 dup(?)
.code
main proc
mov ax, @data
mov ds, ax
lea dx, msg1
mov ah, 09h
int 21h
mov ah, 0Ah
lea dx, charac
int 21h
mov bx, 0
// 11//
mov bl, curcharaclen
mov characfield[bx], "$"
and characfield,11011111B
lea dx, msg2
mov ah, 09h
int 21h
lea dx,characfield
mov ah,09h
int 21h
mov ah, 4ch
int 21h
main endp
end main
14. Write a program in 8086 Mp to enter any character in lower case and convert it into uppercase
.data
msg1 db "Input character in lowercase: ","$"
msg2 db 13,10,"The character in uppercase: ","$"
charac label byte
maxcharaclen db 2
curcharaclen db ?
characfield db 2 dup(?)
.code
main proc
mov ax, @data
mov ds, ax
lea dx, msg1
mov ah, 09h
int 21h
mov ah, 0Ah
lea dx, charac
int 21h
mov bx, 0
mov bl, curcharaclen
mov characfield[bx], "$"
and characfield,11011111B
lea dx, msg2
mov ah, 09h
int 21h
// 12//
lea dx,characfield
mov ah,09h
int 21h
mov ah, 4ch
int 21h
main endp
end main
15. Write a program in assembly 8086mu language to print your name five times.
include 'emu8086.inc'
ORG 100h
MOV CX, 5
mov ax, 3
label1:
mov bx, 2
xchg bx,ax
div ax
add ax,bx
call print_num
LOOP label1
RET
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
16. Write a program in 8086 Mp to print no. 1 to 10 in ascending order.
17. Write a program in 8086 Mp to print no. 1 to 10 in descending order
18. Write a program in 8086 Mp assembly language to print the alphabets from a to z in uppercase and lower case
code segment
assume cs:code, ds:data, ss:stack
mov ah,02h
mov cx,26
mov dl,41h
lop:
int 21h
add dl,1h
loop lop
mov dl,0ah
mov ah,02h
int 21h
// 13//
mov dl,0dh
mov ah,02h
int 21h
mov ah,02h
mov cx,26
mov dl,61h
lop1:
int 21h
add dl,1h
loop lop1
mov ah,4ch
int 21h
code ends
END
19. Write a program to design the following in 8086 Mp
1
22
333
4444
55555
20. Write a program to design the following pattern in 8086 Mp
55555
4444
333
22
1
21. Write a program o design the following pattern in 8086 Mp
*****
****
***
**
*
22. Write a program to design the following pattern in 8086 Mp
*
**
***
****
*****
23. Write a program to design the following pattern in 8086 Mp
1
12
123
1234
12345
24. Write a program to design the following pattern in 8086 Mp
12345
1234
123
// 14//
12
1
25. Write a program to design the following pattern in 8086 Mp
54321
5432
543
54
5
26. Write a program to design the following pattern in 8086 Mp
5
54
543
5432
54321
27. Write a program in 8086 Mp to enter any character and check the input are equal or not
(Comparing of two characters.)
include 'emu8086.inc'
data segment
xx db ?
yy db ?
data ends
code segment
assume cs:code, ds:data
mainp:
mov ax, data
mov ds,ax
mov cx, 03h
nextp:
mov ah, 01h
int 21h
mov xx, al
mov ah, 01h
int 21h
mov yy, al
mov bh, xx
mov bl, yy
cmp bh, bl
jne not_equal
equal:
mov ah,02h
;mov dl, 'y'
printn " "
printn "Characters are equal"
int 21h
jmp continue
not_equal:
// 15//
mov ah, 02h
;mov dl, 'n'
printn " "
printn "Characters are not equal"
int 21h
continue:
loop nextp
mov ah, 4ch
int 21h
code ends
end mainp
28. Write a program to enter any number and print the star pattern using in 8086 Mp having 16bit registers
29. Write a program to print the alphabets in diagonal order in 8086 Mp
main proc
mov ah, 02
mov dl, 61h
start: sub dl,20h
int 21h
push dx
mov dl, 0AH
int 21h
pop dx
add dl, 20h
inc dl
cmp dl, 79H
jne start
int 20h
main endp
end
30. Write a program to press any key and count the no. of hits / Key strokes using in 8086 Mp
org 100h
; print welcome message:
mov dx, offset msg
mov ah, 9
int 21h
;xor bx, bx ; zero bx register.
wait: mov ah, 0 ; wait for any key....
int 16h
// 16//
cmp al, 27 ; if key is 'esc' then exit.
je stop
mov ah, 0eh ; print it.
int 10h
inc bx ; increase bx on every key press.
jmp wait
; print result message:
stop:
mov dx, offset msg2
mov ah, 9
int 21h
mov ax, bx
call print_ax
; wait for any key press:
mov ah, 0
int 16h
ret ; exit to operating system.
msg db "Key Press Counting Program. press 'Esc' to stop...", 0Dh,0Ah, "$"
msg2 db 10,13, "recorded keypresses: $"
print_ax proc
cmp ax, 0
jne print_ax_r
push ax
mov al, '0'
mov ah, 0eh
int 10h
pop ax
ret
print_ax_r:
pusha
mov dx, 0
cmp ax, 0
je pn_done
mov bx, 10
div bx
call print_ax_r
mov ax, dx
add al, 30h
mov ah, 0eh
int 10h
jmp pn_done
pn_done:
popa
ret
endp
// 17//
31. Write a program to enter any number and print its factorial using 8086 Mp.
include "emu8086.inc"
org 100h
jmp start
result dw ?
start:
; get first number:
mov dx, offset msg1
mov ah, 9
int 21h
jmp n1
msg1 db 10,13, 'enter the number: $'
n1:
call scan_num
; factorial of 0 = 1:
mov ax, 1
cmp cx, 0
je print_result
; move the number to bx:
; cx will be a counter:
mov bx, cx
mov ax, 1
mov bx, 1
calc_it:
mul bx
cmp dx, 0
jne overflow
inc bx
loop calc_it
mov result, ax
print_result:
; print result in ax:
mov dx, offset msg2
mov ah, 9
int 21h
jmp n2
msg2 db 10,13, 'factorial: $'
n2:
mov ax, result
call print_num_uns
jmp exit
overflow:
mov dx, offset msg3
mov ah, 9
int 21h
jmp n3
// 18//
msg3 db 10,13, 'the result is too big!', 10,13, 'use values from 0 to 8.$'
n3:
jmp start
exit:
; wait for any key press:
mov ah, 0
int 16h
ret
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
32. Write a program to enter any string and check whether the string is Palindrome or not using 8086 Mp
name "pali"
org 100h
jmp start
m1:
s db 'mbvghfhf'
s_size = $ - m1
db 10,13,'$'
start:
; first let's print it:
mov ah, 9
mov dx, offset s
int 21h
lea di, s
mov si, di
add si, s_size
dec si ; point to last char!
mov cx, s_size
cmp cx, 1
je is_palindrome ; single char is always palindrome!
shr cx, 1 ; divide by 2!
next_char:
mov al, [di]
mov bl, [si]
cmp al, bl
jne not_palindrome
inc di
dec si
loop next_char
is_palindrome:
; the string is "palindrome!"
mov ah, 9
mov dx, offset msg1
// 19//
int 21h
jmp stop
not_palindrome:
; the string is "not palindrome!"
mov ah, 9
mov dx, offset msg2
int 21h
stop:
; wait for any key press:
mov ah, 0
int 16h
ret
msg1 db " this is palindrome!$"
msg2 db " this is not a palindrome!$"
33. Write a program to enter temperature in centigrade and convert into Fahrenheit using 8086 Mp
include 'emu8086.inc'
data segment
input1 db "Enter temperature in (C) : $"
msg db 13,10,"Ferhanheit equivalent = : $"
line db 10,13
ends
code segment
start:
mov ax,@data
mov ds,ax
lea dx,input1
mov ah,09h
int 21h
call scan_num
push cx
lea dx,msg
mov ah,09h
int 21h
je temp
temp:
mov cl, input1
mov al, 9
mul cl
;mov cl, 5
call print_num
// 20//
z: mov ax, 4c00h
int 21h
ends
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
end start
For more suggestion and comments to
Mr. Sachidananda Patnaik
Call @ 91 9861329499
Mail :- [email protected]