1

I'm looking at the ADD instruction, and there are so many things I don't have an idea what they mean.

Intel ADD instruction

The gaps I have are.

  • In the Opcode column what is /0 and /r?

I understand the number is the opcode in hex. The ib/iw/id is byte/word/doubleword. I understand that REX.W is the 64 bit prefix flag.

  • How do I set the REX.W prefix flag?
  • What is the REX flag? how is it different than the REX.W flag?
  • What is the Op/En column portraying? I / MI/ MR / RM

I know that r/m8 in the instruction column is specifying that you can provide an an 8 bit address, and it will add the immediate to it. It looks like r8 means just read from that address.

  • what is the compat/leg mode mean when it says valid vs n.e? Is it typical to switch back and forth in normal higher level language code? Seems on 64 bit systems, you will almost always be in 64 bit mode?
Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
christopher clark
  • 2,026
  • 5
  • 28
  • 47
  • 3
    These are all explained in Section 3.1 of Volume 2A. You might want to look through it and then come back with any remaining questions. – Nate Eldredge Apr 05 '22 at 14:16
  • 1
    Some of your questions go to the machine code encodings, but others go to the assembly syntax. The assembly syntax varies across assemblers -- there are many of them for intel/amd processors. So, you should look to find answers for "How do I set the REX.W prefix" in the appropriate assembler's manual, rather than in the machine code instruction set manual. – Erik Eidt Apr 05 '22 at 15:41
  • 1
    The reason they single out REX for 8-bit operand-size is that `mov ah, sil` is not encodeable: AH is only encodeable with no REX, SIL is only encodeable with a REX. [What's the point of instructions with only the REX prefix in 64bit mode?](https://stackoverflow.com/q/27667065) – Peter Cordes Apr 06 '22 at 04:38
  • https://en.wikipedia.org/wiki/X86-64#Operating_modes - 64-bit code stays in 64-bit mode. Compat mode is how 64-bit OSes run 32-bit user-space (which is still common on Windows, but not other OSes). Legacy mode is a 32-bit or 16-bit OS, including on old CPUs that aren't even 64-bit capable. i.e. CPU in real mode or 16 or 32-bit protected mode. So the compat/leg mode is what you care about when building with `gcc -m32` for example. – Peter Cordes Apr 06 '22 at 04:42
  • Anyway, other than long vs. compat/legacy mode, I think all the other various questions are covered by answer(s) on the duplicates. (Check my answer at the bottom of [How to read the Intel Opcode notation](https://stackoverflow.com/a/53976236) for the `/4` stuff.) If there are any remaining things not covered by duplicates or the introductory chapter of the manual you're reading, post a new more specific question. – Peter Cordes Apr 06 '22 at 08:26

0 Answers0