Microprocessor Assignment Final
Microprocessor Assignment Final
QUESTION: 1
Let two 16-bit numbers are stored in memory locations from C050H, add the
numbers and multiply the result by 4(decimal) and store the result in memory
locations C054H and C055H.
SOURCE CODE
MVI D,00
LXI H,C050
MOV A,M
INX H
INX H
MOV B,M
ADD B
DCX H
MOV A,M
INX H
INX H
MOV C,M
ADC C
STA C054
MVI C,03
MOV D,A
L1: ADD D
DCR C
JNZ L1
STA C055
HLT
2|Page
INPUT 1 : C050 05
C051 23
C052 40
C053 2A
OUTPUT 1 : C054 40
C055 34
INPUT 2 : C050 00
C051 02
C052 00
C053 03
OUTPUT 2 : C054 05
C055 14
INPUT 3 : C050 21
C051 34
C052 45
C053 3A
OUTPUT 3 : C054 6E
C055 B8
DISCUSSION
The program is designed in such a way that only the lower order of the result
of the sum of the two 16-bit numbers are taken. And hence the result that is
obtained after multiplying the sum with addition, that is, the result of the sum
was added four times and hence the final result was obtained.
Since 8085 microprocessor is capable of holding only 8-bit data, we store a 16-
bit data by storing them in two consecutive locations. The lower order of the
data is stored in a location followed by a higher order data, which together
represents a 16-bit hexadecimal number.
4|Page
QUESTION: 2
Add two BCD numbers stored in the memory locations C100H and C101H.
Place the result in memory locations C110H, the result should also be in BCD.
SOURCE CODE
LXI H, C100
MOV A,M
INX H
MOV B,M
ADD B
DAA
STA C110
HLT
INPUT 1 : C100 39
C101 12
OUTPUT 1 : C110 51
INPUT 2 : C100 23
C101 04
OUTPUT 2 : C110 27
INPUT 3 : C100 39
C101 21
OUTPUT 3 : C110 60
DISCUSSION
In this program, only the BCD numbers are accepted as input, that is, the
numbers whose digits are ranging from 0 to 9. According to question, the
numbers are added. But the result that is produced may or may no be a BCD
number. Hence, ‘DAA’ operation is performed on the result, which converts a
non-BCD number to a BCD number. The program ignores a number which
produces more than 8-bit and hence only the result that is accommodated in 8-
bit are stored and hence displayed.
6|Page
QUESTION: 3
Calculate the sum of series of 8-bit numbers, length of the series is stored in
location C100H and the series begins from C101H. The sum will be stored in
some separate memory location.
SOURCE CODE
LXI H,C100
MOV C,M
INX H
MOV A,M
DCR C
MVI D,00
MVI E,00
L1: INX H
MOV B,M
ADD B
JNC L2
INR D
L2: DCR C
JNZ L1
STA FFF1
MOV A,D
STA FFF0
JNC L3
INR E
L3: HLT
7|Page
INPUT 1 : C100 08
C101 24
C102 32
C103 B2
C104 10
C105 10
C106 11
C107 11
C108 12
OUTPUT 1 : FFF0 51
FFF1 5C
INPUT 2 : C100 02
C101 5A
C102 0E
OUTPUT 2 : FFF1 6B
INPUT 3 : C100 04
C101 35
C102 2A
C103 FE
C104 4B
OUTPUT 3 : FFF0 01
FFF1 AB
DISCUSSION
This program generates the sum of ‘n’ 8-bit hexadecimal numbers. The sum of
‘n’ hexadecimal numbers may or may not be an 8-bit hexadecimal numbers,
rather can be 8-bit, 12-bit, or 16-bit numbers. Hence, two memory locations
FFF0 and FFF1 are allocated to store the given result. FFF0 stores the higher
order of the result while the lower order of the result is stored in FFF1.
9|Page
QUESTION: 4
Write an ALP to compute 16-bit sum of N positive entries of a table. The first
entry of the table contains the number of elements N. The 16-bit sum will be
kept in memory location of SUM-LO and SUM-HI. If the sum requires more than
16-bits only the lower bits will be kept and the MSB is said to be truncated.
SOURCE CODE
LXI H,F000
MOV C,M
L1: LDA D001
INX H
INX H
MOV B,M
ADD B
STA D001
LDA D000
DCX H
MOV B,M
ADC B
STA D000
INX H
DCR C
JNZ L1
HLT
10 | P a g e
INPUT 1 : F000 02
F001 F0
F002 01
F003 A2
F004 0B
OUTPUT 1 : D000 92
D001 0C
INPUT 2 : F000 04
F001 10
F002 23
F003 4E
F004 56
F005 10
F006 2A
F007 9B
F008 01
OUTPUT 2 : D000 09
D001 A4
INPUT 3 : F000 03
F001 45
F002 12
F003 4F
F004 56
F005 12
F006 34
OUTPUT 3 : D000 A6
D001 9C
12 | P a g e
DISCUSSION
This program adds’N’ 16-bit numbers. For this reason, register pairs are used,
since a single register is only capable of storing a 8-bit data.
The main disadvantage of the program is that if the result of ‘N’ 16-bit number
exceeds a result of 16-bit then the result is truncated and only the last 16-bit of
the results are stored in memory locations D000 and D001 respectively. D000
holds the higher order of the 16-bit data and D001 holds the lower order of the
16-bit result. And hence a 16-bit result is obtained.
13 | P a g e
QUESTION: 5
Take the first 10 natural numbers in consecutive memory locations starting from
C050H. Add the odd numbers and store the result in register E and add the
even numbers and store the result in register D.
SOURCE CODE
LXI H, C050
MVI C,0A
MVI E,00
MVI D,00
L1: MOV A,M
MOV B,A
INX H
ANI 01
JNZ L2
MOV A,D
ADD B
MOV D,A
JMP L3
L2: MOV A,E
ADD B
MOV E,A
L3: DCR C
JNZ L1
MOV A,E
STA D000
MOV A,D
STA D001
HLT
14 | P a g e
INPUT 1 : C050 0A
C051 07
C052 04
C053 03
C054 0E
C055 09
C056 02
C057 01
C058 0B
C059 0A
OUTPUT 1 : D000 1F
D001 28
INPUT 2 : C050 01
C051 02
C052 01
C053 02
C054 01
C055 02
C056 01
C057 02
C058 01
C059 02
OUTPUT 2 : D000 05
D001 0A
INPUT 3 : C050 01
C051 02
C052 03
C053 04
C054 05
C055 06
C056 07
C057 08
C058 09
C059 0A
16 | P a g e
OUTPUT 3 : D000 19
D001 1E
DISCUSSION
In this program, the sum of all the even and the odd numbers are found stored
in the given memory location. The sum of the odd numbers is stored in D000
and the sum of the even numbers are stored in D001.
Here, ‘ANI 01’ is used to identify the odd and the even numbers. The logic
behind this is that every odd number has the lower significant bit (LSB) as 1
and even numbers have the LSB as 0. So, when ‘ANI 01’ is performed with this
numbers – the answer is ‘00’ is if it is an even number and ’01’ if it is an odd
number. This is how, in this program, differentiation between even and odd
number is done.
17 | P a g e
QUESTION: 6
Write an assembly language program to check a block of data and count how
many times a given data is found in the data block. The size of the data block
to be checked is stored in A100H and data are stored from A101H.
SOURCE CODE
LXI D,E000
LXI H,A100
MOV C,M
L1:INX H
LDA A100
MOV B,A
MOV A,M
PUSH H
PUSH D
LXI H,A100
MVI E,00
L2: INX H
MOV D,M
CMP D
JNZ L3
INR E
L3: DCR B
JNZ L2
MOV B,E
MOV A,B
POP D
STAX D
INX D
POP H
DCR C
18 | P a g e
JNZ L1
HLT
INPUT 1 : A100 05
A101 01
A102 02
A103 01
A104 02
A105 01
OUTPUT 1: E000 03
E001 02
E002 03
E003 02
E004 03
INPUT 2 : A100 03
A101 01
A102 01
A103 01
OUTPUT 2 : E000 03
E001 03
E002 03
INPUT 3 : A100 0A
A101 01
A102 02
A103 05
A104 0A
A105 0B
A106 01
A107 02
A108 0B
A109 0A
A10A 0A
OUTPUT 3 : E000 02
E001 02
E002 01
E003 03
E004 02
E005 02
20 | P a g e
E006 02
E007 02
E008 03
E009 03
DISCUSSION
In this program the frequency of each number entered by the user is counted.
Hence, for ‘n’ inputs, ‘n’ number of output is obtained, that is, the frequency of
the number is calculated and is stored in the corresponding memory locations.
The outputs are stored from memory location E000H onwards, and hence
continued.
21 | P a g e
QUESTION: 7
Write an assembly language program to check a block of memory data to find
out the largest value stored in the block. The data is stored from A050H.
SOURCE CODE
LXI H,A04F
MOV C,M
DCR C
INX H
MOV A,M
L1: INX H
MOV B,M
CMP B
JNC L2
MOV A,B
L2: DCR C
JNZ L1
STA B000
HLT
INPUT 1 : A04F 04
A050 A1
A051 02
A052 F3
A053 03
OUTPUT 1: B000 F3
INPUT 2 : A04F 06
A050 0A
A051 02
A052 03
A053 61
A054 0A
A055 09
OUTPUT 2 : B000 0A
INPUT 3 : A04F 0A
A050 01
A051 03
A052 02
A053 05
A054 08
A055 04
A056 07
A057 0B
A058 06
A059 09
OUTPUT 3 : B000 0B
23 | P a g e
DISCUSSION
In this program, the largest value among the given ‘n’ numbers is found and the
number is stored at B000H. Initially, the first number in the list is supposed to
be the largest number and then it is compared with other ‘n-1’ numbers, thus
updating the value of the largest number, each time a greater number is
occurred.
24 | P a g e
QUESTION: 8
Write an assembly language program to exchange 10 bytes of data stored from
location X with 10 bytes of data stored from location Y.
SOURCE CODE
LXI H,A000
LXI D,B000
MVI B,0A
L1: MOV C,M
LDAX D
MOV M,A
MOV A,C
STAX D
INX H
INX D
DCR B
JNZ L1
HLT
INPUT 1 : A000 01
A001 02
A002 03
A003 04
A004 05
A005 06
A006 07
A007 08
A008 09
A009 0A
B000 0A
B001 0B
B002 0C
B003 0D
B004 0E
B005 0F
B006 10
B007 11
B008 12
B009 13
OUTPUT 1 : A000 0A
A001 0B
A002 0C
A003 0D
A004 0E
A005 0F
A006 10
A007 11
A008 12
A009 13
B000 01
B001 02
26 | P a g e
B002 03
B003 04
B004 05
B005 06
B006 07
B007 08
B008 09
B009 0A
INPUT 2 : A000 01
A001 02
A002 01
A003 02
A004 01
A005 02
A006 01
A007 02
A008 01
A009 02
B000 03
B001 04
B002 03
B003 04
B004 03
B005 04
B006 03
B007 04
B008 03
B009 04
OUTPUT 2 : A000 03
A001 04
A002 03
A003 04
A004 03
A005 04
A006 03
A007 04
A008 03
A009 04
B000 01
B001 02
B002 01
B003 02
B004 01
B005 02
B006 01
27 | P a g e
B007 02
B008 01
B009 02
INPUT 3 : A000 05
A001 02
A002 01
A003 06
A004 0A
A005 09
A006 10
A007 0B
A008 FF
A009 A0
B000 91
B001 23
B002 45
B003 02
B004 01
B005 A2
B006 B6
B007 F1
B008 05
B009 49
OUTPUT 3 : A000 91
A001 23
A002 45
A003 02
A004 01
A005 A2
A006 B6
A007 F1
A008 05
A009 49
B000 05
B001 02
B002 01
B003 06
B004 0A
B005 09
B006 10
B007 0B
B008 FF
B009 A0
28 | P a g e
DISCUSSION
In this program, 10 bytes (each block containing 1 byte) of data is exchanged
with another 10 bytes of data. This is also known as block exchange.
Two register pairs are used to hold the addresses of two memory block that is
given as an input in the program.
The result is stored in the same memory locations where the inputs were given.
29 | P a g e
QUESTION: 9
Let 10 bytes of data are stored from location A100H, write an assembly
language program to transfer a block to A105H.
SOURCE CODE
LXI H,A109
LXI D,A10E
MVI B,0A
L1: MOV A,M
DCX H
STAX D
DCX D
DCR B
JNZ L1
HLT
INPUT 1 : A100 01
A101 02
A102 03
A103 04
A104 05
A105 06
A106 07
A107 08
A108 09
A109 0A
OUTPUT 1 : A105 01
A106 02
A107 03
A108 04
A109 05
A10A 06
A10B 07
A10C 08
A10D 09
A10E 0A
INPUT 2 : A100 A3
A101 23
A102 45
A103 E5
A104 89
A105 9A
A106 DF
A107 C5
A108 6A
A109 87
OUTPUT 2 : A105 A3
A106 23
A107 45
A108 E5
A109 89
A10A 9A
31 | P a g e
A10B DF
A10C C5
A10D 6A
A10E 87
INPUT 3 : A100 56
A101 90
A102 AD
A103 FF
A104 FB
A105 C6
A106 36
A107 01
A108 30
A109 CB
OUTPUT 3 : A105 56
A106 90
A107 AD
A108 FF
A109 FB
A10A C6
A10B 36
A10C 01
A10D 30
A10E CB
DISCUSSION
In this program, a block of 10-bytes of data is shifted from A100H to A105H.
The exchange is done is a reversed manner, that is, the last data byte is shift
fast (A109H to A10EH) and then the second last data byte and so on. In this
way the data are not lost during the exchange, which could occur if the
exchange was done from beginning to end (A100H to A109H).
The exchange is done by storing both the ending addresses in register pair HL
and DE and the values of these pairs are decreased by 1 with each exchange.
32 | P a g e
QUESTION: 10
Write an assembly language program to arrange a block of ten 8-bit numbers
in ascending order.
SOURCE CODE
MVI B,0A
MVI C,0A
DCR C
MOV A,C
L1: LXI H,F001
STA D000
MOV C,M
LXI D,F001
L2: MOV A,M
CMP C
JC L3
MOV C,A
MOV D,H
MOV E,L
L3: INX H
DCR B
JNZ L2
DCX H
CMP C
JZ L4
MOV B,C
STAX D
MOV M,B
L4: LDA D000
MOV B,A
DCR A
JNZ L1
HLT
33 | P a g e
INPUT 1 : F001 0A
F002 09
F003 08
F004 07
F005 06
F006 05
F007 04
F008 03
F009 02
F00A 01
OUTPUT 1 : F001 01
F002 02
F003 03
F004 04
F005 05
F006 06
F007 07
F008 08
F009 09
F00A 0A
INPUT 2 : F001 06
F002 02
F003 09
F004 01
F005 01
F006 05
F007 00
F008 07
35 | P a g e
F009 06
F00A 06
OUTPUT 2 : F001 00
F002 01
F003 01
F004 02
F005 05
F006 06
F007 06
F008 06
F009 07
F00A 09
INPUT 3 : F001 45
F002 9A
F003 23
F004 FF
F005 01
F006 FD
F007 46
F008 89
F009 CB
F00A 02
OUTPUT 3 : F001 01
F002 02
F003 23
F004 45
F005 46
F006 89
F007 9A
F008 CB
F009 FD
F00A FF
DISCUSSION
In this program, ten 8-bit data are sorted in ascending order using Bubble Sort
technique. The sorted elements are placed in the same locations at which they
are stored.
Due to lack to registers, the counter (that is initially equal to 10) is stored in
memory location D000H every time the steps for performing the sorting
algorithm is executed.
36 | P a g e
QUESTION: 11
Write an assembly language program to arrange a block of ten 8-bit numbers
in descending order.
SOURCE CODE
MVI B,0A
MVI C,0A
DCR C
MOV A,C
L1: LXI H,F001
STA D000
MOV C,M
LXI D,F001
L2: MOV A,M
CMP C
JNC L3
MOV C,A
MOV D,H
MOV E,L
L3: INX H
DCR B
JNZ L2
DCX H
CMP C
JZ L4
MOV B,C
STAX D
MOV M,B
L4: LDA D000
MOV B,A
DCR A
JNZ L1
HLT
37 | P a g e
INPUT 1 : F001 01
F002 02
F003 03
F004 04
F005 05
F006 06
F007 07
F008 08
F009 09
F00A 0A
OUTPUT 1 : F001 0A
F002 09
F003 08
F004 07
F005 06
F006 05
F007 04
F008 03
F009 02
F00A 01
INPUT 2 : F001 06
F002 02
F003 09
F004 01
F005 01
F006 05
F007 00
F008 07
F009 06
F00A 06
OUTPUT 2 : F001 09
F002 07
F003 06
F004 06
F005 06
F006 05
F007 02
39 | P a g e
F008 01
F009 01
F00A 00
INPUT 3 : F001 45
F002 9A
F003 23
F004 FF
F005 01
F006 FD
F007 46
F008 89
F009 CB
F00A 02
OUTPUT 3 : F001 FF
F002 FD
F003 CB
F004 9A
F005 89
F006 46
F007 45
F008 23
F009 02
F00A 01
DISCUSSION
In this program, ten 8-bit data are sorted in descending order using Bubble Sort
technique. The sorted elements are placed in the same locations at which they
are stored.
Due to lack to registers, the counter (that is initially equal to 10) is stored in
memory location D000H every time the steps for performing the sorting
algorithm is executed.
40 | P a g e
QUESTION: 12
Write an assembly language program to perform multiplication of two 8-bit
numbers.
SOURCE CODE
LXI H,F000
MOV A,M
MOV E,M
INX H
MOV B,M
DCR B
MVI C,00
L1: ADD E
JNC L2
INR C
L2:DCR B
JNZ L1
STA FFF1
MOV A,C
STA FFF0
HLT
41 | P a g e
INPUT 1 : F000 FF
F001 FF
OUTPUT 1 : FFF0 FE
42 | P a g e
FFF1 01
INPUT 2 : F000 02
F001 04
OUTPUT 2 : FFF0 00
FFF1 08
INPUT 3 : F000 FF
F001 02
OUTPUT 3 : FFF0 01
FFF1 FE
DISCUSSION
In this program, two 8-bit numbers are multiplied using repeated addition
method. The product of two 8-bit multiplication can also produce a result of 16-
bit. In such cases, the higher order 8-bit data is stored in FFF0H and the lower
order bits are stored in FFF1H. In case the result is a 8-bit data, 00H is
presented in FFF0H and the result is presented in FFF1H.
The multiplication is done by incrementing the value of a register by 1 each time
a carry is generated after addition in each step.
43 | P a g e
QUESTION: 13
Write an assembly language program to perform division of two 8-bit numbers.
SOURCE CODE
LXI H,F000
MOV A,M
INX H
MOV B,M
CMP B
JNC L1
MOV B,A
MOV A,M
L1: MVI C,00
L2: SUB B
JC L3
INR C
JMP L2
L3: ADD B
STA FFF1
MOV A,C
STA FFF0
HLT
44 | P a g e
INPUT 1 : F000 42
45 | P a g e
F001 02
OUTPUT 1 : FFF0 21
FFF1 00
INPUT 2 : F000 07
F001 02
OUTPUT 2 : FFF0 03
FFF1 01
INPUT 3 : F000 FF
F001 05
OUTPUT 3 : FFF0 33
FFF1 00
DISCUSSION
In this program, division between two 8-bit numbers are performed using
repeated subtraction technique. At first, the larger number is found between the
two given numbers and then it is divided by the smaller number. The repeated
subtraction takes place until a borrow is generated.
The quotient is stored in memory location FFF0H and the remainder in FFF1H.
46 | P a g e
QUESTION: 14
Write an assembly language program to convert a BCD to Hexadecimal number.
SOURCE CODE
LXI H,F000
MOV D,M
MOV A,D
ANI 0F
MOV B,A
MOV A,D
ANI F0
RRC
RRC
RRC
RRC
MOV C,A
MVI E,09
L1: ADD C
DCR E
JNZ L1
ADD B
STA FFF0
HLT
47 | P a g e
INPUT 1 : F000 98
OUTPUT 1 : FFF0 62
48 | P a g e
INPUT 2 : F000 02
OUTPUT 2 : FFF0 02
INPUT 3 : F000 52
OUTPUT 3 : FFF0 34
DISCUSSION
In this program, a BCD number is converted to a Hexadecimal Number. At first,
each nibble is cut from the input. When the higher order nibble is cut, it is rotated
to the left four times to transfer it to the lower nibble.
Now, simply the numbers are multiplied using decimal adjust method to get the
final decimal result.
49 | P a g e
QUESTION: 15
Find the square of a number using look-up table.
SOURCE CODE
LXI H,F000
MOV B,M
MOV C,M
MVI A,00
MVI D,00
L1: ADC B
DCR C
JNZ L1
STA FFF0
JNC L2
MVI D,01
L2: MOV A,D
STA FFF1
HLT
INPUT 1 : F000 02
OUTPUT 1 : FFF0 04
INPUT 2 : F000 0E
OUTPUT 2 : FFF0 C4
INPUT 3 : F000 05
OUTPUT 3 : FFF0 19
DISCUSSION
In this program, the square of the number is found using look up table. The
program is only able to handle an 8-bit result. The logic of repeated addition is
used to find the square of the number.
The input is stored in the memory location F000H and the result is stored in the
memory location FFF0H.
51 | P a g e
QUESTION: 16
Write an assembly language program to convert a Hexadecimal number to its
equivalent ASCII code.
SOURCE CODE
LDA 4200
MOV B,A
ANI 0F
CALL SUB1
STA 4201
MOV A,B
ANI F0
RLC
RLC
RLC
RLC
CALL SUB1
STA 4202
HLT
SUB1: CPI 0A
JC SKIP
ADI 07
SKIP: ADI 30
RET
INSTRUCTIONS & HEXCODE TABLE
MEMORY RANGE: (0000-FFFF)
STARTING ADDRESS: 0000
52 | P a g e
INPUT 1 : 4200 E4
OUTPUT 1 : 4201 34
4202 45
INPUT 2 : 4200 0A
OUTPUT 2 : 4201 41
4202 30
INPUT 3 : 4200 12
53 | P a g e
OUTPUT 3 : 4201 32
4202 31
DISCUSSION
In this program, a Hexadecimal number is converted to its ASCII equivalent.
Memory location 4200H stores the hexadecimal number and 4201H stores the
ASCII equivalent of the lower nibble of the hex data, while 4202H stores the
ASCII equivalent of the higher nibble of the hex data.
At first, the most significant 4 bits of the hexadecimal number is masked and
then a subroutine is called to get the ASCII of the least significant 4 bits. The
result is stored in the memory and now the least significant 4 bits are masked
of the original hex data. Now, the result is rotated four times to make the higher
nibble to lower nibble and the subroutine is called to get the ASCII of upper
nibble and thus the result is stored in the memory.
54 | P a g e
QUESTION: 17
Find the value of X raised to the power of Y, using assembly language
programming.
SOURCE CODE
LXI H,F000
MVI C,00
MVI A,00
MOV B,M
DCR B
INX H
MOV A,M
L3: MOV E,M
DCR E
MOV D,A
L2: ADD D
JNC L1
INR C
L1: DCR E
JNZ L2
DCR B
JNZ L3
STA FFF1
MOV A,C
STA FFF0
HLT
55 | P a g e
INPUT 1 : F000 02
F001 02
OUTPUT 1 : FFF1 04
INPUT 2 : F000 02
F001 03
OUTPUT 2 : FFF1 09
INPUT 3 : F000 06
F001 03
OUTPUT 3 : FFF0 02
FFF1 D9
DISCUSSION
This program finds the value of Xy as long as the result can be stored in 16-bits.
Memory location F000H stores the value of Y, that is the exponent, while F001H
stores the value of X, that is the number. The result is stored in memory loaction
FFF1H if the result contains less than or equal to 8 bits. But if it exceeds one
nibble, the higher nibble is stored in memory location FFF0H and the lower
nibble is stored in FFF1H.
57 | P a g e
QUESTION: 18
Write a program to subtract two 16-bit numbers.
SOURCE CODE
LHLD 2050
XCHG
LHLD 2052
MVI C,00
MOV A,E
SUB L
STA 2054
MOV A,D
SBB H
STA 2055
HLT
INPUT 1 : 2050 19
2051 6A
2052 15
2053 5C
OUTPUT 1 : 2054 04
2055 0E
INPUT 2 : 2050 FF
2051 FF
2052 21
2053 3A
OUTPUT 2 : 2054 DE
2055 C5
INPUT 3 : 2050 34
2051 FF
2052 25
2053 FF
OUTPUT 3 : 2054 0F
2055 00
DISCUSSION
This program subtracts two 16-bit numbers. Hence, for each 16-bit inputs, two
memory locations of 8-bits are allocated. For the first input, 2050H and 2051H
are allocated. The higher nibble of the hex data is stored in 2050H, while the
lower nibble in 2051H. Similarly, for the second input, memory locations 2052H
and 2053H are allocated, where the higher nibble is stored in 2052H and the
lower in 2053H. The final result is stored in memory locations 2054H and
2055H.
For this subtraction, the lower nibble of the first data is subtracted from the
lower nibble of second data which is followed by subtraction between the
higher nibbles of the hex data. This is done so because, 8085 microprocessor is
only capable of performing 8-bit operation at a time.
59 | P a g e
QUESTION: 19
Write an assembly language program to perform multiplication of two 8-bit
numbers using shift and add method.
SOURCE CODE
LHLD 2050
XCHG
MOV C,D
MVI D,00
LXI H,0000
DAD D
DCR C
JNZ 200A
SHLD 3050
HLT
INPUT 1 : 2050 43
2051 07
OUTPUT 1 : 3050 D5
3051 01
INPUT 2 : 2050 34
2051 E2
OUTPUT 2 : 3050 E8
3051 2D
INPUT 3 : 2050 04
2051 28
OUTPUT 3 : 3050 A8
3051 00
DISCUSSION
In this program, multiplication between two 8-bit numbers is performed using
shift and add method. It is the simpler form of the process in which
multiplication is done using repeated addition method.
The inputs are to be stored in memory locations 2050H and 2051H. After the
multiplication is done, the four lower order bits are stored in memory location
3050H and the four higher order bits are stored in memory location 3051H.
61 | P a g e
QUESTION: 20
Write a program in assembly language to check whether a number is a Prime
number or not.
SOURCE CODE
LXI H,F000
MOV B,M
MOV D,M
MVI C,00
L1: MOV A,D
L2: SUB B
JZ L3
JC L4
JNC L2
L3: INR C
L4: DCR B
JNZ L1
MOV A,C
SUI 02
MVI A,00
JNZ L5
MVI A,01
L5: STA FFF1
HLT
INPUT 1 : F000 05
OUTPUT 1 : FFF1 01
INPUT 2 : F000 06
OUTPUT 2 : FFF1 00
INPUT 3 : F000 0B
63 | P a g e
OUTPUT 3 : FFF1 01
DISCUSSION
This program checks whether the hexadecimal number present in memory
location F000H is a Prime number or not. If the given number is a number prime
number, 01H is displayed in the memory location FFF1H, otherwise 00H is
displayed.
The factors to the numbers are found by repeated subtraction method and
whenever a factor is found, the count of register C is incremented by 1. And at
last, the value of C register is checked. If 02H is present in it, 01H is displayed
otherwise, 00H is displayed.
64 | P a g e
QUESTION: 21
Write a program in assembly language to check whether a number is an even
number or an odd number.
SOURCE CODE
LXI H,F000
MOV A,M
MVI C,00
ANI 01
JZ L1
MVI C,01
L1: MOV A,C
STA F001
HLT
INPUT 1 : F000 05
OUTPUT 1 : F001 01
INPUT 2 : F000 A2
00
OUTPUT 2 : F001
INPUT 3 : F000 FF
OUTPUT 3 : F001 01
DISCUSSION
This program checks whether the hexadecimal number present in memory
location F000H is an even number or an odd number. If the number is an even
number, 00H is displayed in F001H, otherwise 01H is displayed for the odd
number.
The number is divided by 2 by repeated subtraction method and checked
whether a remainder is present or not. If present is termed as an odd number
and if no remainder is present it is termed as an even number.
66 | P a g e
QUESTION: 22
Write a program in assembly language to find the Greatest Common Divisor
(GCD) and Lowest Common Multiple (LCM) of two 8-bit numbers.
SOURCE CODE
LXI H,F000
MOV B,M
MOV A,B
INX H
MOV C,M
MOV D,C
L1: CMP D
JZ L3
JC L2
SUB D
JMP L1
L2: MOV E,A
MOV A,D
SUB E
MOV D,A
MOV A,E
JMP L1
L3: STA FFF0
MOV D,A
MVI A,00
L5: ADD B
DCR C
JNZ L5
MVI C,00
L6: INR C
SUB D
JZ L7
JMP L6
L7: MOV A,C
STA FFF1
HLT
67 | P a g e
INPUT 1 : F000 04
F001 06
OUTPUT 1 : FFF0 02
FFF1 0C
INPUT 2 : F000 05
F001 09
OUTPUT 2 : FFF0 01
FFF1 2D
INPUT 3 : F000 0A
F001 FF
OUTPUT 3 : FFF0 05
FFF1 FE
DISCUSSION
In this program, GCD of two 8-bit numbers if found by repeatedly subtracting
the smaller number from the larger number until two numbers become equal to
each other. The LCM is found by dividing the product of two numbers and the
GCD of two numbers by repeated subtraction.
69 | P a g e
QUESTION: 23
Write a ALP to take a number as input from the user and check whether the
number is present is the array given by the user or not.
SOURCE CODE
LXI H,F000
MOV C,M
INX H
MOV B,M
L1: INX H
MOV A,M
CMP B
JZ L2
DCR C
JNZ L1
MVI A,00
JMP L3
L2: MOV A,L
STA FFF2
MOV A,H
STA FFF3
MVI A,01
L3: STA FFF1
HLT
INPUT 1 : F000 06
F001 23
F002 A1
F003 34
F004 E1
F005 09
F006 23
F007 FC
OUTPUT 1 : FFF1 01
INPUT 2 : F000 0A
F001 FF
F002 06
F003 02
71 | P a g e
F004 09
F005 01
F006 01
F007 05
F008 06
F009 07
F00A 06
F00B 06
OUTPUT 2 : FFF1 00
INPUT 3 : F000 05
F001 B3
F002 AA
F003 B3
F004 F5
F005 B3
F006 2C
OUTPUT 3 : FFF1 01
DISCUSSION
This program checks whether a number entered by the user is present in a list
of numbers or not. This is done by using Linear Search Method.
In memory location F000H, the count for total number of data (n) is to be given.
The next input present in F001H, holds the number that is to be searched from
a list of elements using linear search. The corresponding ‘n’ locations hold
number of elements entered by the user.
The result is presented in memory location FFF1H. 01H is displayed if the
number entered by the user is found in the given list, otherwise 00H is
displayed.
72 | P a g e
QUESTION: 24
Find the square root of a given number using assembly language programming.
SOURCE CODE
LXI H,F000
MOV A,M
MVI B,01
MVI C,01
L1: SUB C
JZ L2
JC L3
INR C
INR C
INR B
JMP L1
L3: DCR B
L2: MOV A,B
STA FFF0
HLT
INPUT 1 : F000 09
OUTPUT 1 : FFF0 03
INPUT 2 : F000 11
04
OUTPUT 2 : FFF0
INPUT 3 : F000 19
OUTPUT 3 : FFF0 05
DISCUSSION
This program finds the square root of the given number. The number entered is
a hexadecimal number whose square root is to be found.
The given number is stored in memory location F000H. If the number entered
by the user is not a perfect-square number, the result is the value of the square
root of the number previous to that of the given number. It is done so because,
8085 is incapable of storing floating point integers. The result is stored in the
memory location FFF0H.
74 | P a g e
QUESTION: 25
Take two 8-bit numbers:
(a) AND them
(b) Complement the sum of the two numbers
(c) Perform OR operation between these two numbers
(d) Perform XOR operation between these two numbers
Write a program in 8085 assembly language to perform the above.
SOURCE CODE
LXI H,F000
MOV A,M
MOV C,A
INX H
MOV B,M
ANA B
STA FFF0
MOV A,C
ADD B
CMA
STA FFF1
MOV A,C
ORA B
STA FFF2
MOV A,C
XRA B
STA FFF3
HLT
INPUT 1 : F000 AA
F001 32
OUTPUT 1 : FFF0 22
FFF1 23
FFF2 BA
FFF3 98
INPUT 2 : F000 FD
F001 FF
OUTPUT 2 : FFF0 FD
FFF1 03
FFF2 FF
FFF3 02
76 | P a g e
INPUT 3 : F000 A2
F001 E4
OUTPUT 3 : FFF0 A0
FFF1 79
FFF2 E6
FFF3 46
DISCUSSION
This program takes two inputs from the user which are stored in memory
locations F000H and F001H. The result of AND operation between the numbers
is stored in memory location FFF0H, the complement of the sum of the two
numbers are stored in memory location FFF1H, the result of their OR operation
is stored in memory location FFF2H and the result of their XOR operation stored
in memory location FFF3H.
77 | P a g e
QUESTION: 26
Write an assembly language program to split 16-bit data into 4-nibbles and find
out largest nibble among them. Store the results in consecutive memory
locations.
SOURCE CODE
LXI H,F000
LXI B,F002
MVI E,02
L1: MOV D,M
MOV A,M
RRC
RRC
RRC
RRC
ANI 0F
STAX B
INX B
MOV A,D
ANI 0F
STAX B
INX B
INX H
DCR E
JNZ L1
LXI H,F002
MVI E,03
MOV A,M
L2: INX H
MOV B,M
CMP B
JNC L3
MOV A,B
L3: DCR E
JNZ L2
STA F006
HLT
78 | P a g e
INPUT 1 : F000 AA
F001 32
OUTPUT 1 : F002 0A
F003 0A
F004 03
F005 02
F006 0A
INPUT 2 : F000 4F
F001 26
OUTPUT 2 : F002 04
F003 0F
F004 02
F005 06
F006 0F
INPUT 3 : F000 AB
F001 EF
80 | P a g e
OUTPUT 3 : F002 0A
F003 0B
F004 0E
F005 0F
F006 0F
DISCUSSION
In this program, a 16-bit number is divided into 4 hexadecimal numbers by
extracting each nibble. Two memory locations are required to store a 16-bit
number in 8085 microprocessors.
The memory locations are F000H and F001H. Now, the number is divided to
get its four nibbles and they are stored in memory locations F002H, F003H,
F004H and F005H respectively. Among them, the largest nibble is found and
stored in memory location F006H.
81 | P a g e
QUESTION: 27
Write an ALP to transfer enitire block of 10 data (1-byte each) into new locations.
Then modify the program to replace positive data by 00 and negative data by
FF.
SOURCE CODE
MVI C,0A
LXI H,F001
LXI D,FF01
L1: MOV A,M
STAX D
ANI 80
JNZ L2
MVI M,00
JMP L3
L2: MVI M,FF
L3: INX H
INX D
DCR C
JNZ L1
HLT
INPUT 1 : F001 DD
F002 7F
F003 3A
F004 8D
F005 A2
F006 C4
F007 4E
F008 2F
F009 9B
F00A AB
OUTPUT 1 : FF01 FF
FF02 00
FF03 00
FF04 FF
FF05 FF
FF06 FF
FF07 00
FF08 00
FF09 FF
FF0A FF
83 | P a g e
INPUT 2 : F001 66
F002 36
F003 39
F004 63
F005 EF
F006 D1
F007 D7
F008 45
F009 DB
F00A 14
OUTPUT 2 : FF01 00
FF02 00
FF03 00
FF04 00
FF05 FF
FF06 FF
FF07 FF
FF08 00
FF09 FF
FF0A 00
INPUT 3 : F001 AB
F002 12
F003 CD
F004 34
F005 EF
F006 56
F007 78
F008 98
F009 89
F00A 87
OUTPUT 3 : FF01 FF
FF02 00
FF03 FF
FF04 00
FF05 FF
FF06 00
FF07 00
FF08 FF
FF09 FF
FF0A FF
84 | P a g e
DISCUSSION
In this program, first 10-bytes of data is taken as input, each in one memory
location. Thus, 10 memory locations are used to take the data as input.
The numbers are now checked using ‘ANI’ operation. If the number turns out to
be a positive number, 00H is displayed as the result in the corresponding output
location, otherwise FFH is displayed.
The inputs are stored from memory location F001H to F00AH and the results
are stored from FF01H to FF0AH.
85 | P a g e
QUESTION: 28
Write a ALP to perform the addition between two 8-bit numbers.
SOURCE CODE
LXI H,C050
MOV A,M
INX H
MOV B,M
MVI C,00
ADD B
JNC L
MVI C,01
L:STA C030
MOV A,C
STA C031
HLT
INPUT 1 : C050 FF
C051 FF
OUTPUT 1 : C030 FE
C031 01
INPUT 2 : C050 AB
C051 36
OUTPUT 2 : C030 E1
C031 00
INPUT 3 : C050 66
C051 FF
OUTPUT 3 : C030 65
C031 01
DISCUSSION
In this program, two 8-bit numbers are added which are stored in memory
locations C050H and C051H. The result of their sum is stored in the memory
location C030H and the carry is displayed in memory location C031H. If a carry
is generated from their addition 01H is displayed in memory location C031H
and if not, 00H is displayed in the same.
87 | P a g e
QUESTION: 29
Write a ALP to convert ‘n’ binary numbers to its equivalent gray code.
SOURCE CODE
LXI H,F000
LXI D,FFF0
MOV C,M
L1: INX H
MOV A,M
RRC
ANI 7F
XRA M
STAX D
INX D
DCR C
JNZ L1
HLT
INPUT 1 : F000 03
F001 A0
F002 B2
F003 05
OUTPUT 1 : FFF0 F0
FFF1 EB
FFF2 07
INPUT 2 : F000 04
F001 62
F002 4A
F003 F2
F004 02
OUTPUT 2 : FFF0 53
FFF1 6F
FFF2 8B
FFF3 03
INPUT 3 : F000 02
F001 AB
F002 66
OUTPUT 3 : FFF0 FE
FFF1 55
DISCUSSION
This program gives the equivalent gray code of ‘n’ binary numbers. The
numbers entered by the user and the results obtained are displayed as its
hexadecimal equivalent.
F000H stores the total count of the numbers that is to be entered by the user.
The following ‘n’ locations store those numbers for the operation. Results of the
numbers are displayed from FFF0H in consecutive memory locations in
accordance to the numbers entered by the number.
89 | P a g e
QUESTION: 30
Write an assembly language program to take a hexadecimal number as input
and generate the resultant byte whose 7th bit is given by:
A7=A2⊕A5⊕A6
SOURCE CODE
LXI H,C030
MOV A,M
ANI 02
RLC
RLC
RLC
RLC
RLC
MOV B,A
MOV A,M
ANI 10
RLC
RLC
MOV C,A
MOV A,M
ANI 20
RLC
XRA B
XRA C
MOV B,A
MOV A,M
ANI BF
ADD B
STA C031
HLT
90 | P a g e
INPUT 1 : C030 CC
OUTPUT 1 : C031 8C
INPUT 2 : C030 2E
OUTPUT 2 : C031 2E
INPUT 3 : C030 F1
OUTPUT 3 : C031 B1
DISCUSSION
A hexadecimal number is given as input to this program, and its 7th bit is
manipulated such that, A7=A2⊕A5⊕A6, where A7 represents the 7th bit, A2
represents the 2nd bit, A5 represents the 5th bit and A6 represents the 6th bit of
the binary equivalent of the hexadecimal number.
Primarily the 2nd bit, 5th bit and 6th bit are extracted from the original number
and rotated to their left such that they become 7th bit of some individual
numbers. It is done by using ‘ANI’ operation. Now, XOR operation is performed
between those extracted numbers. The resultant is kept in register B.
On the other hand, the 7th bit of the original data is converted to zero using ‘ANI’
operation and addition is performed between accumulator and register B to
obtain the new number with the manipulated 7th bit.
--X--