Conditional Jumps Jcond destination  Cond refers to a flag condition  Destination should be a local label  Destination must be within –128 to +127 bytes.

Slides:



Advertisements
Similar presentations
Jump Condition.
Advertisements

CSC 221 Computer Organization and Assembly Language Lecture 21: Conditional and Block Structures: Assembly Programs.
NEG Instruction Change operand content into two’s complement (negative value) and stored back into its operand mov bl, b neg bl; bl = mov.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Conditional Loop Instructions LOOPZ and LOOPE LOOPNZ.
Assembly Language :CSC 225 (Lec#4: Flag Register and Conditional Statements) By Dr. Syed Noman.
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.
CS2422 Assembly Language and System Programming Conditional Processing Department of Computer Science National Tsing Hua University.
Flow Control Instructions
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Conditional Processing If … then … else While … do; Repeat … until.
Quiz #2 Topics Character codes Intel IA-32 architecture Mostly MASM
Lecture 3 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
Low Level Programming Lecturer: Duncan Smeed Low Level Program Control Structures.
Types of Registers (8086 Microprocessor Based)
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
Boolean and Comparison Instructions Operation Description ANDAND Destination, Source OROR Destination, Source XORXOR Destination, Source NOTNOT Destination.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#5) By Dr. Syed Noman.
Sahar Mosleh California State University San MarcosPage 1 Review.
Wednesday Feb 1 Project #1 Due Sunday, February 3 Quiz #2 Wednesday, February 6, in class Programming Project #2 is posted Due Sunday, February 10.
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.
Arithmetic Flags and Instructions
(Flow Control Instructions)
1 ICS 51 Introductory Computer Organization Fall 2009.
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.
EEL 3801 Part V Conditional Processing. This section explains how to implement conditional processing in Assembly Language for the 8086/8088 processors.
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
3.4 Addressing modes Specify the operand to be used. To generate an address, a segment register is used also. Immediate addressing: the operand is a number.
Microprocessor MA Rahim Khan Computer Engineering and Networks Department.
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.
CSC 221 Computer Organization and Assembly Language Lecture 20: Conditional and Block Structures.
Jumps, Loops and Branching. Unconditional Jumps Transfer the control flow of the program to a specified instruction, other than the next instruction in.
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 for Intel-Based Computers, 4 th Edition Lecture 22: Conditional Loops (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 4 th Edition Week 10: Conditional Processing Slides modified by Dr. Osama Younes.
K.K. Leung Fall 2008Introductory Pentium Programming1 Pentium Architecture: Introductory Programming Kin K. Leung
CS-401 Computer Architecture & Assembly Language Programming
Practical Session 2 Computer Architecture and Assembly Language.
CSC 221 Computer Organization and Assembly Language
Assembly Language for Intel-Based Computers, 5th Edition
Data Transfers, Addressing, and Arithmetic
EE3541 Introduction to Microprocessors
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Assembly IA-32.
More on logical instruction and
Assembly Language Programming Part 2
Microprocessor and Assembly Language
Processor Processor characterized by register set (state variables)
Computer Organization and Assembly Language
Shift & Rotate Instructions)
Program Logic and Control
Program Logic and Control
Shift & Rotate Instructions)
Flow Control Instructions
EECE.3170 Microprocessor Systems Design I
Chapter 7 –Program Logic and Control
Chapter 7 –Program Logic and Control
Computer Architecture and Assembly Language
Presentation transcript:

Conditional Jumps Jcond destination  Cond refers to a flag condition  Destination should be a local label  Destination must be within –128 to +127 bytes from the current location Lots of different conditional jump instructions  Four types: Specific flag comparisons Equality between operands, or the value of ECX unsigned comparisons signed comparisons

Conditional Structures Two steps are needed to execute  An operation such as CMP, AND, or SUB To modify the flags  A conditional jump instruction tests the flags and causes a branch to a new address. 1. CMPal, 0 jzL1;jump to L1 if ZF = 1 2. ANDdl, b jnzL2;jump to L2 if ZF = 0

Jumps Based on Specific Flag Values(10) MnemonicDescriptionFlags/Registers JZif zeroZF = 1 JNZif not zeroZF = 0 JCif carryCF = 1 JNCif not carryCF = 0 JOIf overflowOF = 1 JNOIf not overflowOF = 0 JSif signedSF = 1 JNSif not signedSF = 0 JPif parity (even)PF = 1 JNPif not parity (odd)PF = 0

MnemonicDescriptionFlags/Registers JEif equalZF = 1 JNEif not equalZF = 0 JCXZif CX = 0ZF = 0 JECXZif ECX = 0ZF = 0 Jumps Based on Equality(4)

Jumps Based on Unsigned Comparisons(8)

Jumps Based on Signed Comparisons(8)

Conditional Jump Applications

In Class Problems 1. Will the following code jump to the label named Target? movax, 8109h cmpax, 26h jgTarget jg →signed conditional jump (8109h < 26h) so no jump

In Class Problems 2. Will the following code jump to the label named Target? movax, -30 cmpax, -50 jgTarget jg →signed conditional jump (-30 > -50) so jump is taken

In Class Problems 3. Will the following code jump to the label named Target? movax, -42 cmpax, 26 jaTarget ja →unsigned conditional jump -42 = D6h, 26 = 1Ah D6 > 1A so jump is taken

In Class Problems 4. Write instructions that jump to label L1 when the unsigned integer in DX is less than or equal to the integer in CX. cmpdx, cx jbeL1

In Class Problems 5. Write instructions that jump to label L2 when the signed integer in AX is greater than the integer in CX. cmpax, cx jgL2

In Class Problems 6. Write instructions that clear bits 0 and 1 in AL. If the destination operand is equal to zero, jump to label L3. Otherwise, jump to label L4. AND AL, 0FCh JZL3 JMPL4

Block-Structured IF Statements If ( op1 == op2) { X = 1; Y = 2; } Moveax, op1 Cmp eax, op2 JeL1 JmpL2 L1: MovX, 1 Mov Y, 2 L2:

IF, Else Statements If ( op1 == op2) { X = 1; Y = 2; } Else { X = 4; Y = 5; } Moveax, op1 Cmp eax, op2 JeL1 JmpL2 L1: MovX, 1 Mov X, 2 JmpL3 L2: Mov, X, 4 movX, 5 L3:

Logical AND Operator Finding alternate ways to implement expressions may reduce the amount of code needed. Using JBE instead of JA: If (al > bl) AND (bl > cl) { x = 1; } Cmp al, bl jbenext cmpbl, cl jbenext movX, 1 Next:

Logical OR Operator There are several ways to implement expressions If (al > bl) OR (bl > cl) { x = 1; } Cmp al, bl jaL1 cmpbl, cl jbenext L1: movX, 1 Next:

While Loop While (val1 < val2) { val1++; val2--; } mov eax, val1 While: cmpeax, val2 jnlendwhile inceax decval2 jmpwhile Endwhile: movval1, eax

Table-Driven Selections A way of using a table lookup to replace a multiway selection structure. Create a table containing lookup values and the offsets of labels or procedures, and use a loop to search the table. Link to ProcTble.asm

Part of a Table.data CaseTableBYTE‘1’;lookup value DWORDProcess_1 BYTE‘2’ DWORD Process_2 ….. ‘1’ ‘2’ ‘3’ Address of process_2 Lookup value