You are on page 1of 86

Some Solutions of 8085

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]

Label Instructions Comments


LXI H,9650H ;source table
MVI C,0AH ;counter
UP: MOV A,M
CPI 71H ;check of number is greater or equal to 71H
JC PASS ;if no goto PASS
CPI A0H ;check of number is less than A0H
JNC PASS ;if no goto PASS
ANI 48H ;mask all bits except D3 and D6
CPI 00H ;check if result is zero
JZ PASS1 ;if yes goto PASS1(no need to swap, both bits are zero)
CPI 48H ;check if result is 48H
JZ PASS1 ;if yes goto PASS1(no need to swap, both bits are one)
MOV A,M
XRI 48H ;toggle bit D3 and D6
MOV M,A
JMP PASS1
PASS: ORI 08H ;set D3 bit
ANI BFH ;reset D6 bit
MOV M,A
PASS1: INX H
DCR C
JNZ UP
HLT

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.

Label Instructions Comments


LXI H,6000H ;starting location where the data are stored
MVI C,00H ; counter for valid data
LXI D,7000H ;destination table
UP: MOV A,M
ANI 0EFH ;to check the status bits
CPI 00H ;check if all status bits are zero
JZ DOWN ;if yes goto DOWN
MOV A,M
ANI 10H ;Mask all bits except D4
CPI 10H ;check if bit D4=1
JNZ PASS ;if no goto PASS
MOV A,M
STAX D ;store valid data to new table
INR C
INX D
PASS: INX H
JMP UP
DOWN: MOV A,C
OUT PORTA ;display the no. of valid data through PORTA
HLT

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)

Label Instructions Comments


LXI H,D000H ;source table
LXI D,D050H ;destination table
REPEAT: MVI B,00H ;register to count no. of ones
MVI C,08H ;counter to rotate number 8 times
MOV A,M
UP: RLC
JNC PASS
INR B
PASS: DCR C
JNZ UP
MOV A,B
CPI 05H ;check if no. of ones is greater or equal to 5
JNC PASS1 ;if yes goto PASS1
MVI A,00H
JMP PASS2
PASS1: MOV A,M
PASS2: STAX D
INX H
INX D
MOV A,L
CPI 0AH
JNZ REPEAT
HLT

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)

Label Instructions Comments


LXI H,3000H ;source table(assuming starting address of table is 3000H)
MVI C,0AH ;counter
MVI D,00H ;register to store sum
MVI E,00H ;register to store carry
UP: MOV A,M
ANI F0H ;masking lower nibble
CPI 70H ;check if higher nibble is greater or equal to 7
JC PASS ;if no goto PASS
MOV A,M
ADD D
MOV D,A
JNC PASS
INR E
PASS: INX H
DCR C
JNZ UP
MOV M,D ;store sum in memory
INX H
MOV M,E ;store carry in memory
HLT

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.

Label Instructions Comments


LXI H,3000H ;first source table
LXI B,3020H ;second source table
UP: LDAX B
ADD M
MOV E,A ;store sum to register E
JC DOWN ;if carry is generated goto DOWN
MVI D,00H ;store 00H to register D as carry
JMP PASS
DOWN: MVI D,01H ;store 01H to register D as carry
PASS: MOV A,L
ADI 40H ;adding 40H to goto memory location where sum is to be stored
MOV L,A
MOV M,E
ADI 20H ;adding 20H to goto memory location where carry is to be stored
MOV L,A
MOV M,D
SUI 60H ;subtracting 60H to return back to first source table
MOV L,A
INX H
INX B
MOV A,C
CPI 34H
JNZ UP
HLT

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.

Label Instructions Comments


LXI B, 3000H ;first source table
LXI H, 4000H ;second source table
LXI D, 5000H ;destination table
UP: LDAX B
ADD M
CPI C0H
JC PASS
CPI FFH
JNC PASS
JMP DOWN
PASS: MVI A,00H
DOWN: STAX D
INX H
INX B
INX D
MOV A,L
CPI 32H ;for 50 bytes(32 in hex) of data
JNZ UP
HLT

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.

Label Instructions Comments


LXI B, 5050H ;first source table
LXI H, 5060H ;second source table
LXI D, 5000H ;destination table
UP: LDAX B
CMP M
JNC PASS
MVI A,00H
PASS: STAX D
INX B
INX H
INX D
MOV A,C
CPI 5AH
JNZ UP
HLT
10. A table contains ten 8-bit data starting at 8050H. Write an 8085 program to store the
sum of odd numbers at 8060H and sum of even numbers at 8070H. Also display the
sum of even numbers and odd numbers at two different ports

