跳转到内容

X86汇编语言/基本指令集

本页使用了标题或全文手工转换
维基教科书,自由的教学读本

主页 > 计算机科学与技术书架 > X86汇编语言 > 基本指令集


数据搬移指令(Data transfer instructions

[编辑]
  • MOV:在通用寄存器之间移动数据;在主存和通用或区段寄存器之间移动数据;将立即数值移动到通用寄存器。(Move data between general-purpose registers; move data between memory and general purpose or segment registers; move immediates to general-purpose registers.)
  • CMOVE/CMOVZ:Conditional move if equal/Conditional move if zero.
  • CMOVNE/CMOVNZ:Conditional move if not equal/Conditional move if not zero.
  • CMOVA/CMOVNBE:Conditional move if above/Conditional move if not below or equal.
  • CMOVAE/CMOVNB:Conditional move if above or equal/Conditional move if not below.
  • CMOVB/CMOVNAE:Conditional move if below/Conditional move if not above or equal.
  • CMOVBE/CMOVNA:Conditional move if below or equal/Conditional move if not above.
  • CMOVG/CMOVNLE:Conditional move if greater/Conditional move if not less or equal.
  • CMOVGE/CMOVNL:Conditional move if greater or equal/Conditional move if not less.
  • CMOVL/CMOVNGE:Conditional move if less/Conditional move if not greater or equal.
  • CMOVLE/CMOVNG:Conditional move if less or equal/Conditional move if not greater.
  • CMOVC:Conditional move if carry.
  • CMOVNC:Conditional move if not carry.
  • CMOVO:Conditional move if overflow.
  • CMOVNO:Conditional move if not overflow.
  • CMOVS:Conditional move if sign (negative).
  • CMOVNS:Conditional move if not sign (non-negative).
  • CMOVP/CMOVPE:Conditional move if parity/Conditional move if parity even.
  • CMOVNP/CMOVPO:Conditional move if not parity/Conditional move if parity odd.
  • XCHG:交换。(Exchange.)
  • BSWAP:Byte swap.
  • XADD:Exchange and add.
  • CMPXCHG:Compare and exchange.
  • CMPXCHG8B:Compare and exchange 8 bytes.
  • PUSH:Push onto stack.
  • POP:Pop off of stack.
  • PUSHA/PUSHAD:Push general-purpose registers onto stack.
  • POPA/POPAD:Pop general-purpose registers from stack.
  • CWD/CDQ:Convert word to doubleword/Convert doubleword to quadword.
  • CBW/CWDE:Convert byte to word/Convert word to doubleword in EAX register.
  • MOVSX:Move and sign extend.
  • MOVZX:Move and zero extend.

二进制算术指令(Binary Arithmetic Instructions

[编辑]
  • ADCX:Unsigned integer add with carry.
  • ADOX:Unsigned integer add with overflow.
  • ADD:Integer add.
  • ADC:含进位的加法。(Add with carry.)
  • SUB:减法。(Subtract.)
  • SBB:含借位的减法。Subtract with borrow.
  • IMUL:有号数乘法。(Signed multiply.)
  • MUL:无号数乘法。(Unsigned multiply.)
  • IDIV:有号数除法。(Signed divide.)
  • DIV:无号数除法。(Unsigned divide.)
  • INC:加一。(Increment.)
  • DEC:减一。(Decrement.)
  • NEG:Negate.
  • CMP:比较。(Compare.)

十进制算术指令(Decimal Arithmetic Instructions

[编辑]
  • DAA:Decimal adjust after addition.
  • DAS:Decimal adjust after subtraction.
  • AAA:ASCII adjust after addition.
  • AAS:ASCII adjust after subtraction.
  • AAM:ASCII adjust after multiplication.
  • AAD:ASCII adjust before division.

逻辑指令(Decimal Arithmetic Instructions

[编辑]
  • AND:Perform bitwise logical AND.
  • OR:Perform bitwise logical OR.
  • XOR:Perform bitwise logical exclusive OR.
  • NOT:Perform bitwise logical NOT

移位及轮转指令(Shift and Rotate Instruction

[编辑]
  • SAR:Shift arithmetic right.
  • SHR:Shift logical right.
  • SAL/SHL:Shift arithmetic left/Shift logical left.
  • SHRD:Shift right double.
  • SHLD:Shift left double.
  • ROR:Rotate right.
  • ROL:Rotate left.
  • RCR:Rotate through carry right.
  • RCL:Rotate through carry left

比特及字节指令(Bit and Byte Instructions

[编辑]
  • BT:Bit test.
  • BTS:Bit test and set.
  • BTR:Bit test and reset.
  • BTC:Bit test and complement.
  • BSF:Bit scan forward.
  • BSR:Bit scan reverse.
  • SETE/SETZ:Set byte if equal/Set byte if zero.
  • SETNE/SETNZ:Set byte if not equal/Set byte if not zero.
  • SETA/SETNBE:Set byte if above/Set byte if not below or equal.
  • SETAE/SETNB/SETNC:Set byte if above or equal/Set byte if not below/Set byte if not carry.
  • SETB/SETNAE/SETC:Set byte if below/Set byte if not above or equal/Set byte if carry.
  • SETBE/SETNA:Set byte if below or equal/Set byte if not above.
  • SETG/SETNLE:Set byte if greater/Set byte if not less or equal.
  • SETGE/SETNL:Set byte if greater or equal/Set byte if not less.
  • SETL/SETNGE:Set byte if less/Set byte if not greater or equal.
  • SETLE/SETNG:Set byte if less or equal/Set byte if not greater.
  • SETS:Set byte if sign (negative).
  • SETNS:Set byte if not sign (non-negative).
  • SETO:Set byte if overflow.
  • SETNO:Set byte if not overflow.
  • SETPE/SETP:Set byte if parity even/Set byte if parity.
  • SETPO/SETNP:Set byte if parity odd/Set byte if not parity.
  • TEST:Logical compare.
  • CRC32:Provides hardware acceleration to calculate cyclic redundancy checks for fast and efficient implementation of data integrity protocols.
  • POPCNT:This instruction calculates of number of bits set to 1 in the second operand (source) and returns the count in the first operand (a destination register)

控制转移指令(Control Transfer Instruction

[编辑]
  • JMP:无条件跳跃(Jump.)
  • JE/JZ:Jump if equal/Jump if zero.
  • JNE/JNZ:Jump if not equal/Jump if not zero.
  • JA/JNBE:Jump if above/Jump if not below or equal.
  • JAE/JNB:Jump if above or equal/Jump if not below.
  • JB/JNAE:Jump if below/Jump if not above or equal.
  • JBE/JNA:Jump if below or equal/Jump if not above.
  • JG/JNLE:Jump if greater/Jump if not less or equal.
  • JGE/JNL:Jump if greater or equal/Jump if not less.
  • JL/JNGE:Jump if less/Jump if not greater or equal.
  • JLE/JNG:Jump if less or equal/Jump if not greater.
  • JC:Jump if carry.
  • JNC:Jump if not carry.
  • JO:Jump if overflow.
  • JNO:Jump if not overflow.
  • JS:Jump if sign (negative).
  • JN:Jump if not sign (non-negative).
  • JPO/JNP:Jump if parity odd/Jump if not parity.
  • JPE/JP:Jump if parity even/Jump if parity.
  • JCXZ/JECXZ:Jump register CX zero/Jump register ECX zero.
  • LOOP:Loop with ECX counter.
  • LOOPZ/LOOPE:Loop with ECX and zero/Loop with ECX and equal.
  • LOOPNZ/LOOPNE:Loop with ECX and not zero/Loop with ECX and not equal.
  • CALL:调用副程序或函数。(Call procedure.)
  • RET:从副程序或函数返回。(Return.)
  • IRET:从插断返回。(Return from interrupt.)
  • INT:软件插断。(Software interrupt.)
  • INTO:Interrupt on overflow.
  • BOUND:Detect value out of range.
  • ENTER:High-level procedure entry.
  • LEAVE:High-level procedure exit

字符串指令(String Instruction

[编辑]
  • MOVS/MOVSB:Move string/Move byte string.
  • MOVS/MOVSW:Move string/Move word string.
  • MOVS/MOVSD:Move string/Move doubleword string.
  • CMPS/CMPSB:Compare string/Compare byte string.
  • CMPS/CMPSW:Compare string/Compare word string.
  • CMPS/CMPSD:Compare string/Compare doubleword string.
  • SCAS/SCASB:Scan string/Scan byte string.
  • SCAS/SCASW:Scan string/Scan word string.
  • SCAS/SCASD:Scan string/Scan doubleword string.
  • LODS/LODSB:Load string/Load byte string.
  • LODS/LODSW:Load string/Load word string.
  • LODS/LODSD:Load string/Load doubleword string.
  • STOS/STOSB:Store string/Store byte string.
  • STOS/STOSW:Store string/Store word string.
  • STOS/STOSD:Store string/Store doubleword string.
  • REP:Repeat while ECX not zero.
  • REPE/REPZ:Repeat while equal/Repeat while zero.
  • REPNE/REPNZ:Repeat while not equal/Repeat while not zero.

输入及输出指令(I/O Instruction

[编辑]
  • IN:Read from a port.
  • OUT:Write to a port.
  • INS/INSB:Input string from port/Input byte string from port.
  • INS/INSW:Input string from port/Input word string from port.
  • INS/INSD:Input string from port/Input doubleword string from port.
  • OUTS/OUTSB:Output string to port/Output byte string to port.
  • OUTS/OUTSW:Output string to port/Output word string to port

进入及离开指令(Enter and Leave Instruction

[编辑]
  • ENTER:High-level procedure entry.
  • LEAVE:High-level procedure exit

旗标控制(EFLAG)指令(Flag Control (EFLAG) Instructions

[编辑]
  • STC:设置进位旗标。(Set carry flag.)
  • CLC:清除进位旗标。(Clear the carry flag.)
  • CMC:Complement the carry flag.
  • CLD:Clear the direction flag.
  • STD:Set direction flag.
  • LAHF:Load flags into AH register.
  • SAHF:Store AH register into flags.
  • PUSHF/PUSHFD:Push EFLAGS onto stack.
  • POPF/POPFD:Pop EFLAGS from stack.
  • STI:设置插断旗标。(Set interrupt flag.)
  • CLI:清除插断旗标。(Clear the interrupt flag)

区段寄存器指令(Segment Register Instruction

[编辑]
  • LDS:Load far pointer using DS.
  • LES:Load far pointer using ES.
  • LFS:Load far pointer using FS.
  • LGS:Load far pointer using GS.
  • LSS:Load far pointer using SS

杂项指令(Miscellaneous Instruction

[编辑]
  • LEA:Load effective address.
  • NOP:无运算。(No operation.)
  • UD:Undefined instruction.
  • XLAT/XLATB:Table lookup translation.
  • CPUID:Processor identification.
  • MOVBE: Move data after swapping data bytes.
  • PREFETCHW: Prefetch data into cache in anticipation of write.
  • PREFETCHWT: Prefetch hint T1 with intent to write.
  • CLFLUSH:Flushes and invalidates a memory operand and its associated cache line from all levels of the processor’s cache hierarchy.
  • CLFLUSHOPT:Flushes and invalidates a memory operand and its associated cache line from all levels of the processor’s cache hierarchy with optimized memory system throughput

用户模式扩展状态的存储及还原指令(User Mode Extended Sate Save/Restore Instruction

[编辑]
  • XSAVE:Save processor extended states to memory.
  • XSAVEC:Save processor extended states with compaction to memory.
  • XSAVEOPT:Save processor extended states to memory, optimized.
  • XRSTOR:Restore processor extended states from memory.
  • XGETBV:Reads the state of an extended control register

随机数产生指令(Random Number Generator Instructions

[编辑]
  • RDRAND:Retrieves a random number generated from hardware.
  • RDSEED:Retrieves a random number generated from hardwar

BMI1, BMI2

[编辑]
  • ANDN:Bitwise AND of first source with inverted 2nd source operands.
  • BEXTR:Contiguous bitwise extract.
  • BLSI:Extract lowest set bit.
  • BLSMSK:Set all lower bits below first set bit to 1.
  • BLSR:Reset lowest set bit.
  • BZHI:Zero high bits starting from specified bit position.
  • LZCNT:Count the number leading zero bits.
  • MULX:Unsigned multiply without affecting arithmetic flags.
  • PDEP:Parallel deposit of bits using a mask.
  • PEXT:Parallel extraction of bits using a mask.
  • RORX:Rotate right without affecting arithmetic flags.
  • SARX:Shift arithmetic right.
  • SHLX:Shift logic left.
  • SHRX:Shift logic right.
  • TZCNT:Count the number trailing zero bits

Detection of VEX-encoded GPR Instructions, LZCNT and TZCNT, PREFETCH

[编辑]

以下内容待整理

[编辑]

数据搬移指令 (Data transfer instructions

[编辑]

整数运算指令

[编辑]

加法

[编辑]
  • add : 加
  • adc : 加 (含进位)
  • inc : 加1

减法

[编辑]
  • sub : 减
  • sbb : 减 (含借位)
  • dec : 减1

乘法

[编辑]
  • mul : 乘 (无号数)
  • imul : 乘 (有号数)

除法

[编辑]
  • div : 除 (无号数)
  • idiv : 除 (有号数)

逻辑运算指令

[编辑]

比特位移指令

[编辑]

程序流程控制

[编辑]

跳越指令

[编辑]

无条件跳越

[编辑]

无号数运算(比较)后使用的条件跳越指令

[编辑]
指令 意义 条件
je 若等于则跳越 x = y ZF=1
jne 若不等于则跳越 x≠y ZF=0
ja
jnbe
若高于则跳越
若不低于则跳越
x > y CF=0且ZF=0
jae
jnb
若高于或等于则跳越
若不低于或等于则跳越
x≧y CF=0
jb
jnae
若低于则跳越
若不高于或等于则跳越
x < y CF=1
jbe
jna
若低于或等于则跳越
若不高于则跳越
x≦y CF=1或ZF=1

有号数运算(比较)后使用的条件跳越指令

[编辑]
指令 意义 条件
je 若等于则跳越 x = y ZF=1
jne 若不等于则跳越 x≠y ZF=0
jg
jnle
若大于则跳越
若不低于或等于则跳越
x > y ZF=0且SF=OF
jge
jnl
若高于于或等于则跳越
若不低于则跳越
x≧y SF=OF
jl
jngl
若低于则跳越
若不大于或等于则跳越
x < y SF≠OF
jle
jng
若低于或等于则跳越
若不大于则跳越
x≦y ZF=1或SF≠OF

依旗号状态判断的条件跳越指令

[编辑]
指令 意义 条件
jc 若进位则跳越 CF=1
jnc 若无进位则跳越 CF=0
js 若为负数则跳越 SF=1
jns 若为正数则跳越 SF=0
jz 若等于0则跳越 ZF=1
jnz 若不等于0则跳越 ZF=0
jp 若同位则跳越 PF=1
jnp 若没有同位则跳越 PF=0
jpe 若偶同位则跳越 PF=1
jpo 若奇同位则跳越 PF=0
jo 若溢出则跳越 OF=1
jno 若没有溢出则跳越 OF=0

循环控制指令

[编辑]

中断指令(Interrupt Instruction

[编辑]
  • int : 进入中断处理程序
  • into : 运算溢出,产生中断
  • iret : 自中断处理程序中返回

旗标控制相关指令

[编辑]

中断标志位

[编辑]
  • cli : 清中断允许
  • sti : 置中断允许

进位标志位

[编辑]
  • clc : 清进位标志位
  • stc : 置进位标志位
  • cmc : 进位标志位取反

  • 以下暂存
    mov:這是組語裡面最常見的指令,將數值記入暫存器或是將A暫存器的內涵值移入B暫存器等等.
    範例語法:  mov 目的,來源        <==將來源值移入目的暫存器
                 mov DX,[zzz]       <==將zzz變數內涵移入DX暫存器
                 mov EAX,14h        <==移14h值移入EAX
    int:呼叫中斷來處理之前暫存器內涵值所對應的工作.例如Linux是int 0x80.
    add:加
     sub:減
     mul:乘
     div:除