Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

295
Views
c inline assembly loading a register value to esp register

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)

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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!

over 4 years ago · Santiago Trujillo Report

0

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)
);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!