# 8085 program to find sum of digits of 8 bit number

• Last Updated : 22 May, 2018

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 –

1. Load value stored at memory location 2050 in accumulator A
2. Move the value of accumulator A in register B
3. 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
4. Move the value of accumulator A in register C
5. Move the value of register B in accumulator A
6. 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
7. Add value of register C in accumulator A
8. Store the value of A in memory location 3050

Program –

2000LDA 2050A <- M
2003MOV B, AB <- A
2004ANI 0FA <- A (AND) 0F
2006MOV C, AC <- A
2007MOV A, BA <- B
2008RLCRotate left without carry
2009RLCRotate left without carry
200ARLCRotate left without carry
200BRLCRotate left without carry
200CANI 0FA <- A (AND) 0F
200EADD CA <- A + C
200FSTA 3050M <- A
2012HLTEND

Explanation – Registers used A, B, C

1. LDA 2050 –loads the content of memory location 2050 in accumulator A
2. MOV B, A –moves the value of accumulator A in register B
3. ANI 0F –performs AND operation in value of accumulator A and 0F
4. MOV C, A –moves the value of accumulator A in register C
5. MOV A, B –moves the value of register B in accumulator A
6. 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
7. Repeat step 3
8. ADD C –add the content of register of C in accumulator A
9. STA 3050 –stores value of A in 3050
10. HLT –stops executing the program and halts any further execution
My Personal Notes arrow_drop_up