0% found this document useful (0 votes)
154 views77 pages

ALP Programs

The document outlines the structure and examples of Assembly Language Programs (ALP) for the 8085 microprocessor, detailing how to write instructions using mnemonics, labels, and comments. It includes several examples of ALPs for tasks such as adding hexadecimal numbers, finding complements, and handling memory locations. Each example provides a breakdown of the mnemonics, comments, and the total length of the program.

Uploaded by

yusuf85916
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
154 views77 pages

ALP Programs

The document outlines the structure and examples of Assembly Language Programs (ALP) for the 8085 microprocessor, detailing how to write instructions using mnemonics, labels, and comments. It includes several examples of ALPs for tasks such as adding hexadecimal numbers, finding complements, and handling memory locations. Each example provides a breakdown of the mnemonics, comments, and the total length of the program.

Uploaded by

yusuf85916
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 77

Assembly Language Programs (ALP)

• A program is a sequence of instructions written to tell a computer to


perform a specific function.
• The instructions are selected from the instruction set of the
microprocessor.
• To write a program, we divide a given problem into small steps in terms of
the operation the 8085 can perform.
• These steps can also be represented by flowchart.
• These steps can be further translated into instructions.

channel link :
https://www.youtube.com/c/ComputerScienceAcademy7
Assembly Language Programs (ALP)
• The assembly language program has the following format:
Memory address Label Mnemonics OP code (hex) Comments
• Label is name of line. It is used in jump instruction.
• Mnemonics consist of instruction and operands.
For example: MOV A, B.
• OP code (hex) is a corresponding hexadecimal code for the instruction.
Eg. MOV A, B (Op code = 78 H)
• Comments are useful for understanding purpose of instructions.
• Memory address is location where OP code / immediate data / address
are stored.
• Label and comment fields are optional.
Assembly Language Programs (ALP)
1. Write Assembly Language Program (ALP) to add two hexadecimal
numbers 12 H and 7A H. Store sum to memory location C000 H.
Solution 1: 12 H and 7A H
Mnemonics Comments 12 H 4 bit bin 00010010
MVI A, 12 H A = 12 H + 7A H + 01111010
8C H 1000 110 0
ADI 7A H A = A + 7A H
STA C000 H [C000 H] = (A) 8 C
HLT Stop MPU ADD r
ADD M x A = A + data
ADI data 12 H 7A H
ADI 7A H C000 H 8C H
Total Length of program = 8 byte
A = 8C H
Assembly Language Programs (ALP)
1. Write Assembly Language Program (ALP) to add two hexadecimal
numbers 12 H and 7A H. Store sum to memory location C000 H.
Solution 2: 12 H and 7A H
Mnemonics Comments 12 H 4 bit bin 00010010
MVI A, 12 H A = 12 H + 7A H + 01111010
8C H 1000 110 0
MVI B, 7A H B = 7A H
ADD B A=A+B 8 C
STA C000 H [C000 H] = (A) ADD r
HLT Stop MPU ADD M x A=A+B
ADI data 12 H 7A H
ADD B C000 H 8C H
Total Length of program = 9 byte
A = 8C H
Assembly Language Programs (ALP)
2. Write an ALP to add the content of memory location C000 H with the
content of memory location D000 H and store the 8 bit result in E000 H.
Solution 1:
Mnemonics Comments C000 H 03 H D000 H 02 H
LDA C000 H A = 03 H
E000 H 05 H
MOV B, A B = 03 H
LDA D000 H A = 02 H [C000 H] 03 H 4 bit bin 00000011
ADD B + [D000 H] + 02 H + 00000010
A=A+B
STA E000 H [E000 H ] = (A) 05 H 0 000 010 1
HLT Stop MPU 0 5
ADD r
ADD M A=A+ B
ADI data x 03 H 02 H
Total Length of program = 12 byte ADD B A = 05 H
Assembly Language Programs (ALP)
2. Write an ALP to add the content of memory location C000 H with the
content of memory location D000 H and store the 8 bit result in E000 H.
Solution 1: H D0 00 L

Mnemonics Comments C000 H 03 H D000 H 02 H M

LDA C000 H A = 03 H
E000 H 05 H
LXI H, D000 H (HL) = D000H
ADD M A = A + [(HL)] [C000 H] 03 H 4 bit bin 00000011
+ [D000 H] + 02 H + 00000010
STA E000 H [E000 H ] = (A)
HLT 05 H 0 000 010 1
Stop MPU
0 5
ADD r
ADD M A=A+ M
ADI data x 03 H [(HL)]
Total Length of program = 11 byte ADD M A = 05 H
Assembly Language Programs (ALP)
3. Write an ALP to add the content of memory location C000 H with the
content of memory location C001 H and store the 8 bit result in C002 H.
Solution 1: C000 H 03 H M
Mnemonics Comments
C001 H 02 H M
LXI H, C000 H (HL) = C000H C0 00
02
01 C002 H 05 H M
MOV A, M A = [(HL)] A = 03 H H L
INX H (HL) = (HL) + 1 M = 02
ADD M A = A + [(HL)] A = 05 H ADD M A = A + M
INX H (HL) = (HL) + 1 A = A + [(HL)]
MOV M, A [(HL)] = A A = 03 H + 02 H
HLT Stop MPU A = 05 H

Total Length of program = 9 byte


Assembly Language Programs (ALP)
4. Write an ALP to add two 16 bit numbers. The first number stored at memory
location C030 H and C031 H and the second number stored at C032 H and C033 H.
Store 16 bit result at memory location C034 H and C035 H.
Solution : 1122 H and 3344 H C030 H 22 H
Mnemonics Comments C031 H 11 H
1122 H
LHLD C030 H (HL) = 1122 H C032 H 44 H
+ 3344 H
(DE) = 1122 H (HL) = ? C033 H 33 H
XCHG 4466 H C034 H 66 H
LHLD C032 H (HL) = 3344 H
C035 H 44 H
DAD D (HL) = (HL) + (DE) ADD x It perform 8 bit addition
SHLD C034 H [C034 H] = (L) [C035 H] = (H)
DAD rp (HL) = (HL) + (rp)
HLT Stop MPU
It perform 16 (HL) = (HL) + (DE)
bit addition 1122 H 3344 H
channel link :
https://www.youtube.com/c/ComputerScienceAcademy7 DAD D
(HL) = 4466 H
Total Length of program = 12 byte
Assembly Language Programs (ALP)
5. Write an ALP to find 1’s complement of 8 bit number stored in memory location
C000 H. Store result at memory location C001 H.
Solution 1: CMA
Mnemonics Comments C000 H 02 H M
(Complement accumulator) C001 H FDFD HH M
LDA C000 H A = [C000 H] A = 02 H
CMA Complement Accumulator A = FD H A = 02 H C0 00
01
STA C001 H [C000 H] = A H L
CMA
M = 02AH= FD H
HLT Stop MPU
A=M
A = 02 H
Solution 2: A = 02 H
Comments A A==0000000000001100
Mnemonics
LXI H, C000 H (HL) = C000 H M = 02 H AA==1111111111110011
MOV A, M A= [(HL)] A = 02 H AA==FDFDHH
CMA Complement Accumulator A = FD H
INX H (HL) = (HL) + 1
MOV M, A [(HL)] = A M = FD H
HLT Total Length of program = 8 byte
Stop MPU
Assembly Language Programs (ALP)
6. Write an ALP to find 2’s complement of 8 bit number stored in memory location
C000 H. Store result at memory location C001 H.
Solution 1: Solution 2:
Mnemonics CMA C000 H 02 H
Mnemonics
LXI H, C000 H + 1 C001 H FE H
LDA C000 H
CMA MOV A, M 2’S Complement
CMA
INR A OR ADI 01 H A = 02 H
INR A
STA C001 H (A) = (A) + 1 A=00000010
INX H
HLT MOV M, A A = 1 1 1 1 1 1 0 1 A = FD H
HLT + 1
A = 1 1 1 1 1 1 1 0 A = FE H
Total Length of program = 9 byte
Assembly Language Programs (ALP)
7. Write an ALP to find 1’s complement of 16 bit number stored at memory location
C000 H and C001 H and stored result at memory location C002 H and C003 H.
Solution : 12F9 H C000 H F9 H
Mnemonics Comments 12 F9 C001 H 12 H
LHLD C000 H (H) = 12 H (L) = F9 H C002 H 06 H
0001 0010 1111 1001
MOV A, H (A) = (H) = 12 H C003 H ED H
CMA CMA
CMA (A) = ED H 1110 1101 0000 0110
MOV H, A (H) = (A) = ED H
ED 06
MOV A, L (A) = (L) = F9 H
CMA (A) = 06 H (HL) = 12F9 H 1’s complement (HL) = ED06 H
MOV L, A (L) = (A) = 06 H
SHLD C002 H [C002 H] = (L)
HLT [C003 H] = (H)
Total Length of program = 13 byte
Assembly Language Programs (ALP)
8. Write an ALP to find 2’s complement of 16 bit number stored at memory location
C000 H and C001 H and stored result at memory location C002 H and C003 H.
Solution : 12F9 H C000 H F9 H
Mnemonics Comments 12 F9 C001 H 12 H
LHLD C000 H (H) = 12 H (L) = F9 H C002 H 07 H
0001 0010 1111 1001
MOV A, H (A) = (H) = 12 H C003 H ED H
CMA CMA
CMA (A) = ED H 1110 1101 0000 0110
MOV H, A (H) = (A) = ED H
ED 06
MOV A, L (A) = (H) = F9 H
CMA (A) = 06 H (HL) = 12F9 H 1’s complement (HL) = ED06 H
MOV L, A (L) = (A) = 06 H + 1
INX H (HL) = (HL) + 1 (HL) = ED07 H
SHLD C002 H [C002 H] = 07 H
HLT [C003 H] = ED H Total Length of program = 14 byte
Assembly Language Programs (ALP)
9. Write an ALP to find 2’s complement of a 16 bit number stored in DE pair. Store
result in HL pair.
Solution : 85 B6
Mnemonics Comments D E
MOV A, D (A) = (D) = 85 H DE = 85B6 H
CMA (A) = 7A DE = 1 0 0 0 0 1 0 1 1 0 1 1 0 1 1 0
MOV H, A (H) = (A) = 7A H CMA CMA
MOV A, E (A) = (E) = B6 H 01111010 01001001
CMA (A) = 49 H H = 7A L = 49
MOV L, A (L) = (A) = 49 H
INX H (HL) = (HL) + 1 HL = 7A49 H
HLT + 1
7A 4A
HL = 7A4A H
H L

