Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Assembly Instruction Quick Reference

Assembly Instruction Quick Reference

This article focuses on the most common x86 architecture assembly language, organizing common instruction mnemonics by function for easy learning and quick reference.

Instruction mnemonics are largely consistent across different assemblers (MASM, NASM, GAS), with only slight differences in operand syntax.

Overview of the nine major instruction categories:

Classification Number of instructions Main Use
Data transfer instructions 15 instructions Move data between registers, memory, and I/O ports
Arithmetic instructions 18 instructions Addition, subtraction, multiplication, division, comparison, and number-system adjustment
Logical and shift instructions 14 instructions Bitwise AND/OR/NOT/XOR, shifts, and rotates
String operation instructions 8 instructions Handle contiguous memory regions, batch operations with repeat prefixes
Control transfer instructions 30+ instructions Jumps, loops, procedure calls, and interrupts
Conditional set instructions 16 instructions Set a byte value based on flags, used to eliminate branches
Input/output instructions 4 instructions Read and write I/O ports
Processor control instructions 14 instructions Control flags, synchronization, system management
Floating-point instructions (x87 FPU) 14 instructions Traditional x87 floating-point stack operations

Data transfer instructions

Data transfer instructions are the most basic instruction type, responsible for moving data between registers, memory, and I/O ports.

Most transfer instructions do not affect the flags (except SAHF and POPF).

Mnemonic Brief description of function
MOV Copy the source operand to the destination operand, supporting register-to-register, register-to-memory, and immediate-to-register or memory
MOVSX Move with sign extension, sign-extending a smaller operand to a larger size (e.g., byte to doubleword, filling the high bits with the sign bit)
MOVZX Move with zero extension, filling the high bits with 0 (for unsigned number extension)
PUSH Push the operand onto the stack; the stack pointer ESP/RSP decrements automatically (decrement first, then store)
POP Pop data from the stack into the destination operand; the stack pointer increments automatically (fetch first, then increment)
PUSHA / PUSHAD Push all general-purpose registers onto the stack (16-bit uses PUSHA, 32-bit uses PUSHAD), often used to save context
POPA / POPAD Restore all general-purpose registers from the stack, used symmetrically with PUSHA/PUSHAD
XCHG Swap the contents of two operands; at least one operand must be a register
LEA Load Effective Address, storing the address of the source operand rather than its memory content into the destination register, often used for pointer arithmetic
LDS / LES / LFS / LGS / LSS Load a far pointer into a segment register and a general-purpose register (rarely used in the modern flat memory model)
LAHF Load the low 8 bits of the flags register into the AH register
SAHF Store the contents of the AH register back into the low 8 bits of the flags register
PUSHF / PUSHFD Push the flags register onto the stack (16-bit uses PUSHF, 32-bit uses PUSHFD)
POPF / POPFD Restore the flags register from the stack
XLAT / XLATB Table lookup translation instruction: sends the memory byte indexed by the value in AL into AL; BX/EBX points to the table base

LEA The difference between MOV The key difference:LEA REG, [ADDR] loads the address value itself, while MOV REG, [ADDR] loads the memory content at that address. When doing address calculations (such as LEA EAX, [EBX+4*ECX+8]), LEA is very efficient.


Arithmetic instructions

Arithmetic instructions perform addition, subtraction, multiplication, division, and comparison; the results directly affect the relevant flags in the flags register.

Programmers usually judge the result of an operation based on the Zero Flag (ZF), Carry Flag (CF), Sign Flag (SF), and Overflow Flag (OF).

Mnemonic Brief description of function
ADD Addition, destination = destination + source, affects flags such as OF, SF, ZF, CF
ADC Add with carry, destination = destination + source + CF, used for multi-precision arithmetic
SUB Subtraction, destination = destination - source
SBB Subtract with borrow, destination = destination - source - CF, used with ADC for multi-precision arithmetic
INC Increment the operand by 1, does not affect the CF flag
DEC Decrement the operand by 1, does not affect the CF flag
MUL Unsigned multiplication, multiplicand in AL/AX/EAX, product stored in AX/DX:AX/EDX:EAX
IMUL Signed multiplication, supporting one-operand, two-operand, and three-operand forms
DIV Unsigned division, dividend in AX/DX:AX/EDX:EAX, quotient and remainder stored in specified registers
IDIV Signed division, rules similar to DIV but handling the sign
CMP Compare two operands, performs subtraction but does not store the result, only affects the flags (usually followed by a conditional jump)
NEG Negate, invert the operand and add 1, equivalent to 0 minus the operand
DAA Decimal adjust after addition, adjusts AL to packed BCD format
DAS Decimal adjust after subtraction
AAA ASCII adjust after addition, for unpacked BCD
AAS ASCII adjust after subtraction
AAM ASCII adjust after multiplication
AAD ASCII adjust before division
CBW / CWDE Sign extension: CBW sign-extends AL to AX, CWDE sign-extends AX to EAX
CWD / CDQ Sign extension: CWD extends AX to DX:AX, CDQ extends EAX to EDX:EAX (often used to prepare the dividend before division)

