+ All Categories
Home > Documents > CIS 020 Assembly Programming Chapter 06 - Comparisons & Logical control Procedures © John Urrutia...

CIS 020 Assembly Programming Chapter 06 - Comparisons & Logical control Procedures © John Urrutia...

Date post: 18-Jan-2016
Category:
Upload: clara-hill
View: 216 times
Download: 2 times
Share this document with a friend
Popular Tags:
25
CIS 020 Assembly Programming Chapter 06 - Comparisons & Logical control Procedures © John Urrutia 2012, All Rights Reserved. 5/27/2012 1
Transcript
Page 1: CIS 020 Assembly Programming Chapter 06 - Comparisons & Logical control Procedures © John Urrutia 2012, All Rights Reserved.5/27/20121.

© John Urrutia 2012, All Rights Reserved. 1

CIS 020 Assembly Programming

Chapter 06 - Comparisons & Logical control Procedures

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 2

Logical Control ProceduresProgram 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

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 3

Logical Control ProceduresUnconditional Branches

Always alters the program execution path and are used to create repetition or iterative loops.

Only one operand – must be a label.

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 4

Logical Control ProceduresConditional 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

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 5

Logical Control ProceduresSelection 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

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 6

Logical Control Procedures

5/27/2012

True

One-Way Selection Flowchart

Instructions to execute

Yes -branch

No

Two-Way Selection Flowchart

True

Instructions to execute

Instructions to

execute

No

Yes -branch

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

© John Urrutia 2012, All Rights Reserved. 7

Logical Control ProceduresLooping structures pseudocode

Pre-Test LoopDo until true continue in sequenceend Do

Post-Test LoopDo continue in sequenceUntil true

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 8

Logical Control Procedures

5/27/2012

True

Pre-test iteration Flowchart

Instructions to execute

Yes -branch

No

Post-test iteration Flowchart

True

Instructions to

executeb

ran

ch

No

bra

nch

Yes

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

© John Urrutia 2012, All Rights Reserved. 9

Logical Control Procedures

The condition or test is the logical result of a comparison between two values.

2 instructions work with each otherThe comparison instruction sets the condition

codeThe branch instruction determines the next

instruction to execute based on the condition code

5/27/2012

True

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

© John Urrutia 2012, All Rights Reserved. 10

Comparison Statements

Used to determine the relationship between two data fields.

Only three possible resultsField 1 is greater than Field 2Field 2 is greater than Field 1Field 1 is equal to Field 2

5/27/2012

True

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

© John Urrutia 2012, All Rights Reserved. 11

Comparison StatementsThe 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 .

The Condition Code is stored in the PSW.

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 12

Program Execution & the PSWYou previously learned about the parts of the

CPUThe ALUThe CUThe Instruction Pointer – which always

contains the address of the next instruction to execute.

All information about the execution of your

program is stored in the Program Status

Word or PSW5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 13

Program Execution & the PSWThe 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)

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.

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 14

Compare Logical CharactersThe CLC instruction

Like the MVC instruction has two operandsThe 1st is compared byte by byte, left to right,

against the 2nd operandYou can compare up to 256 bytes per

instructionAs soon as one of the bytes are unequal or the

length of the 1st 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 15/27/2012

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

© John Urrutia 2012, All Rights Reserved. 15

Compare Logical CharactersThe 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

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 16

Compare Logical CharactersCLC instruction termination

When one of the bytes are unequal If value of Operand 1 is less than Operand 2

Set condition code to 1st Op Low (1) If value of Operand 2 is less than Operand 1

Set condition code to 1st Op High (2)End of 1st 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

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 17

Compare Logical CharactersSyntax of Instruction

Op Code – CLCOperand 1 – label or addressOperand 2 – label or address

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 18

Compare Logical CharactersWhich field is greater?

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 19

Compare Logical CharactersJust like MVC the CLC operand(s) displacement

and length attributes can be modified.

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 20

Compare Logical ImmediateJust 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 designatorsCannot be a reference

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 21

Branch on Condition StatementSyntax of Instruction

Op Code – BCOperand 1 – Mask value used to interrogate

conditionOperand 2 – branch to label or address

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 22

Branch on Condition StatementSyntax of Instruction

Operand 1 – Mask values01 – condition code = 3 Not set for Characters

02 - condition code = 2 Op1 > Op2

04 - condition code = 1 Op1 < Op2

08 - condition code = 0 Op1 = Op2

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 23

Branch on Condition StatementSyntax of Instruction

Operand 1 – Mask values01 – condition code = 3 Not set for Characters

13 – not condition code = 2 Op1 <= Op2

11 – not condition code = 1 Op1 >= Op2

07 – not condition code = 0 Op1 <> Op2

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 24

Branch on Condition StatementOperand 1 – Mask values difficult to remember and

have mnemonic equivalents

02 - CC = 2 Op1 > Op2BH Branch High

04 - CC = 1 Op1 < Op2BL Branch Low

08 – CC = 0 Op1 = Op2BE Branch Equal

13 – not CC = 2 Op1 <= Op2 BNH Branch not High

11 – not CC = 1 Op1 >= Op2 BNL Branch not Low

07 – not CC = 0 Op1 <> Op2 BNE Branch not Equal

5/27/2012

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

© John Urrutia 2012, All Rights Reserved. 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 theMask 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.

Branch vs. Branch on Condition

5/27/2012


Recommended