Label Instructions Comments


LXI H, 8050H ;source table
MVI B, 00H ;sum register for even number
MVI C, 00H ;sum register for odd number
MVI D, 0AH ;Counter
UP: MOV A, M
RRC ;Rotate right to send bit D0 to carry flag
JC PASS ;If D0( CY flag) is 1, number is odd
MOV A, M
ADD B
MOV B, A
JMP DOWN
PASS: MOV A, M
ADD C
MOV C, A
DOWN: INX H
DCR D
JNZ UP
MOV A, B
OUT PORT1
MOV A, C
OUT PORT2
HLT
Tutorial – 1 (ALP 8085)
Microprocessor (BCT II / II)

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 1


4. Sixteen data are stored in memory location at 1050H to 105FH. Transfer the entire block of
data to new location starting at 1070H.

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 2


7. We have a list of data stored at memory location starting at 2050H. The end of the data array
is indicated by data byte 00H. Add the set of readings. Display the sum at Port 1 and total
carry at Port 2.

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.

LXI B, 3000H MOV A, C


LXI H, 3020H CPI 14H
LXI D, 3040H JNZ NEXT
NEXT: LDAX B HLT
ADD M
STAX D
PUSH H
PUSH D
JNC L1
MVI E, 01H
JMP CSTORE
L1: MVI E, 00H
CSTORE: LXI H, 3060H
MOV A, L
ADD C
MOV L, A
MOV M, E
POP H
POP D
INX B
INX D
INX H

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 3


9. For ten bytes data starting from 1120H, write a program to sort the reading in ascending and
in descending order. (Note : For descending, do self)

START: LXI H, 1120H


MVI D, 00H
MVI C, 0AH
L2: MOV A, M
INX H
CMP M
JC L1
MOV B, M
MOV M, A
DCX H
MOV M, B
INX H
MVI D, 01H
L1: DCR C
JNZ L2
MOV A, D
RRC
JC START
HLT

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 4


11. A set of six data bytes is stored starting from memory location 2050H. The set includes some
blank spaces (bytes with zero values). WAP to eliminate the blanks from the block.

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 5


13. WAP to read BCD number stored at memory location 2020H and converts it into binary
equivalent and finally stores that binary pattern into memory location 2030H.
[Note: BCD number is the combination from 0 to 9]

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 6


15. An 8 bit binary number is stored in memory location 1120H. WAP to store ASCII codes of
these binary digits (0 to F) in location 1160H and 1161H.

LXI SP, 2000H CODE: CPI 0AH


LXI H, 1120H JC L1
LXI D, 1160H ADD 07H
MOV A, M L1: ADD 30H
ANI F0H RET
RRC
RRC
RRC
RRC
CALL CODE
STAX D
INX D
MOV A, M
ANI 0FH
CALL CODE
STAX D
HLT

16. WAP to convert ASCII at location 1040H to binary and store at location 1050H.

LXI SP, 2000H CODE: CPI 40H


LXI H, 1040H JC L1
LXI D, 1050H SUB 07H
MOV A, M L1: SUB 30H
ANI F0H RET
RRC
RRC
RRC
RRC
CALL CODE
STAX D
INX D
MOV A, M
ANI 0FH
CALL CODE
STAX D
HLT

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 7


17. A set of three packed BCD numbers are stored in memory locations starting at 1150H. The
seven segment codes of digits 0 to 9 for a common cathode LED are stored in memory
locations starting at 1170H and the output buffer memory is reserved at 1190H. WAP to
unpack the BCD number and select an appropriate seven segment code for each digit. The
codes should be stored in output buffer memory.

LXI SP, 2999H CODE: PUSH H


LXI H, 1150H LXI H, 1170H
MVI D, 03H ADD L
LXI B, 1190H MOV L, A
NEXT: MOV A, M MOV A, M
ANI F0H STAX B
RRC POP H
RRC RET
RRC
RRC
CALL CODE
INX B
MOV A, M
ANI 0FH
CALL CODE
INX B
INX H
DCR D
JNZ NEXT
HLT

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 8


19. A set of ten packed BCD numbers is stored in the memory location starting at 1150H. WAP
to add these numbers in BCD. If carry is generated save it in register B and adjust it for BCD.
The final sum is less than 9999BCD.

LXI SP, 2000H


