Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

289
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda