Bagikan melalui


x86 Instructions

Dalam daftar di bagian ini, instruksi yang ditandai dengan tanda bintang (*) sangat penting. Instruksi yang tidak ditandai tidak penting.

Pada prosesor x86, instruksi berukuran variabel, jadi membongkar mundur adalah latihan dalam pencocokan pola. Untuk membongkar mundur dari alamat, Anda harus mulai membongkar pada titik lebih jauh ke belakang daripada yang benar-benar ingin Anda lakukan, lalu lihat ke depan sampai instruksi mulai masuk akal. Beberapa instruksi pertama mungkin tidak masuk akal karena Anda mungkin telah mulai membongkar di tengah instruksi. Ada kemungkinan, sayangnya, bahwa pembongkaran tidak akan pernah disinkronkan dengan aliran instruksi dan Anda harus mencoba membongkar pada titik awal yang berbeda sampai Anda menemukan titik awal yang berfungsi.

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). Temukan akhir data dan lanjutkan membongkar di sana.

Notasi Instruksi

Notasi umum untuk instruksi adalah menempatkan register tujuan di sebelah kiri dan sumber di sebelah kanan. Namun, mungkin ada beberapa pengecualian untuk aturan ini.

Instruksi aritmatika biasanya dua-daftar dengan register sumber dan tujuan yang digabungkan. Hasilnya disimpan ke tujuan.

Beberapa instruksi memiliki versi 16-bit dan 32-bit, tetapi hanya versi 32-bit yang tercantum di sini. Tidak tercantum di sini adalah instruksi floating-point, instruksi istimewa, dan instruksi yang hanya digunakan dalam model tersegmentasi (yang tidak digunakan Microsoft Win32).

Untuk menghemat ruang, banyak instruksi dinyatakan dalam bentuk gabungan, seperti yang ditunjukkan dalam contoh berikut.

*

MOV

r1, r/m/#n

r1 = r/m/#n

berarti bahwa parameter pertama harus berupa register, tetapi yang kedua dapat berupa register, referensi memori, atau nilai langsung.

Untuk menghemat lebih banyak ruang, instruksi juga dapat dinyatakan seperti yang ditunjukkan dalam hal berikut.

*

MOV

r1/m, r/m/#n

r1/m = r/m/#n

yang berarti bahwa parameter pertama dapat menjadi referensi register atau memori, dan yang kedua dapat menjadi register, referensi memori, atau nilai langsung.

Kecuali dinyatakan lain, ketika singkatan ini digunakan, Anda tidak dapat memilih memori untuk sumber dan tujuan.

Selain itu, akhiran ukuran bit (8, 16, 32) dapat ditambahkan ke sumber atau tujuan untuk menunjukkan bahwa parameter harus berukuran tersebut. Misalnya, r8 berarti register 8-bit.

Memori, Transfer Data, dan Konversi Data

Instruksi transfer memori dan data tidak memengaruhi bendera.

Alamat Efektif

*

LEA

r, m

Muat alamat yang efektif.

(r = alamat m)

Misalnya, LEA eax, [esi+4] berarti eax = esi + 4. Instruksi ini sering digunakan untuk melakukan aritmatika.

Data Transfer

MOV

r1/m, r2/m/#n

r1/m = r/m/#n

MOVSX

r1, r/m

Pindahkan dengan ekstensi tanda tangan.

*

MOVZX

r1, r/m

Pindahkan dengan ekstensi nol.

MOVSX and MOVZX are special versions of the mov instruction that perform sign extension or zero extension from the source to the destination. Ini adalah satu-satunya instruksi yang memungkinkan sumber dan tujuan menjadi ukuran yang berbeda. (Dan pada kenyataannya, mereka harus berukuran berbeda.

Manipulasi Tumpukan

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

Dorong nilai ke tumpukan.

POP

r/m

Nilai pop dari tumpukan.

PUSHFD

Dorong bendera ke tumpukan.

POPFD

Bendera pop dari tumpukan.

PUSHAD

Dorong semua register bilangan bulat.

POPAD

Pop semua register bilangan bulat.

ENTER

#n, #n

Membangun bingkai tumpukan.

*

LEAVE

Merobek bingkai tumpukan

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

Konversi Data

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).

Semua konversi melakukan ekstensi tanda tangan.

Manipulasi Aritmatika dan Bit

Semua instruksi manipulasi aritmatika dan bit memodifikasi bendera.

Aritmetika

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

Perkalian yang tidak ditandatangani dan ditandatangani. Status bendera setelah perkalian tidak terdefinisi.

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

Pembagian yang tidak ditandatangani dan ditandatangani. Daftar pertama dalam penjelasan pseudocode menerima sisanya dan yang kedua menerima kuota. Jika hasil meluap ke tujuan, pengecualian pembagian luapan dihasilkan.

Status bendera setelah pembagian tidak ditentukan.

*

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. Jika tidak, nilai 8-bit diatur ke nol.

Desimal berkode biner

Anda tidak akan melihat instruksi ini kecuali Anda men-debug kode yang ditulis dalam COBOL.

DAA

Penyesuaian desimal setelah penambahan.

DAS

Penyesuaian desimal setelah pengurangan.

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

AAA

ASCII menyesuaikan setelah penambahan.

AAS

ASCII menyesuaikan setelah pengurangan.

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

AAM

ASCII menyesuaikan setelah perkalian.

AAD

ASCII menyesuaikan setelah pembagian.

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. Biasanya diikuti oleh instruksi lompatan bersyarah yang menguji hasil LOGIS AND.

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

Bit terakhir yang digeser keluar ditempatkan dalam carry.

SHLD

r1, r2/m, cl/#n

Geser ganda kiri.

Shift r1 left by cl/#n, filling with the top bits of r2/m. Bit terakhir yang digeser keluar ditempatkan dalam carry.

SHRD

r1, r2/m, cl/#n

Geser ke kanan ganda.

Shift r1 right by cl/#n, filling with the bottom bits of r2/m. Bit terakhir yang digeser keluar ditempatkan dalam carry.

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.

Rotasi seperti pergeseran, kecuali bahwa bit yang digeser keluar muncul kembali sebagai bit isian masuk. Versi bahasa C dari instruksi rotasi menggabungkan carry bit ke dalam rotasi.

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.

Alur Kontrol

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.

Instruksi ini adalah sisa-sisa warisan CISC x86 dan dalam prosesor terbaru sebenarnya lebih lambat daripada instruksi yang setara yang ditulis jauh.

Manipulasi String

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.

Bendera

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.

Instruksi Yang Saling Mengunci

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

Membandingkan dan bertukar kondisi.

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:

Miscellaneous

INT

#n

Perangkap ke kernel.

BOUND

r, m

Trap if r not in range.

*

NOP

No operation.

XLATB

al = [ebx + al]

BSWAP

r

Tukar urutan byte dalam daftar.

Here is a special case of the int instruction.

INT

3

Jebakan titik henti debugger.

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

Saat men-debug kode, Anda mungkin perlu menambal beberapa kode. Anda dapat melakukan ini dengan mengganti byte yang menyinggung dengan 0x90.

Idiom

XOR

r, r

r = 0

TEST

r, r

Check if r = 0.

*

ADD

r, r

Shift r left by 1.