Signed operations use IMUL / IDIV, while unsigned operations use MUL / DIV. Choosing the wrong instruction will give wrong results—for instance, the same binary value represents different numbers under signed and unsigned interpretation.


Logical and shift instructions

These instructions perform bitwise logical operations such as AND, OR, NOT, XOR, as well as shifts and rotates.

Shift operations are often used for fast multiplication/division by powers of 2, bit-field extraction, and bit masking.

Mnemonic Brief description of function
AND Bitwise AND, often used for masking (clearing specific bits)
OR Bitwise OR, often used to set specific bits to 1
XOR Bitwise XOR, 0 when bits are the same and 1 when different. XOR REG, REG is the classic efficient way to zero a register
NOT Bitwise NOT, flips all bits
TEST Test bits, performs an AND operation but does not store the result, only affects the flags (often used to check whether a bit is 0)
SHL / SAL Logical left shift / arithmetic left shift, the two are functionally identical, low bits filled with 0, high bits shifted into CF
SHR Logical right shift, high bits filled with 0, low bits shifted into CF (for unsigned numbers)
SAR Arithmetic right shift, high bits filled with the original sign bit, preserving the numeric sign (for signed numbers)
ROL Rotate left, the shifted-out bit is fed back to the other side
ROR Rotate right, the shifted-out bit is fed back to the other side
RCL Rotate left through carry, CF participates in the rotation (CF acts as a temporary storage bit)
RCR Rotate right through carry, CF participates in the rotation
SHLD Double-precision left shift, shifts the destination and source operands jointly left, storing the result in the destination
SHRD Double-precision right shift, shifts the destination and source operands jointly right, storing the result in the destination

XOR REG, REG is the best way to zero a register—its machine code is shorter than MOV REG, 0 and it also runs faster.


String operation instructions

String instructions specifically handle contiguous memory regions and are used with repeat prefixes, commonly for batch operations such as array copying, memory comparison, and buffer searching.

For these instructions, the source address is by default pointed to by DS:ESI and the destination address by ES:EDI.

Mnemonic Brief description of function
MOVS String move, copies [DS:ESI] to [ES:EDI] and automatically updates ESI, EDI. Divided by operand size into MOVSB (byte), MOVSW (word), MOVSD (doubleword)
STOS String store, stores AL/AX/EAX into [ES:EDI] and updates EDI. Often used to initialize a memory region to a single value
LODS String load, reads AL/AX/EAX from [DS:ESI] and updates ESI. Less commonly used because it loads only one value into the accumulator at a time
CMPS String compare, compares [DS:ESI] with [ES:EDI] and affects the flags. Usually used with REPE/REPNE to search for matching or non-matching positions
SCAS String scan, compares AL/AX/EAX with [ES:EDI] and updates EDI. Often used to search memory for a specific value
REP Repeat prefix, repeats the following string instruction while ECX is not 0; after each execution, ECX is automatically decremented by 1
REPE / REPZ Repeat while equal/zero, continues when ECX is not 0 and ZF = 1 (usually used with CMPS and SCAS to search for matches)
REPNE / REPNZ Repeat while not equal/not zero, continues when ECX is not 0 and ZF = 0 (used to search for non-matches)

Direction flag DF Controls the movement direction of string operation pointers: after executing CLD DF=0, pointers increment (forward processing); after executing STD DF=1, pointers decrement (backward processing). You should explicitly set DF before using string operations; do not rely on the default value.


Control transfer instructions

Control transfer instructions change the flow of program execution, including unconditional jumps, conditional jumps, loops, and procedure calls and returns.

This is the foundation for implementing program logic branches, loops, and function calls.

Unconditional jumps and calls

Unconditional jumps do not check any condition; they directly change the value of EIP/RIP so the CPU continues execution from a new address.