Total Length of program = 8 byte


ALP : Jump Instructions
12. Write an ALP to add two 8 bits hex numbers stored at memory locations C000 H and
C001 H. Store the two byte result from memory locations C002 H onwards.
Solution : Eg. 1
MVI C, 00 H Reg. C = 00 H 03 H 4 bit bin 0 0 0 0 0 0 1 1 03 H M
C000 H
LXI H, C000 H HL = C000 H + 02 H 02 H M
+ 00000010 C001 H
MOV A, M A = 03 H C002 H 05 H M
INX H HL = C001 H M= 02 H 00 05 H 0 0 0 0 0 0 1 0 1
Carry C003 H 00 H M
ADD M A = 05 H, Cy = 0 Byte 2 Byte 1
00 0 5
J NC SKIP If Cy = 0 then jump Eg. 2
INR C Reg. C = 01 H 8A H 4 bit bin 1 0 0 0 1 0 1 0 8A H
C000 H
SKIP: INX H HL = C002 H + B3 H + 10110011 C001 H B3 H
MOV M, A M = 05 H C002 H 3D H
INX H HL = C003 H 01 3D H 1 0 0 1 1 1 1 0 1 01 H
Carry C003 H
MOV M, C M = 01 H Byte 2 Byte 1 01 3 D
HLT
ALP : Jump Instructions
12. Write an ALP to add two 8 bits hex numbers stored at memory locations C000 H and
C001 H. Store the two byte result from memory locations C002 H onwards.
Solution : Eg. 1
MVI C, 00 H Reg. C = 00 H 03 H 4 bit bin 0 0 0 0 0 0 1 1 C000 H 03 H
LXI H, C000 H HL = C000 H + 02 H C001 H 02 H
+ 00000010 05 H
MOV A, M A = 8A H C002 H
INX H HL = C001 H M= B3 H 00 05 H 0 0000 010 1 C003 H 00 H
Carry
ADD M A = 3D H, Cy = 1 Byte 2 Byte 1
00 0 5
JNC SKIP If Cy = 0 then jump Eg. 2
INR C Reg. C = 01 H 8A H 4 bit bin 1 0 0 0 1 0 1 0 C000 H 8A H M
SKIP: INX H HL = C002 H + B3 H + 10110011 C001 H B3 H M
MOV M, A M = 3D H C002 H 3D H M
INX H HL = C003 H 01 3D H 1 0 011 110 1 C003 H 01 H M
Carry
MOV M, C M = 01 H Byte 2 Byte 1 01 3 D
HLT
Solution : Memory
MVI C, 00 H C000 H 03 H
addresses Label Mnemonics Op code
LXI H, C000 H C001 H 02 H
C002 H 05 H 3000 H MVI C, 00 H 0E
MOV A, M 3001 H 00
C003 H 00 H
INX H 3002 H LXI H, C000 H 21
ADD M 3003 H 00
JNC SKIP 3004 H C0
C000 H 8A H 3005 H MOV A, M 7E
INR C 3006 H INX H 23
SKIP: INX H C001 H B3 H
3007 H ADD M 86
C002 H 3D H
MOV M, A 3008 H JNC SKIP D2
C003 H 01 H 3009 H
INX H 0C
MOV M, C 300A H 30
300B H INR C 0C
HLT 300C H SKIP : INX H 23
300D H MOV M, A 77
Total Length = 17 byte 300E H INX H 23
channel link : 300F H MOV M, C 71
https://www.youtube.com/c/ComputerScienceAcademy7 3010 H HLT 76
ALP : Jump Instructions
13. Write an ALP to add two BCD numbers stored at memory locations AB00 H and
AB01 H. Store the BCD result from memory locations AB02 H onwards starting with
LSB.
MVI C, 00 H 37 4 bit bin 00110111 AB00 H 37 H
LXI H, AB00 H + 93 + 10010011 AB01 H 93 H
AB02 H 30 H
MOV A, M 0 130 CY = 0 1 1 0 0 1 0 1 0 AB03 H 01 H
INX H AC = 0
Here, C A
ADD M
DAA the value of least significant 4 bits (LSB) as well as the value of
JNC SKIP most significant 4 bits (MSB) of the accumulator is greater than
INR C 9 so we have to add 66 to accumulator.
SKIP : INX H
11001010
MOV M, A
+01100110
INX H
MOV M, C 1 001 100 00
HLT 01 3 0
ALP : Jump Instructions
14. Write an ALP to rotate the content of memory location D000 H towards left by one
bit position and add original content with rotated number and store the result from
D001 H onwards.
D000 H 74 H
MVI C, 00 H A = 74 H
D001 H 5C H
LXI H, D000 H A= 01110100 01 H
D002 H
MOV A, M After RLC
RLC A= 11101000
ADD M A = E8 H
JNC SKIP
INR C E8 H 4 bit bin 11101000
SKIP : INX H + 74 H + 01110100
MOV M, A 01 5C H 1 0101 110 0
INX H Carry
MOV M, C Byte 2 Byte 1 01 5 C
HLT
Assembly Language Programs (ALP)
10. A hex number is stored at location AB00 H. Write an ALP to interchange its digits.
And the new number is to be stored at AB01 H. Add original number with new
number and store result at location ABCD H.
Solution: Interchange digits H L AB00 H 23 H M
Mnemonics Comments Reverse digits 01
AB 00 AB01 H 32 H M
LXI H, AB00 H (HL) = AB00 H M = 23 H Swap digits / Nibbles
MOV A, M (A) = [(HL)] A = 23 H
RRC Rotate right A 23 --> 32 ABCD H 55 H
RRC Rotate right A A = 23 H
RRC Rotate right A A = 0 0 1 0 0 0 1 1 RRC
RRC Rotate right A A = 32H A = 1 0 0 1 0 0 0 1 A = 91 H RRC
INX H (HL) = (HL) + 1 A = 1 1 0 0 1 0 0 0 A = C8 H RRC
MOV M, A [(HL)] = (A) M = 32H A = 0 1 1 0 0 1 0 0 A = 64 H RRC
DCX H (HL) = (HL) - 1 M = 23 H A = 0 0 1 1 0 0 1 0
ADD M (A) = (A) + [(HL)] A = 55 H A = 32 H
STA ABCD H [ABCD H] = (A)
HLT Rotate Accumulator right/left 4 times to get
reverse hex number.
11. Write an ALP to separate Nibble of a number stored at memory locations 2000 H.
add separated nibble and store result at 2001 H.
20 00
01
Solution :
35 H H L 2000 H 35 H M
Mnemonics Comments 3 5
LXI H, 2000 H 2001 H 08 H M
M = 35 03 H +
MOV A, M A = 35 05 H
ANI 0F H A = 05 08 H
MOV B, A B = 05
MOV A, M A = 35 A = 35 H 00110101
ANI F0 H A = 30 ^ 0F H ^00001111
RRC Rotate right Acc A = 05 H 00000101
RRC four times B = 05 H
RRC
RRC A = 03 A = 35 H 00110101
ADD B A = A + B A = 08 ^ F0 H ^11110000
INX H (HL) = (HL) + 1 A = 30 H 00110000
MOV M, A Rotate accumulator right four times (RRC)
HLT A = 03 H
ADD B A = 08 H
ALP : Jump Instructions
15. A hex number stored at memory location C000 H. Write an ALP to check whether the
number is even or not. If its even then store FF H in C001 H otherwise store 00 H.
Solution : Eg.
MVI E, FF H Assume its even number
LXI H, C000 H 24 H 0 0 1 0 0 1 0 0 EVEN
C000 H 24 H
MOV A, M A = 24
49 H 49 H 0 1 0 0 1 0 0 1 ODD C001 H FF H
RRC CY = 10 CA H 1 1 0 0 1 0 1 0 EVEN
J NC SKIP Jump if Cy = 0 9F H 1 0 0 1 1 1 1 1 ODD
MVI E, 00 H
SKIP : INX H
RRC C000 H 49 H
MOV M, E [M] = E = FF
00 H
It store last bit (A0) in carry flag C001 H 00 H
HLT
1. After RRC, if Cy = 0 then number is Even.
2. After RRC, if Cy = 1 then number is Odd.
16. Write an ALP to clear register B if the number at memory 20F9 H is palindrome
otherwise store FF H in register B.
Solution : Palindrome number
MVI B, 00 H Assume its Palindrome If original number is equal to the its reverse number
LXI H, 20F9 H M = 7795 Eg
MOV A, M A = 95
77 22 H, AA H A3 H, D6 H
RRC 77 H etc 95 H etc
RRC Reverse of Reverse of
RRC 77 H = 77 H 95 H != 59 H
RRC A = 77
59 A = 77 H A = 95 H
CMP M 77 – 95
A – M, 59 77 , Z = 0
1 RRC RRC
J Z SKIP Jump if Z = 1 Original No. – Reverse No.
RRC RRC If Z = 1, then palindrome
MVI B, FF H RRC RRC
SKIP : HLT RRC RRC
A = 77 H A = 59 H
20F9 H 77 H 20F9 H 95 H
Reg. B 00 H Reg. B FF H
17. Write an ALP to subtract the number stored in memory location 3601 H from the
number stored in memory location 3600 H. Store the positive result / absolute
difference at location at location 3602 H.
Solution : SUB M 3600 H 05 H
LXI H, 3600 H M = 05 A=A–M 3601 H 02 H
MOV A, M A = 05 A = 05 – 02 3602 H 03 H
INX H A = 03 (+ve)
M = 02
SUB M A = A – M = +ve S = 0
JP SKIP Jump on Plus SUB M 3600 H 02 H
MOV A, M i.e. if S = 0
A=A–M 3601 H 05 H
DCX H A = 02 – 05 S = 1 3602 H ?H
SUB M A = 03 (-ve) (? H)
SKIP : STA 3602 H
HLT A = 05 – 02
SUB M
channel link :
https://www.youtube.com/c/ComputerScienceAcademy7 A = 03 (+ve)
23. There is a block of memory from 2501 H to 250A H. Write an ALP replace odd
numbers with data FF H in given block.
Solution :
2501 H 09 H 2501 H FF H
09 M
MVI B, 0A H B = 0A H 2502 H 04 H 2502 H 04 H M
LXI H, 2501 H M = 09 H 2503 H 15 H 2503 H 15 FF H M
UP : MOV A, M 2504 H 06 H 2504 H 06 H
04
A = 15
09 H
..... .....
RRC CY = 10
JNC SKIP Jump if Cy = 0 1. Task : Replace odd number with FF H
MVI M, FF H M = FF H 2. How to check odd number : RRC and If Cy = 1 then its Odd
3. Counter reg. B initial value : B = 0A H DCR B JNZ
SKIP : INX H M = 15
04 H
4. Initial value of Accumulator : A = [M] Then next value ?
DCR B B = 09
08 H
INX H
JNZ UP Jump if B != 00 H
HLT A = 09 H
A=0000 1001 CY = 1
A = 04 H
A=0000 0100 CY = 0
24. There is a block of memory from 2501 H to 250A. Write an ALP replace even
numbers with data FF H in given block.
Solution :
2501 H 04 H 2501 H FF H
04 M
MVI B, 0A H B = 0A H 2502 H 09 H 2502 H 09 H M
LXI H, 2501 H M = 04H 2503 H 06 H 2503 H 06 FF H M
UP : MOV A, M 06 H
04
A = 09H 2504 H 15 H 2504 H 15 H
..... .....
RRC CY = 10
JC SKIP Jump if Cy = 1 1. Task : Replace even number with FF H
MVI M, FF H M = FF H 2. How to check even number :RRC and If Cy = 0 then its Even
3. Counter reg. B initial value : B = 0A H DCR B JNZ
SKIP : INX H 06 H
M = 09
4. Initial value of Accumulator : A = [M] Then next value ?
DCR B B = 09
08 H
INX H
JNZ UP Jump if B != 00 H
HLT A = 04 H
A=0000 0100 CY = 0
A = 09 H
A=0000 1001 CY = 1
25. A 8 bit hexadecimal number stored at memory location C000 H. Write an ALP to
count numbers of zeros in it and store count in memory location C001 H.
Solution : 3A H = 0 0 1 1 1 0 1 0 C000 H 3A H
MVI B, 08 H No. of Zeros = 04 H C001 H 04 H
MVI C, 00 H 1. Task : Count No. of zeros in 8 bit hex number
LXI H, C000 H 2. How ? A = 3A H = 0 0 1 1 1 0 1 0 Reg. C = 00 H
MOV A, M A = 3A H RRC Cy = 0 Reg. C = 01 H
UP : RRC CY = 0 CY = 1 CY = 0 A = 1D H = 0 0 0 1 1 1 0 1 INR C
JC SKIP Jump if CY = 1 RRC Cy = 1 JC
INR C C = 01 H C = 02 H A = 8E H = 1 0 0 0 1 1 1 0
SKIP : DCR B B = 07 H B = 06 H B = 05 H RRC Cy = 0 Reg. C = 02 H
INR C
JNZ UP Jump if B != 0 3. Initial value of counter reg. B ? B = 08 H
INX H DCR B JNZ
MOV M, C Final Value of C = 04 H
HLT Note : To count no. of Ones replace JC by JNC
in above program
25.
26.AA8 8bitbithexadecimal
hexadecimalnumber
numberstoredstored atatmemory
memory location
location C000
C000 H.
H. Write
Write an
anALP
ALPtoto count
count
numbersnumbers of zeros
of 0s and 1s in itinand
it and store
store countcount in memory
in memory location
location C001 HC001 H. H respectively.
and C002
Solution : 3A H = 0 0 1 1 1 0 1 0 C000 H 3A H
DC H = 1 1 0 1 1 1 0 0 C000 H DC H
MVI B, 08 H No. of Zeros = 04 H C001 H
C001 H
04 H
03 H
MVI C, 00 H No. of Zeros = 03 H
1.No.
Task Count=No.
of: Ones 05 Hof zeros in 8 bitC001 05 H
hexH number
LXI H, C000 H 2.No.
How A = 3A H = 0bit0 –1 total
1 1 0 zero
1 0 bits
MOV A, M A = 3A H of?Ones = total Reg. C = 00 H
RRC Cy = 0 Reg. C = 01 H
UP : RRC CY = 0 CY = 1 CY = 0 No. of Ones = 08 – 03 = 05 H
A = 1D H = 0 0 0 1 1 1 0 1 INR C
JC SKIP Jump if CY = 1 RRC Cy = 1 JC
INR C C = 01 H C = 02 H A = 8E H = 1 0 0 0 1 1 1 0
SKIP : DCR B B = 07 H B = 06 H B = 05 H RRC Cy = 0 Reg. C = 02 H
INR C
JNZ UP Jump
C = 03
if BH !=
(No.
0 of Zeros) 3. Initial value of counter reg. B ? B = 08 H
MVI
INX HA, 08 H A = 08 H DCR B JNZ
SUB
MOVC M, C A = Value
Final A – C of C = 04 H
INX
HLT H A = 08 – 03 Note : To count no. of Ones replace JC by JNC
MOV M, C A = 05 H (No. of Ones) in above program
INX H
MOV M, A
HLT
27. Write an ALP to increment the content of alternate memory location each by 2 from
1051 H to 1060 H.
Solution : 1051 H 02 H 1051 H 04 H
MVI B, 10 H B = 10 H 1052 H 05 H 1052 H 05 H
LXI H, 1051 H M = 02 H 1053 H 09 H 1053 H 0B H
UP: INR M M = 03 H M = 0A H . .
INR M M = 04 H M = 0B H . .
INX H M = 05 H 1060 H 1060 H
INX H M = 09H
DCR B B = 0F H
DCR B B = 0E H
JNZ UP 1. Counter reg. B initial value : B = 10 H
HLT DCR B JNZ

