Professional Documents
Culture Documents
8086 Ins Set Branch - GRP 3 PDF
8086 Ins Set Branch - GRP 3 PDF
Conditional Jump instructions in 8086 are just 2 bytes long. 1-byte opcode followed by
1-byte signed displacement (range of –128 to +127).
Jumps based on a single flag Jumps based on more than one flag
JZ r8 ;Jump if zero flag set (if result is 0). JE also means same.
JNZ r8 ;Jump if Not Zero. JNE also means same.
JS r8 ;Jump if Sign flag set to 1 (if result is negative)
JNS r8 ;Jump if Not Sign (if result is positive)
JC r8 ;Jump if Carry flag set to 1. JB and JNAE also mean same.
JNC r8 ;Jump if No Carry. JAE and JNB also mean same.
JP r8 ;Jump if Parity flag set to 1. JPE (Jump if Parity Even) also means same.
JNP r8 ;Jump if No Parity. JPO (Jump if Parity Odd) also means same.
JO r8 ;Jump if Overflow flag set to 1 (if result is wrong)
JNO r8 ;Jump if No Overflow (if result is correct)
JE is abbreviation for Jump if Equal. JNE is abbreviation for Jump if Not Equal.
JB is abbreviation for Jump if Below. JNAE is for Jump if Not Above or Equal.
JAE for Jump if Above or Equal. JNB for Jump if Not Above.
JE, JNE, JB, JNAE, JAE and JNB are used after a compare operation.
Examples for JE or JZ instruction
CMP SI, DI
JE SAME
ADD CX, DX ;Executed if Z = 0
Should be<=127 bytes : (if SI not equal to DI)
:
SAME: SUB BX, AX ;Executed if Z = 1
(if SI = DI)
15
Range for JMP (unconditional jump) can be +2 = + 32K. JMP instruction discussed in
detail later
Terms used in comparison
Above and Below used for comparing Unsigned numbers. Greater than and less than used
when comparing signed numbers. All Intel microprocessors use this convention.
Accordingly, all the following statements are true.
95H is above 65H Unsigned comparison - True
95H is less than 65H Signed comparison – True (as 95H is negative, 65H is positive)
65H is below 95H Unsigned comparison - True
65H is greater than 95H Signed comparison - True
JNBE / JA instruction
[(S=1 AND V=0) OR (S=0 AND V=0)] [(S=0 AND V=0) OR (S=1 AND V=1)]
OR Z=1 AND Z=0
[(surely negative) or (wrong answer [(surely positive) or (wrong answer
positive!)] or Equal negative!)] and not equal
i.e. [S XOR V=1] OR Z=1 i.e.[S XOR V=0] AND Z=0
JNLE / JG instruction
[(S=0 AND V=0) OR (S=1 AND V=1)] [(S=1 AND V=0) OR (S=0 AND V=1)]
AND Z=0 OR Z=1
[(surely positive) or (wrong answer [(surely negative) or (wrong answer
negative!)] and not equal positive!)] or equal
i.e. S XOR V=0 AND Z=0 i.e.S XOR V=1 OR Z=1
JL / JNGE instruction
Jump if No Jump if
[S=1 AND V=0] OR [S=0 AND V=1] [S=0 AND V=0] OR [S=1 AND V=1]
(surely negative)or (wrong answer (surely positive) or (wrong answer
positive!) negative!)
Jump if No Jump if
[S=0 AND V=0] OR (S=1 AND V=1) [S=1 AND V=0] OR (S=1 AND V=1)
(surely positive) or (wrong answer (surely negative) or (wrong answer
negative!) positive!)
Near Jump or Intra segment Jump Far Jump or Inter segment Jump
(Jump within the segment) (Jump to a different segment)
Near Unconditional Jump instruction
Near Jump
2-bytes Short Jump (EB r8) 3-bytes Long Jump (E9 r16) 2 or more bytes
7 15
Range: + 2 Range: +2 Starting with FFH
Range: complete segment
Three Near Jump and two Far Jump instructions have the same mnemonic JMP, but they
have different opcodes
For Backward jump: Assembler knows the quantum of jump. Generates Short Jump code
if <=128 bytes is the required jump. Generates code for Long Jump if >128 bytes is the
required jump.
For Forward jump: Assembler doesn’t know jump quantum in pass 1. Assembler
reserves 3 bytes for the forward jump instruction. If jump distance turns out to be >128
bytes, the instruction is coded as E9 r16 (E9H = Long jump code). If jump distance
becomes <=128 bytes, the instruction is coded as EB r8 followed by code for NOP (E8H
= Short jump code).
Assembler generates only 2 byte Short Jump code for forward jump, if the SHORT
assembler directive is used.
FRWD = CS:FFF0H :
:
CS:FFFFH :
Ex.1: JMP DX
If DX = 1234H, branches to CS:1234H. 1234H is not signed relative displacement.
Ex. 2: JMP wordptr 2000H[BX]
Far Jump
Also called Far Direct Jump. It is the common inter segment jump scheme
It is a 5 byte instruction. 1 byte opcode (EAH), 2 byte offset value, 2 byte segment value
Also called Far Indirect Jump. It is not commonly used. Instruction length depends on the
way jump location is specified. It can be a minimum of 2 bytes.
DS:3234H 5678H
DS:3236H ABCDH
Iteration Instructions
Iteration instructions
JCXZ Instruction
Jump if CX is Zero is useful for terminating the loop immediately if CX value is 0000H
It is a 2 byte instruction. It is used for forward jump only. Maximum distance for forward
jump is only 127 bytes.
LOOPZ instruction
LOOP while Zero is a 2-byte instruction. It is used for backward jump only. Backward
jump takes place if after decrement of CX it is still not zero AND Z flag = 1. LOOPE is
same as LOOPZ. LOOPE is abbreviation for LOOP while Equal. LOOPE is normally
used after a compare instruction.
CALL Instructions
CALL instructions
Near CALL or Intra segment CALL Far CALL or Inter segment CALL
Near Direct CALL Near Indirect CALL Far Direct CALL Far Indirect CALL
It is a 3-byte instruction. It has the format CALL r16 and has the range + 32K bytes.
Covers the entire Code segment. It is the most common CALL instruction.
It is functionally same as the combination of the instructions PUSH IP and ADD IP, r16.
Not commonly used. Instruction length depends on the way the called location is
specified.
DS:3234H 5678H
DS:3236H ABCDH
Not commonly used. Instruction length depends on the way the called location is
specified.
DS:3234H 5678H
DS:3236H ABCDH
Conditional CALL?
Solution:
JC NEXT
CALL COMPUTE ; execute only if Cy = 0
NEXT:
RETURN instructions
RET instructions
Near RET or Intra segment RET Far RET or Inter segment RET
It is a 3-byte instruction. 1-byte opcode (C2H) and 2-byte data. It is functionally same as:
POP IP
SP = SP + d16
RET d16 is useful for flushing out the parameters that were passed to the subroutine
using the stack
Main Program
:
: SP after CALL Compute IP
PUSH Var1 Var2
PUSH Var2 Var1
CALL Compute SP before PUSH Var1
:
:
Subroutine
COMPUTE PROC Near IP
: SP if RET is executed Var2
: Var1
RET 0004H SP if RET 0004H is executed
COMPUTE ENDP
RET d16 is useful for flushing out the parameters that were passed to the subroutine
using the stack.