我正在尝试编写一个程序,将两个 32 位数字相加和相减,并将和和差存储在内存中。我没有任何输出,只是通过调试器得到结果。
这是我的代码。
;---------------------------------------------------------;
;**********************************************************
STACK SEGMENT PARA STACK 'STACK'
DB 64 DUP('STACK')
STACK ENDS
;**********************************************************
DSEG SEGMENT PARA PUBLIC 'DATA'
X1 DD 4967290
X2 DD 4967295
SUM DD ?
DIFF DD ?
DSEG ENDS
;**********************************************************
;---------------------------------------------------------
CSEG SEGMENT PARA PUBLIC 'CODE'
OUR_PROG PROC FAR
ASSUME CS:CSEG, DS:DSEG, SS:STACK
; Set up the stack to contain the proper values
; so this program can return to debug.
;
PUSH DS ; Put return seg. addr on stack
MOV EAX,0 ; Clear a register EAX
PUSH EAX ; Put zero return address on stack
; Initialize the data segment address
MOV EAX,DSEG ;Initialize DS
MOV DS,AX
; -------------------------------------------------------------
; Perform the addition
;
MOV EAX,X1 ; Load 32 bit variable in X1 to reg AX
MOV EBX,X2 ; Load 32 bit variable in X2 to reg BX
ADD EAX,EBX ; Add data in registers AX and BX, store in AX
; Store the sum in memory
;
MOV SUM,EAX ; Store the result at mem loc SUM
; -------------------------------------------------------------
; Perform the subtraction
MOV EAX,X1 ; Reload first word to reg EAX
CMP EAX,EBX ; Compare values of X1 and X2 stored in registers EAX and EBX
JL .SWAPSUB ; If EBX is greater than EAX, jump to SWAPSUB
JL .NOSWAP ; If '' , jump past other sub section
.SWAPSUB: ;Jump point to swap values
XCHG EAX,BX ; Swap values of EAX and EBX
.NOSWAP:
SUB EAX,EBX ; Subtract EBX from EAX
MOV DIFF,EBX ; Store the result at mem loc DIFF
RET ; Retrurn to DEBUG
OUR_PROG ENDP
CSEG ENDS
END OUR_PROG
;**********************************************************
我对 Assembly 了解不多,但我正在使用 DOSBOX、MASM 5.10 和链接器程序来构建我的代码。
我似乎遇到的问题是,当我尝试构建我的代码时,它会这么说EAX
并且EBX
没有定义。它还说明了我对orIllegal size for operand
的每个MOV
调用。SUM
DIFF
谁能告诉我我做错了什么或更简单的方法?我一直试图弄清楚几个小时,但进展甚微。
谢谢!