Is this line needed in the next Assembly program?

I am new to ALP, and looking at this program, I found a line that I think is not needed, and you can simply delete it by changing a few lines.

Here is the code:

DATA SEGMENT
  N1 DW 2804H
  N2 DW 4213H
  BCD_SUM DW ?
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
  MOV DS, AX
  MOV AX, N1
  MOV BX, N2
  ADD AL, BL
  DAA
  MOV CL, AL
  MOV AL, AH    ; Here I have Problem
  ADD AL, BH
  DAA
  MOV CH, AL
  MOV BCD_SUM, CX
  MOV AH, 4CH
  INT 21H
CODE ENDS
END START

Why not just add ah, bh?
Moving a higher byte in AXto decrease and then adding, is there a reason for this or can I just change it?

+4
source share
1 answer

, , 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 , .

, , . , .

+3

Source: https://habr.com/ru/post/1675225/


All Articles