channel link :
https://www.youtube.com/c/ComputerScienceAcademy7
28. Write an ALP to double (multiply by 2) the content of block from D001 H to D00A H and
store the double content at same memory location.
Solution 1 : D001 H 02 H D001 H 04 H
MVI B, 0A H B = 0A H D002 H 05 H D002 H 0A H
LXI H, D001 H M = 02 H D003 H 04 H D003 H 08 H
UP: MOV A, M A = 02 H A = 05 H M = 05 H . .
ADD M A = 04 H A = 0A H . .
MOV M, A M = 04 H M = 0A H D00A H 49 H D00A H 92 H
INX H M = 05 H M = 04 H
DCR B B = 09 H B = 08 H
JNZ UP Solution 2 : 1. Counter reg. B initial value : B = 0A H
HLT MVI B, 0A H DCR B JNZ
LXI H, D001 H
UP: MOV A, M A = 02 H A = 02 H 0 0 0 0 0 0 1 0 RLC
RLC A = 04 H 00000100 A = 04 H
MOV M, A A = 05 H 0 0 0 0 0 1 0 1 RLC
INX H 00001010 A = 0A H 01001001
DCR B + 01001001
A = 49 H 0 1 0 0 1 0 0 1 RLC
JNZ UP 1 0 0 1 0 0 1 0 A = 92 H -----------------------
100 100 1 0
HLT
29. Write an ALP to half (divide by 2) the content of block from D001 H to D00A H and store
the half content at same memory location.
Solution : D001 H 04 H D001 H 02 H
MVI B, 0A H B = 0A H D002 H 0A H D002 H 05 H
LXI H, D001 H M = 04 H D003 H 10 H D003 H 08 H
UP: MOV A, M A = 04 H A = 0A H . .
RRC A = 02 H A = 05 H . .
MOV M, A M = 02 H M = 05 H D00A H D00A H
INX H M = 0A H M = 10 H
DCR B B = 09 H B = 08 H
JNZ UP 1. Counter reg. B initial value : B = 0A H
HLT DCR B JNZ

