Search code examples
cassemblynasmosdev

Return value of a C function to ASM


I'm trying to call a function from within ASM. I know how to call it, but i'm having trouble finding how to get the return value of this function. An example follows:

C code:

int dummy() {  
    return 5;  
}  

(N)ASM code:

dummyFunction:
    call dummy
    ;grab return into eax
    inc eax ; eax should be 6 now
    ret  

Any ideas?


Solution

  • The return value is in eax. If you've called a C function from asm, you can read the return value from eax. If you're trying to return from an asm function to C, store the intended return value in eax.

    Things get a little bit more complicated for returning floating point values, long long values, or structures, so ask if you need that and someone (maybe me) will help you.