How to set a variable in GCC with Intel syntax inline assembly?

后端 未结 3 1557
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 09:25

Why doesn\'t this code set temp to 1? How do I actually do that?

int temp;
__asm__(
    \".intel_syntax;\"
    \"mov %0, eax;\"
    \"mov eax, %         


        
3条回答
  •  攒了一身酷
    2020-11-30 09:44

    This code does what you are trying to achieve. I hope this helps you:

    #include 
    
    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);
    }
    

提交回复
热议问题