Assembly Language StepbyStep Programming with DOS and Linux 2nd Ed [Electronic resources]

Jeff Duntemann

نسخه متنی -صفحه : 166/ 95
نمايش فراداده

CMP Arithmetic Comparison

Flags affected:

O D I T S Z A P C  OF: Overflow flag  TF: Trap flag AF: Aux carry
F F F F F F F F F  DF: Direction flag SF: Sign flag PF: Parity flag
*       * * * * *  IF: Interrupt flag ZF: Zero flag CF: Carry flag

Legal forms:

CMP r8,r8
CMP m8,r8
CMP r8,m8
CMP r16,r16
CMP m16,r16
CMP r16,16
CMP r32,r32    386+
CMP m32,r32    386+
CMP r32,m32    386+
CMP r8,i8
CMP m8,i8
CMP r16,i16
CMP m16,i16
CMP r32,i32    386+
CMP m32,i32    386+
CMP r16,i8
CMP m16,i8
CMP r32,i8     386+
CMP m32,i8     386+
CMP AL,i8
CMP AX,i16
CMP EAX,i32    386+

Examples:

CMP BX,DI
CMP EAX,5
CMP AX,0FFFFH            ;Uses single-byte opcode
CMP AL,42H               ;Uses single-byte opcode
CMP BP,17H
CMP WORD [BX+SI+Inset],5
CMP WORD ES:[BX],0B800H

Notes:

CMP compares its two operations, and sets the flags to indicate the results of the comparison. The destination operand is not affected. The operation itself is identical to subtraction of the source from the destination without borrow (SUB), save that the result does not replace the destination. Typically, CMP is followed by one of the conditional jump instructions; that is, JE to jump if the operands were equal; JNE if they were unequal; and so forth.

r8 = AL AH BL BH CL CH DL DH        r16 = AX BX CX DX BP SP SI DI
sr = CS DS SS ES FS GS              r32 = EAX EBX ECX EDX EBP ESP ESI EDI
m8 = 8-bit memory data              m16 = 16-bit memory data
m32 = 32-bit memory data            i8 = 8-bit immediate data
i16 = 16-bit immediate data         i32 = 32-bit immediate data
d8 = 8-bit signed displacement      d16 = 16-bit signed displacement
d32 = 32-bit unsigned displacement