8086 program to find sum of digits of 8 bit number
Problem – Write an assembly language program in 8086 microprocessor to find sum of digit of an 8 bit number using 8 bit operation.
Example – Assume 8 bit number is stored at memory location 2050.

Assumptions – Addresses of input data and output data are 2050 and 2051 respectively.
Algorithm –
- Load contents of memory location 2050 in register AL
- Copy content of register AL to register AH
- Assign 0004 to CX Register Pair
- Do AND operation on content of AL with 0F and store result in AL
- Rotate the contents of AH by executing ROL instruction using CX
- Do AND operation on content of AH with 0F and store result in AH
- Add AL and AH content and store result in AL
- Store the content of AL in memory location 2051
Program –
| Memory Address | Mnemonics | Comments |
|---|---|---|
| 400 | MOV AL, [2050] | AL<-[2050] |
| 404 | MOV AH, AL | AH<-AL |
| 406 | MOV CX, 0004 | CX <- 0004 |
| 409 | AND AL, 0F | AL <- AL & 0F |
| 40B | ROL AH, CX | Rotate AH content left by 4 bits(value of CX) |
| 40D | AND AH, 0F | AH <- AH & 0F |
| 40F | ADD AL, AH | AL<-AL+AH |
| 411 | MOV [2051], AL | [2051]<-AL |
| 415 | HLT | Stop Execution |
Explanation –
- MOV AL, [2050]: loads contents of memory location 2050 in AL
- MOV AH, AL: copy content of register AL to register AH
- MOV CX, 0004: assign 0004 to CX register pair
- AND AL, 0F: does AND operation on content of AL with 0F and store result in AL
- ROL AH, CX: rotate the content of AH register left by 4 bits i.e. value of CX register pair
- AND AH, 0F: does AND operation on content of AH with 0F and store result in AH
- ADD AL, AH: add AL and AH content and store result in AL
- MOV [2051], AL: stores the content of AL in 2051 memory address
- HLT: stops executing the program
Recommended Posts:
- 8086 program to find the factorial of a number
- 8086 program to find Square Root of a number
- 8085 program to find sum of digits of 8 bit number
- 8086 program to find the min value in a given array
- 8086 program to find sum of odd numbers in a given series
- 8086 program to find GCD of two numbers and print the GCD
- 8086 program to find sum of Even numbers in a given series
- 8086 program to find average of n numbers
- 8086 program to convert an 8 bit BCD number into hexadecimal number
- 8086 program to find the square root of a perfect square root number | Set-2
- 8086 program to convert 8 bit ASCII to BCD number
- 8086 program to reverse 8 bit number using 8 bit operation
- 8086 program to Print a 16 bit Decimal number
- 8086 program to reverse 16 bit number using 8 bit operation
- 8086 program to search a number in a string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

