Why IA32 does not allow memory to memory mov?

前端 未结 4 1568
面向向阳花
面向向阳花 2020-12-01 11:11

In Intel architecture IA32, instructions like movl, movw does not allow operands that are both memory locations. For example, instruction movl (%eax), (%edx) is not permitte

4条回答
  •  [愿得一人]
    2020-12-01 11:57

    ia32 is x86, and x86 is evolution from the intel 8086 (iAPX 86). It was small and cheap chip based on 8-bit instruction sets, and had no "mov" with two explicit memory operands.

    Wikipedia's author gives such explanation about instruction encoding of 8086:

    Due to a compact encoding inspired by 8-bit processors, most instructions are one-address or two-address operations, which means that the result is stored in one of the operands. At most one of the operands can be in memory, but this memory operand can also be the destination, while the other operand, the source, can be either register or immediate. A single memory location can also often be used as both source and destination which, among other factors, further contributed to a code density comparable to (and often better than) most eight-bit machines at the time.

    There were some CISCs with memory-memory instructions (single instruction to operate on two memory operands). The lecture https://www.cis.upenn.edu/~milom/cis501-Fall05/lectures/02_isa.pdf says that VAX can encode memory-memory instructions:

    DEC VAX (Virtual Address eXtension to PDP-11): 1977

    • • Variable length instructions: 1-321 bytes!!!
    • • 14 GPRs + PC + stack-pointer + condition codes
    • • Data sizes: 8, 16, 32, 64, 128 bit, decimal, string
    • Memory-memory instructions for all data sizes
    • • Special insns: crc, insque, polyf, and a cast of hundreds

    This is OpenBSD memcpy source for VAX (instruction set manual http://h20565.www2.hpe.com/hpsc/doc/public/display?docId=emr_na-c04623178):

    https://es.osdn.jp/projects/openbsd-octeon/scm/git/openbsd-octeon/blobs/master/src/sys/lib/libkern/arch/vax/memcpy.S

             movq    8(ap),r1        /* r1 = src, r2 = length */
             movl    4(ap),r3        /* r3 = dst */
    ... 
     1:      /* move forward */
             cmpl    r2,r0
             bgtru   3f              /* stupid movc3 limitation */
             movc3   r2,(r1),(r3)    /* move it all */
    

    The "movc3" instruction here has two memory operands, which addresses are stored in registers.

    x86 has several "string" instruction which will do memory-memory operations (*s, especially movs - http://x86.renejeschke.de/html/file_module_x86_id_203.html), but this instruction will use predefined registers SI & DI as addresses (implicit operands), and two memory operands still can't be encoded in x86.

提交回复
热议问题