In a code, I have following declaration
#if GCC == 1
#define SET_STACK(s) asm("movl temp,%esp");
...
#endif
In the code, exactly at one place, this macro is used, on which line compiler indicates of undefined reference to 'temp'.
temp = (int*)some_pointer;
SET_STACK(temp);
the temp variable is declared as global volatile void pointer
volatile void* temp;
Is there any syntax problem with the inline assembly ?
As of my understanding, the inline assembly tries to load the value of temp (not the dereferenced value , but the pointer itself)
You have to use extended assembler to pass C operands to the assembler: Read the manual. (Note: as you did not specify which version you are using, I just picked one).
Do not forget to add registers used in the assembler into the clobber list. You should also make the assembler asm volatile.
Depending on your execution environment, it might be a very bad idea to manually manipulate the stack pointer! At least you should put that into a __attribute__((naked)) function, not a macro. The trailing ; in the macro is definitively wrong, you will have that already right after the macro (2 semicolons might break conditional statements!
If you want to use C variables in GCC inline assembly, you have to make use of the Extended ASM syntax, e.g.:
volatile int temp = 0;
asm("movl %0,%%esp"
: /* No outputs. */
: "rm" (temp)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With