LXI H, 1150H
MVI C, 0AH
XRA A
MOV B, A
L1: CALL ADD
INX H
DCR C
JNZ L1
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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 9


21. Write a program for 8085 to convert and copy the ten lower case ASCII codes to upper case
from memory location 9050H to 90A0H if any, otherwise copy as they are. Assume there are
fifty codes in the source memory. [Note: ASCII code for A=65 … Z=90, a=97 … z=122].
[2063 Kartik]

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]

LXI B, 4050H ; Starting location of the 16-bit BCD Numbers


LXI D, 0000H
LXI H, 0000H
MVI A, 00H

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 10


23. Write an 8085 program to display the BCD digits from 0 to 9 the seven segments as in the
following diagram. Use the activating data bits same as the segment
number as in figure below. [2059 Shrawan]
0
5 1
6
4 2

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

LDAX B ; Where the BCD digit is located


ANI F0H
RRC
RRC
RRC
RRC
CALL CODE
OUT PORT 1
LDAX B
ANI 0FH
CALL CODE
OUT PORT 2
HLT
CODE: LXI H, 2050H
ADD L
MOV L, A
MOV A, M
RET

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 11


24. Write a program for 8085 to change the bit D5 of ten numbers stored at address 7600H if the
numbers are larger than or equal to 80H. [2061 Ashwin]

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 12


26. Someone has damaged a program written at 4050H for 8085 microprocessor. The damaging
is done by changing the bit D7 and bit D5 of each byte. The size of the program is 100 bytes.
Now write a program for 8085 to correct this damaged program. [2060 Chaitra]

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 13


27. The temperature of two furnaces being monitored by a microprocessor based system. A set of
readings of the first furnace recorded by thermal sensor is stored at memory locations starting
at 4050H. Corresponding readings from the second furnace is stored at the memory location
starting at 4070H. Each reading from the first furnace is expected to be higher than the
corresponding reading from the second furnace. Among the eight bit data bit D7 is used to
test the validity of the data. Write an 8085 program to compare valid data from the two
tables, if data from first table is larger than the corresponding data from the second table
store 01H in the corresponding memory of the third location starting at 4090H and display
01H to indicate the normal operation else store FFH in the corresponding memory location
and display FFH in the port to indicate the emergency. When emergency condition is reached
stop the operation. [2060 Jestha]
LXI B, 4050H
LXI H, 4070H
LXI D, 4090H
L2: LDAX B
CMP M
JC L1
JZ L1
MVI A, 01H
STAX D
OUT PORT
INX B
IND H
INX D
JMP L2
L1: MVI A, FFH
STAX D
OUT PORT
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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 14


29. There are two tables T1, T2 in memory having ten eight bit data in each. Write a program for
8085 to find the difference of the corresponding element of these two tables. Store the result of
each operation on the corresponding element of the third table. Remember that the result should
not be negative ; it should be |T1 – T2|. [2064 Poush]
LXI SP, 2999H
LXI H, 5000H ; TABLE T1
LXI D, 6000H ; TABLE T2
MVI C, 0AH ; COUNTER FOR 10 DATA
L1: LDAX D
MOV B, A
MOV A, M
CMP B
JNC L2
MOV A, B
MOV B, M
L2: SUB B
PUSH D
MVI D, 70H ; TABLE T3
STAX D
POP D
INX H
INX D
DCR C
JNZ L1
HLT
30. 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 in the next table. [2065 Kartik]
LXI H, 5000H ; SOURCE TABLE
LXI D, 6000H ; DESTINATION TABLE
ST: MVI C, 08H ; NO OF BITS
MVI B, 00H ; NO OF 1’S
MOV A, M
L1: RLC
JNC L2
INR B
L2: DCR C
JNZ L1
MOV A, B
CPI 04H
MVI A, 00H
JC L3
JZ L3
MOV A, M
L3: STAX D
INX H
INX D
MOV A, E
CPI 0AH ; SUPPOSE TABLE FOR 10 DATA
JNZ ST
HLT

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 15


31. Write an assembly language program to count no. of –ve element in a data block containing
16 bytes of data; store the count at the end of the block if the count is greater than 8 otherwise
stores 0. [2065 Chaitra]

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 16


Tutorial – 1 (ALP 8085)
Microprocessor (BCT II / II)

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 1


4. Sixteen data are stored in memory location at 1050H to 105FH. Transfer the entire block of
data to new location starting at 1070H.

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 2


