How to set a variable in GCC with Intel syntax inline assembly?
Solution 1:
You want temp
to be an output, not an input, I think. Try:
__asm__(
".intel_syntax;"
"mov eax, %1;"
"mov %0, eax;"
".att_syntax;"
: "=r"(temp)
: "r"(1)
: "eax");
Solution 2:
This code does what you are trying to achieve. I hope this helps you:
#include <stdio.h>
int main(void)
{
/* Compile with C99 */
int temp=0;
asm
( ".intel_syntax;"
"mov %0, 1;"
".att_syntax;"
: "=r"(temp)
: /* no input*/
);
printf("temp=%d\n", temp);
}