I am a beginner in assembly. This program calculates:
(Z+Z)+(X-Y)
DATA_SEG SEGMENT
X DW 2
Y DW 3
Z DW 5
RES1 DW ?
RES2 DW ?
DATA_SEG ENDS
CODE_SEG SEGMENT
ASSUME CS:CODE_SEG, DS:DATA_SEG
;**********************************************
MAIN PROC FAR ;MAIN PROGRAM STARTS HERE.
MOV AX,DATA_SEG
MOV DS,AX ;INITIALIZING THE DS REGISTER.
; ***FIRST WE CALCULATE (Z+Z) AND SAVE IN RES1****
MOV AX,Z ;
add AX,Z ; AX = Z+Z
MOV RES1,AX ; HOLD TEMPORARILY THE RESULT OF (Z-Z) IN RES1
; ***SECOND WE CALCULATE (Y-X) AND SAVE IN RES2***
MOV AX,Y ; NOW STORE VAR Y IN AX REGISTER
SUB AX,X ; PERFORM AX = Y-X
MOV RES2,AX ; HOLD TEMPORARILY THE RESULT OF (Y-X) IN RES2
; ***NOW ADD BOTH RES1 + RES2***
MOV AX,RES1 ; STORE RESULT OF (Z+Z) IN AX REGISTER
ADD AX,RES2 ; ADD RES1 + RES2
;****NOW FOR PRINTING WE MOVE THE VALUE IN DX REGISTER****
MOV DX,AX ; tO PRINT WE FIRST MOVE DATA IN DX REGISTER
ADD DX,30H ;CONVERT TO ACSII CODE
MOV AH,2
INT 21H
MOV AH,04CH
INT 21H
MAIN ENDP
CODE_SEG ENDS
END MAIN
(Z-Z)+(X-Y)
why bother withZ
? It's always going to be simplyX-Y
, right? \$\endgroup\$