7. We have a list of data stored at memory location starting at 2050H. The end of the data array
is indicated by data byte 00H. Add the set of readings. Display the sum at Port 1 and total
carry at Port 2.

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.

LXI B, 3000H MOV A, C


LXI H, 3020H CPI 14H
LXI D, 3040H JNZ NEXT
NEXT: LDAX B HLT
ADD M
STAX D
PUSH H
PUSH D
JNC L1
MVI E, 01H
JMP CSTORE
L1: MVI E, 00H
CSTORE: LXI H, 3060H
MOV A, L
ADD C
MOV L, A
MOV M, E
POP H
POP D
INX B
INX D
INX H

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 3


9. For ten bytes data starting from 1120H, write a program to sort the reading in ascending and
in descending order. (Note : For descending, do self)

START: LXI H, 1120H


MVI D, 00H
MVI C, 0AH
L2: MOV A, M
INX H
CMP M
JC L1
MOV B, M
MOV M, A
DCX H
MOV M, B
INX H
MVI D, 01H
L1: DCR C
JNZ L2
MOV A, D
RRC
JC START
HLT

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 4


11. A set of six data bytes is stored starting from memory location 2050H. The set includes some
blank spaces (bytes with zero values). WAP to eliminate the blanks from the block.

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 5


13. WAP to read BCD number stored at memory location 2020H and converts it into binary
equivalent and finally stores that binary pattern into memory location 2030H.
[Note: BCD number is the combination from 0 to 9]

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 6


15. An 8 bit binary number is stored in memory location 1120H. WAP to store ASCII codes of
these binary digits (0 to F) in location 1160H and 1161H.

LXI SP, 2000H CODE: CPI 0AH


LXI H, 1120H JC L1
LXI D, 1160H ADD 07H
MOV A, M L1: ADD 30H
ANI F0H RET
RRC
RRC
RRC
RRC
CALL CODE
STAX D
INX D
MOV A, M
ANI 0FH
CALL CODE
STAX D
HLT

16. WAP to convert ASCII at location 1040H to binary and store at location 1050H.

LXI SP, 2000H CODE: CPI 40H


LXI H, 1040H JC L1
LXI D, 1050H SUB 07H
MOV A, M L1: SUB 30H
ANI F0H RET
RRC
RRC
RRC
RRC
CALL CODE
STAX D
INX D
MOV A, M
ANI 0FH
CALL CODE
STAX D
HLT

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 7


17. A set of three packed BCD numbers are stored in memory locations starting at 1150H. The
seven segment codes of digits 0 to 9 for a common cathode LED are stored in memory
locations starting at 1170H and the output buffer memory is reserved at 1190H. WAP to
unpack the BCD number and select an appropriate seven segment code for each digit. The
codes should be stored in output buffer memory.

LXI SP, 2999H CODE: PUSH H


LXI H, 1150H LXI H, 1170H
MVI D, 03H ADD L
LXI B, 1190H MOV L, A
NEXT: MOV A, M MOV A, M
ANI F0H STAX B
RRC POP H
RRC RET
RRC
RRC
CALL CODE
INX B
MOV A, M
ANI 0FH
CALL CODE
INX B
INX H
DCR D
JNZ NEXT
HLT

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 8


19. A set of ten packed BCD numbers is stored in the memory location starting at 1150H. WAP
to add these numbers in BCD. If carry is generated save it in register B and adjust it for BCD.
The final sum is less than 9999BCD.

LXI SP, 2000H


LXI H, 1150H
MVI C, 0AH
XRA A
MOV B, A
L1: CALL ADD
INX H
DCR C
JNZ L1
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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 9


21. Write a program for 8085 to convert and copy the ten lower case ASCII codes to upper case
from memory location 9050H to 90A0H if any, otherwise copy as they are. Assume there are
fifty codes in the source memory. [Note: ASCII code for A=65 … Z=90, a=97 … z=122].
[2063 Kartik]

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]

LXI B, 4050H ; Starting location of the 16-bit BCD Numbers


LXI D, 0000H
LXI H, 0000H
MVI A, 00H

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 10


23. Write an 8085 program to display the BCD digits from 0 to 9 the seven segments as in the
following diagram. Use the activating data bits same as the segment
number as in figure below. [2059 Shrawan]
0
5 1
6
4 2

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

LDAX B ; Where the BCD digit is located


ANI F0H
RRC
RRC
RRC
RRC
CALL CODE
OUT PORT 1
LDAX B
ANI 0FH
CALL CODE
OUT PORT 2
HLT
CODE: LXI H, 2050H
ADD L
MOV L, A
MOV A, M
RET

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 11


