Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

8085 program to subtract two 8-bit numbers with or without borrow

  • Difficulty Level : Basic
  • Last Updated : 22 May, 2018

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 –

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.


Algorithm –

  1. Load 00 in a register C (for borrow)
  2. Load two 8-bit number from memory into registers
  3. Move one number to accumulator
  4. Subtract the second number with accumulator
  5. If borrow is not equal to 1, go to step 7
  6. Increment register for borrow by 1
  7. Store accumulator content in memory
  8. Move content of register into accumulator
  9. Store content of accumulator in other memory location
  10. Stop

Program –

2000MVIC, 00[C] <- 00
2002LHLD2500[H-L] <- [2500]
2005MOVA, H[A] <- [H]
2006SUBL[A] <- [A] – [L]
2007JNC200BJump If no borrow
200AINRC[C] <- [C] + 1
200BSTA2502[A] -> [2502], Result
200EMOVA, C[A] <- [C]
2010STA2503[A] -> [2503], Borrow

Explanation – Registers A, H, L, C are used for general purpose:

  1. MOV is used to transfer the data from memory to accumulator (1 Byte)
  2. LHLD is used to load register pair directly using 16-bit address (3 Byte instruction)
  3. MVI is used to move data immediately into any of registers (2 Byte)
  4. STA is used to store the content of accumulator into memory(3 Byte instruction)
  5. INR is used to increase register by 1 (1 Byte instruction)
  6. JNC is used to jump if no borrow (3 Byte instruction)
  7. SUB is used to subtract two numbers where one number is in accumulator(1 Byte)
  8. HLT is used to halt the program

See for: 8086 program to subtract two 16-bit numbers with or without borrow

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!