为什么这个循环的结果是 20 而不是 120?
ORG 100H
facto dw ?
START:
MOV CX, 5
MOV AX, 5
DEC CX
repeat :
MUL CX
MOV facto , AX
LOOP repeat
ENDS
END START :
为什么这个循环的结果是 20 而不是 120?
ORG 100H
facto dw ?
START:
MOV CX, 5
MOV AX, 5
DEC CX
repeat :
MUL CX
MOV facto , AX
LOOP repeat
ENDS
END START :
该代码工作正常,尽管有一些不需要的命令。这是在 FASM 中进行测试的完整代码。您会看到我将 mov cx, 5 和 dec cx 合并到 mov cx, 4 中,并将赋值从 ax 移到 facto 远离循环以避免不必要的代码执行。
format PE console
entry main
include '%INCLUDE%/win32a.inc'
section '.data' data readable writeable
facto dd 0
section '.text' code readable executable
main:
mov ecx, 4
mov eax, 5
L0:
mul ecx
loop L0
mov [facto], eax
invoke ExitProcess, eax
section '.idata' data import readable
library kernel32,'kernel32.dll'
import kernel32,\
ExitProcess,'ExitProcess'