Mnemonic Brief description of function
JMP Unconditional jump, supporting short jumps (-128 to +127 bytes), near jumps (within a segment), and far jumps (across segments)
CALL Call a procedure, first pushes the return address onto the stack, then jumps to the target address
RET / RETF Return from a procedure. RET is used for a near return (within a segment), RETF for a far return (across segments). It can take an immediate parameter to also release parameter space on the stack

Conditional jumps

Conditional jumps decide whether to jump based on the value of specific flags in the flags register.

Usually used immediately after the CMP or TEST instruction.

Mnemonic Jump condition Typical use
JE / JZ ZF = 1 (equal / zero) Jump if equal after CMP
JNE / JNZ ZF = 0 (not equal / not zero) Jump if not equal after CMP
JS SF = 1 (result negative) Jump if the operation result is negative
JNS SF = 0 (result positive) Jump if the operation result is nonnegative
JC CF = 1 (carry/borrow set) Jump if less in an unsigned comparison, equivalent to JB
JNC CF = 0 (no carry/borrow) Jump if greater than or equal in an unsigned comparison, equivalent to JAE
JO OF = 1 (overflow) Jump if a signed operation overflows
JNO OF = 0 (no overflow) Jump if a signed operation does not overflow
JP / JPE PF = 1 (even number of 1 bits in the low 8 bits) Jump if parity is even
JNP / JPO PF = 0 (odd number of 1 bits) Jump if parity is odd
JA / JNBE CF = 0 and ZF = 0 Unsigned greater than (Above)
JAE / JNB CF = 0 Unsigned greater than or equal (Above or Equal)
JB / JNAE CF = 1 Unsigned less than (Below)
JBE / JNA CF = 1 or ZF = 1 Unsigned less than or equal (Below or Equal)
JG / JNLE ZF = 0 and SF = OF Signed greater than (Greater)
JGE / JNL SF = OF Signed greater than or equal (Greater or Equal)
JL / JNGE SF ≠ OF Signed less than (Less)
JLE / JNG ZF = 1 or SF != OF Signed less than or equal (Less or Equal)
JCXZ Jump when CX = 0 Check whether CX is zero in 16-bit mode
JECXZ Jump when ECX = 0 Check whether ECX is zero in 32-bit mode

Unsigned and signed comparisons use different jump instructions, which is where beginners most often make mistakes. For example, when comparing two numbers, JA checks for unsigned greater than, andJG checks for signed greater than—the same CMP result may differ under these two judgments.

Loop instructions

Loop instructions use ECX as a counter, automatically decrementing it each iteration and deciding whether to continue the loop.

Mnemonic Brief description of function
LOOP Decrement ECX by 1, jump to the target address if ECX is not 0
LOOPE / LOOPZ Decrement ECX by 1, jump if ECX is not 0 and ZF = 1 (continue the loop while equal)
LOOPNE / LOOPNZ Decrement ECX by 1, jump if ECX ≠ 0 and ZF = 0 (continue looping while not equal)

Interrupts and Returns

Mnemonic Brief description of function
INT n Software interrupt: calls the interrupt service routine with interrupt vector number n (e.g. under DOS, INT 21h is the system function call)
INTO Overflow interrupt: calls INT 4 when OF = 1 (used to catch arithmetic overflow exceptions)
IRET / IRETD Return from the interrupt service routine, restoring the EFLAGS and return address at the time of interruption

Conditional set instructions

Conditional set instructions (supported on 386 and later processors) set the destination byte to 1 or 0 according to the flag status.

These instructions are often used to eliminate branch jumps and improve code execution efficiency — replacing short branches with conditional sets avoids the performance penalty of branch prediction failures.

Mnemonic Set condition Equivalent semantics
SETZ / SETE ZF = 1 Set if equal / result is zero
SETNZ / SETNE ZF = 0 Set if not equal / result is not zero
SETC CF = 1 Set if carry/borrow
SETNC CF = 0 Set if no carry/borrow
SETO OF = 1 Set if overflow
SETNO OF = 0 Set if no overflow
SETS SF = 1 Set if result is negative
SETNS SF = 0 Set if result is positive
SETG / SETNLE ZF=0 and SF=OF Set if signed greater than
SETGE / SETNL SF = OF Set if signed greater than or equal
SETL / SETNGE SF ≠ OF Set if signed less than
SETLE / SETNG ZF=1 or SF≠OF Set if signed less than or equal
SETA / SETNBE CF=0 and ZF=0 Set if unsigned greater than
SETAE / SETNB CF = 0 Set if unsigned greater than or equal
SETB / SETNAE CF = 1 Set if unsigned less than
SETBE / SETNA CF=1 or ZF=1 Set if unsigned less than or equal

