Error - invalid 'asm': operand number missing after% -letter

I am writing inline assembly code in my program. I wrote the code below and compiled a source file called "context.c". But the compiler shows this error message consistently.

 context.c:42:2: error:
 invalid 'asm': operand number missing after %-letter
    __asm__ __volatile__(


I searched every article with the same error message as me and read the assembly instructions very carefully. But I cannot find the error code. Please, help!

    void _os_restore_context(addr_t sp){
    __asm__ __volatile__(     //line 42
            "movl %0, %%esp             \n\t"
            "popl %%edi                 \n\t"
            "popl %%esi                 \n\t
            "popl %%ebp                 \n\t
            "addl $4, %%esp #pass esp   \n\t
            "popl %%ebx                 \n\t
            "popl %%edx                 \n\t
            "popl %%ecx                 \n\t
            "popl %%eax                 \n\t
            "popl %eflags               \n\t
            "addl $4, %%esp #pass eip   \n\t
            "popl %%ebp                 \n\t
            "ret                        \n\t
            :: "m" (sp) : "%eax"



source to share

1 answer

I solved my problem. The reason is the eflags register. eflags and eip register have a special purpose, so the user program usually cannot access it.

To provide you with more information, this code is part of a small operating system built to teach os. This os, named EOS (instructional operating system), has the hardware emulator source code in another section, and the eflags register is defined as a register variable in this section written in assembly language. Therefore, I am advised to replace% eflags with _eflags, which is the name of a register variable. After that, the error goes out.

Have a nice day!



All Articles