Condividi tramite


x86 Instructions

Nelle liste di questa sezione le istruzioni contrassegnate con un asterisco (*) sono particolarmente importanti. Le istruzioni non così contrassegnate non sono critiche.

Nel processore x86 le istruzioni sono di dimensioni variabili, quindi il disassembling all'indietro è un esercizio nella corrispondenza dei criteri. Per smontare indietro da un indirizzo, è consigliabile iniziare a disassemblare in un punto più indietro di quello che si vuole veramente andare, quindi guardare avanti fino a quando le istruzioni non iniziano a avere senso. Le prime istruzioni potrebbero non avere senso perché potrebbe essere stato avviato il disassembling al centro di un'istruzione. C'è una possibilità, purtroppo, che il disassembly non si sincronizzerà mai con il flusso di istruzioni e si dovrà provare a disassemblare in un punto di partenza diverso fino a trovare un punto di partenza che funziona.

For well-packed switch statements, the compiler emits data directly into the code stream, so disassembling through a switch statement will usually stumble across instructions that make no sense (because they are really data). Trovare la fine dei dati e continuare il disassembling.

Notazione istruzione

La notazione generale per le istruzioni consiste nell'inserire il registro di destinazione a sinistra e l'origine a destra. Tuttavia, possono esserci alcune eccezioni a questa regola.

Le istruzioni aritmetiche sono in genere due registri con i registri di origine e di destinazione che combinano. Il risultato viene archiviato nella destinazione.

Alcune delle istruzioni includono sia versioni a 16 bit che a 32 bit, ma solo le versioni a 32 bit sono elencate qui. Non elencato di seguito sono riportate istruzioni a virgola mobile, istruzioni con privilegi e istruzioni usate solo nei modelli segmentati (che Microsoft Win32 non usa).

Per risparmiare spazio, molte delle istruzioni sono espresse in forma combinata, come illustrato nell'esempio seguente.

*

MOV

r1, r/m/#n

r1 = r/m/#n

significa che il primo parametro deve essere un registro, ma il secondo può essere un registro, un riferimento alla memoria o un valore immediato.

Per risparmiare ancora più spazio, le istruzioni possono essere espresse anche come illustrato di seguito.

*

MOV

r1/m, r/m/#n

r1/m = r/m/#n

il che significa che il primo parametro può essere un registro o un riferimento alla memoria e il secondo può essere un registro, un riferimento alla memoria o un valore immediato.

Se non diversamente specificato, quando viene usata questa abbreviazione, non è possibile scegliere la memoria sia per l'origine che per la destinazione.

Inoltre, è possibile aggiungere un suffisso di dimensioni bit (8, 16, 32) all'origine o alla destinazione per indicare che il parametro deve essere di tale dimensione. Ad esempio, r8 indica un registro a 8 bit.

Memoria, trasferimento dati e conversione dei dati

Le istruzioni di trasferimento di memoria e dati non influiscono sui flag.

Indirizzo effettivo

*

LEA

r, m

Caricare l'indirizzo effettivo.

(r = indirizzo di m)

Ad esempio , LEA eax, [esi+4] significa eax = esi + 4. Questa istruzione viene spesso usata per eseguire operazioni aritmetiche.

Trasferimento dati

MOV

r1/m, r2/m/#n

r1/m = r/m/#n

MOVSX

r1, r/m

Spostarsi con l'estensione del segno.

*

MOVZX

r1, r/m

Spostarsi con zero estensione.

