Code:
; Program to sub two 16 bit BCD number
.MODEL SMALL
.STACK 100
.DATA
NUM1 DW 9000H
NUM2 DW 0999H
RES DW 0
.CODE
MOV AX , @DATA ; Initialize Data Segment
MOV DS , AX
MOV AL , BYTE PTR NUM1 ; Load 1st 8 bit number
SUB AL , BYTE PTR NUM2 ; Substract LSB first
DAS ;Decimal Adjust After Substraction
MOV BYTE PTR RES , AL ; Store first 8 bit result
MOV AL , BYTE PTR NUM1 + 1 ; Load last 8 bit number
SUB AL , BYTE PTR NUM2 + 1 ; Substract MSB 8 bits
DAS ; Decimal Adjust After Substraction
MOV BYTE PTR RES+1 , AL ; Store Result
MOV AH , 4CH ; Intrupt for exit
INT 21H
END
Ouput:
; Program to sub two 16 bit BCD number
.MODEL SMALL
.STACK 100
.DATA
NUM1 DW 9000H
NUM2 DW 0999H
RES DW 0
.CODE
MOV AX , @DATA ; Initialize Data Segment
MOV DS , AX
MOV AL , BYTE PTR NUM1 ; Load 1st 8 bit number
SUB AL , BYTE PTR NUM2 ; Substract LSB first
DAS ;Decimal Adjust After Substraction
MOV BYTE PTR RES , AL ; Store first 8 bit result
MOV AL , BYTE PTR NUM1 + 1 ; Load last 8 bit number
SUB AL , BYTE PTR NUM2 + 1 ; Substract MSB 8 bits
DAS ; Decimal Adjust After Substraction
MOV BYTE PTR RES+1 , AL ; Store Result
MOV AH , 4CH ; Intrupt for exit
INT 21H
END