Coo Oomp

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Planco, Bernabeth O.

EC31FB1

Conditional jump

This is performed by a set of jump instructions j<condition> depending upon the


condition. The conditional instructions transfer the control by breaking the sequential
flow and they do it by changing the offset value in IP.

If some specified condition is satisfied in conditional jump, the control flow is


transferred to a target instruction. There are numerous conditional jump instructions
depending upon the condition and data.

Following are the conditional jump instructions used on signed data used for
arithmetic operations –

Jump instructions that test single flag


Instruction Description Condition Opposite Instruction
JZ , JE Jump if Zero (Equal). ZF = 1 JNZ, JNE

JC , JB, JNAE 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

JNC , JNB, JAE 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

Jump instructions for signed numbers


Instruction Description Condition Opposite Instruction

Jump if Equal (=).


JE , JZ ZF = 1 JNE, JNZ
Jump if Zero.
Jump if Not Equal (<>).
JNE , JNZ ZF = 0 JE, JZ
Jump if Not Zero.

ZF = 0
Jump if Greater (>).
JG , JNLE and JNG, JLE
Jump if Not Less or Equal (not <=).
SF = OF

Jump if Less (<).


JL , JNGE SF <> OF JNL, JGE
Jump if Not Greater or Equal (not >=).

Jump if Greater or Equal (>=).


JGE , JNL SF = OF JNGE, JL
Jump if Not Less (not <).

ZF = 1
Jump if Less or Equal (<=).
JLE , JNG or JNLE, JG
Jump if Not Greater (not >).
SF <> OF

<> - sign means not equal.

Jump instructions for unsigned numbers


Instruction Description Condition Opposite Instruction

Jump if Equal (=).


JE , JZ ZF = 1 JNE, JNZ
Jump if Zero.

Jump if Not Equal (<>).


JNE , JNZ ZF = 0 JE, JZ
Jump if Not Zero.

CF = 0
Jump if Above (>).
JA , JNBE and JNA, JBE
Jump if Not Below or Equal (not <=).
ZF = 0

Jump if Below (<).


JB , JNAE, JC Jump if Not Above or Equal (not >=). CF = 1 JNB, JAE, JNC
Jump if Carry.

Jump if Above or Equal (>=).


JAE , JNB, JNC Jump if Not Below (not <). CF = 0 JNAE, JB
Jump if Not Carry.

CF = 1
Jump if Below or Equal (<=).
JBE , JNA or JNBE, JA
Jump if Not Above (not >).
ZF = 1

JZ Instruction Example:

include 'emu8086.inc'
ORG 100h
MOV AL, 5
CMP AL, 5
JZ label1
PRINT 'AL is not equal to 5.'
JMP exit
label1:
PRINT 'AL is equal to 5.'
exit:
RET

JS Instruction Example:

include 'emu8086.inc'
ORG 100h
MOV AL, 10000000b ; AL = -128
OR AL, 0 ; just set flags.
JS label1
PRINT 'not signed.'
JMP exit
label1:
PRINT 'signed.'
exit:
RET

JPO Instruction Example:

include 'emu8086.inc'
ORG 100h
MOV AL, 00000111b ; AL = 7
OR AL, 0 ; just set flags.
JPO label1
PRINT 'parity even.'
JMP exit
label1:
PRINT 'parity odd.'
exit:
RET
JPE Instruction Example:

include 'emu8086.inc'
ORG 100h
MOV AL, 00000101b ; AL = 5
OR AL, 0 ; just set flags.
JPE label1
PRINT 'parity odd.'
JMP exit
label1:
PRINT 'parity even.'
exit:
RET

JE instruction Example:

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

You might also like