Problem – Write an assembly language program in 8085 microprocessor to subtract two 16 bit numbers.
- Starting address of program: 2000
- Input memory location: 2050, 2051, 2052, 2053
- Output memory location: 2054, 2055
INPUT: (2050H) = 19H (2051H) = 6AH (2052H) = 15H (2053H) = 5CH OUTPUT: (2054H) = 04H (2055H) = OEH
Hence we have subtracted two 16 bit numbers.
- Get the LSB in L register and MSB in H register of 16 Bit number.
- Exchange the content of HL register with DE register.
- Again Get the LSB in L register and MSB in H register of 16 Bit number.
- Subtract the content of L register from the content of E register.
- Subtract the content of H register from the content of D register and borrow from previous step.
- Store the result in memory location.
|2000||LHLD 2050||Load H-L pair with address 2050|
|2003||XCHG||EXCHANGE H-L PAIR WITH D-E PAIR|
|2004||LHLD 2052||Load H-L pair with address 2052|
|2007||MVI C, 00||C<-00H|
|2009||MOV A, E||A<-E|
|200E||MOV A, D||A<-D|
|200F||SBB H||SUBTRACT WITH BORROW|
|2013||HLT||TERMINATES THE PROGRAM|
- LHLD 2050: load HL pair with address 2050.
- XCHG: exchange the content of HL pair with DE.
- LHLD 2052: load HL pair with address 2050.
- MOV A, E: move the content of register E to A.
- SUB L: subtract the content of A with the content of register L.
- STA 2054: store the result from accumulator to memory address 2054.
- MOV A, D: move the content of register D to A.
- SBB H: subtract the content of A with the content of register H with borrow.
- STA 2055: store the result from accumulator to memory address 2055.
- HLT: stops executing the program and halts any further execution.
- 8085 program to subtract two 8-bit numbers with or without borrow
- 8086 program to subtract two 16-bit numbers with or without borrow
- 8086 program to subtract two 16 bit BCD numbers
- 8086 program to subtract two 8 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 2-BCD numbers
- 8085 program to add two 16 bit numbers
- 8085 program to add two 8 bit numbers
- 8085 program to multiply two 8 bit numbers
- 8085 program to sum of two 8 bit numbers without carry
- 8085 program to divide two 8 bit numbers
- 8085 program to swap two 8-bit numbers
- 8085 program to add numbers in an array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.