Jump Condition.

Slides:



Advertisements
Similar presentations
Flow of Control Instruction/Control structure Looping structure Looping structure Branching structure Branching structure For assembly language program.
Advertisements

CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 4: The 80x86 Instruction Set Architecture Registers-Instructions Constantine D. Polychronopoulos.
Assembly Programming Notes for Practical 3 Munaf Sheikh
CSC 221 Computer Organization and Assembly Language Lecture 21: Conditional and Block Structures: Assembly Programs.
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Assembly Language :CSC 225 (Lec#4: Flag Register and Conditional Statements) By Dr. Syed Noman.
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
LAB Flow Control Instructions
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers
CS2422 Assembly Language & System Programming October 17, 2006.
Flow Control Instructions
Conditional Processing If … then … else While … do; Repeat … until.
Topics Control Flow Structure – Conditional Jump – Unconditional Jump Control Flow Structures – IF-THEN – IF-THEN-ELSE – CASE Branches with Compound Conditions.
1 Flow Control Instructions and Addressing Modes Chapter 3.
Lecture 3 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
Comparing and Branching ifs and loops part A. JMP instruction Consider the forever loop: for ( ; ; ) { … } How can we accomplish this in Assembler?
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#5) By Dr. Syed Noman.
Dr. José M. Reyes Álamo 1.  Review: ◦ of Comparisons ◦ of Set on Condition  Statement Labels  Unconditional Jumps  Conditional Jumps.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
(Flow Control Instructions)
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 5 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Chapter 5 Branching and Looping.
LEA instruction The LEA instruction can be used to get the offset address of a variable Example ORG 100h MOV AL, VAR1 ; check value of VAR1 by moving it.
Conditional Loop Instructions, Conditional Structures
COMP 2003: Assembly Language and Digital Logic Chapter 2: Flags and Instructions Notes by Neil Dickson.
Assembly 06. Outline cmp (review) Jump commands test mnemonic bt mnemonic Addressing 1.
2/20/2016CAP 2211 Flow Control Instructions. 2/20/2016CAP 2212 Transfer of Control Flow control instructions are used to control the flow of a program.
Comparison Instructions Test instruction –Performs an implied AND operation between each of the bits in 2 operands. Neither operand is modified. (Flags.
Jumps, Loops and Branching. Unconditional Jumps Transfer the control flow of the program to a specified instruction, other than the next instruction in.
Assembly Language Wei Gao. Assembler language Instructions.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Selection and Iteration Chapter 8 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Assembly Language Programming Petra University Dr. Hadi Hassan Conditional Processing.
CS-401 Computer Architecture & Assembly Language Programming
Practical Session 2 Computer Architecture and Assembly Language.
Homework Reading Labs PAL, pp
Instruksi Set Prosesor 8088
Microprocessor and Assembly Language
Lecture 4 Control Flow Structures (LOOPS)
EE3541 Introduction to Microprocessors
Morgan Kaufmann Publishers Computer Organization and Assembly Language
INSTRUCTION SET.
More on logical instruction and
Assembly Language Programming Part 2
Microprocessor and Assembly Language
Processor Processor characterized by register set (state variables)
CS 301 Fall 2002 Assembly Instructions
Computer Organization and Assembly Language
Flags Register & Jump Instruction
فصل پنجم انشعاب و حلقه.
Shift & Rotate Instructions)
Program Logic and Control
Program Logic and Control
Homework Reading Machine Projects Labs PAL, pp
Flow Control Instructions
X86 Assembly Review.
EECE.3170 Microprocessor Systems Design I
High-level language structures
Assembly Language for Intel 8086 Jump Condition
Jump & Loop instructions
Chapter 7 –Program Logic and Control
Carnegie Mellon Ithaca College
Chapter 8: Instruction Set 8086 CPU Architecture
Chapter 7 –Program Logic and Control
Computer Architecture and Assembly Language
Part VI Looping Structures
Presentation transcript:

Jump Condition

Topic Control Flow Structure Control Flow Structures Conditional Jump Unconditional Jump Control Flow Structures IF-THEN IF-THEN-ELSE CASE Branches with Compound Conditions

Labels r needed in cases where one instruction refers to another. An Example of Jump Display the entire IBM character set The function number .MODEL SMALL .CODE .STARTUP MOV AH, 2 ; display char function MOV CX, 256 ; no. of chars to display MOV DL, 0 ; DL has ASCII code for null char PRINT_LOOP: INT 21H ; display a char INC DL ; increment ASCII code DEC CX ; decrement counter JNZ PRINT_LOOP: ; keep going if CX not 0 .EXIT END Calls system routine/functions Statement label Labels r needed in cases where one instruction refers to another. Section 6-1 of Assembly Language Programming Book

Conditional Jumps JNZ Syntax: Jxxx destination_label True or False [no gray area – like our minds!] JNZ is an example of conditional jump instruction Checks the Z flag. If Z = 0 then jump to the location Three categories of conditional jumps Signed jumps, for signed interpretation Unsigned jumps, for unsigned interpretation Single-flag jumps, operates on settings of individual flags

How to decide? Implement? CPU looks at the FLAGS register If jump conditions r TRUE – the CPU adjusts the IP  to point to the destination_label, so that the instruction at this label will be done next. If FALSE – no change in IP

1. Signed Conditional Jumps Opcodes Description Condition for jumps JG/JNLE Jump if Greater than Jump if Not Less than or Equal to ZF = 0 and SF = OF JGE/JNL Jump if Greater than or Equal to Jump if Not Less than SF = OF JL/JNGE Jump if Less than Jump if Not Greater than or Equal to SF <> OF JLE/JNG Jump if less than or equal Jump if not greater than ZF = 1 or SF <> OF

2. Unsigned Conditional Jumps Symbol Description Condition for jumps JA/JNBE Jump if above Jump if not below or equal CF = 0 and ZF = 0 JAE/JNB Jump if above or equal Jump if not below CF = 0 JB/JNAE Jump if below Jump if not above or equal CF = 1 JBE/JNA Jump if below or equal Jump if not above CF = 1 or ZF = 1

3. Single-Flag Jumps Symbol Description Condition for jumps JE/JZ Jump if equal Jump if equal to zero ZF = 1 JNE/JNZ Jump if not equal Jump if not zero ZF = 0 JC Jump if carry CF = 1 JNC Jump if no carry CF = 0 JO Jump if overflow OF = 1 JNO Jump if no overflow OF = 0 JS Jump if sign negative SF = 1 JNS Jump if nonnegative sign SF = 0 JP/JPE Jump if parity even PF = 1 JNP/JPO Jump if parity odd PF = 0

Range of a Conditional Jump ref Range of a Conditional Jump The destination label must precede the Jump instruction by no more than 126 bytes Or, follow by no more than 127 bytes LABEL: ; statement JNZ LABEL 126 bytes JZ LABEL ; statements LABEL: ; statement 127 bytes

CMP Instruction The jump condition is often provided by the CMP (compare) instruction CMP destination, source  dest[contents] – source[contents] It is like SUB, except that destination is not changed Destination may not be a constant The result is not stored but the flags are affected CMP AX, 10 JG BELOW CMP AX, BX JG BELOW ;JG – jump if > If AX = 7FFFh, and BX = 0001h, the result is 7FFFh - 0001h = 7FFEh. ZF = SF = OF = 0, JG is satisfied, so control transfers to label BELOW

Signed vs. Unsigned Jumps Each signed jump corresponds to an analogous unsigned jump e.g., signed JG (if >) corresponds to unsigned JA (if above) Use depends on the interpretation The jumps operate on different flags Symbol Description Condition for jumps JG/JNLE Jump if greater than Jump if not less than or equal to ZF = 0 and SF = OF JA/JNBE Jump if above Jump if not below or equal CF = 0 and ZF = 0 Wrong jumps  wrong results! [same as life]

Until 4/11 Wrong jumps  wrong results! [same as life]

Signed vs. Unsigned Jumps cont. For signed interpretation, let us take AX = 7FFFh, BX = 8000h and we execute Even though 7FFFh > 8000h in a signed sense, the program does not jump to BELOW_LABEL  why? Because 7FFFh < 8000h in an unsigned sense JA, which is the unsigned jump CMP AX, BX JA BELOW_LABEL

Signed vs. Unsigned Jumps cont. working with CHAR With standard ASCII character set [character code 0-31 for control chars; 32-127 for printable characters] – either signed/unsigned jumps may be used. Why? Because the sign bit of a byte containing a character code is always  zero [0]. BUT, unsigned jumps should be used when comparing extended ASCII characters [code 80h ~ FFh]

Extended ASCII codes (character code 128-255) There are several different variations of the 8-bit ASCII table. E.g., ISO 8859-1, also called ISO Latin-1. Codes 129-159 contain the Microsoft® Windows Latin-1 extended characters. http://www.ascii-code.com/

The JMP Instruction JMP destination/target_label ref The JMP Instruction JMP (jump) instruction causes an unconditional jump Syntax is: JMP can be used to get around the range restriction [126/127 byte] Flags – no change JMP destination/target_label TOP: ; the loop body contains so many instructions ; that label TOP is out of range for JNZ. Solution is- DEC CX JNZ BOTTOM JMP EXIT BOTTOM: JMP TOP EXIT: MOV AX, BX TOP: ; body of the loop, say 2 instructions DEC CX ; decrement counter JNZ TOP ; keep looping if CX > 0 MOV AX, BX Section 6-3: Assembly Language Programming

TOP: EXIT: When CX=0 - It will not Jump to BOTTOM It will go to next instr. JMP EXIT JMP TOP  is unconditional – just Jump! TOP: ; the loop body contains so many instructions ; that label TOP is out of range for JNZ. Solution is- DEC CX JNZ BOTTOM JMP EXIT BOTTOM: JMP TOP EXIT: MOV AX, BX

Lets Jump to another lecture?

References Ch 6, Assembly Language Programming – by Charls Marut Some materials are from Dr. Sazzad, NSU