strange error message about GCC inline assembly

前端 未结 2 1885
面向向阳花
面向向阳花 2021-01-15 13:46
int main()
{
    __asm__(\"movl $0x1,%%eax;
            movl $0x0,%%ebx;
            int $0x80;
            \":::\"eax\",\"ebx\");
}

I try to simul

相关标签:
2条回答
  • 2021-01-15 14:28

    From what I remember of inline assembly, you probably need to terminate each line with \n\t after the semicolon or something like that.

    Clarification:
    It is not enough to terminate each line in inline assembly with ;. Inline assembly is fed directly to the assembler by gcc as a string. If you do not terminate each line with \n, the assembler will get strings like movl $0x1,%%eax;movl $0x0,%%ebx; which it will not be able to parse. You probably do not need to use \n\t any longer since gcc can handle assembly files where commands are not preceded by \t.

    0 讨论(0)
  • 2021-01-15 14:39

    You cannot have embedded newlines inside quoted strings

    // bad
    "two
    lines"
    

    Rewrite as

    // good
    "two\n"
    "lines"
    

    The preprocessor will join the strings seamlessly, to

    "two\nlines"
    
    0 讨论(0)
提交回复
热议问题