Search code examples
assemblygccx86clangatt

x86 Far return mnemonic in Clang 9/GCC assembler?


I'm trying to write a piece of x86 assembly code in .S file that I compile with Clang 9. I need to use "far return imm16" instruction in my code, I tried to use "retf" with or without an immediate operand, but the compiler doesn't recognize it and gives me "error: invalid instruction mnemonic 'retf'". It only recognizes "ret" and "retn".

What am I doing wrong? What is correct mnemonic that I need to use?


Solution

  • The mnemonic is lret. Use it like this:

    lret $0x1234
    

    For future questions like this, you can always assemble a file in Intel syntax:

    .syntax intel,noprefix
    
            retf 0x1234
    

    and then disassemble it with objdump to get the AT&T syntax for the instruction:

       0:   ca 34 12                lret   $0x1234