CIS 020 Assembly Programming Chapter 06 - Comparisons & Logical control Procedures © John Urrutia 2012, All Rights Reserved.5/27/20121.

Slides:



Advertisements
Similar presentations
Chapter 4: Control Structures I (Selection)
Advertisements

CIS 020 Assembly Programming Chapter 13 - Branching and Looping With Registers © John Urrutia 2012, All Rights Reserved.5/27/20121.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
CIS 020 Assembly Programming Chapter 02 - Numbering Systems & Data Representation © John Urrutia 2012, All Rights Reserved.5/27/20121.
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
16/27/ :53 PM6/27/ :53 PM6/27/ :53 PMLogic Control Structures Arithmetic Expressions Used to do arithmetic. Operations consist of +,
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
Group 5 Alain J. Percial Paula A. Ortiz Francis X. Ruiz.
CIS 020 Assembly Programming Chapter 14 - Instruction Formats & Interrupt Codes for DEBUGGING PROGRAMS © John Urrutia 2012, All Rights Reserved.5/27/20121.
MIPS Instruction Set Advantages
CIS Computer Programming Logic
EGR 2261 Unit 4 Control Structures I: Selection  Read Malik, Chapter 4.  Homework #4 and Lab #4 due next week.  Quiz next week.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
CIS 020 Assembly Programming Chapter 07 - Decimal Arithmetic Operations © John Urrutia 2012, All Rights Reserved.5/27/20121.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
1 © 2000 John Urrutia. All rights reserved. Qbasic Looping Statements & Formatted Output.
S2008Final_part1.ppt CS11 Introduction to Programming Final Exam Part 1 S A computer is a mechanical or electrical device which stores, retrieves,
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
CIS 020 Assembly Programming Chapter 12 - RR-Format Instructions & more RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.
Flow of Control Part 1: Selection
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Cis303a_chapt04.ppt Chapter 4 Processor Technology and Architecture Internal Components CPU Operation (internal components) Control Unit Move data and.
Chapter 7 Additional Control Structures. Chapter 7 Topics l Switch Statement for Multi-Way Branching l Do-While Statement for Looping l For Statement.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
TK 1914 : C++ Programming Control Structures I (Selection)
1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA.
(Flow Control Instructions)
Python Selection. All the programs you have been developing so far have been sequential, this means that each instruction is executed in a set order.
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
CIS 020 Assembly Programming Chapter 11 - Binary Operations Using RX-Format Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
ICT Introduction to Programming Chapter 4 – Control Structures I.
Chapter 5: Control Structures I (Selection). Objectives In this chapter you will: Learn about control structures Examine relational and logical operators.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
CIS 020 Assembly Programming Chapter 08 - Advanced Decimal Arithmetic Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.
1 Programming in C++ Dale/Weems/Headington Chapter 9 Additional Control Structures (Switch, Do..While, For statements)
CIS 020 Assembly Programming Chapter 05 - Move Statements © John Urrutia 2012, All Rights Reserved.5/27/20121.
CIS 020 Assembly Programming
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
CC213 Programming Applications Week #2 2 Control Structures Control structures –control the flow of execution in a program or function. Three basic control.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
LOGICAL CONTROL STRUCTURES (chp. 8)
PROGRAMMING THE BASIC COMPUTER
MIPS Instruction Set Advantages
Assembly Language Programming of 8085
Microprocessor T. Y. B. Sc..
Computer Architecture & Operations I
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Topics The if Statement The if-else Statement Comparing Strings
Introduction to MATLAB
Topics The if Statement The if-else Statement Comparing Strings
Chapter 8 JavaScript: Control Statements, Part 2
Computer Science 210 Computer Organization
Chapter 7 Additional Control Structures
Chapter 8: More on the Repetition Structure
COMS 361 Computer Organization
COMS 361 Computer Organization
The .ASCII and .END Assembler Input ;Stan Warford ;January 13, 2005
Chap 7. Advanced Control Statements in Java
Decision Making Using the IF and EVALUATE Statements
Conditional Branching (beq)
Presentation transcript:

CIS 020 Assembly Programming Chapter 06 - Comparisons & Logical control Procedures © John Urrutia 2012, All Rights Reserved.5/27/20121

Logical Control Procedures Program logic All programs will execute in sequential order unless told to do otherwise. The set of branch instructions will alter the order of program execution and work in conjunction with comparison instructions © John Urrutia 2012, All Rights Reserved.25/27/2012

Logical Control Procedures Unconditional Branches Always alters the program execution path and are used to create repetition or iterative loops. Only one operand – must be a label. © John Urrutia 2012, All Rights Reserved.35/27/2012

Logical Control Procedures Conditional Branches May alter the program execution path and are used to create both selection structures and repetition loops 2 operands Test condition mask (0 – 15) Label to branch to if condition matches © John Urrutia 2012, All Rights Reserved.45/27/2012

Logical Control Procedures Selection structures One-way selection  if true then branch to label Two-way selection  if true then branch to label else continue in sequence if false then branch to label else continue in sequence © John Urrutia 2012, All Rights Reserved.55/27/2012

Logical Control Procedures © John Urrutia 2012, All Rights Reserved.65/27/2012 True One-Way Selection Flowchart Instructions to execute Yes -branch No Two-Way Selection Flowchart True Instructions to execute No Yes -branch

Logical Control Procedures Looping structures pseudocode Pre-Test Loop  Do until true continue in sequence end Do Post-Test Loop  Do continue in sequence Until true © John Urrutia 2012, All Rights Reserved.75/27/2012

