Instrukcja skoku bezwarunkowego
jmp etykieta ... etykieta:
| short | 1 bajt | -128 ... +128 |
| near | 2 bajty | -32 768 ... +32 768 |
| domyślny | 4 bajty | -2 147 483 648 ... +2 147 483 648 |
Aby porównać wartości całkowitoliczbowe 80x86 dostarcza funkcji
cmp x, y
x - y i ustawia odpowiednie flagi (wynik odejmowania nie jest dostępny).
x = y : ZF = 1
Dla liczb bez znaku
x < y : ZF = 0, CF = 1 ; odejmowanie z pożyczką x > y : ZF = 0, CF = 0
Dla liczb ze znakiem
x < y : ZF = 0, OF != SF x > y : ZF = 0, OF = SF
Aby sprawdzić czy dany rejestr np. EAX jest równy zero można użyć instrukcji
test eax, eax
cmp eax, 0
W ogólności
test x, y
Wykonanie skoku zależy tylko od jednej z flag procesora
;Skok jeżeli w ostatniej operacji JZ ZF = 1 ; był wynik 0 JNZ ZF = 0 JO OF = 1 ; było przepełnienie JNO OF = 0 JS SF = 1 ; wynik był ujemny JNS SF = 0 JC SF = 1 ; przepełnienie lub niedomiar JNC SF = 0 ; dla liczb bez znaku JP PF = 1 ; najmłodszy bajt ma parzystą liczbę jedynek JNP PF = 0
Bezpośrednio po wykonaniu
cmp x, y
liczby ze znakiem liczby bez znaku skok jeżeli JE, JZ JE, JZ x = y JNE, JNZ JNE, JNZ x != y JL, JNGE JB, JNAE x < y JLE, JNG JBE, JNA x <= y JG, JNLE JA, JNBE x > y JGE, JNL JAE, JNB x >= y
LOOP etykieta ; wykonuje skok jeżeli ecx!=0 LOOPZ etykieta ; wykonuje skok jeżeli ecx!=0 oraz ZF=1 LOOPNZ etykieta ; wykonuje skok jeżeli ecx!=0 oraz ZF=0
mov eax, 0 mov ecx, 10 poczatek_petli: add eax, ecx loop poczatek_petli | int suma=0; for(int i=10; i!=0; --i) suma += i; |
cmp eax, ebx jle else_ mov ecx, ebx jmp koniec else_: mov ecx, eax sub ecx, ebx koniec: | if( eax>ebx ) ecx = ebx; else ecx = eax - ebx; |
mov ebx, 0 mov eax, 0 petla_start: add ebx inc ebx cmp eax, 100 jb petla_start | unsigned int b=0, suma=0; do{ suma += b; ++b; }while(suma < 100); |
mov ecx, 0 poczatek: cmp dword [tab + 4*ecx], 0 jz koniec cmp ecx, 100 jge koniec inc ecx jmp poczatek koniec: | int i=0; while(tab[i]!=0 && i<10){ i++; } |
section .data tab dd 1, 2, 3, 4, 0, 4, 14, 2, 3, 3 section .text global _start _start: mov ecx, 0 poczatek: mov edx, [tab + 4*ecx] cmp edx, 0 jz koniec cmp ecx, 10 cmp ecx, 10 jae koniec inc ecx jmp poczatek koniec: mov eax, 1 int 80h
JUMPS (general) Name Comment Syntax CALL Call subroutine CALL Proc JMP Jump JMP Dest RET Return from subroutine RET JE Jump if Equal JE Dest JZ Jump if Zero JZ Dest JCXZ Jump if CX Zero JCXZ Dest JP Jump if Parity (Parity Even) JP Dest JPE Jump if Parity Even JPE Dest JNE Jump if not Equal JNE Dest JNZ Jump if not Zero JNZ Dest JECXZ Jump if ECX Zero JECXZ Dest JNP Jump if no Parity (Parity Odd) JNP Dest JPO Jump if Parity Odd JPO Dest JUMPS unsigned (Cardinal) JA Jump if Above JA Dest JAE Jump if Above or Equal JAE Dest JB Jump if Below JB Dest JBE Jump if Below or Equal JBE Dest JNA Jump if not Above JNA Dest JNAE Jump if not Above or Equal JNAE Dest JNB Jump if not Below JNB Dest JNBE Jump if not Below or Equal JNBE Dest JC Jump if Carry JC Dest JNC Jump if no Carry JNC Dest JUMPS signed (Integer) JG Jump if Greater JG Dest JGE Jump if Greater or Equal JGE Dest JL Jump if Less JL Dest JLE Jump if Less or Equal JLE Dest JNG Jump if not Greater JNG Dest JNGE Jump if not Greater or Equal JNGE Dest JNL Jump if not Less JNL Dest JNLE Jump if not Less or Equal JNLE Dest JO Jump if Overflow JO Dest JNO Jump if no Overflow JNO Dest JS Jump if Sign (= negative) JS Dest JNS Jump if no Sign (= positive) JNS Dest
Pełne zestawy instrukcji można znaleźć na stronach INTELa i AMD.
Podstawowy zestaw instrukcji jest wspólny dla wszystkich współczesnych procesorów.
Jednakże im nowszy procesor tym ma więcej rozszerzeń.