Branch Type Instructions 8086


Branch Instruction:

  • The branch instruction is used to transfer the control of the program to a new address. This branch can be Conditional or Unconditional. Once the branch is taken the execution of instructions will take place from this new address called branch address. Usually the Conditional branch is taken after the ADD, SUB, INC, DEC  and the instructions used to implement the LOOP.  When these types of instructions are executed, the CS and IP registers get loaded with new values of CS and IP corresponding to the location where a branch is required. The branch instruction can be one of the following types.
  • Unconditional Jump instructions: JMP, CALL, RET, INT N, INTO, IRET, LOOP,
  • Conditional Jump instructions: JA/JNBE, JAE/JNB, JB/JNAE, JC, JNC, JE /JZ, JNE /JNZ, JO, JNO, JP/JPE, JG/JNG, JNP/JPO, JG/JNLE, JA /JNL, JL/JNGE, JLE/JNG, JS, JNS

Unconditional Jump instructions

CALL : Unconditional call
call a subroutine (procedure) from the main program. Address of procedure may be Specified Directly or indirectly. Two types are:
Near Call:  within +/- 32k DISP.
Far Call : anywhere outside the segment
In both case CS and IP Change to new address
RET : Return from procedure
On execution, the previously stored content of IP and CS Along with flags are retrieved into the CS, IP and Flag registers from the stack and execution of the main programs continues further
INT N : Interrupt Type N
When executed, the type byte N is multiplied by 4 and the contents of the IP and CS of the interrupt service routine will be taken from memory Block in 0000 segment.
INTO : Interrupt in overflow
This instruction is executed when the overflow flag is set, This is equivalent to a Type 4  interrupt instruction.
JMP : Conditional jump
unconditionally transfers the control of execution to the Specified address using an 8 bit ot 16 bit Displacement
IRET : Return from stack
When its is executed the values of IP , CS and flags are retrieved from the stack to continue the execution of the main program.
LOOP : LOOP Unconditional
This instruction executes the part of the program from the Label or address Specified in the instruction up to the loop instruction CX number of times . At each iteration , CX is decremented automatically and JUMP OF NOT ZERO structure.

Conditional Jump instructions: 

  • The following table gives a list of instructions that will take the program to a Specified location if a particular condition is matched.
    The Conditional types of instruction test a certain condition such as the flags (CF, PF, SF, ZF, OF, ), on testing for equality/non-equality, above or less etc. and then jump to a new Specified address. The execution the program then starts from the new address. The Different Conditional instructions are given below.
Instructions
Description
JA/JNBE label
Jump if above /jump if not below nor equal
JAE/JNB label
Jump if above or equal /jump if not below
JB/JNAE label
Jump if below/jump if not above nor equal
JC label
Jump on carry
JE /JZ label
Jump if equal/jump if zero flag is set
JNC label
Jump if no carry
JNE/JNZ label
Jump if not equal/jump if zero (ZF is not set)
JO label
Jump if overflow (OF is set)
JNO label
Jump if no overflow (OF =0)
JP/JPE label
Jump if PF = 1/jump if parity if is even
JNP /JPO label
Jump if not parity PF = 0/jump if parity if is odd
JG/JNLE label
Jump if greater/jump id
JA /JNL label
Jump if above / jump if not less than
JL/JNGE label
Jump if less than /jump if not greater nor equal
JLE/JNG label
Jump if less than and equal to / jump if not greater
JS label
Jump if -ve (SF = 1)
JNS label
Jump if not -ve (SF=0)

Conditional LOOP instructions:

Format
Purpose
Example
LOOPZ / LOOPE label
Loop through a sequence of instructions from label while ZF = 1 and CX # 0. The loop exits if CX becomes zero or the quantities being compared become unequAL.
LEA BX, ARRAY
DEC BX
MOV CX, 12
L1: INC BX
CMP [BX], 0FFh
LOOPE L1
LOOPNZ / LOOPNE Label
Loop through a sequence of instructions from label while ZF = 0 and CX is not equal to zero. Looping is done as long as count is not equal to zero, and the element of the array is not equal to a certain value you are looking for.
JCXZ label
Jump to a Specified address if CX is zero

 

Examples:

Write an ALP for 8086 to convert 8-bit binary number stored in memory into ASCII and store the converted ASCII data back in memory

Using assemble such as MASM
Using KIT
Source variable X

Destination variable : Y

Assume source packed data at location : 2500:1000

Converted Binary to be stored at 2500: 1001 and 1002

Data SEGMENT

    X db 10101010B

    Y db 2 dup(?)

Data ENDS

Code SEGMENT

ASSUME CS: code, DS: data

    MOV ax, data

    MOV ds, ax

    MOV SI, offset Y

    MOV AL, X

    MOV BL, AL

    AND AL, 0F0h

    MOV CL, 04

    ROR AL, CL

    CALL ASCII

    MOV [SI], AL

    INC SI

    MOV AL, BL

    ANL AL, 0F0h

    CALL ASCII

    MOV [SI], AL

    JMP L1

ASCII:   CMP AL, 0Ah

   JC L2

   ADD AL, 07h

L2:       ADD AL, 30h

            RET

L1:       MOV AH, 4Ch

            INT 21h

Code ENDS

END

 

    MOV ds, ax

    MOV AL, [1000]

    MOV BL, AL

    AND AL, 0F0h

    MOV CL, 04

    ROR AL, CL

    CALL ASCII

    MOV [1001], AL

    MOV AL, BL

    ANL AL, 0F0h

    CALL ASCII

    MOV [102], AL

    JMP L1

ASCII:   CMP AL, 0Ah

     JC L2

     ADD AL, 07h

L2:         ADD AL, 30h

      RET

L1:  HLT

 

 

error: Content is protected !!