我正在尝试打印链接列表,当我在主函数中编写孔程序时,它工作正常,但当我尝试将其分离到不同的函数并调用"打印列表&#34时;从主要的,它没有工作
INCLUDE Irvine32.inc
next EQU 4
.data
sundaystr byte 'today sunday ', 0
mondaystr byte 'monday ',0
tuesdaystr byte "tuesday ",0
sunday dword sundaystr
dword monday
dword 0
monday dword mondaystr
dword tuesday
dword sunday
tuesday dword tuesdaystr
dword 0
dword monday
.code
main PROC
push offset sunday
call printList
Exit
main ENDP
printlist PROC
push edx
push esi
push ebp
mov ebp, esp
mov esi, [ebp+12]
print:
mov edx,[esi]
call writestring
add esi, next
cmp [esi], dword ptr 0
je done
mov esi,[esi]
loop print
done:
pop ebp
pop esi
pop edx
ret
printlist endp
END main
答案 0 :(得分:0)
CALL
将EIP
推送到堆栈上,因为RET
需要该信息才能返回。将堆栈指针偏移到访问函数参数时,必须考虑到这一点。
push edx
push esi
push ebp
mov ebp, esp
mov esi, [ebp+12]
在您执行mov esi, [ebp+12]
时,您ebp
的旧值为[ebp+0]
,esi
位于[ebp+4]
,edx
} [ebp+8]
,以及EIP
的旧值[ebp+12]
。
我猜你真的想要你在push offset sunday
推送的地址,你会在[ebp+16]
找到。