MOV src, dest (or) MOV dest, src?

后端 未结 4 1512
轮回少年
轮回少年 2020-12-02 17:58

MOV is probably the first instruction everyone learns while learning ASM.

Just now I encountered a book Assembly Language Programming in GNU/Linux for IA32 Architect

相关标签:
4条回答
  • 2020-12-02 18:12

    mov dest, src is called Intel syntax. (e.g. mov eax, 123)

    mov src, dest is called AT&T syntax. (e.g. mov $123, %eax)

    UNIX assemblers including the GNU assembler uses AT&T syntax, all other x86 assemblers I know of uses Intel syntax. You can read up on the differences on wikipedia.

    0 讨论(0)
  • 2020-12-02 18:14

    Yes, as/gas use AT&T syntax that uses the order src,dest. MASM, TASM, NASM, etc. all use the order 'dest, src". As it happens, AT&T syntax doesn't fit very well with Intel processors, and (at least IMO) is a nearly unreadable mess. E.g. movzx comes out particularly bad.

    0 讨论(0)
  • 2020-12-02 18:15

    There are two distinct types of assembly language syntax - Intel and AT&T syntax. You can find a comparison of both on Wikipedia's assembly language page.

    Chances are your book uses the AT&T syntax, where the source operand comes before the destination.

    0 讨论(0)
  • As already mentioned in the answer by Jerry Coffin, the Intel syntax fits better with the encoding of instructions for the x86 architecture. As a comment in my debugger's disassembler states, "the operands appear in the instruction in the same order as they appear in the disassembly output". For example, consider this instruction:

    -a
    1772:0100 test word [AA55], 1234
    1772:0106
    -u 100 l 1
    1772:0100 F70655AA3412      test    word [AA55], 1234
    -
    

    As you can read in the opcode hexdump, the instruction opcode 0F7h is first, then the ModR/M byte 06h, then the little-endian offset word 0AA55h, and then finally the immediate word 1234h. The Intel syntax matches that order in the assembly source. In the AT&T syntax this would look like testw $0x1234, (0xAA55) which swaps the order compared to the encoding.

    Another example that obeys the Intel syntax order is comparison conditions. For example, consider this sequence:

    cmp ax, 26
    jae .label
    

    This will jump to .label if ax is above-or-equal-to 26 (in unsigned comparison). This mnemonic is only true of the cmp dest, src operand order, which sets flags as for dest -= src.

    0 讨论(0)
提交回复
热议问题