+ All Categories
Home > Engineering > Flow control instructions

Flow control instructions

Date post: 15-Feb-2017
Category:
Upload: prodip-ghosh
View: 258 times
Download: 0 times
Share this document with a friend
32
WELCOME TO MY PRESENTATION
Transcript
Page 1: Flow control instructions

WELCOMETO MY

PRESENTATION

Page 2: Flow control instructions

PRODIP GHOSH

Page 3: Flow control instructions

Flow Control Instructions

Page 4: Flow control instructions

Flow Control Instructions

Program using the different instruction :- Conditional and Unconditional Jump InstructionsCompare InstructionLoop Instruction

Page 5: Flow control instructions

Conditional Jump

Syntax: Jxxx destination_label Where xxx represents the condition

If condition is true, the next instruction to be executed is the one at destination_label.

If condition is false, the instruction immediately following the jump is done next.

Page 6: Flow control instructions

Conditional Jump

The destination_label must precede the jump instruction by no more than 126 bytes.

To implement a conditional jump, the CPU looks at the FLAG register (set by last instruction executed by the processor).

JMP instructions themselves do not affect flags.

Page 7: Flow control instructions

Unconditional JumpSyntax:

JMP destination_labelPurpose: To Transfer control to another part of the program.

Example: MOV AX, 5 MOV BX, 2 JMP LABEL_SUB ADD AX, BX ;this instruction will never execute LABEL_SUB: SUB AX, BX

Page 8: Flow control instructions

Categories of Conditional Jump

Signed Jumps: This is used when a signed interpretation is being given to result.

Symbol Description Condition for Jumps

JG/JNLE Jump if greater thanJump if not less than or equal to

ZF = 0 and SF = OF

JGE/JNL Jump if greater than or equal toJump if not less than

SF = OF

JL/JNGE Jump if less thanJump if not greater than or equal to

SF <> OF

JLE/JNG Jump if less than or equal toJump if not greater than

ZF = 1 and SF <> OF

Page 9: Flow control instructions

Categories of Conditional Jump

Unsigned Jumps: This is used for an unsigned interpretation of result

Symbol Description Condition for Jumps

JA/JNBE Jump if above thanJump if not below than or equal to

ZF = 0 and CF = 0

JAE/JNB Jump if above than or equal toJump if not below than

CF = 0

JB/JNAE Jump if below thanJump if not above than or equal to

CF = 1

JBE/JNA Jump if below than or equal toJump if not above than

ZF = 1 and CF = 1

Page 10: Flow control instructions

Categories of Conditional JumpSingle-Flag Jumps: Which operate on settings of individual flags.

Page 11: Flow control instructions

Compare InstructionCMP (compare) instruction performs an implied subtraction of a

source operand from destination operand. Neither operand is modified. CMP destination, source

Compare Instruction maintain three condition: Destination < Source Destination = Source Destination > Source

Page 12: Flow control instructions

Examples

Page 13: Flow control instructions

OUTPUT

Page 14: Flow control instructions

High Level Language Structures

Branching Structure IF-THEN IF-THEN-ELSE CASE

Page 15: Flow control instructions

IF-THEN

Page 16: Flow control instructions

IF-THEN-ELSE

Page 17: Flow control instructions

CASEA case is a multiway branch structure that tests a register,

variable, or expression for particular values or range of values. The general form is as follows:

Case Expression values_1: statements_1 values_2: statements_2

………….. values_n: statements_n END_CASE

Page 18: Flow control instructions

CASE Examples

Page 19: Flow control instructions

High Level Language Structures

Branching with Compound Conditions AND CONDITIONS OR CONDITIONS

Page 20: Flow control instructions

AND CONDITION An AND condition is true if and only if condition_1 and

condition_2 are both true. If any condition is false, then the whole thing is false.

Page 21: Flow control instructions

AND CONDITION EXAMPLES

Page 22: Flow control instructions

OR CONDITION

If condition_1 OR condition_2 is true then an OR conditions is true. If both conditions are false, then the whole thing is false.

Page 23: Flow control instructions

OR CONDITION EXAMPLES

Page 24: Flow control instructions

High Level Language Structures

Looping StructuresFOR LOOPWHILE LOOPREPEAT LOOP

Page 25: Flow control instructions

LOOPING STRUCTURES

FOR LOOP Executed at least once. If CX contains 0, the loop instruction decrements CX (CX = FFFFh) To prevent this, use instruction JCXZ before the loop. ;initialize CX JCXZ SKIP TOP: ;body of the loop LOOP TOPSKIP:

Page 26: Flow control instructions

Examples For Looping Structures

Page 27: Flow control instructions

LOOPING STRUCTURESWHILE LOOP

WHILE condition DO ;statements

END_WHILE

WHILE LOOP checks the terminating condition at the top of the loop, so don’t forget to initialize variables.

Page 28: Flow control instructions

EXAMPLES WHILE STRUCTURES

Page 29: Flow control instructions

LOOPING STRUCTURES

REPEAT LOOP REPEAT

;statements UNTIL condition

First statements are executed, then the condition is checked.If true, the loop terminates; if false, control branches to the top of the loop

Page 30: Flow control instructions

Examples Repeat Structures

Page 31: Flow control instructions

Any Question?

Page 32: Flow control instructions

ThankYou!!!


Recommended