x86 Instruction Set
revise and note what's before!
Multiplication and division
Multiplication
- Single argument -> result 2x longer than source:
MUL - unsigned
IMUL - signed - Two arguments -> register, register/memory
result of the same length as source arguments - Three arguments -> register, register/memory, immediate
result of the same length as source arguments
The lower half of result is the same for unsigned and signed multiplication
The 2- and 3-argument instruction is IMUL but may be used for both unsigned and signed
MULX - new instruction, 3 arguments, doesn't set flags
Division
only single argument form with implied arguments
complementary to single argument multiplication
dividend 2x longer than divisor and result
two variants:
- DIV - unsigned
- IDIV - signed
Single argument multiplication
| Instruction | Explicit arg | Implicit arguments |
|---|---|
| MUL, IMUL | Multiplier | Product / Multiplicand / / |
| DIV, IDIV | Divisor | Divident / Quotient / Remainder |
| r/m8 | AX, AL, AH | |
| r/m16 | DX:AX, AX, DX | |
| r/m32 | EDX:EAX, EAX, EDX | |
| r/m64 | RDX, RAX, RAX, RDX | |
| Divion of numbers (of the same length) - required extension of a dividend |
- *Division of numbers - ex. MOV EDX 0
- IDIV - sign extension using special no-argument instructios: CBW, CWD, CDQ
Division instructions generate trap if overflow occurs - DIV, IDIB and AAM 0 instructions
- usually when we forget to expand the dividend
Operations on flag register
- CLC, STC, CMC
- LAHF, SAHF
Jump instructions
User to transfer the constrol from one contigous addres
Jump
Constant (immediate) target address - unconditional and conditional
Sobroutine returns
RET - return
RET n - return and deallocate arguments
Variable target address - JMP & CALL ex.
- MP EAKX
- JMP [code_pointer]
- JMP [Table + EAX*4]
Conditional instructions other than jumps
CMOVcc - conditional move
SETcc - convert condition to Boolean value 0/1
Instructions for HLL support
RET n - subroutine return with argument deallocation
...
x86 iterative instructions
5 instructions (+2 privileged) using implied registers
- RAX/EAX/AX/AL - data register (a)
- RDX/ECX - loop counter
- RSI/ESI - source pointer (s)
- RDI/EDI - destination pointer (d) - uses ES selector, cannot be altered2
2 forms: - single - performs operation, modifies pointer(s)
- iterated - instruction forms while() loop iterated EXC time (while equal/not equal)
- iterated form prefixed with
REP (repeat) - data move instructions
REPE (repeat while equal)
REPNE (repeat while not equal)
Pointers are modified after data access, depending on setting of DF flag in EFLAGS
- DF = 0 - incremented, DF = 1 - decremented
- DF value may be set using CLD and STD instructions
- calling conventions require DF = 0 during every control transfer (CALL, RET)
- Instruction name must be appended with data size specifier (B, W, D, Q)
Instructions
LOAD - load -
STOS - store -
MOVS - copy -
SCAS - scan -
CMPS - compare -
Self looping instructions
...
CPUID instruction
Before execution, EAX is loaded with leaf identifies (32-bit arg. for CPUID)
After execution, EAX, EBX, ECX, EDX contain useful information (changes depending on EAX leaf value)
- Processor name and version
- Units and instruction available (FPU, MMX, SSE...SSE5, ADM64)
- System programming model extensions
- Cache and TLB capacity and organization details
- Implemented address size
- Processing speed and power