8085 program to find sum of digits of 8 bit number

MicrocontrollerMicroprocessor8085

In this program we will see how to add the digits of an 8-bit number.

Problem Statement

Write 8085 Assembly language program to add the digits of an 8-bit number stored in memory location 8000H.

Discussion

To get the digits of an 8-bit number, we can use the masking operation. At first we will mask the upper nibble, and then the lower nibble. After masking the lower nibble, we have to rotate it to the right to make it least significant nibble. Then we can simply add it to the stored nibble to get the sum.

Input

Address
Data
...
...
8000
8A
...
...

Program

Address
HEX Codes
Mnemonics
Comments
F000
3A, 00, 80
LDA 8000H
Load the number into A
F003
4F
MOV C, A
Copy the number to C
F004
E6, 0F
ANI 0FH
Take the lower nibble
F006
47
MOV B, A
Store the result into B
F007
79
MOV A, C
Restore the actual number
F008
E6, F0
ANI F0
Take the upper nibble
F00A
0F
RRC
Rotate the bits four times
F00B
0F
RRC


F00C
0F
RRC


F00D
0F
RRC


F00E
80
ADD B
Add A with B
F00F
32, 50, 80
STA 8050H
Store the result at 8050H
F012
76
HLT
Terminate the program


Output

Address
Data
...
...
8050
12
...
...
raja
Published on 22-Jan-2019 10:01:00
Advertisements