天天看点

operand order in x86 assembly languageADD—AddCMP—Compare Two OperandsSUB—Subtract

order in x86 assembly language

ADD—Add

Opcode Instruction Op/En   64-bit Mode   Compat/Leg Mode Description

04 ib ADD AL, imm8 I Valid Valid Add imm8 to AL.

05 iw ADD AX, imm16 I Valid Valid Add imm16 to AX.

05 id ADD EAX, imm32 I Valid Valid Add imm32 to EAX.

REX.W + 05 id ADD RAX, imm32 I Valid N.E. Add imm32 sign-extended to 64-bits to RAX.

Description

Adds the destination operand (first operand) and the source operand (second operand) and then stores the result 

in the destination operand. The destination operand can be a register or a memory location; the source operand 

can be an immediate, a register, or a memory location. (However, two memory operands cannot be used in one 

instruction.) When an immediate value is used as an operand, it is sign-extended to the length of the destination 

operand format.

The ADD instruction performs integer addition. It evaluates the result for both signed and unsigned integer oper-

ands and sets the OF and CF flags to indicate a carry (overflow) in the signed or unsigned result, respectively. The 

SF flag indicates the sign of the signed result.

ADD  a  b  ==> a = a + b

a ==> destination operand / first operand

b ==> source operand  / second operand

CMP—Compare Two Operands

Opcode Instruction Op/En   64-bit Mode Compat/Leg Mode Description

3C ib CMP AL, imm8 I Valid Valid Compare imm8 with AL.

3D iw CMP AX, imm16 I Valid Valid Compare imm16 with AX.

3D id CMP EAX, imm32 I Valid Valid Compare imm32 with EAX.

REX.W + 3D id CMP RAX, imm32 I Valid N.E. Compare imm32 sign-extended to 64-bits with RAX.

Description

Compares the first source operand with the second source operand and sets the status flags in the EFLAGS register 

according to the results. The comparison is performed by subtracting the second operand from the first operand 

and then setting the status flags in the same manner as the SUB instruction. When an immediate value is used as 

an operand, it is sign-extended to the length of the first operand.

CMP a b ==> a - b

a ==> destination operand / first operand

b ==> source operand  / second operand

CMP  <==> SUB

SUB—Subtract

2C ib SUB AL, imm8 I Valid  Valid Subtract imm8 from AL.

2D iw SUB AX, imm16 I Valid  Valid Subtract imm16 from AX.

2D id SUB EAX, imm32 I Valid  Valid Subtract imm32 from EAX.

REX.W + 2D id SUB RAX, imm32 I Valid  N.E. Subtract imm32 sign-extended to 64-bits from RAX.

Description

Subtracts the second operand (source operand) from the first operand (destination operand) and stores the result 

in the destination operand. The destination operand can be a register or a memory location; the source operand 

can be an immediate, register, or memory location. (However, two memory operands cannot be used in one 

instruction.) When an immediate value is used as an operand, it is sign-extended to the length of the destination 

operand format.

SUB a  b ==> a = a - b

a ==> destination operand / first operand

b ==> source operand  / second operand