Calling Asm functions from C, how to?
Posted: Wed Aug 27, 2008 5:30 am
Hello everyone,
I am using Cygwin under windows vista and programming in nasm and gcc (c, c++).
I wrote successfully an bootsector, enabled the A20 gate and switched to Pmode
with a GDT. That is all working. But now my question: Some functions I want to
write in assembler, assemble it with nasm to an elf32-file and using the linker ld to
link it with the other files. IMO first the arguments from right to left where pushed
on the stack (Every Arg 4 bytes aligned). then the address to return is pushed and at
least ebp will be pushed on the stack. Then there is a jump to the function. So if I
programm a function in asm, the initially things are coded in the calling function, right?
But what I must do to do a return successfully? I mean, what does the calling function
and what I have to do. Have I only to do pop ebp and then make a return? Or Have I to
free the parameteres too?
The Stack of my function I must free myself, that's clear. ^^
TIA Sebihepp
I am using Cygwin under windows vista and programming in nasm and gcc (c, c++).
I wrote successfully an bootsector, enabled the A20 gate and switched to Pmode
with a GDT. That is all working. But now my question: Some functions I want to
write in assembler, assemble it with nasm to an elf32-file and using the linker ld to
link it with the other files. IMO first the arguments from right to left where pushed
on the stack (Every Arg 4 bytes aligned). then the address to return is pushed and at
least ebp will be pushed on the stack. Then there is a jump to the function. So if I
programm a function in asm, the initially things are coded in the calling function, right?
But what I must do to do a return successfully? I mean, what does the calling function
and what I have to do. Have I only to do pop ebp and then make a return? Or Have I to
free the parameteres too?
The Stack of my function I must free myself, that's clear. ^^
TIA Sebihepp