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:28

Maybe the full function will help:

#include <stdlib.h>

unsigned long sp(void){ asm("movl %esp, %eax");}
int main(int argc, char *argv[])
{
long esp;
esp = sp();
printf("Stack Pointer (ESP) : 0x%x\n", esp);
return 0;
}

So all the program does is print whatever sp() gives, which apparently is the sp. But I don't get why asm returns a value.

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