33
 Control Transfer Instructions

Control Transfer Instructions

Embed Size (px)

DESCRIPTION

Briefly discusses control transfer functions for 8086/8088 assembly codes

Citation preview

Control Transfer Instructions

Control Transfer InstructionsUnconditional Jump Instruction - JMPThis instruction unconditionally transfers control to the target location. The target location contains the next instruction to be executed by the microprocessor.

Unconditional Jump Instruction - JMP

Unconditional Jump Instruction - JMP

Unconditional Jump Instruction - JMPIntrasegment Jumpthe jump is limited to within the code segment only.Intersegment Jumpthe jump is allowed to any other code segment. Both the code segment and the IP are modified.Unconditional Jump Instruction - JMPRelative OperandA relative operand is a signed displacement from the JMP instruction to the target location. The address of the target location can be obtained by adding the displacement from the JMP instruction.Indirect OperandAn indirect operand can be a 16-bit register that contains the offset address of the next instruction to be executed by the microprocessor. An indirect operand can be a 16-bit register that indirectly points a memory location where the offset address can be found.Unconditional Jump Instruction - JMPShort-labelA short jump displacement is a distance represented by a one-byte signed number whose value ranges between +127 and -128. A negative displacement (80 to FF) means jump backward and A positive displacement (01 to 7F) means jump upward.Near-labelA near jump allows a branch or jump within +32K bytes or anywhere in the current code segment from the instruction in the current code segment.Unconditional Jump Instruction - JMPRegptr16A 16-bit register that contains the offset address to be loaded to IP.Memptr16the physical address of the next instruction is located in the memory pointed to by Memptr16. IP = [mem] & [mem+1].Unconditional Jump Instruction - JMPFar-labelit signifies an intersegment jump.Memptr32the physical address of the next instruction is located in the memory pointed to by Memptr32. IP = [mem] & [mem+1]; CS = [mem+ 2] & [mem+3].Examples:Intrasegment Jump(Relative, short-label, jump forward)

Examples:Intrasegment Jump(Relative, short-label, jump forward)

Examples:Intrasegment Jump(Relative, near-label)

Examples:Intrasegment Jump(Indirect, Regptr16)

Examples:Intrasegment Jump(Indirect, Memptr16)

Examples:Intrasegment Jump(Indirect, Memptr32)

Examples:Intrasegment Jump(Relative, short-label, jump backward)

Conditional Jump Instructions - JccConditional transfer instructions are jumps that may or may not transfer control depending on the state of the status flags at the time the instruction is executed.

Conditional Jump Instructions - JccImportant Facts:Only the short-label operand is supported by conditional jump instructions.Conditional jump should be placed immediately after an instruction that will modify the status flags such as CMP, INC, DEC, etc.Conditional Jump Instructions - JccComparing Unsigned Numbers

Conditional Jump Instructions - JccComparing Signed Numbers

Conditional Jump Instructions - JccTest Flags

Conditional Jump Instructions - JccTest Flags

Example:

Iteration ControlsLOOPIt is a combination of decrement CX and JNZ. It transfers control to the target location while CX 0. If CX becomes 0, the next sequential instruction is executed.

Iteration ControlsLOOPE/LOOPZIt decrements CX by 1 and transfers control to the target location while CX 0 and ZF = 1. If CX = 0 or ZF = 0, the loop is terminated and the instruction following loop is executed.

Iteration ControlsLOOPNE/LOOPNZIt decrements CX by 1 and transfers control to the target location while CX 0 and ZF = 0. If CX = 0 or ZF = 1, the loop is terminated and the instruction following loop is executed.

Iteration ControlsLOOPNE/LOOPNZIt decrements CX by 1 and transfers control to the target location while CX 0 and ZF = 0. If CX = 0 or ZF = 1, the loop is terminated and the instruction following loop is executed.

Iteration ControlsJCXZIt transfers control to the target operand if CX is 0.

Subroutine and Subroutine Handling InstructionsCALLIt transfers control to a subroutine. After executing the subroutine, control is transferred back to the instruction following the CALL instruction. . In order to do this, the contents of either both registers CS and IP, or register IP only (if Intrasegment call), are pushed into the stack before the control is relinquished to the subroutine.

Subroutine and Subroutine Handling Instructions

Subroutine and Subroutine Handling InstructionsRETIt transfers control from a subroutine back to the instruction following the CALL instruction.

Subroutine and Subroutine Handling InstructionsRETImportant Facts:For intrasegment CALL, RET pops out the contents of the register IP at the top of the stack. For intersegment CALL, RET pops out both the contents of the register IP and CS at the top of the stack.The optional Disp16 operand is an offset value added to register SP after restoring the return address into register CS and IP, or register IP only. This is provided to discard the parameters that are pushed into the stack before the CALL instruction is initiated.Examples:

Examples: