Microprocessor Programming Solution
Microprocessor Programming Solution
1. Write a program for 8085 to swap bit D3 and D6 of ten numbers stored in memory at
9650H if any number is greater than 70H and less than A0H. Otherwise set D3 and
reset D6 of the number stored. [2063 Ashad]
2. Seven status and one control signal of a single microprocessor based instrument are
read from data bus and are stored sequentially from memory location 6000H. Control
bit is represented by bit D4 and D4=1 represents valid data. Other bits are status
signals. Write an assembly language program for 8085 microprocessor which will check
control bit of each data and transfer the valid data to new memory location starting
from 7000H. The program should count and display the number of valid data and the
checking process should stop when all status signals are zero.
3. Write a program for 8085 to transfer data from a table to another if the number of ones
in the data is greater than four else store 00 to next table. [2065 Kartik]
(Assuming 10 data)
4. Write a program in 8085 to add all the numbers from a table of 8-bit numbers whose
higher nibble value is greater than 6 and store the 16-bit result just after the table.
[2067 Shrawan]
(Assuming 10 data)
5. There are two tables holding twenty data whose starting address is 3000H and 3020H
respectively. WAP to add the content of first table with the content of second table
having same array index. Store sum and carry into the third and fourth table indexing
from 3040H and 3060H respectively.
6. WAP in 8085 to calculate the sum of numbers stored in memory location from 7000H
to 700FH only if the number has higher nibble greater than lower nibble. Store the
sum at end of the table.
Label Instructions Comments
LXI H, 7000H ;source table
MVI B, 00H ;sum register
MVI C, 00H ;carry register
MVI D, 10H ;counter
UP: MOV A,M
ANI 0FH
MOV E,A
MOV A,M
ANI F0H
RLC
RLC
RLC
RLC
CMP E
JC PASS
MOV A,M
ADD B
MOV B,A
JNC PASS
INR C
PASS: INX H
DCR D
JNZ UP
MOV M,B
INX H
MOV M,C
HLT
7. WAP for 8085 to add corresponding data from two tables if the data from the first
table is smaller than the second table else subtract data of second table from the first
table. Store the result of each operation in the corresponding location of the third
table. Assume each has ten 8-bit data.
Label Instructions Comments
LXI B, 2000H ;first source table
LXI H, 3000H ;second source table
LXI D, 4000H ;destination table
UP: LDAX B
CMP M
JNC SUBTRACT
ADD M
JMP PASS
SUBTRACT: SUB M
PASS: STAX D
INX H
INX B
INX D
MOV A, L
CPI OAH
JNZ UP
HLT
8. Two tables with starting location 3000H and 4000H contains 50 bytes of data. WAP in
8085 to find sum of data from the tables and store the result in third table starting
from 5000H if the result is in between C0H and FFH, else store 00H to the
corresponding location.
9. Ten 8-bit data are stored in two tables starting at 5050H and 5060H. Transfer the data
of 1st table to third table starting at 5070H if data at 1st table is greater than data at 2nd
table, else store 00H at third table.
1. Add two numbers located at 3030H and 4040H. Display sum on Port 1. If carry is generated,
display it on Port 2. Store sum on 5050H.
LDA 3030H
MOV B, A
LDA 4040H
ADD B
STA 5050H
OUT PORT 1
JNC L1
MVI A, 01H
OUT PORT 2
L1: HLT
2. Write an Assembly Language Program that retrieves a data located at 2050H and it displays,
if it is even and stores FFH on that location if it is odd.
LDA 2050H
ANI 01H
JNZ L1
LDA 2050H
OUT PORT 1
HLT
L1: MVI A, FFH
STA 2050H
HLT
3. Sixteen bytes of data are stored in memory location at 1050H to 105FH. Replace each data
byte by FF.
LXI H, 1050H
MVI C, 10H
L1: MVI M, FFH
INX H
DCR C
JNZ L1
HLT
LXI H, 1050H
MVI C, 10H
LXI D, 1070H
L1: MOV A, M
STAX D
INX H
INX D
DCR C
JNZ L1
HLT
5. Six bytes are stored in memory locations starting at 2050H. Add all the data bytes, save any
carry generated while adding the data bytes. Display entire sum at two output ports and store
total carry in 2070H and sum in 2071H.
LXI H, 2050H
MVI C, 06H
MVI B, 00H
MVI D, 00H
L2: MOV A, M
ADD B
MOV B, A
JNC L1
INR D
L1: INX H
DCR C
JNZ L2
HLT
6. If the content of memory location 2050H is greater than or equal to 64H, display 0FH else
display FFH.
LDA 2050H
CPI 64H
JC L1
MOV A, 0FH
OUT PORT 1
HLT
L1: MOV A, FFH
OUT PORT 1
HLT
LXI H, 2050H
MVI B, 00H
MVI C, 00H
L3: MOV A, M
CPI 00H
JZ L1
ADD C
JNZ L2
INR B
L2: MOV C, A
INX H
JMP L3
L1: MOV A, C
OUT PORT 1
MOV A, B
OUT PORT 2
HLT
8. There are two tables holding twenty data whose starting address is 3000H and 3020H
respectively. WAP to add the content of first table with the content of second table having
same array index. Store sum and carry into the third and fourth table indexing from 3040H
and 3060H respectively.
10. A set of ten readings is stored in memory location starting at 1160H. The readings are
expected to be positive (<127). WAP to
- Check each reading to determine whether it is positive or negative.
- Reject all negative readings.
- Add all positive readings & display sum in Port 1 and carry in Port 2.
MVI B, 00H
MVI C, 00H
MVI D, 0AH
LXI H, 1160H
L2: MOV A, M
RAL
JC NEGLECT
RAR
ADD B
JC L1
MOV B, A
L1: INR D
NEGLECT: INX H
DCR D
JNZ L2
MOV A, B
OUT PORT 1
MOV A, D
OUT PORT 2
HLT
MVI C, 06H
LXI H, 2050H
LXI B, 2050H
L2: MOV A, M
CPI 00H
JZ L1
STAX B
INX B
L1: INX H
DCR C
JNZ L2
HLT
12. A set of eight data bytes (4 Pairs) are stored in memory locations starting from 1040H. WAP
to add two bytes at a time and store the sum in same memory location, sum replacing the first
byte and the carry replacing the second byte. If any pair does not generate a carry, the
memory location of the second byte should be cleared i.e. store 00H over there.
MVI C, 04H
LXI H, 1040H
L2: MOV A, M
INX H
ADD M
DCX H
MOV M, A
INX H
MVI M, 00H
JNC L1
MVI M, 01H
L1: INX H
DCR C
JNZ L2
HLT
MVI C, 0AH
LXI H, 2020H
MOV A, M
ANI F0H
RRC
RRC
RRC
RRC
MOV B, A
MOV A, 00H
L1: ADD B
DCR C
JNZ L1
MOV D, A
MOV A, M
ANI 0FH
ADD D
STA 2030H
HLT
14. A binary number (Suppose FF: 1111 11112) is stored in memory location 2020H. Convert the
number into BCD and store each BCD as two unpacked BCD digits in memory location from
2030H.
LXI SP, 2000H
LXI H, 2020H
MOV A, M
CALL PWRTEN
HLT
PWETEN: LXI H, 2030H
MVI B, 64H
CALL BINBCD
MOV M, D
INX H
MVI B, 0AH
CALL BINBCD
MOV M, D
INX H
MOV M, A
RET
BINBCD: MVI D, 00H
NEXT: INR D
SUB B
JNC NEXT
DCR D
ADD B
RET
16. WAP to convert ASCII at location 1040H to binary and store at location 1050H.
18. A multiplicand is stored in memory location 1150H and a multiplier is stored in location
1151H. WAP to multiply these numbers and store result from 1160H.
MVI B, 08H
MVI D, 00H
LXI H, 1150H
MOV A, M
MOV E, A
LXI H, 1151H
MOV A, M
L2: RAR
JNC L1
LXI H, 0000H
DAD D
L1: XCHG
DAD H
XCHG
DCR B
LNZ L2
HLT
ADD: ADD M
DAA
RNC
MOV D, A
MOV A, B
ADI 01H
DAA
MOV B, A
MOV A, D
RET
20. A dividend is stored in memory location 2020H and a divisor is stored in 2021H. WAP to
divide these numbers and store quotient and remainder from 2040H.
MVI C, 00H
LXI H, 2021H
MOV A, M
MOV D, A
DCX H
MOV B, M
L2: MOV A, B
SUB D
JC L1
MOV B, A
INR C
JMP L2
L1: MOV L, C
MOV H, B
SHLD 2040H
HLT
LXI H, 9050H
LXI D, 90A0H
MVI C, 32H
L2: MOV A, M
CPI 60H
JC L1
SUI 20H
L1: STAX D
DCR C
JNZ L2
HLT
22. Write a program for 8085 to add ten 16-bit BCD numbers from location 4050H and store 24-
bit BCD result at the end of the ten given numbers. [2062 Chaitra]
L2: LDAX B
ADD L
INX B
LDAX B
ADC H
JNC L1
INR E
L1: INX B
MOV A, C
CPI 0AH
JC L2
MOV A, L
STAX B
INX B
MOV A, H
STAX B
INX B
MOV A, E
STAX B
HLT
3
LXI SP, 2999H
LXI H, 2050H
MOV M, 3FH
INX H
MOV M, 06H
INX H
MOV M, 5BH
INX H
MOV M, 4FH
INX H
MOV M, 66H
INX H
MOV M, 6DH
INX H
MOV M, 7DH
INX H
MOV M, 07H
INX H
MOV M, 7FH
INX H
MOV M, 6FH
LXI B, 2060H
LXI H, 7600H
MVI C, 0AH
L2: MOV A, M
CPI 80H
JC L1
XRI 20H
MOV M, A
L1: INX H
DCR C
JNZ L2
25. Write a program for 8085 to find the smallest number among ten numbers stored at memory
location 4500H. [2060 Bhadra]
LXI H, 4500H
MVI C, 0AH
MOV A, M
L2: INX H
CMP M
JC L1
MOV B, A
MOV A, M
MOV M, B
L1: DCR C
JNZ L2
OUT PORT 1
HLT
LXI H, 4050H
MVI C, 64H
L1: MOV A, M
ANI 80H ; 10000000 B
RRC
RRC
MOV B, A
MOV A, M
ANI 20H ; 00100000 B
RLC
RLC
MOV C, A
MOV A, M
ANI 5FH ; 01011111 B
ORA B
ORA C
STAX H
INX H
DCR C
JNZ L1
HLT
28. Write a program to transfer eight-bit numbers from 9080H to 9090H if bit D5 is 1 and D3 is 0.
Otherwise transfer data by changing bit D2 and D6 from 1 to 0 or from 0 to 1. Assume there
are ten numbers. [2064 Shrawan]
LXI H, 9080H
LXI D, 9090H
MVI C, 0AH
L2: MOV A, M
ANI 28H
CPI 20H
JZ L1
MOV A, M
XRI 44H
MOV M, A
L1: MOV A, M
STAX D
INX H
INX D
DCR C
JNZ L2
HLT
1. Add two numbers located at 3030H and 4040H. Display sum on Port 1. If carry is generated,
display it on Port 2. Store sum on 5050H.
LDA 3030H
MOV B, A
LDA 4040H
ADD B
STA 5050H
OUT PORT 1
JNC L1
MVI A, 01H
OUT PORT 2
L1: HLT
2. Write an Assembly Language Program that retrieves a data located at 2050H and it displays,
if it is even and stores FFH on that location if it is odd.
LDA 2050H
ANI 01H
JNZ L1
LDA 2050H
OUT PORT 1
HLT
L1: MVI A, FFH
STA 2050H
HLT
3. Sixteen bytes of data are stored in memory location at 1050H to 105FH. Replace each data
byte by FF.
LXI H, 1050H
MVI C, 10H
L1: MVI M, FFH
INX H
DCR C
JNZ L1
HLT
LXI H, 1050H
MVI C, 10H
LXI D, 1070H
L1: MOV A, M
STAX D
INX H
INX D
DCR C
JNZ L1
HLT
5. Six bytes are stored in memory locations starting at 2050H. Add all the data bytes, save any
carry generated while adding the data bytes. Display entire sum at two output ports and store
total carry in 2070H and sum in 2071H.
LXI H, 2050H
MVI C, 06H
MVI B, 00H
MVI D, 00H
L2: MOV A, M
ADD B
MOV B, A
JNC L1
INR D
L1: INX H
DCR C
JNZ L2
HLT
6. If the content of memory location 2050H is greater than or equal to 64H, display 0FH else
display FFH.
LDA 2050H
CPI 64H
JC L1
MOV A, 0FH
OUT PORT 1
HLT
L1: MOV A, FFH
OUT PORT 1
HLT
LXI H, 2050H
MVI B, 00H
MVI C, 00H
L3: MOV A, M
CPI 00H
JZ L1
ADD C
JNZ L2
INR B
L2: MOV C, A
INX H
JMP L3
L1: MOV A, C
OUT PORT 1
MOV A, B
OUT PORT 2
HLT
8. There are two tables holding twenty data whose starting address is 3000H and 3020H
respectively. WAP to add the content of first table with the content of second table having
same array index. Store sum and carry into the third and fourth table indexing from 3040H
and 3060H respectively.
10. A set of ten readings is stored in memory location starting at 1160H. The readings are
expected to be positive (<127). WAP to
- Check each reading to determine whether it is positive or negative.
- Reject all negative readings.
- Add all positive readings & display sum in Port 1 and carry in Port 2.
MVI B, 00H
MVI C, 00H
MVI D, 0AH
LXI H, 1160H
L2: MOV A, M
RAL
JC NEGLECT
RAR
ADD B
JC L1
MOV B, A
L1: INR D
NEGLECT: INX H
DCR D
JNZ L2
MOV A, B
OUT PORT 1
MOV A, D
OUT PORT 2
HLT
MVI C, 06H
LXI H, 2050H
LXI B, 2050H
L2: MOV A, M
CPI 00H
JZ L1
STAX B
INX B
L1: INX H
DCR C
JNZ L2
HLT
12. A set of eight data bytes (4 Pairs) are stored in memory locations starting from 1040H. WAP
to add two bytes at a time and store the sum in same memory location, sum replacing the first
byte and the carry replacing the second byte. If any pair does not generate a carry, the
memory location of the second byte should be cleared i.e. store 00H over there.
MVI C, 04H
LXI H, 1040H
L2: MOV A, M
INX H
ADD M
DCX H
MOV M, A
INX H
MVI M, 00H
JNC L1
MVI M, 01H
L1: INX H
DCR C
JNZ L2
HLT
MVI C, 0AH
LXI H, 2020H
MOV A, M
ANI F0H
RRC
RRC
RRC
RRC
MOV B, A
MOV A, 00H
L1: ADD B
DCR C
JNZ L1
MOV D, A
MOV A, M
ANI 0FH
ADD D
STA 2030H
HLT
14. A binary number (Suppose FF: 1111 11112) is stored in memory location 2020H. Convert the
number into BCD and store each BCD as two unpacked BCD digits in memory location from
2030H.
LXI SP, 2000H
LXI H, 2020H
MOV A, M
CALL PWRTEN
HLT
PWETEN: LXI H, 2030H
MVI B, 64H
CALL BINBCD
MOV M, D
INX H
MVI B, 0AH
CALL BINBCD
MOV M, D
INX H
MOV M, A
RET
BINBCD: MVI D, 00H
NEXT: INR D
SUB B
JNC NEXT
DCR D
ADD B
RET
16. WAP to convert ASCII at location 1040H to binary and store at location 1050H.
18. A multiplicand is stored in memory location 1150H and a multiplier is stored in location
1151H. WAP to multiply these numbers and store result from 1160H.
MVI B, 08H
MVI D, 00H
LXI H, 1150H
MOV A, M
MOV E, A
LXI H, 1151H
MOV A, M
L2: RAR
JNC L1
LXI H, 0000H
DAD D
L1: XCHG
DAD H
XCHG
DCR B
LNZ L2
HLT
ADD: ADD M
DAA
RNC
MOV D, A
MOV A, B
ADI 01H
DAA
MOV B, A
MOV A, D
RET
20. A dividend is stored in memory location 2020H and a divisor is stored in 2021H. WAP to
divide these numbers and store quotient and remainder from 2040H.
MVI C, 00H
LXI H, 2021H
MOV A, M
MOV D, A
DCX H
MOV B, M
L2: MOV A, B
SUB D
JC L1
MOV B, A
INR C
JMP L2
L1: MOV L, C
MOV H, B
SHLD 2040H
HLT
LXI H, 9050H
LXI D, 90A0H
MVI C, 32H
L2: MOV A, M
CPI 60H
JC L1
SUI 20H
L1: STAX D
DCR C
JNZ L2
HLT
22. Write a program for 8085 to add ten 16-bit BCD numbers from location 4050H and store 24-
bit BCD result at the end of the ten given numbers. [2062 Chaitra]
L2: LDAX B
ADD L
INX B
LDAX B
ADC H
JNC L1
INR E
L1: INX B
MOV A, C
CPI 0AH
JC L2
MOV A, L
STAX B
INX B
MOV A, H
STAX B
INX B
MOV A, E
STAX B
HLT
3
LXI SP, 2999H
LXI H, 2050H
MOV M, 3FH
INX H
MOV M, 06H
INX H
MOV M, 5BH
INX H
MOV M, 4FH
INX H
MOV M, 66H
INX H
MOV M, 6DH
INX H
MOV M, 7DH
INX H
MOV M, 07H
INX H
MOV M, 7FH
INX H
MOV M, 6FH
LXI B, 2060H
LXI H, 7600H
MVI C, 0AH
L2: MOV A, M
CPI 80H
JC L1
XRI 20H
MOV M, A
L1: INX H
DCR C
JNZ L2
25. Write a program for 8085 to find the smallest number among ten numbers stored at memory
location 4500H. [2060 Bhadra]
LXI H, 4500H
MVI C, 0AH
MOV A, M
L2: INX H
CMP M
JC L1
MOV B, A
MOV A, M
MOV M, B
L1: DCR C
JNZ L2
OUT PORT 1
HLT
LXI H, 4050H
MVI C, 64H
L1: MOV A, M
ANI 80H ; 10000000 B
RRC
RRC
MOV B, A
MOV A, M
ANI 20H ; 00100000 B
RLC
RLC
MOV C, A
MOV A, M
ANI 5FH ; 01011111 B
ORA B
ORA C
STAX H
INX H
DCR C
JNZ L1
HLT
28. Write a program to transfer eight-bit numbers from 9080H to 9090H if bit D5 is 1 and D3 is 0.
Otherwise transfer data by changing bit D2 and D6 from 1 to 0 or from 0 to 1. Assume there
are ten numbers. [2064 Shrawan]
LXI H, 9080H
LXI D, 9090H
MVI C, 0AH
L2: MOV A, M
ANI 28H
CPI 20H
JZ L1
MOV A, M
XRI 44H
MOV M, A
L1: MOV A, M
STAX D
INX H
INX D
DCR C
JNZ L2
HLT
MOV CX, AX
Back: DEC CX
MUL CX
LOOP back
; results stored in AX
MOV [D000], AX
HLT
2. The 8 data bytes are stored from memory location E000H to E007H. Write 8086 ALP to
transfer the block of data to new location B001H to B008H.
MOV [EX], DL
DEC BL
JNZ loop
HLT
3. Write a program to display string ‘Electrical and Electronics Engineering’ for 8086.
Dosseg
.stack 100h
.data
.code
Main proc
MOV DS, AX
INT 21H
INT 21H
Main endp
End Main
Dosseg
.model small
.stack 100h
.data
Length dw $-String1-1
.code
MOV DS, AX
ADD SI, CX
INT 21H
DEC SI
LOOP Back
INT 21H
Main endp
End Main
Dosseg
.model small
.stack 100h
.data
Multiplier dw 1234H
Multiplicant dw 3456H
Product dw ?
MULT proc
MOV DS, AX
MUL Multiplier
MOV Product, AX
MOV Product+2, DX
INT 21H
MULT endp
End MULT
Dosseg
.model small
.stack 100h
.data
List db 12,34,56,78,98,01,13,78,18,36
Total dw ?
.code
Main proc
MOV DS, AX
JC Label
Back1: INC SI
LOOP Back
MOV Total, AX
MOV Total+2, BL
INT 21H
Label: INC BL
JMP Back1
Main endp
End Main
7. Write a program to find Largest No. in a block of data. Length of block is 0A. Store the
maximum in location result.
Dosseg
.model small
.stack 100h
.data
List db 80, 81, 78, 65, 23, 45, 89, 90, 10, 99
Result db ?
Main proc
MOV DS, AX
JNC Ahead
Ahead: INC SI
LOOP Back
MOV Result, AL
INT 21H
Main endp
End Main
8. Find number of times letter ‘e’ exist in the string ‘exercise’, Store the count at memory
ans.
Dosseg
.model small
.stack 100h
.data
Ans db ?
Length db $-String
.code
Main proc
MOV DS, AX
MOV AL,00H
JNZ Label
INC AL
Label: INC SI
LOOP Back
MOV Ans, AL
INT 21H
Main endp
End Main
9. Write an ALP to generate square wave with period of 200µs and address of output
device is 55H for 8086 microprocessor.
OUT 30H, AX
OUT 30H, AX
Label1: DEC BX
JNZ Label1
JMP START
Note: Find the value of Count using technique used in 8085 so that delay will be of 200 µs.
10. Write an assembly language program to count number of vowels in a given string.
Dosseg
.model small
.stack 100h
.code
Main proc
MOV DS, AX
JB VOW
JA VOW
JNZ a3
INC BL
JMP a2
JNZ a4
INC BL
JMP a2
JNZ a5
INC BL
JMP a2
JNZ a6
INC BL
JMP a2
JNZ a2
INC BL
LOOP Back
MOV Vowel, BL
INT 21H
Main endp
.data
String db ‘The quick brown fox jumped over lazy sleeping dog’, $
Len dw $-string
Vowel db ?
End Main
11. Write an 8086 ALP which will input the user name from the keyboard. If the user is
‘Pokhara’ it will output ‘The username is valid’ else it will output ‘Invalid user name’.
Note: This program is not verified in MASM so, please verify this program. This program can be
done in the same approach as question 10, which is done above by comparing each character
input.
.data
input db 7 dup(?)
comparestring db 'Pokhara','$'
outputstring1 db 'The username is valid','$'
outputstring2 db 'The username is invalid','$'
.code
main proc
mov ax, @data
mov ds, ax
; read string
mov dx, offset input
JZ label1
mov dx, offset outputstring2
jmp label2
By Sudip Lama
8086 assembly program and solution of past question
By Sudip Lama
8086 assembly program and solution of past question
mov ah,09h
lea dx,kbdat
int 21h
mov ax,4c00h
int 21h
main endp
6. Display the string character wis
.model small
.stack 100h
.data
string db "kathmandu Engineering",'$'
.code
main proc
mov ax,@data
mov ds,ax
lea si,string
again:
mov dl,[si] ;char to be displayed
cmp dl,24h ;ascii value of $ is 24h i.e end of string
jz last
mov ah,02h ;display character to output
int 21h
inc si
jmp again
last:
By Sudip Lama
8086 assembly program and solution of past question
mov ax,4c00h
int 21h
main endp
7. WAP to display string with Background Blue and Foreground red is(note to display string
with background and foreground we use character method)
.model small
.stack 100h
.data
string db "kathmandu Engineering",'$'
.code
main proc
mov ax,@data
mov ds,ax
lea si,string
mov dx,0000h
again:
mov ah,02h
int 10h
mov ah,09h ;display character with foreground and background color
mov al,[si]
cmp al,'$'
je last
mov bh,0
mov bl,14h ;background and foreground
mov cx,01h
int 10h
inc si
inc dx
jmp again
last:
mov ax,4c00h
int 21h
8. WAP to read a string character wise without echo and display the character by converting
the small case latter to uppercase
.model small
.stack 100h
.code
main proc
mov ax,@data
mov ds,ax
a1:
mov ah,08h
inc al
int 21h
cmp al,0dh
je a3
cmp al,'a'
jb a2
cmp al,'z'
ja a2
By Sudip Lama
8086 assembly program and solution of past question
sub al,20h
a2:
mov ah,2
mov dl,al
int 21h
jmp a1
a3:
mov ah,4ch
int 21h
main endp
.data
9. .WAP to read string and convert the small case letter to upper case and display the
converted string in next line.(2060 bhadra)
.........
.model small
.stack 100h
.data
kbdat db 21 dup(' '),'$'
.code
main proc
mov ax,@data
mov ds,ax
again:
mov al,[si]
cmp al,'$' ;Comparing for last of string
je a3
cmp al,0dh ;Compare for enter
je a3
cmp al,'a'
jb a1
cmp al,'z'
ja a1
sub al,20h
mov [si],al
a1:
inc si
jmp again
a3:
mov ah,02h
mov dh,12
mov dl,40
int 10h
By Sudip Lama
8086 assembly program and solution of past question
mov ah,0ah
lea dx,kbdat
int 21h
lea si,kbdat
mov bl,00h
again:
mov al,[si]
cmp al,'$' ;Compare for end of string
je a3
cmp al,0dh ;Compare for enter
je a3
cmp al,'a'
jb a1
cmp al,'z'
ja a1
sub al,20h ;Convert to upper case
a1:
cmp al,'A'
jnz a4
inc bl
jmp a2
a4:
cmp al,'E'
jnz a5
inc bl
jmp a2
a5:
cmp al,'I'
jnz a6
inc bl
By Sudip Lama
8086 assembly program and solution of past question
jmp a2
a6:
cmp al,'O'
jnz a7
inc bl
jmp a2
a7:
cmp al,'U'
jnz a2
inc bl
jmp a2
a2:
inc si
jmp again
a3:
mov ah,02h
mov dh,12
mov dl,40
int 10h
rcr bl,01h
jnc chan
mov ah,09h
lea dx,odd
int 21h
jmp l1
chan:
mov ah,09h
lea dx,even
int 21h
l1:
mov ax,4c00h
int 21h
main endp
11. Taking the string input and displaying each word of the string in separate line
.model small
.stack 100h
.data
string db 99 dup(?)
.code
main proc
mov ax,@data
mov ds,ax
mov bl,00h
lea si,string
again:
mov ah,01h
int 21h
cmp al,0dh ;carrage return ie enter
jz display
mov [si],al
By Sudip Lama
8086 assembly program and solution of past question
inc si
inc bl
jmp again
display:
mov cl,bl
mov ch,00h
lea si,string
repeat:
mov dl,[si]
cmp dl,20h ;ascii value of space is 20h
jz newline
mov ah,02h
int 21h
inc si
loop repeat
jmp last
newline:
inc si
mov dl,0ah ;Next line code
mov ah,02h
int 21h
mov dl,0dh
mov ah,02h
int 21h
dec cx
jmp repeat
last: mov ax,4c00h
int 21h
main endp
12. .WAP in 8086 to read a string and separate the words from the string, display each word
at the center of each line of a clear screen with blue back ground and cyan
foreground.(2062 bhadra)
.model small
.stack 100h
.data
string db 15 dup(' '),'$'
.code
main proc
mov ax,@data
mov ds,ax
mov ah,0ah
lea dx,string
int 21h
By Sudip Lama
8086 assembly program and solution of past question
mov dx,0040h
lea si,string
again:
mov ah,02h ;for cursor position
int 10h
inc dl
mov al,[si]
cmp al,'$'
je last
cmp al,20h
jnz chartodis
inc dh ;Next line curser positon
mov dl,40h
jmp next
chartodis:
mov ah,09h
mov bh,0
mov bl,13h ;background and foreground
mov cx,01h ;repeating the number of al character
int 10h
next:
inc si
jmp again
last:
mov ax,4c00h
int 21h
main endp
13. WAP in 8086 to read a single digit number and display the multiplication table of that
number as 2 4 6 8 10 12 14 16 18 20 if the users enter digit 2.(2067 shrawan).
.model small
.stack 100h
.data
string db ' '
.code
main proc
mov ax,@data
mov ds,ax
mov ah,08h ;for inputing character without echo
int 21h
By Sudip Lama
8086 assembly program and solution of past question
and al,0fh
mov dh,al
mov bl,01h
mov cx,000ah
again:
mov al,dh
mul bl
aam
mov bh,al
cmp ah,00h
je lable
or ah,30h
mov dl,ah
mov ah,02h
int 21h
lable:
mov al,bh
or al,30h
mov dl,al
mov ah,02h
int 21h
.model small
.stack 64
.data
multiplier db '5','3','4','2','1' ;5 number stored in memory
.code
main proc
mov ax,@data
mov ds,ax
mov cx,0005h
lea si,multiplier
nextnum:
By Sudip Lama
8086 assembly program and solution of past question
mov dh,al
mov bl,01h
mov cx,000ah
again:
mov al,dh
mul bl
aam
mov bh,al
cmp ah,00h
je lable
or ah,30h ;DISPLAYING HIGHER BIT
mov dl,ah
mov ah,02h
int 21h
lable:
mov al,bh ;DISPLAYING LOWER BIT
or al,30h
mov dl,al
mov ah,02h
int 21h
mov dl,0ah
mov ah,02h
int 21h
mov dl,0dh
mov ah,02h
int 21h
jmp nextnum
last:
mov ax,4c00h
int 21h
main endp
15.Write a program to take string input and display the vowel count at the center of the
screen.
By Sudip Lama
8086 assembly program and solution of past question
.model small
.stack 100h
.data
kbdat db 21 dup(' '),'$'
count db "Vowel count is:",'$'
.code
main proc
mov ax,@data
mov ds,ax
mov ah,0ah
lea dx,kbdat
int 21h
lea si,kbdat
mov bl,00h
again:
mov al,[si]
cmp al,'$' ;Compare for end of string
je a3
cmp al,0dh ;Compare for enter
je a3
cmp al,'a'
jb a1
cmp al,'z'
ja a1
sub al,20h ;Convert to upper case
a1:
cmp al,'A'
jne a4
inc bl
jmp a2
a4:
cmp al,'E'
jnz a5
inc bl
jmp a2
a5:
cmp al,'I'
jnz a6
inc bl
jmp a2
a6:
cmp al,'O'
jnz a7
inc bl
jmp a2
a7:
cmp al,'U'
By Sudip Lama
8086 assembly program and solution of past question
jnz a2
inc bl
jmp a2
a2:
inc si
jmp again
a3:
mov ah,02h
mov dh,12
mov dl,40
int 10h
mov bh,al
cmp ah,00h
je noneed
add ah,30h
mov dl,ah
mov ah,02h
int 21h
noneed:
mov al,bh
add al,30h
mov dl,al
mov ah,02h
int 21h
mov ax,4c00h
int 21h
main endp
By Sudip Lama
Microprocessor
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
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 1
Microprocessor
mov si,offset list1 ;move the offset address of list1 to si
mov di,offset list2 ;move the offset address of list2 to di
mov cx,0004h ;cx is always used as counter
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
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 2
Microprocessor
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
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 3
Microprocessor
main proc
mov ax,@data
mov ds,ax
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
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 4
Microprocessor
mov bl,[si]
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
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 5
Microprocessor
8. 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
cmp al,[si] ;compare with (k+1)th element
jnc ahead ;not interchange if kth<=(k-1)th
mov dl,[si]
mov [si],al
dec si
mov [si],dl
inc si
mov bl,01 ;interchange flag =1
ahead:
loop back ;is interchange flag=1
dec bl
jz sort ;yes, do another pass
mov ax,4c00h
int 21h
main endp
end main
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 6
Microprocessor
mov ax,@data
mov ds,ax
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
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 7
Microprocessor
cmp ah,00h ; not showing 0 in output
je label
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
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 8
Microprocessor
cmp al,[si] ;compare with (k+1)th element
jnc ahead ;not interchange if kth<=(k-1)th
mov dl,[si]
mov [si],al
dec si
mov [si],dl
inc si
mov bl,01 ;interchange flag =1
ahead:
loop back ;is interchange flag=1
dec bl
jz sort ;yes, do another pass
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
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 9
Microprocessor
mov cx,10 ;counter
again:
mov al,dh
mul bl
aam
mov bh,al
cmp ah,00h ; not showing 0 in output
je label
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
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 10
Microprocessor
13. Write a program that finds the sum of the following series up-to 10th term and store the
result in a variable. Series -> 2*3+4*5+6*7+…..+ up-to 10th term.
Solution:
.model small
.stack 100h
.data
sum dw ?
.code
main proc
mov ax,@data
mov ds,ax
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
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 11
Microprocessor
mov ax,@data
mov ds,ax
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:
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 12
Microprocessor
mov ah,08h ; reading character without echo
int 21h
cmp al,0dh
je a3
cmp al,'a'
jb a2
cmp al,'z'
ja a2
sub al,32
a2:
mov ah,02h
mov dl,al
int 21h
mov [di],al
inc di
jmp a1
a3:
inc di
mov dl,'$'
mov [di],dl
mov dx,offset string
mov ah,09h
int 21h
mov ah,4ch
int 21h
main endp
end main
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 13
Microprocessor
jb vowel
cmp [si],'z'
ja vowel
vowel:
cmp [si],'a'
jnz a3
inc bl
jmp a2
a3:
cmp [si],'e'
jnz a4
inc bl
jmp a2
a4:
cmp [si],'i'
jnz a5
inc bl
jmp a2
a5:
cmp [si],'o'
jnz a6
inc bl
jmp a2
a6:
cmp [si],'u'
jnz a2
inc bl
a2:
inc si
loop back
mov vow,bl
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
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 14
Microprocessor
numbers db 00h
others 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
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 16
Microprocessor
again:
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'
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 17
Microprocessor
max1 db 20
act1 db ?
name1 db 20 dup(0),'$'
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
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 18
Microprocessor
20. Write a program to display your name at center of the screen with green background
and red foreground.
Solution:
.model small
.stack 100h
.data
paralist1 label byte ;Giving 1st byte the Label 'paralist1'
max1 db 20
act1 db ?
name1 db 20 dup(0),'$'
.code
main proc
mov ax,@data
mov ds,ax
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
Compiled by Sudeep Shakya
Deputy Head
Kathmandu Engineering College Page 19