Search code examples
c++assemblyx86x86-64gnu-assembler

How to determine which x86 memory operand width and type is used from an asm listing?


There are several versions of the same instruction: IDIV M32, IDIV R32, IDIV M64, IDIV R64 (https://www.felixcloutier.com/x86/idiv)

How to understand which one is used? Let's say

vdiv(std::vector<int, std::allocator<int> >&):
        mov     rcx, QWORD PTR [rdi]
        mov     eax, DWORD PTR [rcx+4]
        cdq
        idiv    DWORD PTR [rcx+8]
        mov     DWORD PTR [rcx], eax
        ret

Is it 32 bit since it uses int? Is it 64 bit since it uses 64 bit rcx register? Probably 32 bit, but is it M or R? How to spot the difference between those (M/R) two?


Solution

  • 'R' is 'Register , like ah/al/ax/eax/bx/cx/dx...etc.

    'M' is 'Memory' , a Address of your Memory

    R8 = 8 Bits Register, like ah/al/bh/bl/ch/cl/dh/dl/...

    R16 = 16 bits one, ax/bx/cx/dx/si/di/bp/sp/...

    R32 = 32 bits, EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI,...

    R64 = RAX, RBX, RCX, RDX, RDI, RSI, RBP, RSP, R8~R15

    M8 = 8 Bits(1Byte) memory, byte ptr [si] , byte ptr [edx] , mov byte ptr [rdx], 255

    M16 = 16 bits(1Word), word ptr [rdx], word ptr [esi], mov WORD ptr [di], 65535

    M32 = 32 bits(1Dword - Double Word), DWord ptr [si], mov DWORD ptr [bx], 10

    M64 = 64 bits(1qword), QWord pre [] ...

    so, the idiv DWORD PTR [xxx] is M32

    idiv QWORD PTR [xxx] is M64

    ...