Q. Write an 8085 program and draw a flowchart to Subtract two 16-bit numbers along with considering the borrow.(8085 Microprocessor Program)
Flowchart/Algorithm
Program
Address | Mnemonics | Operand | Opcode | Comments |
2000 | LHLD | 3000 H | 2A | Load H-L pair with data from 3000H |
2001 | 00 | |||
2002 | 30 | |||
2003 | XCHG | EB | Exchange data from H-L pair with D-E | |
2004 | LHLD | 3002 H | 2A | Load H-L pair with data from 3002 H |
2005 | 02 | |||
2006 | 30 | |||
2007 | MVI | B, 00 H | 06 | Move 0 H to B |
2008 | 00 | |||
2009 | MVI | C, 00 H | 0E | Move 0 H to C |
200A | 00 | |||
200B | MOV | A, E | 7B | Move lower order of 1st no. to A |
200C | SUB | L | 95 | Subtract lower order L from A |
200D | JNC | 2011 H | D2 | Jump to2011 H if there is no borrow |
200E | 0F | |||
200F | 20 | |||
2010 | INR | C | 0C | If borrow, then increment C |
2011 | MOV | E, A | 5F | Move lower order back to E |
2012 | MOV | A, D | 7A | Move higher order of 1st no. to A |
2013 | SUB | C | 91 | First, subtract borrow from A |
2014 | SUB | H | 94 | Now, subtract higher order from A |
2015 | JNC | 2019 H | D2 | Jump to 2019 H if there is no borrow |
2016 | 19 | |||
2017 | 20 | |||
2018 | INR | B | 04 | If borrow, increment B |
2019 | MOV | D, A | 57 | Move higher order back to D |
201A | XCHG | EB | Exchange the result from D-E with H-L | |
201B | SHLD | 3004 H | 22 | Store the result at location 3004 H |
201C | 04 | |||
201D | 30 | |||
201E | MOV | A, B | 78 | Move borrow to A |
201F | STA | 3006 H | 32 | Store borrow at location 3006 H |
2020 | 06 | |||
2021 | 30 | |||
2022 | HLT | 76 | Halt |
Output
Before Execution:
3000: 02 H
3001: 02 H
3002: 04 H
3003: 04 H
After Execution:
3004: FE H
3005: FD H
3006: 01 H
The result is in 2’s complement form.