24. Write a program for 8085 to change the bit D5 of ten numbers stored at address 7600H if the
numbers are larger than or equal to 80H. [2061 Ashwin]

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 12


26. Someone has damaged a program written at 4050H for 8085 microprocessor. The damaging
is done by changing the bit D7 and bit D5 of each byte. The size of the program is 100 bytes.
Now write a program for 8085 to correct this damaged program. [2060 Chaitra]

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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 13


27. The temperature of two furnaces being monitored by a microprocessor based system. A set of
readings of the first furnace recorded by thermal sensor is stored at memory locations starting
at 4050H. Corresponding readings from the second furnace is stored at the memory location
starting at 4070H. Each reading from the first furnace is expected to be higher than the
corresponding reading from the second furnace. Among the eight bit data bit D7 is used to
test the validity of the data. Write an 8085 program to compare valid data from the two
tables, if data from first table is larger than the corresponding data from the second table
store 01H in the corresponding memory of the third location starting at 4090H and display
01H to indicate the normal operation else store FFH in the corresponding memory location
and display FFH in the port to indicate the emergency. When emergency condition is reached
stop the operation. [2060 Jestha]
LXI B, 4050H
LXI H, 4070H
LXI D, 4090H
L2: LDAX B
CMP M
JC L1
JZ L1
MVI A, 01H
STAX D
OUT PORT
INX B
IND H
INX D
JMP L2
L1: MVI A, FFH
STAX D
OUT PORT
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

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 14


29. There are two tables T1, T2 in memory having ten eight bit data in each. Write a program for
8085 to find the difference of the corresponding element of these two tables. Store the result of
each operation on the corresponding element of the third table. Remember that the result should
not be negative ; it should be |T1 – T2|. [2064 Poush]
LXI SP, 2999H
LXI H, 5000H ; TABLE T1
LXI D, 6000H ; TABLE T2
MVI C, 0AH ; COUNTER FOR 10 DATA
L1: LDAX D
MOV B, A
MOV A, M
CMP B
JNC L2
MOV A, B
MOV B, M
L2: SUB B
PUSH D
MVI D, 70H ; TABLE T3
STAX D
POP D
INX H
INX D
DCR C
JNZ L1
HLT
30. 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 in the next table. [2065 Kartik]
LXI H, 5000H ; SOURCE TABLE
LXI D, 6000H ; DESTINATION TABLE
ST: MVI C, 08H ; NO OF BITS
MVI B, 00H ; NO OF 1’S
MOV A, M
L1: RLC
JNC L2
INR B
L2: DCR C
JNZ L1
MOV A, B
CPI 04H
MVI A, 00H
JC L3
JZ L3
MOV A, M
L3: STAX D
INX H
INX D
MOV A, E
CPI 0AH ; SUPPOSE TABLE FOR 10 DATA
JNZ ST
HLT

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 15


31. Write an assembly language program to count no. of –ve element in a data block containing
16 bytes of data; store the count at the end of the block if the count is greater than 8 otherwise
stores 0. [2065 Chaitra]

Compiled By: Er. Hari Aryal email: haryal@hotmail.com 16


Important programs of 8086 (Exam point of view)
1. Write an ALP to find factorial of number for 8086.

MOV AX, 05H

MOV CX, AX

Back: DEC CX

MUL CX

LOOP back

; results stored in AX

; to store the result at D000H

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 BL, 08H

MOV CX, E000H

MOV EX, B001H

Loop: MOV DL, [CX]

MOV [EX], DL

DEC BL

JNZ loop

HLT

3. Write a program to display string ‘Electrical and Electronics Engineering’ for 8086.

Title display the string

Dosseg

Written by CHANDRA THAPA (October 2012) 1


.model small

.stack 100h

.data

String1 db ‘Electrical and Electronics Engineering’, $

.code

Main proc

MOV AX, @data

MOV DS, AX

MOV AH, 09H

MOV DX, offset String1

INT 21H

MOV AH, 4CH

INT 21H

Main endp

End Main

4. Write a program to reverse the given string for 8086.

Title reverse the given string

Dosseg

.model small

.stack 100h

.data

String1 db ‘assembly language program’, $

Length dw $-String1-1

.code

Written by CHANDRA THAPA (October 2012) 2


Main proc

MOV AX, @data

MOV DS, AX

MOV SI, offset String1

MOV CX, Length

