Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Newbie Assembly Question

Name: Anonymous 2009-09-03 12:00

Stupid question:

I call the following function:

asm("movl %esp, %eax");

in part of my program and I get the stack pointer (no problems so far).

Why does the asm function return whatever is in the EAX register? Is that the point of the function, and if so why (i.e. why not let it return a value of your choosing, etc.)? This might seem incredibly stupid, but I have been learning Motorola 68000 processor architecture while looking at fiddling with assembly through high-level languages and I don't have a great grasp on x86 architecture on top of that...

Thanks in advance

Name: Anonymous 2009-09-03 13:52

>>2
8.2.1.5 Returning a Value from the Procedure

Assembly can return values to the C calling program using only the EAX register. If the returned value is only four bytes or less, the result is returned in register EAX. If the item is larger than four bytes, a pointer is returned in EAX which points to the item. Here is a short table of the C variable types and how they are returned by the assembly code:

http://courses.ece.illinois.edu/ece390/books/labmanual/c-prog-mixing.html
I believe there is a way to get the contents of other registers to be returned using extended asm, but I'm not sure at the moment

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List