NASM - instrukcje
Przenoszenie danych

 
Name     Comment                      Syntax
MOV    Move (copy)                    MOV Dest,Source
XCHG   Exchange                       XCHG Op1,Op2
 
Zmiany flag procesora
 
STC    Set Carry                      STC
CLC    Clear Carry                    CLC
CMC    Complement Carry               CMC
STD    Set Direction                  STD
CLD    Clear Direction                CLD
STI    Set Interrupt                  STI
CLI    Clear Interrupt                CLI
 
Konwersje (rozszerza bitem znaku)
 
CBW    Sign-extend  AL into AX        CBW  
CWD    Sign-extend  AX into DX:AX     CWD
CDQ    Sign-extend EAX into EDX:EAX   CDQ
CWDE   Sign-extend  AX into EAX       CWDE
CQO    Sign-extend RAX into RDX:RAX   CQO  (tylko 64bit) 
 
Operacje na portach 
 
IN     Input                      IN Dest, Port
OUT    Output                     OUT Port, Source

Stos

Odkładanie na stos

push eax
push rdx
pushf      ; odkłada flagi
pusha      ; odkłada wszystkie ogolne rejestry 
             (tylko 32bit)

Przykład

push rdx
jest równoważne
sub rsp, 8
mov [rsp], rdx

Zdejmowanie ze stosu

pop ebx
pop rcx
popf      ; zdejmuje flagi 
popa      ; zdejmuje wszystkie ogólne rejestry 
          ; (tylko 32bit)

Przykład

pop rbx
jest równoważne
mov rbx, [rsp]
add rsp, 8

Przykład operacji na stosie

Opreacje arytmetyczne

 
Name    Comment                     Syntax
ADD     Add                         ADD Dest,Source
ADC     Add with Carry              ADC Dest,Source
SUB     Subtract                    SUB Dest,Source
SBB     Subtract with borrow        SBB Dest,Source
DIV     Divide (unsigned)           DIV Op
IDIV    Signed Integer Divide       IDIV Op
MUL     Multiply (unsigned)         MUL Op
IMUL    Signed Integer Multiply     IMUL Op
INC     Increment                   INC Op
DEC     Decrement                   DEC Op
 
CMP     Compare                     CMP Op1,Op2
 
SAL     Shift arithmetic left       SAL Op,Quantity
SAR     Shift arithmetic right      SAR Op,Quantity
RCL     Rotate left through Carry   RCL Op,Quantity
RCR     Rotate right through Carry  RCR Op,Quantity
ROL     Rotate left                 ROL Op,Quantity
ROR     Rotate right                ROR Op,Quantity

Mnożenie
Zestawy parametrów i wyniki instrukcji MUL (pierwsze 3 wiersze) i IMUL
 dest  source  source1  Akcja
   reg/mem8    AX = AL*source
   reg/mem16    DX:AX = AX*source
   reg/mem32    EDX:EAX = EAX*source
   reg/mem64    RDX:RAX = RAX*source
 reg16  reg/mem16    dest *= source
 reg32  reg/mem32    dest *= source
 reg16  immed8    dest *= immed8
 reg32  immed8    dest *= immed8
 reg16  immed16    dest *= immed16
 reg32  immed32    dest *= immed32
 reg16  reg/mem16  immed8  dest = source*source1
 reg32   reg/mem32  immed8  dest = source*source1
 reg16  reg/mem16  immed16  dest = source*source1
 reg32   reg/mem32  immed32  dest = source*source1
Przykład mnożenia

mul cl          ; AX = AL*CL
mul bx          ; DX:AX = AX*BX
mul esi         ; EDX:EAX = EAX*ESI
mul rdi         ; RDX:RAX = RAX*RDI
 
imul eax        ; EDX:EAX = EAX*EAX
imul ebx,ecx,2  ; EBX = ECX*2
imul ebx,ecx    ; EBX = EBX*ECX
imul si,5       ; SI = SI*5

Operacje logiczne

LOGIC
 
Name    Comment                 Syntax
NEG     Negate (two-complement) NEG Op
NOT     Invert each bit         NOT Op
AND     Logical and             AND Dest,Source
OR      Logical or              OR Dest,Source
XOR     Logical exclusive or    XOR Dest,Source
SHL     Shift logical left      SHL Op,Quantity
SHR     Shift logical right     SHR Op,Quantity
 
MISCELLANEOUS
 
Name    Comment                 Syntax
NOP     No operation            NOP
LEA     Load effective adress   LEA Dest,Source
INT     Interrupt               INT Nr


Tomasz Kapela, Kraków 2011-2020