Curs 11 Setul Extins de Instructiuni x86
Curs 11 Setul Extins de Instructiuni x86
Augustin
Curs 11
1
PIII = PII + SSE (70 instr.) – 8 reg x 128b – FP-DP
P4= PIII + SSE2 (144 instr.) + SSE3 (13 instr)-Prescott +SSE4(54) +SSE5 (170)…..
Instructiuni
de baza
8086/8088 SSE = SIMD Streaming Extension
2
MMX=Multi Media eXtention
Setul de instructiuni extins x86 (32 biti)
Regiştri generali:
EAX — acumulatorul implicit
EBX — conţine implicit o adresă de bază ptr. anumite moduri de adresare
ECX — contor implicit
EDX — acumulator extins implicit sau registru de date
ESI — index pentru sursă
EDI — index pentru destinaţie
EBP — indicatorul bazei în stivă
ESP — indicatorul curent în stivă
Regiştri de stare şi control:
EIP — indicator (numărător) de instrucţiuni
EF — registrul de flaguri
CR0…CR4 — regiştri de control procesor
DR0…DR7 — regiştri pentru depanare (debug)
Regiştri segment:
DS, ES
FS — registru segment suplimentar (de date)
GS — registru segment suplimentar (de date)
3
4
Setul de instructiuni extins x86
⚫ Utilizarea setului extins de instrucţiuni în aplicaţii trebuie
anunţată asamblorului folosind directivele:
⚫ .8086 .8087 .186 .286 .287 ;
⚫ .286P .386 .387 .386P .486;
⚫ .486P .586 .586P .MMX
vezi Lucrarea 12
5
Setul de instructiuni extins
1. Instrucţiuni de transfer
MOVSX (Move with Sign Extension) –
MOVSX destinaţie, sursă ; destinaţie sign_extend(sursă)
Operanzi: reg,reg
reg,mem
Exemplu:
MOVSX EAX, AL ;octet → dublucuvânt
MOVSX EDI, WORD PTR [ESI] ;cuvânt → dublucuvânt
10001111 Source
0 10001111 Source
POPF (Pop Stack into FLAGS) – aduce din stivă cei mai puţin
semnificativi 16 biţi ai registrului EF. Instrucţiunea nu are operanzi,
iar flagurile se schimbă în mod corespunzător.
POPFD EFlow [SS:ESP]
ESP ESP + 2 8
PUSHAD (Push 32-bit General Registers ) –
;temp ESP
;PUSH EAX PUSH ECX PUSH EDX PUSH EBX
;PUSH temp PUSH EBP PUSH ESI PUSH EDI
9
Lseg (Load Segment Register)
LDS reg, mem ;destinaţie [sursă]
LES reg, mem ;seg [sursă+4]
LFS reg, mem
LGS reg, mem
LSS reg, mem
10
INSB, INSW, INSD (Input String from I/O Port)
– destinaţia dată de (ES:EDI) primeşte date de la portul de intrare,
specificat de către DX.
INSB, INSW, INSD (ES:EDI) port(DX)
(EDI) = (EDI)+(d) ;d=1 / 2 / 4
11
2. Instructiuni aritmetice
CMPXCHG (Compare and Exchange) –
CMPXCHG operand1, operand2
;ACC = operand1 ?? , dacă sunt egale atunci
;ZF=1 şi operand1:= operand2
;altfel ZF=0 ACC = operand2
Operanzi: reg,reg
mem,reg
12
IMUL (Integer (Signed) Multiplication) –
IMUL op1
IMUL op1,op2
IMUL op1,op2,op3
13
BSF (Bit Scan Forward) –
BSF destinaţie, sursă; dacă (sursa = 0) atunci ZF = 1 şi destinaţia???
altfel ZF 0, temp 0
while (bit(sursa, temp) =0)
temp temp+1
destinaţie temp
Operanzi: reg,reg
reg,mem
Exemplu:
MOV AX, 85C0H ; AX = 1000 0101 1100 0000 b
BSF BX, AX ;(BX) 6
BT (Bit Test) –
BT destinaţie, index ; CF destinaţie [index]
Operanzi: reg, data
mem, data
reg, reg
mem, reg
Exemplu:
MOV EAX, 18 ;poziţia bitului care va fi testat
MOV EBX, 0F749EH ;data pentru test
BT EBX, EAX ;CF 1 (1111 0111 0100 1001 1110)
JC eticheta ;salt conform bitului de test
15
BTC (Bit Test and Complement) –
BTC destinaţie, index CF destinaţie [index]
destinaţie [index] not destinaţie [index]
Operanzi: reg, data
mem, data
reg,reg
mem,reg
BTR (Bit Test and Reset)
BTR destinaţie, index CF destinaţie [index]
destinaţie [index] 0
Operanzi: reg, data
mem, data
reg,reg
mem,reg
Condiţia ‚cc’ poate fi: A/ AE/ B/ BE/ C/ E/ G/ GE/ L/ LE/ NA/ NAE/ NB/ NBE/ NC/ NE/
NG/ NGE/ NL/ NLE/ NO/ NP/ NS/ NZ/ O/ P/ PE/ PO/ S/ Z
Exemplu:
SETC dest ;Set if Carry/ CF=1=> dest=1
SETLE dest ;Set if less or equal/ S ≠ O&Z=1 => dest=1
Exemplu:
XOR EBX,EBX ; EBX=0
ADD ECX,[Val] ; ECX=ECX+val
CMOVC ECX,EBX ; If C=1, ECX=EBX =0 17
SHLD (Shift Left Double)
SHLD destinaţie, sursă, count
temp max (count, 31)
value sursă destinaţie
value value * 2temp
dest value
Operanzi:
reg, reg, imed
mem, reg, imed
reg, reg, CL
mem, reg, CL
.data
wval AX
wval WORD 9BA6h
inainte: 9BA6 AC36
.code
mov ax,0AC36h BA6A AC36
dupa:
shld wval,ax,4 18
SHRD (Shift Right Double) –
SHRD destinaţie, sursă, count
temp max (count, 31)
value sursă destinaţie
value valoare div 2temp
dest valoare
Operanzi:
reg, reg, imed
mem, reg, imed
reg, reg, CL
mem, reg, CL
DX AX
mov ax,234Bh
inainte: 7654 234B
mov dx,7654h
shrd ax,dx,4 dupa: 7654 4234
19
3. Instructiuni speciale
CPUID (CPU IDentification) – returnează informaţii de identificare a procesorului
MOV (Move Special) – copiază sau încarcă un registru special al CPU în /dintr-un
registru general. Regiştrii speciali sunt CR0, CR2, CR3 (Control Register), respectiv
DR0, DR1, DR2, DR3, DR6, DR7 (Debug Register).
MOV destinaţie, sursă; (destinaţie) sursă
Operanzi: reg,reg
Exemplu:
MOV EAX, CR0 ;se salvează CR0 în EAX
MOV DR7, ECX ;se încarcă DR7 cu conţinutul ECX
RDMSR (Read from Model Specific Register) – conţinutul unui registru MSR, precizat
de ECX, este copiat în EDXEAX. Cu ajutorul MSR pot fi observate şi controlate
detaliile specifice procesorului (configuration of OS-relevant things ) – instr.
privilegiate executate de OS.
RDMSR EDXEAX MSR[ECX]
WRMSR (Write to Model Specific Register) – un operand din EDXEAX este copiat
într-un registru MSR 20
#include “stdafx.h”