Tuesday, June 26, 2012

49. 16 & 32-BIT SUBTRACTIONS IN 8086



16-BIT SUBTRACTION

DATA SEGMENT
NUM DW 4567H,2345H
DIF DW 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME
CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
CLC
                              
LEA SI,NUM                           
MOV AX,[SI]                          
SBB AX,[SI+2]                        
MOV DIF,AX                                    
MOV AH,4CH
INT 21H
CODE ENDS
END START


INPUT: 4567H,2345H
OUTPUT:2222


32-BIT SUBTRACTION

DATA SEGMENT
NUM1 DW 2345H,6762H
NUM2 DW 1111H,1111H
DIF DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
LEA SI,NUM1
LEA DI,NUM2
MOV AX,[SI]
MOV BX,[DI]
SUB AX,BX
MOV DIF,AX
INC SI
INC SI
INC DI
INC DI
MOV AX,[SI]
MOV BX,[DI]
SBB AX,BX MOV DIF+2,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START

INPUT: 23456762,-11111111
OUTPUT:12345651

INPUT:11111111,-23451234
OUTPUT:EDCBFEDD