Saturday, September 12, 2009

Subtract two 16-bit numbers(8085)



Statement: Subtract the 16-bit number in memory locations 4002H and 4003H from the 16-bit number in memory locations 4000H and 4001H. The most significant eight bits of the two numbers are in memory locations 4001H and 4003H. Store the result in memory locations 4004H and 4005H with the most significant byte in memory location 4005H.
Sample problem
(4000H) = 19H
(400IH) = 6AH
(4004H) = I5H (4003H) = 5CH
Result = 6A19H - 5C15H = OE04H
(4004H) = 04H
(4005H) = OEH
Source program:
LHLD 4000H : Get first 16-bit number in HL
XCHG : Save first 16-bit number in DE
LHLD 4002H : Get second 16-bit number in HL
MOV A, E : Get lower byte of the first number
SUB L : Subtract lower byte of the second number
MOV L, A : Store the result in L register
MOV A, D : Get higher byte of the first number
SBB H : Subtract higher byte of second number with borrow
MOV H, A : Store l6-bit result in memory locations 4004H and 4005H.
SHLD 4004H : Store l6-bit result in memory locations 4004H and 4005H.
HLT : Terminate program execution

6 comments:

  1. i guess this must be the answer (4005H) = OEH, Please check it out.

    ReplyDelete
  2. i need 16 bit divison using 8085

    ReplyDelete
  3. What if the result is negetive? Should we need to set a carry flag in that case?

    ReplyDelete
  4. plz post sutraction of 2 8 bit BCD numbers if carry not present using 10s complement

    ReplyDelete
  5. plz post sutraction of 2 8 bit BCD numbers if carry not present using 10s complement

    ReplyDelete