EECE.3170 Microprocessor Systems Design I

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.
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2013 Lecture 14 Compare instructions; conditional execution.
80x86 Instruction Set Dr. Qiang Lin.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Assembly Language for Intel-Based Computers
Flow Control Instructions
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2012 Lecture 10: Flag control instructions Conditional execution.
Microprocessor Systems Design I
Microprocessor Programming II
Lecture 3 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
Low Level Programming Lecturer: Duncan Smeed Low Level Program Control Structures.
ICS312 Set 9 Logic & Shift Instructions. Logic & Shift Instructions Logic and Shift Instructions can be used to change the bit values in an operand. The.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
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)
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.
Microprocessor Programming II To discuss more complicated programming techniques Flag control instructions Compare and jump Subroutines Loop and string.
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.
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.
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,
K.K. Leung Fall 2008Introductory Pentium Programming1 Pentium Architecture: Introductory Programming Kin K. Leung
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Homework Reading Labs PAL, pp
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Instruksi Set Prosesor 8088
Microprocessor and Assembly Language
EE3541 Introduction to Microprocessors
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Assembly IA-32.
INSTRUCTION SET.
More on logical instruction and
Assembly Language Programming Part 2
16.317: Microprocessor System Design I
Microprocessor and Assembly Language
Introduction to Assembly Language
Computer Organization and Assembly Language
Flags Register & Jump Instruction
Shift & Rotate Instructions)
Program Logic and Control
EECE.3170 Microprocessor Systems Design I
Program Logic and Control
Homework Reading Machine Projects Labs PAL, pp
EECE.3170 Microprocessor Systems Design I
Shift & Rotate Instructions)
Flow Control Instructions
Assembly Language for Intel 8086 Jump Condition
Chapter 7 –Program Logic and Control
Carnegie Mellon Ithaca College
EECE.3170 Microprocessor Systems Design I
Chapter 8: Instruction Set 8086 CPU Architecture
Chapter 7 –Program Logic and Control
Presentation transcript:

EECE.3170 Microprocessor Systems Design I Instructor: Dr. Michael Geiger Summer 2016 Lecture 6: Conditional execution Jump/loop instructions

Microprocessors I: Lecture 6 Lecture outline Announcements/reminders HW 3 to be posted; due Monday, 6/6 Today’s lecture Conditional execution Jump/loop instructions 4/7/2019 Microprocessors I: Lecture 6

Microprocessors I: Lecture 6 4/7/2019 Compare Instructions Compare 2 values; store result in ZF/SF General format: CMP D,S Works by performing subtraction (D) – (S) D, S unchanged ZF/SF/OF indicate result (signed values) ZF = 1  D == S ZF = 0, (SF XOR OF) = 1  D < S ZF = 0, (SF XOR OF) = 0  D > S (D) (S) result CF SF AF AX BX 2345>1234 0 0 0 1234<2345 1 1 1 1234>ABCD 1 0 1 ABCD<1234 0 1 0 ABCD>A000 0 0 0 A000<ABCD 1 1 1 7FFF 8000 overflow 4/7/2019 Microprocessors I: Lecture 6 Chapter 6 part 1

Microprocessors I: Lecture 6 Condition codes Conditional execution: result depends on value of flag bit(s) Intel instructions specify condition codes Condition code implies certain flag values Opcodes written with cc as part of name cc can be replaced by any valid code Examples: CMOVcc, SETcc, Jcc Specific examples: CMOVE, SETL, SETZ, JNE, JG 4/7/2019 Microprocessors I: Lecture 6

Condition codes (cont.) Testing overflow O (OF = 1), NO (OF =0) Testing carry flag C (CF = 1) NC (CF = 0) Testing sign flag S (SF = 1), NS (SF = 0) Testing parity flag P or PE (PF = 1) NP or PO (PF = 0) 4/7/2019 Microprocessors I: Lecture 6

Condition codes (cont.) Testing equality/zero result E or Z (ZF = 1) NE or NZ (ZF = 0) Signed comparison L or NGE (SF XOR OF = 1) NL or GE (SF XOR OF = 0) LE or NG ((SF XOR OF) OR ZF = 1) NLE or G ((SF XOR OF) OR ZF = 0) Unsigned comparison “Below”  less than, “above”  greater than B, NAE (CF = 1) NB, AE (CF = 0) BE or NA (CF OR ZF = 1) NBE or A (CF OR ZF = 0) 4/7/2019 Microprocessors I: Lecture 6

Conditional move (CMOV) Only in Pentium Pro & later Perform move only if condition is true Examples: CMOVZ AX, [SI]  move if ZF == 1 CMOVG EBX, EAX  move if greater than 4/7/2019 Microprocessors I: Lecture 6

Byte Set on Condition Instruction 4/7/2019 Byte Set on Condition Instruction Byte set on condition instruction Used to set byte based on condition code Can be used for boolean results—complex conditions General format: SETcc D cc = one of the supported conditional relationships Result D = 01h if condition true D = 00h if condition false 4/7/2019 Microprocessors I: Lecture 6 Chapter 6 part 1

Byte Set on Condition Instruction 4/7/2019 Byte Set on Condition Instruction Operation: Flags tested for conditions defined by “cc” and the destination in a register or memory updated as follows If cc test True: 000000012 = 01H  D If cc test False: 000000002 = 00H  D Examples of conditional tests: SETE = set byte if equal  ZF = 1 SETC = set byte if carry  CF =1 SETBE = set byte if below or equal  CF = 1 +(or) ZF = 1 Example: SETA AL = set byte if above if CF = 0  (and) ZF = 0 (AL) = 01H Otherwise, (AL) =00H 4/7/2019 Microprocessors I: Lecture 6 Chapter 6 part 1