A = 04 H 0 0 0 0 0 1 0 0 RRC
00000010 A = 02 H
A = 0A H 0 0 0 0 1 0 1 0 RRC
00000101 A = 05 H
A = 10 H 0 0 0 1 0 0 0 0 RRC
0 0 0 0 1 0 0 0 A = 08 H
30. Write an ALP to exchange the Nibble of each memory location, content of block which
begins from 2501 H. The length of block is at 2500 H. Store the result at same memory
location.
Solution : Exchange the Nibble ?
2500 H 03 H M
LXI H, 2500 H M = 03 H Reverse Number 2501 H 25 H 52 H M
MOV B, M B = 03 H Interchange digits 2502 H AE H EA H M
UP: INX H M = 25 H M = AE H A = 25 H 2503 H 95 H
MOV A, M A = 25 H A = AE H RRC
RRC RRC Initial value of counter
RRC RRC (Length of block / series of
RRC RRC A = 52 H memory) is given at 2500 H
RRC
MOV M, A
A = 52 H A = EA H
M= 52 H M = EA H
X
MVI B, 03 H

DCR B B = 02 H B = 01H LXI H, 2500 H


JNZ UP Jump if B != 0 MOV B, M DCR B JNZ
HLT
channel link :
https://www.youtube.com/c/ComputerScienceAcademy7
31. Write an ALP to count number of Odd data bytes in the block of memory starting from
AB01 H to AB10 H and store count at ABAB H.
Solution :
MVI B, 10 H 1. Task : Count total Odd AB01 H 03 H
MVI C, 00 H numbers. AB02 H 06 H
LXI H, AB01 H 2. Initial value of AB03 H 11 H
UP: MOV A, M A = 03 H A = 06 H A = 11 H count (Reg C) : C = 00 H . 04 H
RRC CY = 1 CY = 0 CY = 1 .
3. How ? A = 03 H AB10 H
J NC SKIP Jump if Cy = 0 A=00000011
INR C C = 01 H C = 02 H RRC Cy = 1 C = 01 H INR C
SKIP: INX H M = 06 H M = 11 H
A = 06 H
DCR B B = 0F H B = 0E H
A=00000110
JNZ UP Jump if B != 0
RRC Cy = 0 Skip INR C Instruction JNC
LXI H, ABAB H Final Count of odd numbers
MOV M, C C = ?? H 4. Initial value of
HLT OR Counter (Reg. B) : B = 10 H DCR B JNZ
MOV A, C
ABAB H C = ?? H
STA ABAB H
32. Write an ALP to count number of Even data bytes in the block of memory starting from
AB01 H to AB10 H and store count at ABAB H.
Solution : Note : To count total even numbers
MVI B, 10 H then replace JNC by JC in previous
MVI C, 00 H program.
LXI H, AB01 H
UP : MOV A, M
RRC channel link :
JC SKIP https://www.youtube.com/c/ComputerScienceAcademy7
INR C
SKIP : INX H
DCR B
JNZ UP
LXI H, ABAB H MOV A, C
MOV M, C OR STA ABAB H
HLT HLT
33. Write an ALP to count number of even data byte occurring in a block stored from
memory location 3001 H and onwards. The length of block is stored in location 3000 H.
Stored result in location 3100 H.
Solution : 3000 H 04 H M
MVI C, 00 H C = 00 H 3001 H 06 H M
1. Task : Count total Even 3002 H AE09
H H
LXI H, 3000 H M = 04 H M
numbers. 3003 H AC H
MOV B, M B = 04 H 2. Initial value of
UP : INX H M = 06 H M = 09 H 3004 H 7E H
count (Reg C) : C = 00 H
MOV A, M A = 06 H A = 09 H
RRC CY = 0 CY = 1 3. How ? A = 06 H 3100 H 03 H
JC SKIP Jump if CY = 1 A=00000110
INR C C = 01 H RRC Cy = 0 C = 01 H INR C
SKIP : DCR B B = 03 H B = 02 H A = 09 H
JNZ UP Jump if B != 0 A=00001001
LXI H, 3100 H Final value Reg C = 03 H RRC Cy = 1 Skip INR C Instruction JC
MOV M, C 4. Initial value of
HLT Counter (Reg. B) : MVI B,X04 H
LXI H, 3000 H
MOV B, M
34. Write an ALP to count number of Odd data byte occurring in a block stored from
memory location 3001 H and onwards. The length of block is stored in location 3000 H.
Stored result in location 3100 H.
3000 H
Solution : MVI C, 00 H 3001 H
LXI H, 3000 H 3002 H
MOV B, M 3003 H
UP: INX H 3004 H
MOV A, M
RRC 3100 H
JNC SKIP
INR C
SKIP : DCR B
JNZ UP
LXI H, 3100 H MOV A, C Note : To count total Odd numbers
MOV M, C OR
STA 3100 H then replace JC by JNC in previous
HLT HLT program.
35. Write an ALP to count number of Odd and Even data byte occurring in a block stored
from memory location 3001 H and onwards. The length of block is stored in location
3000 H. Stored odd count in location 3100 H and even count at 3101 H.
Solution : MVI C, 00 H 3000 H
LXI H, 3000 H Logic : count either all odd 3001 H
MOV B, M number or all even number 3002 H
UP: INX H Then subtract count from 3003 H
MOV A, M length to get another count. 3004 H
RRC
Solution 1. 3100 H
JNC SKIP Count all odd numbers. (reg C)
INR C 3101 H
Length = 08 H [3000 H] Get length in Accumulator.
SKIP : DCR B Let Odd count (C) = 05 Perform SUB C
JNZ UP Result in Reg. A is count of even
LDA 3000 H A = 08 H numbers.
SUB C A = 03 H
LXI H, 3100 H
MOV M, C
INX H
MOV M, A
HLT
36. The block of data is stored in memory locations from 9101 H to 9105 H. Write an ALP to
get sum of series and stored result at memory locations 9200 H onwards.
Solution:
MVI B, 05 H Logic : Sum = 0 A = 00 H
MVI A, 00 H 9101 H B2 H M
CY = 0 C = 00 H 9102 H 63 H
MVI C, 00 H M
LXI H, 9101 H ADD M 9103 H A9 H M
UP : ADD M A = 00 H 00000000 9104 H 78 H M
JNC SKIP + M = B2 H + 1 0 1 1 0 0 1 0 9105 H 03 H M
INR C ------------- -------------------- M
SKIP : INX H A = B2 H 1 0 1 1 0 0 1 0 CY = 0
9200 H 39H M
DCR B B = 04 ,03,02,01,00 + M = 63 H + 0 1 1 0 0 0 1 1 C = 00 9201 H 02 H M
JNZ UP Jump if B != 0 ------------- --------------------
LXI H, 9200 H A = 15 H 1 0 0 0 1 0 1 0 1 CY = 1
+ M = A9 H + 1 0 1 0 1 0 0 1 C = 01 H
MOV M, A
Sum = 0239 H ------------- --------------------
INX H A = BE H 1 0 1 1 1 1 1 0 CY = 0
MOV M, C + M = 78 H + 0 1 1 1 1 0 0 0 C = 01 H
HLT ------------- --------------------
A = 36 H 1 0 0 1 1 0 1 1 0 CY = 1
+ M = 03 H + 0 0 0 0 0 0 1 1 C = 02 H
Note : For BCD (decimal) numbers ------------- --------------------
A = 39 H 0 0 1 1 1 0 0 1 CY = 0
and BCD sum use DAA after ADD M
C = 02 H
37. Write an ALP to get sum of series of numbers whose length is stored in C000 H and
series itself start from C001 H. store the result in C050 H and C051 H.
Solution: MVI A, 00 H
Logic : Sum = 0 A = 00 H C000 H 04 H
MVI C, 00 H CY = 0 C = 00 H C001 H 01 H
LXI H, C000 H
ADD M C002 H 03 H
MOV B, M C003 H 02 H
Initial value of counter :
UP : INX H Reg B = ? C004 H 06 H
ADD M LXI H, C000 H
JNC SKIP MOV B, M C050 H 0C H
INR C C051 H 00 H
SKIP : DCR B
JNZ UP
LXI H, C050 H
MOV M, A
INX H channel link :
https://www.youtube.com/c/ComputerScienceAcademy7
MOV M, C
HLT
38. Write an ALP to get sum of series of BCD (Decimal) numbers whose length is stored in
C000 H and series itself start from C001 H. store the result in C050 H and C051 H.
Solution: MVI A, 00 H
Logic : Sum = 0 A = 00 H C000 H 04 H
MVI C, 00 H CY = 0 C = 00 H C001 H 01 H
LXI H, C000 H
ADD M DAA C002 H 03 H
MOV B, M C003 H 02 H
Initial value of counter :
UP : INX H Reg B = ? C004 H 06 H
ADD M LXI H, C000 H
DAA MOV B, M C050 H 12 H
JNC SKIP C051 H 00 H
INR C
SKIP : DCR B
JNZ UP
LXI H, C050 H
MOV M, A
INX H
MOV M, C
HLT
39. A series of number are stored in memory location from C001 H to C008 H. Write an
ALP to find greatest / largest number among this numbers and store largest number in
the location C009 H. Logic :
Solution: 1. Reduced length if length is big then C001 H 02 H M
MVI B, 03
08 H try to develop ALP. C002 H 09 H M
MVI A, 00 H (if ALP is worked with small length, it C003 H 07 H M
LXI H, C001 H A-M would work with big length too.) C004 H 09 H M
UP : CMP M 02
09 -- 09
00 02
07 -VE
-VE
+VE 2. Now consider B = 03 H. (Length)
CY
CY =1
JNC SKIP CY==01 i.e. Largest of 3 Hex number.
3. Take extra number that would not
MOV A, M 09 H
A = 02
affect the our final result A = 00 H
SKIP : INX H
DCR B 01
00 HH
B = 02 4. Compare numbers with Accumulator
JNZ UP Jump if B != 00 H (If number is greater than A then get that
MOV M, A number in A)
HLT And repeat these steps until counter
become zero.
Largest number will be in Accumulator
5. Now change the length B = 08 H (Actual
length given in program)
40. A series of number are stored in memory location from C001 H to C008 H. Write an
ALP to find smallest number among this numbers and store largest number in the
location C009 H. Logic :
Solution: 1. Reduced length if length is big then C001 H 46 H M
MVI B, 03
08 H try to develop ALP. C002 H 05 H M
MVI A, FF H (if ALP is worked with small length, it C003 H AB H M
LXI H, C001 H A-M would work with big length too.) C004 H 05 H M
UP : CMP M 46
FF - 46
05 05 -VE
AB +VE 2. Now cosider B = 03 H. (Length)
CY = 01 i.e. smallest of 3 Hex number.
JC SKIP
3. Take extra number that would not
MOV A, M A = 46
05 HH
affect the our final result A = FF H
SKIP : INX H
DCR B 01
00 HH
B = 02 4. Compare numbers with Accumulator
JNZ UP Jump if B != 00 H (If number is smaller than A then get that
MOV M, A number in A)
HLT And repeat these steps until counter
become zero.
Smallest number will be in Accumulator
5. Now change the length B = 08 H (Actual
length given in program)
41. Write an ALP to find the smallest number among contents of block of memory which
starts from D001 H, the length of block is stored at D000 H store the smallest number
at the end of block.
Solution: Initial Value of A = FF H D000 H 03 H M
MVI A , FF H D001 H 74 H M
LXI H, D000 H Initial value of counter : D002 H 01 H M
MOV B, M Reg B = ? D003 H F3 H M
UP: INX H LXI H, D000 H D004 H 01 H M
CMP M MOV B, M
JC SKIP CY = 1
MOV A, M A = 74
01 H
SKIP : DCR B B = 00 H
JNZ UP channel link :
INX H https://www.youtube.com/c/ComputerScienceAcademy7
MOV M, A
HLT
42. Write an ALP to find the largest number among contents of block of memory which
starts from D001 H, the length of block is stored at D000 H store the smallest number
at the end of block.
Solution: Initial Value of A = 00 H D000 H 03 H M
MVI A , 00 H D001 H 06 H M
LXI H, D000 H Initial value of counter : D002 H CB H M
MOV B, M Reg B = ? D003 H 09 H M
UP: INX H LXI H, D000 H D004 H CB H M
CMP M MOV B, M
JNC SKIP CY = 0
MOV A, M A = CB
06 H
SKIP : DCR B B = 00 H
JNZ UP
INX H
MOV M, A
HLT
43. Write an ALP to transfer/copy block of memory starting from 1050 H to 1059 H to a new
location starting from 1070 H to 1079 H.
Solution:
MVI B, 0A H 1050 H 1070 H 22 H
22 H M DE
LXI H, 1050 H 1051 H 55 H M DE 1071 H 55 H
LXI D, 1070 H 1052 H 33 H 1072 H 33 H
UP : MOV A, M A = 22
ADHH LDAX D
55 . .
STAX D [DE] = A MOV M, A . .
INX H 1059 H AD H M DE 1079 H AD H
INX D
DCR B B = 00 H
JNZ UP Initial value of counter :
Jump if B != 0
HLT Reg B = ? B = 0A H
Logic: ? Use two memory pointer
One is HL and other is DE
then Copy
channel link :
https://www.youtube.com/c/ComputerScienceAcademy7
INX H
INX D
Repeat
44. Write an ALP to copy a block of data having starting address 4500 H in new location
starting from 4600 H. The length of block is stored at memory location 44FF H.
Solution:
LXI H, 44FF H
MOV B, M 44FF H 03 H M
LXI D, 4600 H 4500 H 85 H M DE 4600 H 85 H
4501 H 99 H M DE 4601 H 99 H
UP: INX H 12 H M DE
4502 H 4602 H 12 H
MOV A, M 12
99 H
A = 85
STAX D [DE] = A DE
INX D
DCR B B = 00
02
01 HH Initial value of counter :
JNZ UP Jump if B != 0 Reg B = ?
HLT LXI H, 44FF H
MOV B, M Logic: ? Use two memory pointer
One is HL and other is DE
then Copy
INX H
INX D
Repeat
45. Write an ALP to find 1’s complement of five numbers stored from memory location
C030 H and onwards. Store the result from memory locations D000 H.
Solution:
MVI B, 05 H C030 H 11 H D000 H EE H
LXI H , C030 H C031 H E3 H D001 H 1C H
C032 H 46 H 1’S D002 H
LXI D, D000 H D003 H
C033 H 35 H
UP: MOV A, M C034 H D9 H D004 H
CMA
STAX D
INX H
INX D
DCR B
JNZ UP
HLT
46. Write an ALP to find 2’s complement of five numbers stored from memory location
C030 H and onwards. Store the result from memory locations D000 H.
Solution:
MVI B, 05 H C030 H 11 H D000 H EF H
LXI H , C030 H C031 H E3 H D001 H 1D H
C032 H 46 H 2’S D002 H
LXI D, D000 H D003 H
C033 H 35 H
UP: MOV A, M C034 H D9 H D004 H
CMA
INR A
STAX D
INX H
INX D
DCR B
JNZ UP
HLT
47. Write an ALP to find 2’s complement of block of data having starting address 6000 H and
store result in new location having starting address 7000 H. The length of block is stored
at memory location 5FFF H.
Solution:
LXI H, 5FFF H 5FFF H 03 H
MOV B, M 6000 H 7000 H
6001 H 7001 H
LXI D, 7000 H 7002 H
6002 H
UP : INX H
MOV A, M
CMA
INR A
STAX D
INX D
DCR B
JNZ UP
HLT
48. A block of data stored in memory location from D000 H to D00F H. Write an ALP to shift
the data contain of the block in reverse order starting from memory location D100 H.
Solution:
MVI B, 10
03 H Logic : Reduce length
LXI H , D000 H B = 03 H ( D000 H to D002 )
LXI D , D10F
D102 H DE
UP : MOV A, M 77
99 HH
A = DD D000 H DD H M DE D100 H 99 H
STAX D [DE] = A D001 H 77 H M DE D101 H 77 H
INX H D002 H 99 H M DE D102 H DD H
DCX D M
DCR B 01 HH
B = 02
00
JNZ UP • Take two memory pointer one is HL and
Jump if B != 0
HLT other is DE
• Point HL pointer to 1st address of 1st block.
• Point DE pointer to last address of 2nd block.
• Shift data
• INX H and DCX D
• Repeat until B = 00 H.
• STOP
49. A block of data is stored in memory from D001 H. The length of block is stored in
D000 H. Another block of same length is stored from D101 H. Write an ALP to
exchange contain of these two blocks.
Solution: LXI H, D000 H
D000 H 03 H M
LXI D, D101 H D001 H 33BBHH M DE D101 H 33 BB HH
MOV B, M B = 03 H D002 H 55EE H M DE D102 H 55 EE H
UP: INX H 55 H
M = 33 H D003 H 77 H DE D103 H AA H
LDAX D EE HH
A = BB
MOV C, M 55HH
C = 33 • Take two memory pointer one is HL and
MOV M, A
MOV A, C A = 33 other is DE
55HH
STAX D • Point HL pointer to 1st address of 1st block.
INX D • Point DE pointer to 1ST address of 2nd block.
DCR B B = 02
01 HH • Get length in Reg. B from M
JNZ UP • INX H
HLT • Swap data
• INX D
• Repeat until B = 00 H.
• STOP
50. Write an ALP to count number of times the data A4 H is found in block of memory
location starting from 4000 H. length of block is stored in location 3FFF H. Store result
in location 5000 H.
Solution:
MVI C, 00 H 3FFF H 03 H M
LXI H , 3FFF H 4000 H A4 H M
M
5000 H 02 H M
MOV B, M 4001 H 22 H
UP: INX H 4002 H A4 H M
MOV A, M 22 H
A = A4
CPI A4 H A – A4 H • Initialize count Reg. C = 00 H (count of A4 H)
JNZ SKIP 22A4
A4 H – A4 H Z = 01 • Point HL pointer to 1st address of memory block.
INR C C = 01
02 H • Get Initial value of counter Reg. B from M
SKIP : DCR B B = 02
01HH
00 • INX H
JNZ UP Jump if B ! = 00 H • Get 1st number in A and compare with A4 H
LXI H, 5000 H • If number found increment C or skip step (INR C)
MOV M, C • Repeat
HLT • Store result in 5000 H
• stop
51. A block of data is stored in memory location from 4500 H. the length of block is store in
memory location 44FF H. Write an ALP to search for the first occurrence of data D9 H in
given block. Store the address of the occurrence in HL reg pair. If the number is not
found then HL pair should contain 5000 H.
Solution:
LXI H , 4FFF H HL = 4FFF H 4FFF H 02 H M
MOV B, M B = 02 H 4500 H 23 H M
UP: INX H HL = 4500
4501 H
4501 H 11 H M
MOV A, M A = 2311 H
H
CPI D9 H A – D9 H
JZ SKIP 23 HH – D9 H Z = 00
11
DCR B B = 00
01 H Here B became zero i.e. it indicate that D9 H
JNZ UP is not found anywhere in the block.
LXI H, 5000 H
SKIP : HLT

