Can't pass parameter from C to Assembly code -
from understand, when parameter passed in function phone call in c, callee can find first parameter @ [ebp+8]
. returning value through eax
works me, reading right parameter value stack doesn't.
right i'm trying write assembly function, can called c , returns same value, beingness passed.
when run next program, prints number: 1
console, no matter value passed myfunc
. doing wrong?
assembly.s
section .text global _myfunc _myfunc: mov eax, [ebp+8] ret
main.c
#include <stdio.h> extern unsigned int myfunc(unsigned int somedata); int main() { unsigned int = myfunc(6); printf("number: %i\n",i); homecoming 0; }
i'm using mac, nasm assemble code , gcc c compilation.
makefile
macho32: nasm -f macho32 assembly.s gcc -m32 -o macho32 assembly.o main.c
you refer argument on stack, reading [ebp+offset] - has ebp been set point @ stack? if no, may have first, conventionally done by:
push ebp mov ebp,esp
only points ebp stacked previous contents, below stacked homecoming address, , below passed arguments.
c assembly nasm
No comments:
Post a Comment