, , AL, . ADD AL , DAA ().
, , , :
; Set the segment register 'DS' to the constant value 'DATA'
; (indirectly via 'AX', since you can't move an immediate into a segment register).
MOV AX, DATA
MOV DS, AX
; Put the constant values 'N1' and 'N2' into the 'AX' and 'BX' registers, respectively.
MOV AX, N1
MOV BX, N2
; Add the lower 8 bits of 'BX' to the lower 8 bits of 'AX'.
ADD AL, BL
; Using the results of that last addition ('AL' and flags),
; adjust for packed binary-coded decimal arithmetic.
DAA
; Save the result (from 'AL') in 'CL' (since 'AL' is about to be clobbered).
MOV CL, AL
; Having just done the low 8 bits of 'AX' ('AL'), we are now going to do
; the high 8 bits ('AH'). But because the DAA instruction uses 'AL'
; as an implicit operand, we first need to swap 'AL' and 'AH'.
MOV AL, AH
ADD AL, BH
DAA
; Just like we saved the result of the low 8 bits in 'CL',
; save the result of the high 8 bits in 'CH'.
MOV CH, AL
; Now, the result is in 'CX' (low byte in 'CL', high byte in 'CH'),
; so store/save it into the WORD-sized variable 'BCD_SUM'.
MOV BCD_SUM, CX
; Call DOS interrupt to terminate the process.
;
; Note that there is a bug here: you should be setting the 'AL' register
; to the process return code. You could do this explicitly with a
; 'MOV AL, ReturnCode' instruction, or you could just do
; 'MOV AX, 4C00h' to set both halves at once.
MOV AH, 4CH
INT 21H
, , . WORD AX BX, - ( 8 ) BYTE. , WORD BCD_SUM, CX .
, , -, . , - , :
ADD AH, BH ; add high bytes first
MOV AL, AH ; swap order of bytes
DAA ; adjust result of addition, now in AL
, . , .
( ), ADD DAA back-to-back. ? DAA , ADD ( , AF). MOV , , ADD DAA , .
, , . , .