如何將參數傳遞給Assembly中的函數? 我沒有推最後帕拉姆,推動二帕拉姆,推第一個參數..ASM x86中的函數參數FASM
但我不能Meh
功能中訪問參數..我在做什麼導致程序崩潰..
format PE console ;Format PE OUT GUI 4.0
entry main
include 'macro/import32.inc'
section '.idata' import data readable ;Import Section.
library msvcrt,'msvcrt.dll'
import msvcrt, printf, 'printf',\
exit,'exit', getchar, 'getchar'
section '.data' data readable writeable ;Constants/Static Section.
InitialValue dd 0
section '.code' code readable executable
main:
push 67
push 66
push 65
call MEH
call [getchar]
mov eax, 0
ret 0
MEH:
push ebx
mov ebp, esp
sub esp, 0
mov eax, [ebp + 8] ; Trying to print first parameter..
push eax
call [printf]
add esp, eax
mov esp, ebp
pop ebx
ret
我刪除了子esp,0和添加esp,eax ..它仍然崩潰,但是:l它不打印65這是字符A. – Brandon
我從來沒有使用msvcrt從asm,但我有一種感覺您沒有正確調用printf - c運行時函數通常使用cdecl調用約定。您可能想要查看此問題的線索:http://stackoverflow.com/questions/3902697/x86-masm-hello-world –
我認爲這是調用正確..當我這樣做: mov eax,65 push eax call [printf] pop eax 它打印字符A. – Brandon