Logical Control Procedures © John Urrutia 2012, All Rights Reserved.85/27/2012 True Pre-test iteration Flowchart Instructions to execute Yes -branch No Post-test iteration Flowchart True Instructions to execute branch  No branch  Yes

Logical Control Procedures The condition or test is the logical result of a comparison between two values. 2 instructions work with each other The comparison instruction sets the condition code The branch instruction determines the next instruction to execute based on the condition code © John Urrutia 2012, All Rights Reserved.95/27/2012 True

Comparison Statements Used to determine the relationship between two data fields. Only three possible results Field 1 is greater than Field 2 Field 2 is greater than Field 1 Field 1 is equal to Field 2 © John Urrutia 2012, All Rights Reserved.105/27/2012 True

Comparison Statements The result of a comparison is stored in a special area called the Condition Code which is part of the arithmetic logic unit of the CPU. For now we will concentrate only on how character data effects the Condition Code. PSW The Condition Code is stored in the PSW. © John Urrutia 2012, All Rights Reserved.115/27/2012

PSW Program Execution & the PSW You previously learned about the parts of the CPU The ALU The CU next The Instruction Pointer – which always contains the address of the next instruction to execute. PSW PSW All information about the execution of your program is stored in the P rogram S tatus W ord or PSW © John Urrutia 2012, All Rights Reserved.125/27/2012

PSW Program Execution & the PSW PSW The PSW is 8 bytes long and consists of: Bits 00 thru 31 (4 bytes) of system control information CC (bits 18,19) – Condition Code Bits 32 thru 63 (4 bytes) of program information Next instruction address (bits 40 thru 63) CC Many instructions will cause the CC to be updated which we will cover later All branching instructions interrogate the Condition Code and take action depending on the value. © John Urrutia 2012, All Rights Reserved.135/27/2012

Compare Logical Characters The CLC instruction Like the MVC instruction has two operands The 1 st is compared byte by byte, left to right, against the 2 nd operand You can compare up to 256 bytes per instruction As soon as one of the bytes are unequal or the length of the 1 st operand is reached the condition code is set and the instruction terminates. Just like MVC the length of the compare is governed by the length of Operand 1 © John Urrutia 2012, All Rights Reserved.145/27/2012

Compare Logical Characters The CLC instruction When dealing with printable characters the collating sequence determines which character is larger. ASCII – from low to high (abbreviated) Special characters, numerals, upper then lower case letters EBCDIC – from low to high (abbreviated) Special characters, lower then upper case letters, numerals © John Urrutia 2012, All Rights Reserved.155/27/2012

Compare Logical Characters CLC instruction termination When one of the bytes are unequal If value of Operand 1 is less than Operand 2  Set condition code to 1 st Op Low ( 1 ) If value of Operand 2 is less than Operand 1  Set condition code to 1 st Op High ( 2 ) End of 1 st operand is reached  Set condition code Op equal ( 0 ) The Condition Code does not change until another instruction is executed that updates the condition code © John Urrutia 2012, All Rights Reserved.165/27/2012

Compare Logical Characters Syntax of Instruction Op Code – CLC Operand 1 – label or address Operand 2 – label or address © John Urrutia 2012, All Rights Reserved.175/27/2012

Compare Logical Characters Which field is greater? © John Urrutia 2012, All Rights Reserved.185/27/2012

Compare Logical Characters Just like MVC the CLC operand(s) displacement and length attributes can be modified. © John Urrutia 2012, All Rights Reserved.195/27/2012

Compare Logical Immediate Just like MVI the CLI instruction compares only one byte which is imbedded as part of the instruction. CLI FIELD1,C’$’ Operand2 can be Any of the data type designators Cannot be a reference © John Urrutia 2012, All Rights Reserved.205/27/2012

Branch on Condition Statement Syntax of Instruction Op Code – BC Operand 1 – Mask value used to interrogate condition Operand 2 – branch to label or address © John Urrutia 2012, All Rights Reserved.215/27/2012

Branch on Condition Statement Syntax of Instruction Operand 1 – Mask values 01 – condition code = 3Not set for Characters 02 - condition code = 2Op1 > Op condition code = 1Op1 < Op condition code = 0Op1 = Op2 © John Urrutia 2012, All Rights Reserved.225/27/2012

Branch on Condition Statement Syntax of Instruction Operand 1 – Mask values 01 – condition code = 3Not set for Characters 13 – not condition code = 2Op1 <= Op2 11 – not condition code = 1Op1 >= Op2 07 – not condition code = 0Op1 <> Op2 © John Urrutia 2012, All Rights Reserved.235/27/2012

Branch on Condition Statement Operand 1 – Mask values difficult to remember and have mnemonic equivalents 02 - CC = 2Op1 > Op2 BH Branch High 04 - CC = 1Op1 < Op2 BL Branch Low 08 – CC = 0Op1 = Op2 BE Branch Equal 13 – not CC = 2Op1 <= Op2 BNH Branch not High 11 – not CC = 1Op1 >= Op2 BNL Branch not Low 07 – not CC = 0Op1 <> Op2 BNE Branch not Equal © John Urrutia 2012, All Rights Reserved.245/27/2012

B and BC are equivalent when the Mask value is set to 15 BC becomes a null operator or NOP which will execute the next instruction in all cases when the Mask value is set to 0 In assembly we can modify the Mask value during execution of the program thereby changing a NOP instruction into a conditional branch. vs. Branch vs. Branch on Condition © John Urrutia 2012, All Rights Reserved.255/27/2012