Doubt in Intel docs

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
modshah

Doubt in Intel docs

Post by modshah »

hi everyone,

I have doubt whether r/m16 is just a superset of r16. But the intel doc(IA-32, part-2) seems to specify registers in both r16 and r/m16 as the same. But they use different opcodes for the two cases.

This is how they define it:
-----------------------------------------------------------------------------
r/m16 - A byte operand that is either the contents of a byte general-purpose register or a byte from memory.

r16 - One of the word general purpose registers.-----------------------------------------------------------------------------
Now what if I had something like


       mov ax, imm16       ;imm16 is immediate value of size 16 bits


What will be the opcode ? Which one would it ?

       1. mov r/m16, imm16
                     or

       2. mov r16, imm16


Thanking you in advace.
modshah
HOS

RE:Doubt in Intel docs

Post by HOS »

someone else feel free to correct me if i am wrong, but i belive that r/m16 refers to instructions like this:

mov word [16], 0x1234
mov word [bx], 0x5678

where as r16 is used when MOVing directly to a register like this:

mov bx, 0x9abc
Khumba

RE:Doubt in Intel docs

Post by Khumba »

the mod/rm byte looks like this:
7-6  5-3  2-0
Mod  Reg  R/M

So "mov word [16], 0x1234" would set Mod and R/M to [16], but "mov bx, 0x9abc" could be either. (Actually there's a shorter way for immed->reg). r16 (i think) refers to the reg field (which refers to a 16-bit register). Read page 33 on the Intel Manual 2: Instruction Set Reference.
ftp://download.intel.com/design/Pentium ... 547112.pdf


Ps. Btw, mov ax, imm16 would compile to "a8 xxxx". A0-A8 are special shorthands for loading registers with immediates.
Post Reply