Getting a return variable.. (mixing C and asm)

Programming, for all ages and all languages.
Post Reply
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Getting a return variable.. (mixing C and asm)

Post by earlz »

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..
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Getting a return variable.. (mixing C and asm)

Post by JohnnyTheDon »

Usually RAX/EAX/AX/AL.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: Getting a return variable.. (mixing C and asm)

Post by earlz »

JohnnyTheDon wrote:Usually RAX/EAX/AX/AL.
Thanks! that's the trick.. I always thought C intended to be more portable than that though...
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Getting a return variable.. (mixing C and asm)

Post by JohnnyTheDon »

Well the calling convention will always depend on the platform. For example, the C calling convention on x86-64 uses registers to hold parameters.
quok
Member
Member
Posts: 490
Joined: Wed Oct 18, 2006 10:43 pm
Location: Kansas City, KS, USA

Re: Getting a return variable.. (mixing C and asm)

Post by quok »

earlz wrote:Ok, maybe this should go in general programming, but it is for my kernel.. lol
Moved to General Programming.
pcmattman
Member
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)

Post by pcmattman »

I always thought C intended to be more portable than that though...
It is - the C compiler hides the machine-specific details from you.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: Getting a return variable.. (mixing C and asm)

Post by earlz »

pcmattman wrote:
I always thought C intended to be more portable than that though...
It is - the C compiler hides the machine-specific details from you.
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 works
pcmattman
Member
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)

Post by pcmattman »

Well, I always thought it an agreed upon unspoken standard that parameters are passed on the stack
That's not so on some RISC architectures.

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.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Getting a return variable.. (mixing C and asm)

Post by AJ »

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
User avatar
Troy Martin
Member
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)

Post by Troy Martin »

(inappropriate remark removed - Combuster)
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
Post Reply