MOVSX and MOVZX are special versions of the mov instruction that perform sign extension or zero extension from the source to the destination. Questa è l'unica istruzione che consente all'origine e alla destinazione di avere dimensioni diverse. (E in effetti, devono essere dimensioni diverse.

Manipolazione dello stack

The stack is pointed to by the esp register. The value at esp is the top of the stack (most recently pushed, first to be popped); older stack elements reside at higher addresses.

PUSH

r/m/#n

Eseguire il push del valore nello stack.

POP

r/m

Valore pop dallo stack.

PUSHFD

Eseguire il push dei flag nello stack.

POPFD

Flag pop dallo stack.

PUSHAD

Eseguire il push di tutti i registri integer.

POPAD

Pop all integer registers .Pop all integer registers.

ENTER

#n, #n

Frame dello stack di compilazione.

*

LEAVE

Smontare lo stack frame

The C/C++ compiler does not use the enter instruction. (The enter instruction is used to implement nested procedures in languages like Algol or Pascal.)

The leave instruction is equivalent to:

mov esp, ebp
pop ebp

Conversione dei dati

CBW

Convert byte (al) to word (ax).

CWD

Convert word (ax) to dword (dx:ax).

CWDE

Convert word (ax) to dword (eax).

CDQ

convert dword (eax) to qword (edx:eax).

Tutte le conversioni eseguono l'estensione del segno.

Manipolazione aritmetica e bit

Tutte le istruzioni di manipolazione aritmetica e bit modificano i flag.

Aritmetica

ADD

r1/m, r2/m/#n

r1/m += r2/m/#n

ADC

r1/m, r2/m/#n

r1/m += r2/m/#n + carry

SUB

r1/m, r2/m/#n

r1/m -= r2/m/#n

SBB

r1/m, r2/m/#n

r1/m -= r2/m/#n + carry

NEG

r1/m

r1/m = -r1/m

INC

r/m

r/m += 1

DEC

r/m

r/m -= 1

CMP

r1/m, r2/m/#n

Compute r1/m - r2/m/#n

The cmp instruction computes the subtraction and sets flags according to the result, but throws the result away. It is typically followed by a conditional jump instruction that tests the result of the subtraction.

MUL

r/m8

ax = al * r/m8

MUL

r/m16

dx:ax = ax * r/m16

MUL

r/m32

edx:eax = eax * r/m32

IMUL

r/m8

ax = al * r/m8

IMUL

r/m16

dx:ax = ax * r/m16

IMUL

r/m32

edx:eax = eax * r/m32

IMUL

r1, r2/m

r1 *= r2/m

IMUL

r1, r2/m, #n

r1 = r2/m * #n

Moltiplicazione senza segno e con segno. Lo stato dei flag dopo la moltiplicazione non è definito.

DIV

r/m8

(ah, al) = (ax % r/m8, ax / r/m8)

DIV

r/m16

(dx, ax) = dx:ax / r/m16

DIV

r/m32

(edx, eax) = edx:eax / r/m32

IDIV

r/m8

(ah, al) = ax / r/m8

IDIV

r/m16

(dx, ax) = dx:ax / r/m16

IDIV

r/m32

(edx, eax) = edx:eax / r/m32

Divisione senza segno e firmata. Il primo registro nella spiegazione pseudocodice riceve il resto e il secondo riceve il quoziente. Se il risultato supera la destinazione, viene generata un'eccezione di overflow della divisione.

Lo stato dei flag dopo la divisione non è definito.

*

SETcc

r/m8

Set r/m8 to 0 or 1

If the condition cc is true, then the 8-bit value is set to 1. In caso contrario, il valore a 8 bit è impostato su zero.

Decimale codificato in formato binario

Queste istruzioni non verranno visualizzate a meno che non si stia eseguendo il debug del codice scritto in COBOL.

DAA

Regolazione decimale dopo l'aggiunta.

DAS

Regolazione decimale dopo la sottrazione.

These instructions adjust the al register after performing a packed binary-coded decimal operation.

AAA

ASCII regola dopo l'aggiunta.

AAS

ASCII regola dopo la sottrazione.

These instructions adjust the al register after performing an unpacked binary-coded decimal operation.

AAM

ASCII regola dopo la moltiplicazione.

AAD

ASCII regola dopo la divisione.

These instructions adjust the al and ah registers after performing an unpacked binary-coded decimal operation.

Bit

AND

r1/m, r2/m/#n

r1/m = r1/m and r2/m/#n

OR

r1/m, r2/m/#n

r1/m = r1/m or r2/m/#n

XOR

r1/m, r2/m/#n

r1/m = r1/m xor r2/m/#n

NOT

r1/m

r1/m = bitwise not r1/m

*

TEST

r1/m, r2/m/#n

Compute r1/m and r2/m/#n

The test instruction computes the logical AND operator and sets flags according to the result, but throws the result away. In genere è seguita da un'istruzione di salto condizionale che testa il risultato dell'AND logico.

SHL

r1/m, cl/#n

r1/m <<= cl/#n

SHR

r1/m, cl/#n

r1/m >>= cl/#n zero-fill

*

SAR

r1/m, cl/#n

r1/m >>= cl/#n sign-fill

L'ultimo bit spostato fuori è posizionato nel trasporto.

SHLD

r1, r2/m, cl/#n

Sposta il doppio a sinistra.

Shift r1 left by cl/#n, filling with the top bits of r2/m. L'ultimo bit spostato fuori è posizionato nel trasporto.

SHRD

r1, r2/m, cl/#n

Sposta il doppio a destra.

Shift r1 right by cl/#n, filling with the bottom bits of r2/m. L'ultimo bit spostato fuori è posizionato nel trasporto.

ROL

r1, cl/#n

Rotate r1 left by cl/#n.

ROR

r1, cl/#n

Rotate r1 right by cl/#n.

RCL

r1, cl/#n

Rotate r1/C left by cl/#n.

RCR

r1, cl/#n

Rotate r1/C right by cl/#n.

La rotazione è simile allo spostamento, ad eccezione del fatto che i bit spostati vengono nuovamente spostati come bit di riempimento in ingresso. La versione in linguaggio C delle istruzioni di rotazione incorpora il bit di trasporto nella rotazione.

BT

r1, r2/#n

Copy bit r2/#n of r1 into carry.

BTS

r1, r2/#n

Set bit r2/#n of r1, copy previous value into carry.

BTC

r1, r2/#n

Clear bit r2/#n of r1, copy previous value into carry.

Flusso di controllo

Jcc

dest

Branch conditional.

JMP

dest

Jump direct.

JMP

r/m

Jump indirect.

CALL

dest

Call direct.

*

CALL

r/m

Call indirect.

The call instruction pushes the return address onto the stack then jumps to the destination.

*

RET

#n

Return

The ret instruction pops and jumps to the return address on the stack. A nonzero #n in the RET instruction indicates that after popping the return address, the value #n should be added to the stack pointer.

LOOP

Decrement ecx and jump if result is nonzero.

LOOPZ

Decrement ecx and jump if result is nonzero and zr was set.

LOOPNZ

Decrement ecx and jump if result is nonzero and zr was clear.

JECXZ

Jump if ecx is zero.

Queste istruzioni sono resti del patrimonio CISC di x86 e nei processori recenti sono in realtà più lenti rispetto alle istruzioni equivalenti scritte per lungo tempo.

Manipolazione delle stringhe

MOVST

Move T from esi to edi.

CMPST

Compare T from esi with edi.

SCAST

Scan T from edi for accT.

LODST

Load T from esi into accT.

STOST

Store T to edi from accT.

After performing the operation, the source and destination register are incremented or decremented by sizeof(T), according to the setting of the direction flag (up or down).

The instruction can be prefixed by REP to repeat the operation the number of times specified by the ecx register.

The rep mov instruction is used to copy blocks of memory.

The rep stos instruction is used to fill a block of memory with accT.

Bandiere

LAHF

Load ah from flags.

SAHF

Store ah to flags.

STC

Set carry.

CLC

Clear carry.

CMC

Complement carry.

STD

Set direction to down.

CLD

Set direction to up.

STI

Enable interrupts.

CLI

Disable interrupts.

Istruzioni interlocked

XCHG

r1, r/m

Swap r1 and r/m.

XADD

r1, r/m

Add r1 to r/m, put original value in r1.

CMPXCHG

r1, r/m

Confronto e scambio condizionale.

The cmpxchg instruction is the atomic version of the following:

   cmp     accT, r/m
   jz      match
   mov     accT, r/m
   jmp     done
match:
   mov     r/m, r1
done:

Misto

INT

#n

Trap per il kernel.

BOUND

r, m

Trap if r not in range.

*

NOP

No operation.

XLATB

al = [ebx + al]

BSWAP

r

Scambiare l'ordine dei byte nel registro.

Here is a special case of the int instruction.

INT

3

Trap del punto di interruzione del debugger.

The opcode for INT 3 is 0xCC. The opcode for NOP is 0x90.

Durante il debug del codice, potrebbe essere necessario applicare patch ad alcuni codice. A tale scopo, sostituire i byte che causano l'offesa con 0x90.

Idiomi

XOR

r, r

r = 0

TEST

r, r

Check if r = 0.

*

ADD

r, r

Shift r left by 1.