【发布时间】:2014-06-09 03:12:13
【问题描述】:
代码如下:
.586
.MODEL FLAT
INCLUDE io.h ; header file for input/output
.STACK 4096
.DATA
prompt1 BYTE "Enter n1", 0
prompt2 BYTE "Enter n2", 0
n1 dword ?
n2 dword ?
gcdp dword ?
remp dword ?
string BYTE 40 DUP (?)
resultLbl BYTE "gcd is:",0
.CODE
_MainProc PROC
input prompt1, string, 40
atod string
mov n1, eax
input prompt1, string, 40
atod string
mov n2, eax
push n2
push n1
call gcd
add esp, 8
dtoa string, eax
output resultLbl, string
mov eax, 0
ret
_MainProc ENDP
gcd PROC
push ebp
mov ebp, esp
push n2
push n1
mov eax, n1
mov gcdp, eax
mov eax, n2
mov remp, eax
L1: mov eax, gcdp
cdq
idiv remp
mov ebx, remp
mov gcdp, ebx
mov remp, edx
cmp edx, 0
jnz L1
mov eax, gcdp
pop ebx
pop edx
pop ebp
ret
gcd ENDP
END
这就是问题所在(正如我的老师所说): “从堆栈中读取参数丢失。请确保您正在使用字节 ptr [ebp+8] 和字节 ptr [ebp+12] 读取 n2 和 n1,您也不必推送 n1、n2 和 pop n1n2在程序中。其余的看起来都很好。”
那么……怎么了?什么需要改变,什么是多余的?
【问题讨论】:
标签: assembly parameters x86 stack greatest-common-divisor