Syntax_Error
Syntax_Error

Reputation: 6230

x86 assembly memory operands

Hello all I have a question relating to x86. In the Intel manual some instruction might take different types of memory operands. eg. IDIV r/m8 or IDIV r/m16 or IDIV r/m32 or IDIV r/m64 now they are all IDIV is there a possibility to know if the operand is m8, m16,m32 or m64? I was thinking if operand is m8 then it is addressed by an 8 bit register eg. ax if 32 then eax,esp... Is my assumption correct? Correct me if I'm wrong Any suggestions welcome Thanks

Upvotes: 2

Views: 3264

Answers (2)

Anshuman Fotedar
Anshuman Fotedar

Reputation: 93

  1. Whether the operand is m8, m16 or m32, the register used to address the memory location can be 16 or 32 bits. (Or in 64-bit mode, 64 or 32-bit). Almost always, you want pointers of the same width as the mode, unlike with data.

  2. To specify how many bits are to be read from memory, you need to use one of the size specifiers byte, word or dword before the address. For example in NASM syntax:

idiv byte [bx] ; m8

idiv word [bx] ; m16

idiv dword [bx] ; m32

Upvotes: 2

Martin B
Martin B

Reputation: 24170

Yes, the register that is used as an operand resolves the ambiguity. (Note, however, that ax is a 16-bit register, not an 8-bit register -- that would be ah or al for the high or low byte, respectively.)

If you're only referring to memory operands, you need to use a BYTE PTR, WORD PTR or DWORD PTR specifier to resolve the ambiguity, like this:

mov dword ptr [eax], 0

This example sets the 32-bit quantity ("double word") at the address contained in eax to 0.

Upvotes: 2

Related Questions