- Code: Select all
#include <stdio.h>
unsigned long get_sp(void){
__asm__("movl %esp, %eax");
}
int main(){
printf("Stack Pointer (ESP): 0x%x\n", get_sp());
}
That works fine. But when I try to put in as nasm syntax like this:
- Code: Select all
#include <stdio.h>
unsigned long get_sp(void){
__asm__("mov eax, esp");
}
int main(){
printf("Stack Pointer (ESP): 0x%x\n", get_sp());
}
I get this error from the compiler:
- Code: Select all
$ gcc -o get_nasm get_nasm.c
get_nasm.c: Assembler messages:
get_nasm.c:3: Error: too many memory references for `mov'
Does C not allow inline-assembly in nasm syntax? Or am I missing something in the code. I'm quite new to Assembly so I won't be surprised.