ADD SI, CX

Back: MOV DL, [SI]

MOV AH, 02H

INT 21H

DEC SI

LOOP Back

MOV AH, 4CH

INT 21H

Main endp

End Main

5. Write a program to multiply 2 numbers (16-bit data) for 8086.

Title multiply two numbers

Dosseg

.model small

.stack 100h

.data

Multiplier dw 1234H

Multiplicant dw 3456H

Product dw ?

Written by CHANDRA THAPA (October 2012) 3


.code

MULT proc

MOV AX, @data

MOV DS, AX

MOV AX, Multiplicant

MUL Multiplier

MOV Product, AX

MOV Product+2, DX

MOV AH, 4CH

INT 21H

MULT endp

End MULT

6. Sum of series of 10 numbers and store result in memory location total.

Title Sum of series

Dosseg

.model small

.stack 100h

.data

List db 12,34,56,78,98,01,13,78,18,36

Total dw ?

.code

Main proc

MOV AX, @data

MOV DS, AX

MOV AX, 0000H

Written by CHANDRA THAPA (October 2012) 4


MOV CX, 0AH ; counter

MOV BL, 00H ; to count carry

MOV SI, offset List

Back: ADD AL, [SI]

JC Label

Back1: INC SI

LOOP Back

MOV Total, AX

MOV Total+2, BL

MOV AH, 4CH

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.

Title maximum in given series

Dosseg

.model small

.stack 100h

.data

List db 80, 81, 78, 65, 23, 45, 89, 90, 10, 99

Result db ?

Written by CHANDRA THAPA (October 2012) 5


.code

Main proc

MOV AX, @data

MOV DS, AX

MOV SI, offset List

MOV AL, 00H

MOV CX, 0AH

Back: CMP AL, [SI]

JNC Ahead

MOV AL, [SI]

Ahead: INC SI

LOOP Back

MOV Result, AL

MOV AH, 4CH

INT 21H

Main endp

End Main

8. Find number of times letter ‘e’ exist in the string ‘exercise’, Store the count at memory
ans.

Title string operation

Dosseg

.model small

.stack 100h

.data

Written by CHANDRA THAPA (October 2012) 6


String db ‘exercise’, $

Ans db ?

Length db $-String

.code

Main proc

MOV AX, @data

MOV DS, AX

MOV AL,00H

MOV SI, offset String

MOV CX, Length

Back: MOV BH, [SI]

CMP BH, ‘e’

JNZ Label

INC AL

Label: INC SI

LOOP Back

MOV Ans, AL

MOV AH, 4CH

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.

START: MOV AX, 01H

OUT 30H, AX

Written by CHANDRA THAPA (October 2012) 7


; to generate loop for 200 µs using system frequency 5MHz

MOV BX, Count ;7T

Label: DEC BX ;4T

JNZ Label ;10T/7T

MOV AX, 00H

OUT 30H, AX

MOV BX, Count

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.

Title to count number of vowels in given line of a text

Dosseg

.model small

.stack 100h

.code

Main proc

MOV AX, @data

MOV DS, AX

MOV SI, offset String ;initialize p

MOV CX, Len ;length in CX register

MOV BL, 00 ;vowel count=0

Written by CHANDRA THAPA (October 2012) 8


Back: MOV AL, [SI]

CMP AL, ‘a’

JB VOW

CMP AL, ‘z’ ;Convert the character to upper case

JA VOW

SUB AL, 20H

VOW: CMP AL, ‘A’

JNZ a3

INC BL

JMP a2

a3: CMP AL, ‘E’

JNZ a4

INC BL

JMP a2

a4: CMP AL, ‘I’

JNZ a5

INC BL

JMP a2

a5: CMP AL, ‘O’

JNZ a6

INC BL

JMP a2

a6: CMP AL, ‘U’

JNZ a2

INC BL

Written by CHANDRA THAPA (October 2012) 9


a2: INC SI

LOOP Back

MOV Vowel, BL

MOV AX, 4C00H

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.

title input name and comparision


dosseg
.model small
.stack 100h

.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

Written by CHANDRA THAPA (October 2012) 10


mov ah,0ah
int 21h
;string comparision
mov si, offset input
mov di, offset comparestring
mov cx,07h ;length of string in cx
CLD ; DF-> direction flag clear i.e. autoincrement mode
repe cmpsw ;compare words of two string if equal then ZF will be set

JZ label1
mov dx, offset outputstring2
jmp label2

label1: mov dx, offset outputstring1


