8085 program to find sum of digits of 8 bit number
Problem – Write an assembly language program in 8085 microprocessor to find sum of digit of an 8 bit number.
Example –
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

Assumptions – Addresses of input data and output data are 2050 and 3050 respectively.
Algorithm –
- Load value stored at memory location 2050 in accumulator A
- Move the value of accumulator A in register B
- Perform masking of nibbles i.e. do AND operation of accumulator A with OF by help of ANI instruction. We will get lower nibble value in accumulator A
- Move the value of accumulator A in register C
- Move the value of register B in accumulator A
- Reverse the number which is stored in accumulator A by using RLC instruction 4 times and again do masking of nibbles as done in step 3
- Add value of register C in accumulator A
- Store the value of A in memory location 3050
Program –
| MEMORY ADDRESS | MNEMONICS | COMMENT |
|---|---|---|
| 2000 | LDA 2050 | A <- M[2050] |
| 2003 | MOV B, A | B <- A |
| 2004 | ANI 0F | A <- A (AND) 0F |
| 2006 | MOV C, A | C <- A |
| 2007 | MOV A, B | A <- B |
| 2008 | RLC | Rotate left without carry |
| 2009 | RLC | Rotate left without carry |
| 200A | RLC | Rotate left without carry |
| 200B | RLC | Rotate left without carry |
| 200C | ANI 0F | A <- A (AND) 0F |
| 200E | ADD C | A <- A + C |
| 200F | STA 3050 | M[3050] <- A |
| 2012 | HLT | END |
Explanation – Registers used A, B, C
- LDA 2050 –loads the content of memory location 2050 in accumulator A
- MOV B, A –moves the value of accumulator A in register B
- ANI 0F –performs AND operation in value of accumulator A and 0F
- MOV C, A –moves the value of accumulator A in register C
- MOV A, B –moves the value of register B in accumulator A
- RLC –instruction rotate the value of accumulator A, left by 1 bit. Since it is performed 4 times therefore this will reverse the number i.e swaps the lower order nibble with higher order nibble
- Repeat step 3
- ADD C –add the content of register of C in accumulator A
- STA 3050 –stores value of A in 3050
- HLT –stops executing the program and halts any further execution



