01
Program 1¶
Add two 2-digit hexadecimal numbers (method 1)
DATA SEGMENT
ORG 1000H
NUM1 DB 89H
NUM2 DB 7CH
RES DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AH, 0
MOV AL, NUM1
ADD AL, NUM2
ADC AH, 0
MOV RES, AX
INT 3
CODE ENDS
END START
Program 2¶
Add two 2-digit hexadecimal numbers (method 2)
.model small
.stack 20
.data
org 1000H
num1 DB 80H
num2 DB 86H
res DW ?
.code
start:
mov ax, @data
mov ds,ax
mov ah,0
mov al,num1
add al,num2
adc ah,0
mov res,ax
int 3
end start
Program 3¶
Write a program to add two 2-digit decimal numbers available in memory and store the result in memory.
\[ 89+78 = 167 \]
DATA SEGMENT
ORG 1000H
NUM1 DB 89H
NUM2 DB 78H
RES DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AH, 0
MOV AL, NUM1
ADD AL, NUM2
DAA
ADC AH, 0
MOV RES, AX
INT 3
CODE ENDS
END START
Program 4¶
The above program without H in the input Data
This gives wrong answer cuz we do DAA, even though the stored values are decimal
DATA SEGMENT
ORG 1000H
NUM1 DB 89
NUM2 DB 78
RES DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AH, 0
MOV AL, NUM1
ADD AL, NUM2
DAA
ADC AH, 0
MOV RES, AX
INT 3
CODE ENDS
END START
DAA
¶
DAA corrects the result of a previous addition of two valid packed decimal operands (note that this result must be in AL). This instruction changes the content of AL so that it will contain a pair of valid packed decimal digits.