label2: mov ah, 0ah
int 21h
mov ah,4ch
int 21h
main endp
end main

Written by CHANDRA THAPA (October 2012) 11


8086 assembly program and solution of past question

1. To find the largest number among array of number in an array


.model small
.stack 100h
.data
array db 45h,12h,5h,78h,12h
large db ?
.code
main proc
mov ax,@data
mov ds,ax
mov bl,large
mov cx,0005h
lea si,array
again:
cmp bl,[si]
jnc lll
mov bl,[si]
lll: inc si
loop again
mov large,bl
mov ax,4c00h
int 21h
main endp
2. Add the list of 2 table and store in third table
.model small
.stack 100h
.data
val1 db 44h,45h,48h,45h,75h
val2 db 44h,45h,48h,45h,75h
val3 db 5 dup(?)
.code
main proc
mov ax,@data
mov ds,ax
mov bx,0000h
;mov cx,0005h
repeat:
mov al,val1[bx]
add al,val2[bx]
mov val3[bx],al
inc bx
loop repeat
mov ax,4c00h
int 21h
main endp

By Sudip Lama
8086 assembly program and solution of past question

3. To display string at the central of the screen


.model small
.stack 100h
.data
val db "wait for second..$"
.code
main proc
mov ax,@data
mov ds,ax
mov ah,02h
mov dh,0ch ;Row mov dh,12
mov dl,27h ;column mov dl,40
int 10h;Set the curser position
mov ah,09h
lea dx,val
int 21h ;display string pointed by dx
mov ax,4c00h
int 21h
main endp
4. WAP in 8086 to sort 5 numbers in ascending order and descending order.(2062
baisakh).
.model small
.stack 100h
.data
list db 10h,20h,4h,50h,01h
.code
main proc
mov ax,@data
mov ds,ax
repeat:
lea si,list
mov bl,00h
mov cx,0004h
lll:
mov al,[si]
inc si
cmp al,[si]
jc nochange
mov dl,[si]
mov [si],al
dec si
mov [si],dl
inc si
mov bl,01h ;keep flag =1
nochange:
loop lll
dec bl
jz repeat ;yes do another pass
mov ax,4c00h
int 21h
main endp

By Sudip Lama
8086 assembly program and solution of past question

5. Taking input and displaying string


.model small
.stack 100h
.data
paralist LABEL BYTE
max db 20
act db ?
kbdat db 21 dup(' '),'$'
prompt db 'name is ','$'
.code
main proc
mov ax,@data
mov ds,ax

mov ah,0ah ;for input to the string


lea dx,paralist
int 21h
mov ah,02h
mov dh,12
mov dl,40
int 10h
mov ah,09h ;display string
lea dx,prompt
int 21h

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

mov ah,0ah ;string input to kbdat


lea dx,kbdat
int 21h

lea si,kbdat ;pointing at starting of string

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,09h ;Display string


lea dx,kbdat
int 21h
mov ax,4c00h
int 21h
main endp
10. WAP to get an string input; count number of vowels and display msg "even vowels" on
the screen if the count is even otherwise display "odd vowels"(2055 chaitra)
.model small
.stack 100h
.data
kbdat db 21 dup(' '),'$'
odd db "odd vowel",'$'
even db "even vowel",'$'
.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'
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 ax,0600h ;For clearing screen


mov bh,71h
mov cx,0000h
mov dx,184fh
int 10h

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 ax,0600h ;For clearing screen


mov bh,0
mov bl,17h
mov cx,0000h
mov dx,184fh
int 10h

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

mov dl,20h ;display space after a number


mov ah,02h
int 21h
inc bl
loop again:
mov ax,4c00h
int 21h
main endp
14. WAP in 8086 to generate multiplication table of 5 numbers strored in memory as array,
store the result and display in following format:(2064 shrawan).
5 10 15 20 25 30 35 40 45 50
3 6 9 12 15 18 21 24 27 30
........................................

.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:

push cx ;Saving the counter of number


mov al,[si]
and al,0fh

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,20h ;display space after a number


mov ah,02h
int 21h
inc bl
loop again:

pop cx ;Retriving the counnt of the number


inc si
dec cl
cmp cl,00h
je last

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 dx,offset count


mov ah,09h
int 21h

;converting count to ascii


mov al,01h
mul bl
aam

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

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,0005h ;cx is always used as counter

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

mov si,offset list


mov bl,large
mov cx,0006h
mov bl,[si]
again:

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

mov si,offset list


