.1. X86
REPE/REPNE(AKAREPZ/REPNZ) used with CMPSx and SCASx instructions: execute the last instruction
in a loop, the count is set in theCX/ECX/RCXregister. It terminates prematurely if ZF is 0 (REPE) or if
ZF is 1 (REPNE).
For a detailed description, you can read more about the CMPSx (.1.6 on page 1032) and SCASx (.1.6
on page 1030) instructions.
Instructions prefixed by REPE/REPNE are sensitive to the DF flag, which is used to set the direction.
Most frequently used instructions
These can be memorized in the first place.
ADC(add with carry) add values,incrementthe result if the CF flag is set. ADC is often used for the
addition of large values, for example, to add two 64-bit values in a 32-bit environment using two
ADD and ADC instructions. For example:
; work with 64-bit values: add val1 to val2.
; .lo means lowest 32 bits, .hi means highest.
ADD val1.lo, val2.lo
ADC val1.hi, val2.hi ; use CF set or cleared at the previous instruction
One more example:1.28 on page 396.
ADDadd two values
ANDlogical “and”
CALLcall another function:
PUSH address_after_CALL_instruction; JMP label
CMPcompare values and set flags, the same asSUBbut without writing the result
DECdecrement.Unlike other arithmetic instructions,DECdoesn’t modify CF flag.
IMULsigned multiplyIMULoften used instead ofMUL, read more about it:2.2.1.
INCincrement.Unlike other arithmetic instructions,INCdoesn’t modify CF flag.
JCXZ, JECXZ, JRCXZ(M) jump if CX/ECX/RCX=0
JMPjump to another address. The opcode has ajump offset.
Jcc(where cc—condition code)
A lot of these instructions have synonyms (denoted with AKA), this was done for convenience. Syn-
onymous instructions are translated into the same opcode. The opcode has ajump offset.
JAEAKAJNC: jump if above or equal (unsigned): CF=0
JAAKAJNBE: jump if greater (unsigned): CF=0 and ZF=0
JBEjump if lesser or equal (unsigned): CF=1 or ZF=1
JBAKAJC: jump if below (unsigned): CF=1
JCAKAJB: jump if CF=1
JEAKAJZ: jump if equal or zero: ZF=1
JGEjump if greater or equal (signed): SF=OF
JGjump if greater (signed): ZF=0 and SF=OF
JLEjump if lesser or equal (signed): ZF=1 or SF≠OF
JLjump if lesser (signed): SF≠OF
JNAEAKAJC: jump if not above or equal (unsigned) CF=1
JNAjump if not above (unsigned) CF=1 and ZF=1
JNBEjump if not below or equal (unsigned): CF=0 and ZF=0
JNBAKAJNC: jump if not below (unsigned): CF=0
JNCAKAJAE: jump CF=0 synonymous to JNB.