所以我正在尝试编写一个非递归的阶乘过程使用循环指令,该参数通过运行时堆栈传递。
我还需要主 PROC 中的指令序列来调用阶乘过程。任何人都想帮助我完成这部分,这是我到目前为止所拥有的。
.IF eax == 0 || eax == 1 ;special cases
mov eax, 1 ;factorial == 1
jmp L2 ;quit procedure
.ELSEIF eax > 12 ;n is too large
mov edx, OFFSET msgError
call Crlf
call WriteString
jmp L2 ;quit procedure
.ENDIF
mov ecx, eax ;ecx = counter
L1:
dec ecx ;ecx = n - 1
mul ecx ;eax = n * (n - 1)
cmp ecx, 1 ;is counter > 1?
ja L1 ;true? then continue
L2:
ret
nonRecurFact ENDP