channel link :
https://www.youtube.com/c/ComputerScienceAcademy7
52. Write an ALP to find the position of data 05 H in a block of memory D001 H to D005 H.
If data is found then store the position of data at memory location D100 H else store 00 H
at the same memory location. (Note : It is assume that 05 H may present only once )
Solution:
MVI B, 05 H Position (Reg. C)
MVI C, 01 H C = 01 H D001 H 05
12 H M
C = 02 H D002 H 05 HH
45 M
LXI H, D001 H D003 H 6B H
C = 03 H
UP: MOV A, M A = 0512
10HH
05 C = 04 H D004 H A9 H
CPI 05 H Z = 1010 C = 05 H D005 H 10 H M
JZ SKIP
INX H
INR C C = 02
06HH D100 H 02
01 HH
00
DCR B
JNZ UP B = 00 H
Here B became zero i.e. it indicate that 05 H
MVI C, 00 H C = 00 H is not found anywhere in the block.
SKIP: LXI H, D100 H
MOV M, C
HLT
53. There are two block of memory, one is from 2501 H to 2505 H, another is from 3501 H to
3505 H. Write an ALP to check whether content of this two block are exactly same or not.
If the contents are same then memory location D100 H should contain 00 H else FF H.
Solution:
MVI B, 05 H
MVI C, 00 H 2501 H 10 H M DE 3501 H 10
20 H
H
LXI H, 2501 H M = 10 H 2502 H 30 H M DE 3502 H 30
40 H
LXI D, 3501 H 2503 H 50 H 3503 H 50 H
UP: LDAX D A = 20 10 H
90
40 H 2504 H 70 H 3504 H 70 H
CMP M Z = 0011 2505 H 90 H M DE 3505 H 90 H
JNZ SKIP
INX H M = 30
90 HH
INX D D100 H 00HHH
FF
FF
DCR B B = 04
00 HH
JNZ UP
JMP NXT Here B became zero i.e. it indicate that two
SKIP: MVI C, FF H
blocks are exactly same.
NXT : LXI H, D100 H
MOV M, C
HLT
Multiplication of two 8 bit Hexadecimal numbers :
Decimal Multiplication :
Eg. 15 x 03 = 45
• Repeated addition is adding equal groups together. It is also known as multiplication.
• If the same number is repeated then, we can write that in the form of multiplication.
15 15 00 Sum = 00 Counter = 03
+ 15 + 15 + 15 Sum = Sum + 15
+ 15 ------- ------- Sum = 00 + 15
------- 30 15 Sum = 15 Decrement counter Counter = 02
45 + 15 + 15
------- ------- Sum = Sum + 15
45 30 Sum = 15 + 15
+ 15 Sum = 30 Decrement counter Counter = 01
-------
Sum = 45 Sum = Sum + 15
Sum = 30 + 15
Sum = 45 Decrement counter Counter = 00
Multiplication of two 8 bit Hexadecimal numbers :
Logic of our Program ?