Microprocessors I: Lecture 6 Example Show the results of the following instructions, assuming that “A” = (100H) = 0001H “B” = (102H) = 0003H “C” = (104H) = 1011H “D” = (106H) = 1011H “E” = (108H) = ABCDH “F” = (10AH) = DCBAH What complex condition does this sequence test?  MOV AX, [100H] CMP AX, [102H] SETLE BL MOV AX, [104H] CMP AX, [106H] SETE BH AND BL, BH MOV AX, [108H] CMP AX, [10AH] SETNE BH OR BL, BH 4/7/2019 Microprocessors I: Lecture 6

Microprocessors I: Lecture 6 Example solution Condition being tested: To simplify, treat each word as a variable named “A” through “F” ((A <= B) && (C == D)) || (E != F) Source: http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_6/CH06-4.html 4/7/2019 Microprocessors I: Lecture 6

Microprocessors I: Lecture 6 Jump instructions Used to change flow of program Next instruction specified by operand Two general types Unconditional: JMP <target> Always goes to address indicated by <target> Conditional: Jcc <target> Jump only occurs if condition true cc replaced by valid condition code Most codes discussed in previous lecture Additional codes: CXZ/ECXZ  CX/ECX register is zero 4/7/2019 Microprocessors I: Lecture 6

Microprocessors I: Lecture 6 4/7/2019 Jump Instructions 4/7/2019 Microprocessors I: Lecture 6 Chapter 6 part 1

Example: program structure 1 Given the instructions below, what are the resulting register values if: AX = 0010H, BX = 0010H AX = 1234H, BX = 4321H What type of high-level program structure does this sequence demonstrate? Instructions CMP AX, BX JE L1 ADD AX, 1 JMP L2 L1: SUB AX, 1 L2: MOV [100H], AX 4/7/2019 Microprocessors I: Lecture 6

Microprocessors I: Lecture 6 Example solution First case: AX = BX = 0010H CMP AX, BX  Shows AX == BX JE L1  Cond. true—jump to L1 ADD AX, 1 JMP L2 L1: SUB AX, 1  AX = AX – 1 = 000F L2: MOV [100H], AX  Store 000F at DS:100H 4/7/2019 Microprocessors I: Lecture 6

Example solution (cont.) Second case: AX = 1234H, BX = 4321H CMP AX, BX  Shows AX < BX JE L1  Cond. false—no jump ADD AX, 1  AX = AX + 1 = 1235H JMP L2 L1: SUB AX, 1  AX = AX – 1 = 000F L2: MOV [100H], AX  Store 000F at DS:100H 4/7/2019 Microprocessors I: Lecture 6

Example solution (cont.) High-level program structure: if/else statement If part: compare + jump (if (AX == BX)) Else part: what follows if condition false Unconditional jump used to skip “if” part Both parts have same exit (L2) 4/7/2019 Microprocessors I: Lecture 6

Example: program structure 2 Given the instructions below, what are the resulting register values if, initially, AX = 0001H? What type of high-level program structure does this sequence demonstrate? Instructions MOV CL, 5 L: SHL AX, 1 DEC CL JNZ L 4/7/2019 Microprocessors I: Lecture 6

Example: program structure 3 Given the instructions below, what are the resulting register values if, initially, AX = 0001H? What type of high-level program structure does this sequence demonstrate? Instructions MOV CX, 5 L: JCXZ END ADD AX, AX DEC CX JMP L END: MOV [10H], AX 4/7/2019 Microprocessors I: Lecture 6

Microprocessors I: Lecture 6 4/7/2019 Block Move Program 4/7/2019 Microprocessors I: Lecture 6 Chapter 6 part 1

Microprocessors I: Lecture 6 Loop instructions Common operations in basic loops Compare Conditional jump Decrement loop counter (CX) Loop instructions combine all into one op All decrement CX by 1, then check if CX == 0 <target> must be short-label (8-bit immediate) LOOP <target>: Return to <target> if CX != 0 LOOPE/LOOPZ <target>: Return to <target> if (CX != 0) && (ZF == 1) LOOPNE/LOOPNZ <target>: Return to <target> if (CX != 0) && (ZF != 1) 4/7/2019 Microprocessors I: Lecture 6

Loop Program Structure 4/7/2019 Loop Program Structure Structure of a loop CX = initial count Loop body: code to be repeated Loop instruction– determines if loop is complete or if the body is to repeat Example: block move 4/7/2019 Microprocessors I: Lecture 6 Chapter 6 part 2

Microprocessors I: Lecture 6 Loop example 1 Rewrite the post-tested loop seen earlier using a loop instruction: MOV CL, 5 L: SHL AX, 1 DEC CL JNZ L Solution: MOV CL, 5 L: SHL AX, 1 LOOP L 4/7/2019 Microprocessors I: Lecture 6

Microprocessors I: Lecture 6 Loop example 2 Describe the operation of the following program (Example 6.15-6.16). What is the final value of ESI if the 15 bytes between 0A001 and 0A00F have the following values? 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E MOV DL, 05 MOV EAX, 0000A000h MOV ESI, 00000000h MOV CX, 000F AGAIN:INC SI CMP [EAX + ESI], DL LOOPNE AGAIN 4/7/2019 Microprocessors I: Lecture 6

Microprocessors I: Lecture 6 Final notes Next time: Subroutines HLL and x86 assembly Reminders: HW 3 to be posted; due date TBD 4/7/2019 Microprocessors I: Lecture 6