Download presentation
Presentation is loading. Please wait.
Published byClara Hill Modified over 9 years ago
1
CIS 020 Assembly Programming Chapter 06 - Comparisons & Logical control Procedures © John Urrutia 2012, All Rights Reserved.5/27/20121
2
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
3
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
4
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
5
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
6
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
7
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
8
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
9
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
10
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
11
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
12
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
13
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
14
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
15
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
16
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
17
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
18
Compare Logical Characters Which field is greater? © John Urrutia 2012, All Rights Reserved.185/27/2012
19
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
20
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
21
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
22
Branch on Condition Statement Syntax of Instruction Operand 1 – Mask values 01 – condition code = 3Not set for Characters 02 - condition code = 2Op1 > Op2 04 - condition code = 1Op1 < Op2 08 - condition code = 0Op1 = Op2 © John Urrutia 2012, All Rights Reserved.225/27/2012
23
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
24
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
25
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.