0

I have the following assembly code for moving immediates into an 8,16,32,64-bit register:

.globl _start
_start:
    mov $1, %rax
    mov $2, %eax
    mov $3, %ax
    mov $4, %ah
    mov $5, %al

And when debugging in gdb:

 0x0000000000401000  48 c7 c0 01 00 00 00  ? mov    $0x1,%rax
 0x0000000000401007  b8 02 00 00 00        ? mov    $0x2,%eax
 0x000000000040100c  66 b8 03 00           ? mov    $0x3,%ax
 0x0000000000401010  b4 04                 ? mov    $0x4,%ah
 0x0000000000401012  b0 05                 ? mov    $0x5,%al

And on the intel page it shows:

enter image description here

Some questions on the Opcode column:

  • What does the +rb or +rw or +rd mean?
  • I'm guessing the ib, iw, id, means immediate-byte, -word, -double- is that correct? What does the io in the last row mean?
  • What is the REX prefix on the ah instruction that increments the op code from b0 to b4 ?
  • Why does the mov imm, r16 require the 66 prefix? It doesn't list any prefix in the row for imm16. It seems the 66 just flags this at a 16bit register?
  • Finally, why the three-byte code, 48 c7 c0 for mov imm, r64? I don't see
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
samuelbrody1249
  • 4,379
  • 1
  • 15
  • 58
  • `48 c7 c0` isn't `mov imm, r64`, it's `mov sign_extended_imm32, r/m64`. i.e. a REX.W form of the `mov imm32, r/m32` opcode, which you omitted from your image. – Peter Cordes Oct 08 '20 at 03:04
  • Asking multiple questions in 1 makes it hard to handle for duplicates, but [How does x86 handle byte vs word addressing when executing instructions and reading/writing data?](https://stackoverflow.com/q/58628157) covers the fact that Intel's manuals leave it up to you to know when to use an operand-size prefix depending on what mode you're assembling for (16 or 32/64). Oh, [Matching the intel codes to disassembly output](https://stackoverflow.com/q/63875061) is an almost exact duplicate of that, using the same example as you. – Peter Cordes Oct 08 '20 at 03:09
  • There is no REX or other prefix on the `b4 04 mov $1, %ah` instruction. It's just pointing out that mov to AH *can't* be encoded with a REX prefix; that would change the meaning to mov-to-SPL or something like that. – Peter Cordes Oct 08 '20 at 03:12
  • 1
    Ok, I think that list of duplicates covers all your bullet points. – Peter Cordes Oct 08 '20 at 03:15

0 Answers0