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   ;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s