CMP EAX, EBX followed by SETG AL has the effect: if EAX is signed greater than EBX, AL is set to 1, otherwise 0. This is JG label; MOV AL, 1; JMP done; label: MOV AL, 0; done: more concise and efficient.


Input/output instructions

I/O instructions are used for data exchange between the CPU and external device ports.

In the x86 architecture, the port address space and memory address space are independent of each other and must be accessed through dedicated I/O instructions.

Mnemonic Brief description of function
IN Read data from the specified port into AL/AX/EAX. When the port address is 0-255 an immediate can be written directly; above 255 it must be specified via the DX register
OUT Write data from AL/AX/EAX to the specified port. The port address rule is the same as IN
INS Read a byte/word/dword from the port into the memory pointed to by ES:EDI, automatically updating EDI (similar to STOS but reading from I/O)
OUTS Output the byte/word/dword at the memory pointed to by DS:ESI to the port, automatically updating ESI

In modern operating systems (Windows, Linux), user-mode programs usually cannot execute I/O instructions directly — these instructions are restricted by the OS to kernel mode only. They can be used freely in a DOS environment or bare-metal programming.


Processor Control and Miscellaneous Instructions

These instructions control the processor's operating state, including flag operations, synchronization control, and system information retrieval.

Mnemonic Brief description of function
CLC Clear carry flag, set CF to 0
STC Set carry flag, set CF to 1
CMC Complement carry flag, CF becomes its opposite value
CLD Clear direction flag, set DF to 0, string operation pointers auto-increment
STD Set direction flag, set DF to 1, string operation pointers auto-decrement
CLI Clear interrupt flag, set IF to 0, disable maskable hardware interrupts
STI Set interrupt flag, set IF to 1, enable maskable hardware interrupts
NOP No operation, machine code 0x90, performs no effective operation. Often used for instruction alignment, delay padding, or reserving patch space
HLT Halt: the processor suspends execution until an external interrupt or reset signal is received
WAIT / FWAIT Wait for the FPU to complete its current operation, mainly used to synchronize with the x87 coprocessor
LOCK Bus lock prefix, makes the following instruction execute atomically. Classic uses: LOCK XCHG for spinlocks, LOCK CMPXCHG for CAS operations
CPUID Get CPU feature information, including vendor ID, supported instruction set extensions, etc. The function number must be set in EAX before the call
RDTSC Read the time-stamp counter, storing the 64-bit count into EDX:EAX, used for high-precision performance measurement

Floating-Point Instructions

The following are traditional x87 FPU floating-point instructions, suitable for scientific computing scenarios using the floating-point stack.

In modern programming, SIMD instruction sets such as SSE/SSE2 have gradually replaced x87, but x87 is still widely used when understanding legacy code or performing simple floating-point operations.

Mnemonic Brief description of function
FLD Load a floating-point number from memory onto the FPU stack top ST(0), moving the stack pointer up
FST / FSTP Store the stack top data to memory. FST does not pop the stack, FSTP pops the stack (stack pointer moves down)
FADD Floating-point addition: add ST(0) and the specified operand, storing the result in ST(0)
FSUB Floating-point subtraction: ST(0) minus the specified operand
FMUL Floating-point multiplication
FDIV Floating-point division: ST(0) divided by the specified operand
FCOM / FCOMP Compare ST(0) with the specified operand, setting the condition codes in the FPU status word. FCOMP pops the stack after comparison
FCHS Change the sign of the value in ST(0) (positive to negative, negative to positive)
FSQRT Compute the square root of ST(0), storing the result in ST(0)
FSIN / FCOS Compute the sine/cosine of ST(0) (argument in radians), storing the result in ST(0)
FPTAN Compute the tangent of ST(0)
FLD1 Push the constant 1.0 onto the FPU stack top
FLDZ Push the constant 0.0 onto the FPU stack top
FLDPI Push the constant π (3.14159...) onto the FPU stack top

Using the x87 FPUfloating-point register stack(ST(0) - ST(7), 8 registers of 80 bits each). Note the stack depth limit before use — pushing more than 8 values causes a stack overflow exception.


Notes