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
||[C] <- 00
||[H-L] <- 
||[A] <- [H]
||[A] <- [A] – [L]
||Jump If no borrow
||[C] <- [C] + 1
||[A] -> , Result
||[A] <- [C]
||[A] -> , Borrow
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
- The program is a simple and efficient way to subtract two 8-bit numbers with or without borrow using the 8085 microprocessor.
- The program uses only a few instructions and requires minimal memory space, making it easy to implement in a microcontroller.
- The program produces accurate results since it handles both with and without borrow conditions using conditional jump and complement instructions.
- The program can be easily modified to subtract larger or smaller numbers by changing the memory addresses.
- The program is specific to the 8085 microprocessor and cannot be used directly on other microprocessors.
- The program assumes that the numbers are stored in consecutive memory locations, which may not always be the case in real-world applications.
- The program does not handle overflow or underflow conditions, which may occur if the difference of two numbers exceeds the maximum or minimum value that can be represented in 8-bit format.
- The program does not provide any error checking or reporting mechanism, which may make it difficult to identify errors or faults in the program.
See for: 8086 program to subtract two 16-bit numbers with or without borrow
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!