Search This Blog

Monday, April 4, 2011

Program to Subtract 2 16 bit numbers


; 2000H = 21H
; 2001H = 12H
; 2002H = 21H
; 2003H = 43H
; RESULT = 1221H - 4321H
; = 3100H
; 2004H = 00H LOWER 2 BYTES
; 2005H = 31H HIGHER 2 BYTES


LHLD 2000H ; LOAD FIRST 16 BIT INTO HL PAIR H=12H L=21H
XCHG   ; SAVE IT IN DE PAIR
LHLD 2002H ; LOAD SECOND 16 BIT INTO HL PAIR H=21H L=43H
MOV A, E   ; LOAD LOWER BYTE OF FIRST NUMBER IN ACCUMULATOR
SUB L   ; SUBTRACT 2 LOWER BYTES
MOV L, A   ; STORE RESULT
MOV A, D   ; LOAD HIGHER BYTE INTO ACCUMULATOR
SBB H   ; SUBTRACT HIGHER BYTE OF SECOND NUMBER WITH BORROW OF PREVIOUS SUBTRACTION
MOV H, A   ; A = A - H - CY
SHLD 2004H ; STORE RESULT
HLT   ;

10 comments:

  1. Fine & simple . If subtrahend is greater than minuend how can we get the result?

    ReplyDelete
  2. Replies
    1. Sorry not familiar with the acronym BOGAS....

      Delete
  3. Replies
    1. There are no standard orientation in assembly coding... Everything is shown in portrait...
      I dont get what you mean by orientation...

      Delete
  4. Please add the program for carry. if carry is come.
    Please add carry

    ReplyDelete