ADD: Add

For information about interpreting this page, see the help page.
Opcode and MnemonicEncoding16 bit Mode32 bit Mode64 bit ModeDescription
04 ib
ADD AL, imm8
AIValidValidValidAdds imm8 to AL.
05 iw
ADD AX, imm16
AIValidValidValidAdds imm16 to AX.
05 id
ADD EAX, imm32
AIValidValidValidAdds imm32 to EAX.
REX.W 05 id
ADD RAX, imm32
AINot EncodableNot EncodableValidAdds imm32 (sign extended to 64 bits) to RAX.
80 /0 ib
ADD r/m8, imm8
MIValidValidValidAdds imm8 into r/m8.
REX 80 /0 ib
ADD r/m8*, imm8
MINot EncodableNot EncodableValidAdds imm8 into r/m8.
81 /0 iw
ADD r/m16, imm16
MIValidValidValidAdds imm16 into r/m16.
81 /0 id
ADD r/m32, imm32
MIValidValidValidAdds imm32 into r/m32.
REX.W 81 /0 id
ADD r/m64, imm32
MINot EncodableNot EncodableValidAdds imm32 into r/m64.
82 /0 ib
ADD r/m8, imm8
MIValidValidInvalidUndocumented alias for 80 /0 ib. Adds imm8 (sign extended to 8 bits) into r/m8.
83 /0 ib
ADD r/m16, imm8
MIValidValidValidAdds imm8 (sign extended to 16 bits) into r/m16.
83 /0 ib
ADD r/m32, imm8
MIValidValidValidAdds imm8 (sign extended to 32 bits) into r/m32.
REX.W 83 /0 ib
ADD r/m64, imm8
MINot EncodableNot EncodableValidAdds imm8 (sign extended to 64 bits) into r/m64.
00 /r
ADD r/m8, r8
MRValidValidValidAdds r8 into r/m8.
REX 00 /r
ADD r/m8*, r8
MRNot EncodableNot EncodableValidAdds r8 into r/m8.
01 /r
ADD r/m16, r16
MRValidValidValidAdds r16 into r/m16.
01 /r
ADD r/m32, r32
MRValidValidValidAdds r32 into r/m32.
REX.W 01 /r
ADD r/m64, r64
MRNot EncodableNot EncodableValidAdds r64 into r/m64.
02 /r
ADD r8, r/m8
RMValidValidValidAdds r/m8 into r/8.
REX 02 /r
ADD r8, r/m8*
RMNot EncodableNot EncodableValidAdds r/m8 into r8.
03 /r
ADD r16, r/m16
RMValidValidValidAdds r/m16 into r16.
03 /r
ADD r32, r/m32
RMValidValidValidAdds r/m32 into r32.
REX.W 03 /r
ADD r64, r/m64
RMNot EncodableNot EncodableValidAdds r/m64 into r64.

Encoding

EncodingOperand 1Operand 2
AIAL/AX/EAX/RAX[rw]imm8/16/32[r]
MIModRM.r/m[rw]imm8/16/32[r]
MRModRM.r/m[rw]ModRM.reg[r]
RMModRM.reg[rw]ModRM.r/m[r]

Description

The ADD instruction adds the destination operand with the source operand and stores the result in the destination operand.

This instruction can be used with the LOCK prefix to allow atomic execution.

In 64 bit mode, the default operand size is 32 bits, but REX.W will change it to 64 bits.

Operation

This pseudo-code uses C# syntax. A list of the types used is available here.
// `src` is sign extended to the width of `dest`

public void ADD_8(ref byte dest, byte src)
{
  CF:dest = dest + src;
}

public void ADD_16(ref ushort dest, ushort src)
{
  CF:dest = dest + src;
}

public void ADD_32(ref uint dest, uint src)
{
  CF:dest = dest + src;
}

public void ADD_64(ref ulong dest, ulong src)
{
  CF:dest = dest + src;
}

Flags Affected

CF (carry flag)
Set according to the result.
PF (parity flag)
Set according to the result.
AF (auxiliary flag)
Set according to the result.
ZF (zero flag)
Set according to the result.
SF (sign flag)
Set according to the result.
OF (overflow flag)
Set according to the result.

Exceptions

Protected Mode

#GP(0)
If the destination is located in a non-writable segment.
If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.
If the DS, ES, FS, or GS register is used to access memory and it contains a NULL segment selector.
#SS(0)
If a memory operand effective address is outside the SS segment limit.
#PF(fault-code)
If a page fault occurs.
#AC(0)
If alignment checking is enabled and an unaligned memory reference is made while the current privilege level is 3.
#UD
If the LOCK prefix is used but the destination is not a memory operand.

Real-Address Mode

#GP
If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.
#SS
If a memory operand effective address is outside the SS segment limit.
#UD
If the LOCK prefix is used but the destination is not a memory operand.

Virtual-8086 Mode

#GP(0)
If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.
#SS(0)
If a memory operand effective address is outside the SS segment limit.
#PF(fault-code)
If a page fault occurs.
#AC(0)
If alignment checking is enabled and an unaligned memory reference is made.
#UD
If the LOCK prefix is used but the destination is not a memory operand.

Compatibility Mode

Same exceptions as in protected mode.

Long Mode

#SS(0)
If a memory address referencing the SS segment is in a non-canonical form.
#GP(0)
If a memory operand address is in a non-canonical form.
#PF(fault-code)
If a page fault occurs.
#AC(0)
If alignment checking is enabled and an unaligned memory reference is made while the current privilege level is 3.
#UD
If the LOCK prefix is used but the destination is not a memory operand.