Getting a return variable.. (mixing C and asm)
Getting a return variable.. (mixing C and asm)
Ok, maybe this should go in general programming, but it is for my kernel.. lol
ok, how exactly do you get the return value of a C function from assembly?
yes.. I know it seems very noobish.. but I can't seem to find the answer.. I've only seen stuff about passing parameters, and nothing more... and I tried experimenting with pushing and popping different things and I can't seem to get it..
ok, how exactly do you get the return value of a C function from assembly?
yes.. I know it seems very noobish.. but I can't seem to find the answer.. I've only seen stuff about passing parameters, and nothing more... and I tried experimenting with pushing and popping different things and I can't seem to get it..
-
- Member
- Posts: 524
- Joined: Sun Nov 09, 2008 2:55 am
- Location: Pennsylvania, USA
Re: Getting a return variable.. (mixing C and asm)
Usually RAX/EAX/AX/AL.
Re: Getting a return variable.. (mixing C and asm)
Thanks! that's the trick.. I always thought C intended to be more portable than that though...JohnnyTheDon wrote:Usually RAX/EAX/AX/AL.
-
- Member
- Posts: 524
- Joined: Sun Nov 09, 2008 2:55 am
- Location: Pennsylvania, USA
Re: Getting a return variable.. (mixing C and asm)
Well the calling convention will always depend on the platform. For example, the C calling convention on x86-64 uses registers to hold parameters.
Re: Getting a return variable.. (mixing C and asm)
Moved to General Programming.earlz wrote:Ok, maybe this should go in general programming, but it is for my kernel.. lol
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: Getting a return variable.. (mixing C and asm)
It is - the C compiler hides the machine-specific details from you.I always thought C intended to be more portable than that though...
Re: Getting a return variable.. (mixing C and asm)
Well, I always thought it an agreed upon unspoken standard that parameters are passed on the stack.. though I suppose a compiler could do just about anything it wants as long as it compiles C code and it workspcmattman wrote:It is - the C compiler hides the machine-specific details from you.I always thought C intended to be more portable than that though...
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: Getting a return variable.. (mixing C and asm)
That's not so on some RISC architectures.Well, I always thought it an agreed upon unspoken standard that parameters are passed on the stack
That's the beauty of C - it still works on practically every architecture because the compiler actually creates the assembly code for the target architecture for you, following the relevant ABIs and other standards.
Re: Getting a return variable.. (mixing C and asm)
Hi,
You may be interested in Googling the System V ABI, particularly if you want to mix a lot of C/C++/ASM.
Cheers,
Adam
You may be interested in Googling the System V ABI, particularly if you want to mix a lot of C/C++/ASM.
Cheers,
Adam
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Getting a return variable.. (mixing C and asm)
(inappropriate remark removed - Combuster)