mov bl,small
mov cx,0006h
mov bl,[si]
again:

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

7. Write a program to generate the multiplication table of a given number.


Solution:
.model small
.stack 100h
.data
list db 10 dup(?)
num db 03h
.code
main proc
mov ax,@data
mov ds,ax

mov si,offset list


mov cx,0ah

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

9. Write a program to generate the Fibonacci series up-to 10 numbers.


Solution:
.model small
.stack 100h
.data
list db 10 dup (?)
.code
main proc

Compiled by Sudeep Shakya 
Deputy Head 
Kathmandu Engineering College  Page 6 
 
Microprocessor 
mov ax,@data
mov ds,ax

mov si,offset list


mov bh,00h
mov bl,01h
mov cx,000ah

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

mov ah,08h ;number entered by the user


int 21h

and al,0fh ;taking only LSB


mov dh,al
mov bl, 01h
mov cx,10 ;counter
again:
mov al,dh
mul bl
aam
mov bh,al

Compiled by Sudeep Shakya 
Deputy Head 
Kathmandu Engineering College  Page 7 
 
Microprocessor 
cmp ah,00h ; not showing 0 in output
je label

add ah,30h ; adding 30 converts the contents of ah to decimal.


mov dl,ah
mov ah,02h
int 21h

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

add ah,30h ; adding 30 converts the contents of ah to decimal.


mov dl,ah
mov ah,02h
int 21h

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 dl,0dh ;carriage return


mov ah,02h
int 21h

mov dl,0ah ;next line


mov ah,02h
int 21h

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

string db 'I would love to program in 8086 assembly language$'


;count dw $-string
.code
main proc

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

16. Write a program to count the number of vowel in given sentence.


Solution:
.model small
.stack 100h
.data
list db 'the quick brown fox jumped over lazy sleeping dog'
len dw $-list
vow db ?
.code
main proc far
mov ax,@data
mov ds,ax
mov si,offset list
mov cx,len
mov ch,00h
mov bl,00
back:
cmp [si],'a'

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

para label byte


ml db 45h
len db ?
msg db 45 dup(?)

.code
main proc far
mov ax,@data ;initializing data segment
mov ds,ax

mov ah,0ah ;taking input from user


mov dx,offset para
int 21h

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

cmp [si],'Z' ;else compare it with 'Z'


ja comp ;if it is above A, jump to comp

add [si],20h ;if it is between A and Z, convert it to


small letters
comp:
cmp [si],'a' ;compare it with 'a'
jb number ;if it is below a, jump to number
cmp [si],'z' ;else compare it with 'z'
ja number ;if it is above z, jump to number
cmp [si],'a' ;if it is between 'a' and 'z', check if
it is a vowel and jump to inc_vowels
je inc_vowels:
cmp [si],'e'
je inc_vowels:
cmp [si],'i'
je inc_vowels:
cmp [si],'o'
je inc_vowels:
cmp [si],'u'
je inc_vowels:

inc consonents ;if not a vowel, increment count of


consonents
jmp update ;jump to update to take next character
Compiled by Sudeep Shakya 
Deputy Head 
Kathmandu Engineering College  Page 15 
 
Microprocessor 
inc_vowels:
inc vowels ;increment vowel counter
jmp update ;jump to update to take next character

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 numbers ;if it is a number, increment the number


counter
jmp update ;jump to update to take next character

inc_others:
inc others ;increment other counter

update:
inc si
loop again

mov ax,4c00h
int 21h

main endp
end main

18. Write a program to scroll the text from right to left.


Solution:
.model small
.stack 100h
.data
msg db 'I am scrolling... and its fun $'
len dw $-msg
.code
main proc

mov ax,@data
mov ds,ax
mov ah,00 ;defining vedio mode
mov al,03 ;80*25
int 10h

mov cx,80-len ;value need to scroll(move) from right to left


mov bl,cl

Compiled by Sudeep Shakya 
Deputy Head 
Kathmandu Engineering College  Page 16 
 
Microprocessor 
again:

mov ah,02 ;setting cursor position


mov dh,12 ;row 12th
mov dl,bl ;variable column (decreasing fashion)
int 10h

mov ah,09 ;displaying the messege


lea dx,msg
int 21h

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

new_line macro ;macro definition


mov ah,02h
mov dl,0ah
int 21h

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),'$'

paralist2 label byte


max2 db 20
act2 db ?
address db 20 dup(0),'$'
.code
main proc

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 
 

You might also like