JMP labelTo declare a label in your program, just type its name and add ":" to the end, label can be any character combination but it cannot start with a number, for example here are 3 legal label definitions:
label1:Label can be declared on a separate line or before any other instruction, for example:
label2:
a:
x1:here's an example of JMP instruction:
MOV AX, 1
x2: MOV AX, 2
org 100h mov ax, 5 ; set ax to 5. mov bx, 2 ; set bx to 2. jmp calc ; go to 'calc'. back: jmp stop ; go to 'stop'. calc: add ax, bx ; add bx to ax. jmp back ; go 'back'. stop: ret ; return to operating system.
Instruction | Description | Condition | Opposite Instruction |
JZ , JE | Jump if Zero (Equal). | ZF = 1 | JNZ, JNE |
Jump if Carry (Below, Not Above Equal). | CF = 1 | JNC, JNB, JAE | |
JS | Jump if Sign. | SF = 1 | JNS |
JO | Jump if Overflow. | OF = 1 | JNO |
JPE, JP | Jump if Parity Even. | PF = 1 | JPO |
JNZ , JNE | Jump if Not Zero (Not Equal). | ZF = 0 | JZ, JE |
Jump if Not Carry (Not Below, Above Equal). | CF = 0 | JC, JB, JNAE | |
JNS | Jump if Not Sign. | SF = 0 | JS |
JNO | Jump if Not Overflow. | OF = 0 | JO |
JPO, JNP | Jump if Parity Odd (No Parity). | PF = 0 | JPE, JP |
jnc a jnb a jae a mov ax, 4 a: mov ax, 5 ret
Instruction | Description | Condition | Opposite Instruction |
JE , JZ | Jump if Equal (=). Jump if Zero. |
ZF = 1 | JNE, JNZ |
JNE , JNZ | Jump if Not Equal (<>). Jump if Not Zero. |
ZF = 0 | JE, JZ |
JG , JNLE | Jump if Greater (>). Jump if Not Less or Equal |
ZF = 0 and SF = OF | JNG, JLE |
JL , JNGE | Jump if Less (<). Jump if Not Greater or Equal |
SF <> OF | JNL, JGE |
JGE , JNL | Jump if Not Less (not <). |
SF = OF | JNGE, JL |
JLE , JNG | Jump if Not Greater |
ZF = 1 or SF <> OF | JNLE, JG |
Instruction | Description | Condition | Opposite Instruction |
JE , JZ | Jump if Equal (=). Jump if Zero. |
ZF = 1 | JNE, JNZ |
JNE , JNZ | Jump if Not Equal (<>). Jump if Not Zero. |
ZF = 0 | JE, JZ |
JA , JNBE | Jump if Above (>). Jump if Not Below or Equal |
CF = 0 and ZF = 0 | JNA, JBE |
Jump if Below (<). Jump if Not Above or Equal Jump if Carry. |
CF = 1 | JNB, JAE, JNC | |
Jump if Above or Equal (>=). Jump if Not Below Jump if Not Carry. |
CF = 0 | JNAE, JB | |
Jump if Below or Equal (<=). Jump if Not Above |
CF = 1 or ZF = 1 | JNBE, JA |
include "emu8086.inc" org 100h mov al, 25 ; set al to 25. mov bl, 10 ; set bl to 10. cmp al, bl ; compare al - bl. je equal ; jump if al = bl (zf = 1). putc 'n' ; if it gets here, then al <> bl, jmp stop ; so print 'n', and jump to stop. equal: ; if gets here, putc 'y' ; then al = bl, so print 'y'. stop: ret ; gets here no matter what.
instruction | operation and jump condition | opposite instruction |
LOOP | decrease cx, jump to label if cx not zero. | DEC CX and JCXZ |
LOOPE | decrease cx, jump to label if cx not zero and equal (zf = 1). | LOOPNE |
LOOPNE | decrease cx, jump to label if cx not zero and not equal (zf = 0). | LOOPE |
LOOPNZ | decrease cx, jump to label if cx not zero and zf = 0. | LOOPZ |
LOOPZ | decrease cx, jump to label if cx not zero and zf = 1. | LOOPNZ |
JCXZ | jump to label if cx is zero. | OR CX, CX and JNZ |
org 100h mov bx, 0 ; total step counter. mov cx, 5 k1: add bx, 1 mov al, '1' mov ah, 0eh int 10h push cx mov cx, 5 k2: add bx, 1 mov al, '2' mov ah, 0eh int 10h push cx mov cx, 5 k3: add bx, 1 mov al, '3' mov ah, 0eh int 10h loop k3 ; internal in internal loop. pop cx loop k2 ; internal loop. pop cx loop k1 ; external loop. retbx counts total number of steps, by default emulator shows values in hexadecimal, you can double click the register to see the value in all available bases.
include "emu8086.inc" org 100h mov al, 5 mov bl, 5 cmp al, bl ; compare al - bl. ; je equal ; there is only 1 byte jne not_equal ; jump if al <> bl (zf = 0). jmp equal not_equal: add bl, al sub al, 10 xor al, bl jmp skip_data db 256 dup(0) ; 256 bytes skip_data: putc 'n' ; if it gets here, then al <> bl, jmp stop ; so print 'n', and jump to stop. equal: ; if gets here, putc 'y' ; then al = bl, so print 'y'. stop: ret
org 100h ; unconditional jump forward: ; skip over next 3 bytes + itself ; the machine code of short jmp instruction takes 2 bytes. jmp $3+2 a db 3 ; 1 byte. b db 4 ; 1 byte. c db 4 ; 1 byte. ; conditional jump back 5 bytes: mov bl,9 dec bl ; 2 bytes. cmp bl, 0 ; 3 bytes. jne $-5 ; jump 5 bytes back ret |