Q. Write an 8085 program and draw a flowchart to Subtract two 16-bit numbers without considering the borrow.(8085 Microprocessor Program)
|2000||LHLD||3000H||2A||Load H-L pair with 1st operand from 3000H.|
|2003||XCHG||EB||Exchange H-L pair with D-E pair.|
|2004||LHLD||3002H||2A||Load H-L pair with 2nd operand from 3002H.|
|2007||MOV||A, E||7B||Move the lower-order of 1st number from reg. E to reg. A.|
|2008||SUB||L||95||Subtract the lower-order of 2nd number from lower-order of 1st number.|
|2009||MOV||L, A||6F||Move the result from reg. A to register L.|
|200A||MOV||A, D||7A||Move the higher-order of 1st number from reg. D to reg. A.|
|200B||SBB||H||9C||Subtract the higher-order of 2nd number from higher-order of 1st number with borrow from the previous subtraction.|
|200C||MOV||H, A||67||Move the result from reg. A to reg. H.|
|200D||SHLD||3004H||22||Store the 16-bit result from H-L pair to memory.|
- This program subtracts two 16-bit operands stored in memory locations 3000H-3001H and 3002H-3003H, without considering the borrow taken (if any).
- Let us assume that the operands stored at memory locations 3000H-3001H is 08H-06H and 3002H-3003H is 05H-04H.
- The H-L pair is loaded with the first 16-bit operand 0806H from memory locations 3000H- 3001H.
- Then, the first 16-bit operand is moved to D-E pair.
- The second 16-bit operand 0504H is loaded to H-L pair from memory locations 3002H- 3003H.
- The lower-order of the first number is moved from register E to accumulator.
- The lower-order of 2nd number in register L is subtracted from lower-order of 1st number in the accumulator.
- The result of the subtraction is moved from the accumulator to register L.
- Then, the higher-order of 1st number is moved from register D to accumulator.
- The higher-order of 2nd number in register H is subtracted from higher-order of the first number in the accumulator, along with the borrow from the previous subtraction.
- The result of the subtraction is moved from the accumulator to register H.
- Now, the final result is in H-L pair.
- The result is stored from H-L pair to memory locations 3004H-3005H.