Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
C and assembly __asm doesn't work

I found this piece of code to put the stack pointer into EAX register(It should be the register used by "return" in C)

#include <stdio.h>
unsigned long get_sp(){
    unsigned long stp;
    __asm{
        mov
        eax, esp
        }
}

void main(void){
printf("\n0x%x", get_sp());
}

I tried it with Geany but it doesn't works!! Then I follow the compiler log and I changed the code in this way:

#include <stdio.h>

unsigned long get_sp(void);

int main(void){
printf("\n0x%ld", get_sp());
return 0;
}


unsigned long get_sp(void){
    unsigned long stp;
    __asm{
        mov eax, esp
    }
}

this time I have no problems with the main but the other function is a tragedy!!! It doesn't recognize __asm. unknown type name 'mov'.... unused variable 'eax'... It seems like it wants __asm() instead of __asm{}, like a normal call of a function. Somebody can help me? PS I have debian 64....it can have some problems with the 64 architecture??

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The correct GCC code would be

__attribute__((noinline,noclone))
unsigned long get_sp(void) {
  unsigned long stp;
  asm(
    // For x86_64: "movq %%rsp, %0"
    "movl %%esp, %0"
    : "=r"(stp)
  );
  return stp;
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda