You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于X86 SDM中ADD指令格式与8086差异及04指令码的技术问询

Understanding the ADD 04 ib Instruction Format in x86 SDM vs. 8086 General Format

Great question—this is a super common confusion when transitioning from learning the original 8086 instruction set basics to diving into the full x86 Architecture Software Developer Manual (SDM). Let’s break this down clearly:

1. Your 8086 "general format" isn’t the only 8086 format

The OPCODE | DIRECTION | WIDTH | MOD | REG | R/M structure you’re thinking of is the general-purpose instruction format used for operations that involve registers, memory, or both (e.g., ADD AX, BX or ADD [BX], CL). But the 8086 instruction set also includes short-form, specialized opcodes designed to save space and speed up common operations—like immediate-value additions to the accumulator register (AL/AX).

2. Breaking down 04 ib

The 04 ib entry in the SDM refers to one of these specialized 8086-era instructions:

  • 04: This is the single-byte opcode that explicitly encodes the operation AL = AL + imm8 (8-bit addition of an immediate value to the AL register). No MOD/RM fields are needed here because the destination is fixed as AL, and the source is an immediate byte.
  • ib: The suffix ib stands for immediate byte—this is exactly what you guessed: the second byte in the instruction is the 8-bit immediate value to add to AL.

Example in action

If you write the assembly instruction:

ADD AL, 0x15

The corresponding machine code will be 04 15—where 04 is the opcode, and 15 is the ib immediate byte.

3. Why this doesn’t match your general format

The general format you learned applies to instructions where the CPU needs to decode which registers/memory locations to use. For accumulator-specific immediate operations, the opcode itself already defines the destination (AL/AX/EAX/RAX, depending on mode), so there’s no need for the MOD/RM fields. This was a deliberate design choice in 8086 to optimize common operations (since the accumulator was heavily used in early assembly code).

For completeness, there’s also a 16/32/64-bit version of this instruction:

  • 05 iw (8086): AX = AX + imm16
  • In 32-bit mode, 05 id becomes EAX = EAX + imm32
  • In 64-bit mode, 05 id extends to RAX = RAX + imm32 (sign-extended to 64 bits)

Wrap-up

The SDM’s instruction format descriptions include all x86 instructions—both the general-purpose ones with MOD/RM fields and the specialized short-form ones like 04 ib. This is why it looks different from the single general format you initially learned: you’re looking at a purpose-built opcode for accumulator immediate additions, which was part of the 8086 set from day one.

内容的提问来源于stack exchange,提问作者mahmood

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:34:24