我是Winx64上Assembly的新程序员。我正在尝试建立代码,以使用Assembly编程中的基本算术将一个数组的值划分为另一个数组的值。我无法完成的实验是:
这是我尝试实现的代码(已放置在Hyper-V虚拟机中,对我最终遇到的缩进效果感到抱歉):
TITLE DISPLAY
.MODEL SMALL
.386
.STACK
.DATA
S EQU 12 ;size of arrays
X BYTE 4, 16, 100, -116, -68, -104, 125, 60, 99, 33, 55, 77
Y BYTE 2, 3, 4, -5, -6, -7, -8, -9, -10, 11, 12, 13
Q BYTE 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ;quotient = X/Y
R BYTE 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ;remainder = X/Y
;Address of X is _______:_______
;Address of Y is _______:_______
;Address of Q is _______:_______
;Address of R is _______:_______
.CODE
MAIN PROC FAR
.STARTUP
;Program
MOV ESI, 0 ;use ESI and index to arrays
MOV CX, S ;counter for loop
L1: MOV AX, 0 ;clear the AX register
MOV AL, [X+ESI] ;load dividend
MOV BL, [Y+ESI]
MOV DX, 0 ;clear the DX register
IDIV AX ;divide X by Y
MOV [Q+ESI], EAX ;store quotient in Q
INC ESI ;increment index by 1
LOOP L1
.EXIT
MAIN ENDP
END
我遇到的第一个问题是第29行的错误为A2070:无效的指令操作数。第二个问题是,我不确定代码的整体以及错误是否正确。我相信我可以在调试器的内存中找到X和Y的值(特别是Q和R的值),但是我在首先汇编此代码时遇到了麻烦。
这里也是一个Excel,除了Q和R的期望值。
好。由fuz发现的问题是我没有正确存储商。
TITLE DISPLAY
.MODEL SMALL
.386
.STACK
.DATA
S EQU 12 ;size of arrays
X BYTE 4, 16, 100, -116, -68, -104, 125, 60, 99, 33, 55, 77
Y BYTE 2, 3, 4, -5, -6, -7, -8, -9, -10, 11, 12, 13
Q BYTE 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ;quotient = X/Y
R BYTE 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ;remainder = X/Y
;Address of X is _______:_______
;Address of Y is _______:_______
;Address of Q is _______:_______
;Address of R is _______:_______
.CODE
MAIN PROC FAR
.STARTUP
;Program
MOV ESI, 0 ;use ESI and index to arrays
MOV CX, S ;counter for loop
L1: MOV AX, 0 ;clear the AX register
MOV AL, [X+ESI] ;load dividend
MOV BL, [Y+ESI]
MOV DX, 0 ;clear the DX register
IDIV AX ;divide X by Y
MOV [Q+ESI], AL ;store quotient in Q
INC ESI ;increment index by 1
LOOP L1
.EXIT
MAIN ENDP
END