1

It seems that this 8086 instruction:

add ax, 0x22

Can be encoded in two different ways: 83 C0 22 and 05 22 00.

Microsoft Macro Assembler compiles it into 05 22 00, whereas the Keystone Assembler compiles it into 83 C0 22 (https://alexaltea.github.io/keystone.js/).

Is one of the two options considered "wrong"?

If not, then does either option have any advantage over the other?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
obe
  • 7,378
  • 5
  • 31
  • 40
  • 4
    Both are correct and the same length, equivalent for all practical purposes. If you had `add eax, 0x22` that would be different because the `05` opcode would take 4 bytes of immediate while the `83` could do with a 1 byte sign-extended. Conversely, `add al, 0x22` would be 2 bytes with the `05` opcode but 3 with the `80`. – Jester May 16 '20 at 23:52
  • 3
    Semi-related: [x86 instruction encoding how to choose opcode](https://stackoverflow.com/q/37611247) in 32-bit mode, the `op ax, imm16` form has an LCP stall with the `66` prefix necessary to encode it, but the `op r/m16, imm8` doesn't. But in 16-bit mode there are no disadvantages to either encoding for this instruction. `adc ax, 0x22` would be different; again the imm16 would be worse because for some reason [Which Intel microarchitecture introduced the ADC reg,0 single-uop special case?](https://stackoverflow.com/q/51664369) doesn't apply. – Peter Cordes May 16 '20 at 23:55

0 Answers0