1

Unlike the other registers, I've noticed doing something like add $1, %al encodes the instruction much differently than the other (8-bit) registers. For example:

add $3, %al
add $3, %bl
add $3, %cl
add $3, %dl

Translates to:

0x0000000000401000  04 03     ? add    $0x3,%al
0x0000000000401002  80 c3 03  ? add    $0x3,%bl
0x0000000000401005  80 c1 03  ? add    $0x3,%cl
0x0000000000401008  80 c2 03  ? add    $0x3,%dl

I went through the encoding of add-imm8 in my previous question, but the add $3, %al seems to completely contradict that (no mod-reg-rm byte?). Is this a legacy instruction or something, or why does it look so much different than the other ones?

samuelbrody1249
  • 4,379
  • 1
  • 15
  • 58
  • [Instruction Lengths](https://stackoverflow.com/q/4567903) mentions the AL, imm8 short form encodings that exist for most ALU instructions, along with various other short-form encodings. Yes, these date back to 8086, just like the modrm encodings, so these are *all* part of x86's 8086 legacy. – Peter Cordes Oct 08 '20 at 04:44
  • 2
    See also [Tips for golfing in x86/x64 machine code](https://codegolf.stackexchange.com/a/160739) - that answer of mine on that question has a section about 8086 history / design decisions. 8086 definitely favoured using AL/AX as "the accumulator", hence the name, providing special short-forms for it. – Peter Cordes Oct 08 '20 at 04:50

0 Answers0