A = 00 Counter
Sum B = 03
1st Hex Number (multiplier) C = 00
Sum = Sum + 15
ADD M
Sum = 00 + 15 [M] = 2nd Hex Number (multiplicand)
Sum = 15 Decrement counter Counter = 02
If CY = 1 then INR C
Otherwise SKIP
Repeat
Sum = Sumwhile
+ 15 B != 00
Sum = 15 + 15
Store
Sum = 3016 bit result
Decrement counter Counter = 01
A (Lower byte)
Sum = Sum + byte)
C (Higher 15
Sum = 30 + 15
Sum = 45 Decrement counter Counter = 00
channel link :
https://www.youtube.com/c/ComputerScienceAcademy7
54. Write an ALP to multiply two 8 bit data where multiplier is stored at D000 H and
multiplicand stored at D001 H. Store the 16 bit product from memory location D002 H.
Solution:
MVI A, 00 H A = 00 H
D000 H 03 H M
MVI C, 00 H C = 00 H D001 H 8A H M
D002 H 9E H M
LXI H , D000 H B = 03 H
D003 H 01 H M
MOV B, M
INX H M= 8A H A = 00 H 00000000
UP : ADD M + M = 8A H + 10001010
JNC SKIP ------------- --------------------
A = 8A H 1000 10 10 CY = 0
INR C 01 HH
C = 00
C = 00
SKIP: DCR B + M = 8A H + 10001010
00HH
B = 02
01 -------------
JNZ UP --------------------
Jump if B != 00 H A = 14 H 1 000 101 0 0 CY = 1
INX H + M = 8A H + 10001010 C = 01
MOV M, A ------------- --------------------
INX H A = 9E H 100 1 11 1 0 CY = 0
MOV M, C C = 01
HLT
55. Write an ALP to to exchange position of digit of number stored at C040 H. multiply
original number with the exchanged number, the result to be stored at memory
location from C041 H onwards.
Solution: C040 H 40 H M
MVI C, 00 H
C041 H Reg. A M
LXI H, C040 H M = 40 H
C042 H Reg. C M
MOV A, M
RRC A = 40 H
RRC RRC
RRC RRC
RRC RRC
MOV B, A B = 04 H RRC
MVI A, 00 H A = 04 H MOV B, A B = Reverse number
UP : ADD M (counter)
JNC SKIP
INR C
SKIP : DCR B
JNZ UP INX H
INX H MOV M, C
MOV M, A HLT
56. Write an ALP to separate nibbles of a number stored at memory location 2000 H.
Multiply separated nibbles and store result at 2001 H.
Solution: 2000 H 23 H M
LXI H, 2000 H
2001 H 06 H M
MOV A, M
ANI 0F H
MOV B, A A = 23 H
MOV A, M A ^ 0F H = 03 H MOV B, A B = 2nd Nibble
RRC A = 23 H (multiplier /counter)
RRC Four time RRC
RRC A = 32 H
RRC A ^ 0F H = 02 H MOV C, A C = 1st Nibble
ANI 0F H (multiplicand)
MOV C, A
MVI A, 00 H
UP: ADD C INX H
DCR B MOV M, A
JNZ UP HLT
57. Write an ALP that separate the two nibble of an 8 bit hex number stored in memory
location D000 H. Store the same in memory location D001 H and D002 H. The program
must also multiply the two nibble and store the product in memory location D003 H.
Solution: LXI H, D000 H
MOV A, M A = 23 H D000 H 23 H M
MOV C, A C = 23 H D001 H 03 H M
ANI 0F H A = 03 H D002 H 02 H M
MOV B, A B = 03 H
INX H D003 H 06 H M
MOV M, A
MOV A, C A = 23 H
RRC
RRC
RRC
RRC A = 32 H
ANI 0F H A = 02 H
INX H
MOV M, A M = 02 H
MVI A, 00 H INX H
UP: ADD M MOV M, A
DCR B HLT
JNZ UP
58. Write an ALP that multiplies the original number stored at C030 H with its lower
nibble. Store the result starting from C031 H onwards.
Solution:
MVI C, 00 H
LXI H, C030 H F2 H C030 H F2 H M
MOV A, M F 2 C031 H Reg. A M
ANI 0F H Lower Nibble C032 H Reg. C M
A = 02 H
MOV B, A B = 02 H (02 H)
MVI A, 00 H A = 00 H
UP: ADD M
JNC SKIP
INR C
SKIP: DCR B
JNZ UP
INX H
MOV M, A
INX H
MOV M, C
HLT
59. Write an ALP to multiply number stored at 8085 H by 09 H and store result at 8086 H
and 8087 H with lower byte 8086 H.
Solution: (Multiplier) Reg B = 09H
MVI C, 00 H M 8085 H 4B H X 09 H
MVI A, 00 H M 8086 H Reg. A
MVI B, 09 H M 8087 H Reg. C
LXI H, 8085 H
UP: ADD M
JNC SKIP
INR C
SKIP: DCR B
JNZ UP
INX H
MOV M, A
INX H
MOV M, C
HLT
60. Write an ALP to multiply 16 bit number stored at memory location C000 H and C001 H
by 8 bit number stored at memory location C002 H and store product in memory
location from C003 H.
Solution:
MVI C, 00 H 7A93 H C000 H 93 H
LHLD C000 H HL = 7A93 H X 03 H C001 H 7A H
XCHG DE = 7A93 H -------------- C002 H 03 H
C003 H B9 H
LDA C002 H A = 03 H
C004 H 6F H
LXI H, 0000 H HL = 0000 H A = =? 0000 H
HL C005 H 01 H M
UP : DAD D HL = HL + DE
JNC SKIP F526 HH + 7A93 H
7A93
HL = 0000 Carry may generate, C = 00 H
INR C F526 H
HL = 7A93
6FB9 H CY = 01 Get Multiplicand in Reg. Pair DE
SKIP : DCR A A = 02
01 H
00 H C = 00
01 H
H Get Multiplier in Reg. B
A (counter)
JNZ UP Jump if B != 00 H Add DE with HL DAD D Until A B become zero
SHLD C003 H Store 3 byte result
LXI H, C005 H
MOV M, C
HLT
Division of two 8 bit Hexadecimal numbers :
Decimal Division :
Quotient = 3 Remainder = 2
Eg. 11 / 03 = 3.67
• Repeated subtraction is a method of subtracting the equal number of items from a
larger group. It is also known as division.
• If the same number is repeatedly subtracted from another larger number until the
remainder is zero or a number smaller than the number being subtracted, we can
write that in the form of division.
Quotient = 0 (it’s the
(Reg. C =count
00 H)of How many times 2nd number is subtracted from 1st number)
Compare ( CMP M ) if Cy = 0 then continue
Is 11 >= 3 ? If yes, then Is 08 >= 3 ? Is 05 >= 3 ? Is 2 >= 3 ? (CY = 1 )
11 (A) SUB M 08 (A) 05 (A) If No then stop subtraction
- 03 (M) - 03 (M) - 03 (M) Result = ?
-------- -------- -------- Quotient = 3 ( C = 03 H )
08 (A) 05 (A) 02 (A) Remainder = 2 ( A = 02 H )
Quotient = 1 JMP Quotient = 2 JMP Quotient = 3 JMP
INR C C = 01 H INR C C = 02 H INR C C = 03 H
61. Write an ALP that divides two 1 byte Hex number where dividend is store in memory
location C000 H and divisor is stored in memory location C001 H. Store quotient and
remainder in memory location C002 H and C003 H respectively.
Solution: MVI C, 00 H C = 00 H (Quotient ) C000 H 0B H M
LXI H, C000 H C001 H 03 H M
MOV A, M A = 0B H (Dividend) C002 H 03 H M
INX H M = 03 H (Divisor) C003 H 02 H M
UP: CMP M A - M 02 05 - 03 CY = 01
0B
08
JC SKIP
SUB M A = A - M A = 08 05H(Remainder)
02
INR C 02 H
C = 01
03
JMP UP Unconditional Jump
SKIP: INX H
MOV M, C
INX H
MOV M, A
HLT

channel link :
https://www.youtube.com/c/ComputerScienceAcademy7
62. Write an ALP to interchange (swap) the content of memory location 1201 H and 1202 H.
Solution:

LXI H, 1201 H 1201 H 77


FF H M
MOV A, M A = FF H
1202 H FF
77 H M
INX H M = 77 H
MOV C, M C = 77 H
MOV M, A
DCX H
MOV M, C
HLT
63. Write an ALP to arrange the content of memory location 1201 H and 1202 H in
ascending order.
Solution:
LXI H, 1201 H 1201 H 22 H M
MOV A, M A = 22
33 H
INX H 22 H
M = 33
1202 H 33 H M
CMP M A - M 3322 -22
- 33 CY = 10
JC SKIP
MOV C, M C = 22 H 1201 H 33 H
22 M
MOV M, A
1202 H 22
33 H M
DCX H
MOV M, C
SKIP : HLT
64. Write an ALP to count total number of occurrence of data 9C H in a memory block of
length 16 byte starting from 1000 H. store count in register E.
Solution: Block of Length = 16 byte
MVI E, 00 H E = 00 H Counter Reg. B = 10 H
MVI B, 10 H B = 10 H
MVI A, 9C H A = 9C H 1000 H 9C H M
LXI H, 1000 H M = 9C H 1001 H 42 H M
UP : CMP M A-M Z = 10 1002 H 9C H M
JNZ SKIP 1003 H 33 H
.
INR E 02HH
E = 01
.
SKIP : INX H 9CHH
M = 42
.
DCR B 0EH
E = 0F
JNZ UP Jump if B != 00 H
HLT
65. Write an ALP to generate the Fibonacci series for first 8 numbers. Store the series in a
memory block starting from C100 H.
Solution: First 8 numbers of Fibonacci series :
MVI B, ??
06HH 06HH
B = ?? 00 H, 01 H, 01 H, 02 H, 03 H, 05 H, 08 H, 0D H,
MVI A, 00 H A = 00 H (A) + (?) (A)
MVI C, 01 H C = 01 H (A) + (?)
LXI H, C100 H
MOV M, A C100 H 00 H M
C101 H 01 H M
INX H
C102 H 01 H M
MOV M, C C103 H 02 H M
UP : ADD C A = 00
01 ++ 01
01 = 01
02 03H
02 H M
C104 H 03 H
INX H C105 H
MOV M, A C107 H
MOV A, C 01 HH
A = 01 C108 H
MOV C, M C = 01
02HH
DCR B
JNZ UP
HLT
66. Write an ALP to add all odd numbers stored in memory block of 10 locations starting
from 2000 H store 2 byte sum at memory location starting from 3000 H.
Solution: MVI B, 0A H B= 0A H
MVI E, 00 H E = 00 H (Lower byte ) 2000 H 03 H M 3000 H (Reg. E) M
MVI C, 00 H C = 00 H (Higher byte ) 2001 H 06 H M 3001 H (Reg. C) M
LXI H, 2000 H M = 03 H 2002 H 05 H M
UP : MOV A, M 06H
A = 03
05 HH 2003 H 02 H M
RRC (Even)
CY = 110 (Odd) .
(Odd)
JNC SKIP2 .
MOV A, E 03 H
A = E = 00 .
ADD M A = 0003+ +0305==03
08HH
JNC SKIP1 • Here Register A (Accumulator) will be used
INR C C = 00 H to check whether numbers are odd or not as
SKIP1: MOV E, A E = A = 03
08 H well as to store result of addition.
SKIP2: INX H • Use register E to store result of addition.
DCR B B = 09
07
08 H
JNZ UP
LXI H, 3000 H
MOV M, E Note for new program :
INX H To add all Even numbers use JC instead of JNC
MOV M, C after RRC.
HLT
67. A memory block start from 6001 H and its block length count is stored at 6000 H .
Write an ALP to add all even numbers and store 2 byte result at 7000 H onwards.
Solution:
MVI E, 00 H
MVI C, 00 H
LXI H, 6000 H
MOV B, M
UP : INX H
MOV A, M
RRC
JC SKIP2 channel link :
MOV A, E https://www.youtube.com/c/ComputerScienceAcademy7
ADD M
JNC SKIP1
INR C
SKIP1 : MOV E, A
SKIP2 : DCR B
JNZ UP
LXI H, 7000 H
MOV M, E
INX H Note for new program :
MOV M, C To add all Odd numbers use JNC instead of JC
HLT after RRC.
68. Study the following program and answer the questions given below :
MVI C, 08 H ii. Comments
LXI H, 6000 H
MOV A, M MVI C, 08 H Initialize reg. C = 00 H
BACK : RRC LXI H, 6000 H Set HL to 6000 H
DCR C MOV A, M Get number In A from M
JNZ BACK BACK : RRC Rotate A right by 1 bit
INX H DCR C Decrement C by 1
MOV M, A JNZ BACK Jump if Z == 0
HLT INX H Increment HL by 1
i. Write the purpose of the program. MOV M, A Store A to M [(HL)]
ii. Write comments for the instructions used in program. HLT Stop MPU
iii. If the input data at memory locations 6000 H is FF H,
then write the result along with corresponding iii. After Execution of program :
memory locations.
Before Execution After Execution
Solution: i. Purpose of program :
This program will rotate the content of 6000 H FF H 6000 H FF H
memory location 6000 H to right by 1 bit 6001 H 6001 H FF H
position 8 times .
Eventually we will get Same number. and
store this number in next memory location.

You might also like