8085 program to subtract two 8-bit numbers with or without borrow
Problem – Write a program to subtract two 8-bit numbers with or without borrow where first number is at 2500 memory address and second number is at 2501 memory address and store the result into 2502 and borrow into 2503 memory address.
Example –

Algorithm –
- Load 00 in a register C (for borrow)
- Load two 8-bit number from memory into registers
- Move one number to accumulator
- Subtract the second number with accumulator
- If borrow is not equal to 1, go to step 7
- Increment register for borrow by 1
- Store accumulator content in memory
- Move content of register into accumulator
- Store content of accumulator in other memory location
- Stop
Program –
| Memory | Mnemonics | Operands | Comment |
|---|---|---|---|
| 2000 | MVI | C, 00 | [C] <- 00 |
| 2002 | LHLD | 2500 | [H-L] <- [2500] |
| 2005 | MOV | A, H | [A] <- [H] |
| 2006 | SUB | L | [A] <- [A] – [L] |
| 2007 | JNC | 200B | Jump If no borrow |
| 200A | INR | C | [C] <- [C] + 1 |
| 200B | STA | 2502 | [A] -> [2502], Result |
| 200E | MOV | A, C | [A] <- [C] |
| 2010 | STA | 2503 | [A] -> [2503], Borrow |
| 2013 | HLT | Stop |
Explanation – Registers A, H, L, C are used for general purpose:
- MOV is used to transfer the data from memory to accumulator (1 Byte)
- LHLD is used to load register pair directly using 16-bit address (3 Byte instruction)
- MVI is used to move data immediately into any of registers (2 Byte)
- STA is used to store the content of accumulator into memory(3 Byte instruction)
- INR is used to increase register by 1 (1 Byte instruction)
- JNC is used to jump if no borrow (3 Byte instruction)
- SUB is used to subtract two numbers where one number is in accumulator(1 Byte)
- HLT is used to halt the program
See for: 8086 program to subtract two 16-bit numbers with or without borrow
Recommended Posts:
- 8085 program to subtract two 16-bit numbers with or without borrow
- 8086 program to subtract two 16-bit numbers with or without borrow
- 8086 program to subtract two 8 bit BCD numbers
- 8086 program to subtract two 16 bit BCD numbers
- 8085 program to count total even numbers in series of 10 numbers
- 8085 program to count total odd numbers in series of 10 numbers
- Subtract content of two ports by interfacing 8255 with 8085 microprocessor
- 8085 program to add two 16 bit numbers
- 8085 program to add 2-BCD numbers
- 8085 program to add two 8 bit numbers
- 8085 program to multiply two 8 bit numbers
- 8085 program to divide two 8 bit numbers
- 8085 program to divide two 16 bit numbers
- 8085 program to multiply two 16-bit numbers
- 8085 program to sum of two 8 bit numbers without carry
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.

