1 / 76

UNIT

UNIT. Comparing and Branching. Topics:. Decision Making in Assembler Compare Instructions Branching Building Structured Constructs. Unit: Comparing and Branching. Unit Introduction.

tulia
Download Presentation

UNIT

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UNIT Comparing and Branching Topics: • Decision Making in Assembler • Compare Instructions • Branching • Building Structured Constructs

  2. Unit: Comparing and Branching Unit Introduction • In order to write programs that take full advantage of the computer's capabilities, you must be able to do more • than execute a series of instructions sequentially. Interesting programs, programs that model significant real • world processes, must also make decisions and repeat sequences of instruction multiple times. • In this unit, we will cover conditional execution and looping which are basic programming components. You • will also learn how to implement these structures in Assembler Language. Introduction

  3. Unit: Comparing and Branching Unit Objectives • At the end of this unit, you will be able to: • Make decisions in Assembler using the condition code • Describe numerical and logical comparisons • Describe and use branching instructions • Understand the framework of structured constructs Introduction

  4. UNIT Comparing and Branching Topics: • Decision Making in Assembler • Compare Instructions • Branching • Building Structured Constructs

  5. Topic: Decision Making in Assembler Unit: Comparing and Branching Topic Objectives • At the end of this topic, you will be able to: • Understand implementing Conditional execution Introduction

  6. Topic: Decision Making in Assembler Unit: Comparing and Branching Implementing Conditional Execution • How is conditional execution implemented? • High Level Languages implement conditional • execution with IF-THEN and IF-THEN-ELSE • structures. They implement looping with DO- • WHILE or other iterative constructs. Assembler • Language does not have these high level control • statements. Rather, conditional execution and • looping structures must be built from lower level • instructions. • In Assembler Language, conditional execution is • broken into parts. One instruction tests a • condition. A following instruction, a conditional • branch, alters the execution path, depending on • the result of the test. The condition code, a two-bit • field in the Program Status Word (PSW) is where • the result of the test is held, awaiting subsequent • conditional branch instruction. EC Mode PSW 2 bit Field CC Program Mask 18 20 CC Possible Values: 00 01 10 11 Binary 0 1 2 3 Decimal Continued… Concepts

  7. Topic: Decision Making in Assembler Unit: Comparing and Branching Implementing Conditional Execution (cont’d) • Some instructions set the condition code and • some do not. If and how an instruction sets the • condition code is an important part of the • instruction description. Once the condition code is • set by an instruction, that value remains in the • condition code until a subsequent instruction • changes it. Condition Code: - Some Examples AP SP MVCL CC – is set MP DP MVC Condition Code is unchanged. Continued… Concepts

  8. Topic: Decision Making in Assembler Unit: Comparing and Branching Implementing Conditional Execution (cont’d) • The condition code is a two-bit field, so that it may • take on 4 unique values; 0,1,2 or 3. The CC • always contains one of these four values. • You have seen that many arithmetic instructions • set the condition code to indicate if the result is • zero (CC=0), negative (CC=1), positive (CC=2) or • if overflow has occured (CC=3). You have seen • other instructions that set the condition code in • other ways. • Another major group of instructions that set the • condition code is the compare instructions. These • instructions compare two operands and set the • condition code to indicate their relative • magnitudes. The condition code set by compare • instructions are shown on the right. Compare Instructions set CC as follows: Relation of Operands CC Setting Op1 = Op2 0 Op1< Op2 1 Op1 > Op2 2 Continued… Concepts

  9. Topic: Decision Making in Assembler Unit: Comparing and Branching Compare Instructions • A condition code setting of 3 does not occur after • compare instructions. For brevity, these settings • will be referred to as CC setting - Comparison in • the instruction descriptions that follow. CC Setting – Comparison: Condition Code Setting: 0 - Equal 1 – First Operand is Low 2 – First Operand is High 3 – Not Used Continued… Concepts

  10. Topic: Decision Making in Assembler Unit: Comparing and Branching Are We on Track? • Match the condition code setting to the condition tested in a compare instruction. • 1. 1st operand < 2nd A. 0 • 2. 1st operand > 2nd B. 1 • 3. Operands are equal C. 2 • 4. Does not occur D. 3 Review

  11. Topic: Decision Making in Assembler Unit: Comparing and Branching Are We on Track? • How would a condition code set by one instruction be tested? • A. By the next sequential instruction • B. By any following instruction • C. Before it is reset by a subsequent instruction • D. By a previous instruction Review

  12. Topic: Decision Making in Assembler Unit: Comparing and Branching Glossary • Conditional Execution – A basic programming component which uses IF-THEN, and IF-THEN- ELSE structures. One instruction sets a condition while another, a conditional branch, alters the execution path, depending on the condition. • Looping – A program function, where a set of statements in a program execute repeatedly, either a fixed number of times based on some condition being true or false. • Iterative Construct – Statements designed to execute one or more statements or instructions repeatedly. Examples of iterative statements are DO-WHILE • Magnitude – The size of a number, regardless of its sign (+ or -). For example +16 and -16 have the same magnitude. Glossary

  13. Topic: Decision Making in Assembler Unit: Comparing and Branching Topic Summary • Now that you have completed this topic, you should be able to: • Understand implementing Conditional execution Summary

  14. UNIT Comparing and Branching Topics: • Decision Making in Assembler • Compare Instructions • Branching • Building Structured Constructs

  15. Topic: Compare Instructions Unit: Comparing and Branching Topic Objectives • At the end of this topic, you will be able to: • Understand Numeric and Logical comparisons • Describe the various kinds of Compare Instructions and their functions Introduction

  16. Topic: Compare Instructions Unit: Comparing and Branching Numeric Comparison • What is numeric comparison? • When two operands are compared, it is important • that you be clear about their format. If the • operands represent signed numeric quantities, • then a numeric comparison is needed. On the • other hand, if the operands do not represent • signed numeric data, a logical comparison is • performed, treating the operands simply as strings • of bits. Comparisons: 1st Operand 2nd Operand NUMERIC NUMERIC = Arithmetic TEXT TEXT = Logical Concepts

  17. Topic: Compare Instructions Unit: Comparing and Branching Kinds of Comparison • If you compared R3 containing X'FFFFFFF6' and • FDW1 containing X'0000000A', the condition code • that will be set will depend on the type of • comparison. • In an arithmetic comparison, the register contents • would be interpreted as -10. The storage operand • is interpreted as +10, so the first operand (the • register) would be lower, and the condition code is • set to 1. • In a logical comparison, FFFFFFF6 is a higher • hex value than 0000000A, so the first operand • would be higher and the condition code be set to • 2. Comparisons: 1st Operand 2nd Operand R3 FWD1 ARITHMETIC FFFFFFF6 0000000A < +10 -10 = CC set to 1 R3 FWD1 LOGICAL FFFFFFF6 0000000A Higher Hex > Lower Hex = CC set to 2 Concepts

  18. Topic: Compare Instructions Unit: Comparing and Branching Logical Comparison • What is Logical Comparison? • Comparison of textual data would be a Logical • Comparison, based on the relative position of the • characters in the EBCDIC code tables. If C'A' is • compared with C'5', the second operand • would be larger, since the EBCDIC code for 5 • (F5) is higher than the EBCDIC code for A (C1), • as shown on the table in the right. EBCDIC CODE A C1 5 F5 Concepts

  19. Topic: Compare Instructions Unit: Comparing and Branching Compare Instruction • What is the Compare (C) Instruction? • The Compare (C) instruction is used to • arithmetically compare the first operand, a • fullword in GPR and the second operand, a • fullword in main storage. Neither operand is • modified but the condition code is set to indicate • the result of the comparison. • For example: C R4,FWD1 • The contents of R4, as shown in the table on the • right, are compared arithmetically to the contents • of the fullword at location FWD1. The condition • code is set to indicate the result of the • comparison. Compare (C): RX Format – Register to Indexed Storage C R4,FWD1 1st Operand 2nd Operand R4 FWD1 FW FW COMPARE C CC Setting: If R4 = FWD1 -- 1 If R4 < FWD1 -- 1 If R4 > FWD1 -- 2 Concepts

  20. Topic: Compare Instructions Unit: Comparing and Branching Compare Halfword Instruction • What is the Compare Halfword (CH) • Instruction? • The Compare Halfword (CH) instruction is used to • expand the second operand, a halfword in main • storage, to a fullword by sign extension, and • compare it arithmetically to the first operand, a • fullword in a GPR. Neither operand is modified but • the condition code is set to indicate the result of • the comparison. • For example: CH R3, HWD1 • The halfword at HWD1, as shown in the table on • the right, is transparently expanded to a fullword • through sign extension, and compared • arithmetically to the value in R3. The condition • code is set to indicate the result of the • comparison. Compare Half word (CH): RX Format – Register to Indexed Storage CH R3,HWD1 1st Operand 2nd Operand R3 HWD1 FW HW COMPARE S FW S HW CH CC Setting: If R3 = HWD1 -- 0 If R3 < HWD1 -- 1 If R3 > HWD1 -- 2 SIGN EXTENSION Concepts

  21. Topic: Compare Instructions Unit: Comparing and Branching Compare Register Instruction • What is the Compare Register (CR) • Instruction? • The Compare Register (CR) instruction is used to • compare two operands, both fullwords in GPRs, • arithmetically. Neither operand is modified but the • condition code is set to indicate the result of the • comparison. • For example: CR R5,R6 • The contents of R5 are compared arithmetically to • the contents of R6, as shown in the table on the • right. The condition code is set to indicate the • result of the comparison. Compare Register (CR): RR Format – Register to Register CR R5,R6 1st Operand 2nd Operand R5 R6 FW FW COMPARE CR CC Setting: If R5 = R6 -- 0 If R5 > R6 -- 1 If R5 > R6 -- 2 Concepts

  22. Topic: Compare Instructions Unit: Comparing and Branching Fixed-Point Compare Instruction • Fixed-point compare instructions are used • whenever the larger of the two fixed-point • quantities is to be determined, or if they are equal. • One common application is rounding after • division. • Fixed-point division yields a fixed-point quotient • and a fixed-point remainder. In many applications, • you will want to round the quotient up to the next • higher integer if the remainder is equal to or • greater than half the divisor. This is called half • rounding. Half-Rounding: 1st Operand 2nd Operand DIVIDEND DIVISOR EVEN/ODD Register Pair QUO REM COMPARE REM * 2 APPLY HALF ROUNDING If Remainder is = or > than Divisor (ROUND UP) If Remainder is < than Divisor (DO NOT ROUND) Concepts

  23. Topic: Compare Instructions Unit: Comparing and Branching Compare Decimal Instruction • What is the Compare Decimal (CP) instruction? • Packed decimal operands too have an arithmetic • comparison operation. • The Compare decimal (CP) instruction is used to • compare two operands, both packed numbers in • main storage arithmetically. If the fields are of • different lengths, the shorter length is expanded • by inserting leading zeroes. Neither operand is • modified, but the condition code is set to indicate • the result of the comparison. • For example: CP PK1,PK2 • As shown in the example on the right, the • contents of PK1 and PK2 are compared • arithmetically. The condition code is set to • indicate the result of the comparison. Compare Decimal (CP): SS Format – (2 length) Storage to Storage CP PK1,PK2 2nd Operand 1st Operand PK2 PK1 CONTENTS CONT. COMPARE 00 00 CONT CP LEADING ZEROS If needed CC Setting: If PK1 = PK2 -- 0 If PK1 < PK2 -- 1 If PK1 > PK2 -- 2 Concepts

  24. Topic: Compare Instructions Unit: Comparing and Branching Rounding Up – Example 1 move sum work area divide to get quotient and remainder double the remainder is it less then divisor? Yes – don’t round no – round up • You may want to implement half rounding with decimal arithmetic. Suppose a series of numbers have been • summed into SUM, and the numbers have been counted into a field called COUNT. The average of the • numbers, half rounded would be calculated as shown above. ZAP QUOREM, SUM DP QUOREM, COUNT AP REM, REM CP REM, COUNT BL NOROUND AP QUO, = P ‘1’ EQU * . DSPL6 DS PL3 DS PL9 DS PL6 DS PL3 NOROUND SUM COUNT DS QUOREM QUO REM Concepts

  25. Topic: Compare Instructions Unit: Comparing and Branching Rounding Up – Example 2 move mark to calculate field multiply by 1.1 to add 10% (10 times too large) divide by 10 and round is adjusted mark > 100? no (branch if first operand not high) yes – reduce to 100 move increased mark back to mark • In this example, a teacher wants to raise student marks on a test by 10%, but also wants to assure that no • mark exceeds 100. If the original mark was in a field called MARK, the above code would perform the • calculation for a single student. ZAP CALC, MARK MP CALC, = P ’11’ SRP CALC, 64 –1,5 CP CALC, = P’100’ BNH NOADJUST ZAP CALC, = P’100’ EQU * ZAP MARK, CALC . . DS PL2 DS PL2 NOADJUST MARK CALC MARK CALC Concepts

  26. Topic: Compare Instructions Unit: Comparing and Branching Are We on Track? • What would be the condition code setting be after the following instructions were executed? • LM R3,R4,=F'-3,7' • CR R4,R3 • __________ Review

  27. Topic: Compare Instructions Unit: Comparing and Branching Are We on Track? • Match the compare operations to their operand types. • 1. CR A. A halfword in storage and a fullword in a GPR • 2. CP B. Two fixed point numbers in GPRs • 3. C C. A fullword in storage and a fullword in a GPR • 4. CH D. Two packed numbers in storage Review

  28. Topic: Compare Instructions Unit: Comparing and Branching Compare Logical Register • What is the Compare Logical Register? • There are several logical comparison instructions • to handle the various types of operands. In each • case, the instruction compares its two operands, • treating them as logical quantities that are simply • strings of bits. • The Compare Logical Register (CLR) instruction • is used to compare its operands logically, both 32 • bit logical quantities in GPRs. Neither operand is • modified but the condition code is set to indicate • the result of the comparison. • For example: CLR R4,R5 • The contents of R4 and the contents of R5 are • compared logically. The condition code is set to • indicate the result of the comparison. Compare Logical Register (CLR): RR Format – Register to Register CLR R4,R5 1st Operand 2nd Operand R4 R5 CONTENTS CONTENTS Register Register COMPARE CLR CC Setting: If R4 = R5 -- 0 If R4 < R5 -- 1 If R4 > R5 -- 2 CC Setting - Comparison Concepts

  29. Topic: Compare Instructions Unit: Comparing and Branching Compare Logical Instruction • What is the Compare Logical Instruction? • The Compare Logical (CL) instruction is used to • compare logically the first operand, a 32 bit logical • quantity in a register, with the second operand, a • 32 bit logical quantity in main storage. Neither • operand is modified but the condition code is set • to indicate the result of the comparison. • For example: CL R3,FWD2 • The contents of R3 and the contents of FWD2 are • compared logically. The condition code is set to • indicate the result of the comparison. Compare Logical (CL): RX Format – Register to Indexed Storage CL R3,FWD2 1st Operand 2nd Operand R3 FWD2 CONTENTS CONTENTS Main Storage Register COMPARE CL CC Setting: If R3 = FWD2 -- 0 If R3 < FWD2 -- 1 If R3 > FWD2 -- 2 CC Setting - Comparison Concepts

  30. Topic: Compare Instructions Unit: Comparing and Branching Compare Logical Immediate Instruction • What is the Compare Logical Immediate • Instruction? • The CLI instruction is used to compare the first • operand logically with the second operand. The • first operand is a byte in main storage. The • second operand is a byte of immediate data in the • instructions. Neither operand is modified during • comparison but the condition code is set to • indicate the result of the comparison. • For example: CLI STATEMENT,C'*' • The byte of main storage at STATEMENT is • compared to an asterisk. The condition code is • set to indicate the result of the comparison. Compare Logical Immediate (CLI): SI Format – Storage to Immediate Data CLI STATEMEMT,C’*’ 1st Operand 2nd Operand STATEMENT * BYTE BYTE Immediate Data Main Storage COMPARE CLI CC Setting: If STATEMENT = C’*’ -- 0 If STATEMENT < C’*’ -- 1 If STATEMENT > C’*’ -- 2 Continued… Concepts

  31. Topic: Compare Instructions Unit: Comparing and Branching Compare Logical Immediate Instruction (cont’d) • The CLI instruction is very commonly used to check the contents of single byte areas in storage. Remember • that Assembler Language statements that are completely comments have an asterisk in the first position. * read a statement into STATEMENT CLI STATEMENT, C’ * ’ is it a comment? BE IGNORE yes - ignore ( branch if equal) B PROCESS no – process (branch unconditionally) Concepts

  32. Topic: Compare Instructions Unit: Comparing and Branching Compare Logical Characters • What is the Compare Logical Character? • The Compare Logical Characters (CLC) • instruction is used to compare logically the two • operands, equal length character strings in • storage. Neither operand is changed, but the • condition code is set to indicate the result of the • comparison. • For example: CLC FLD1,FLD2 • The contents of FLD1 and FLD2 are compared • logically. The condition code is set to indicate the • result of the comparison. Compare Logical Characters (CLC) SS Format (1 length) – Storage to Storage CLC FLD1,FLD2 1st Operand 2nd Operand FLD1 FLD2 CONTENTS CONTENTS Main Storage Main Storage COMPARE CLC CC Setting: If FLD1 = FLD2 -- 0 If FLD1 < FLD2 -- 1 If FLD1 > FLD2 -- 2 Continued… Concepts

  33. Topic: Compare Instructions Unit: Comparing and Branching Compare Logical Characters (cont’d) • The CLC instruction is used to compare fields in • storage. Suppose you want to determine • whether a 20-byte field SURNAME, contained the • value SMITH. You could use the code as shown • in the example on the right. CLC SURNAME,=CL20’SMITH’ Does it contain SMITH? BE PROCSMITH yes (branch if equal) SURNAME SMITH CONTENTS SMITH Main Storage Main Storage COMPARE CLC PROCEED IF EQUAL Concepts

  34. Topic: Compare Instructions Unit: Comparing and Branching Compare Logical Characters Under Mask Instruction • What is the CLM instruction? • The Compare Logical Characters Under Mask • (CLM) instruction is used to compare logically the • bytes of the GPR specified by 1 bit in the mask, • with an equal number of consecutive bytes in • main storage beginning at the third operand • location. The operands are unchanged, but • the condition code is set to indicate the results of • the comparison. • For example: CLM R3,5,FWD3 • Bytes 1 and 3 of R3 are compared logically with • the two bytes in storage beginning at FWD3. The • condition code is set to indicate the results of the • comparison. Compare Logical Characters Under Mask (CLM): RS Format – Register to Storage 3rd Operand CLM R3,5,FWD3 1st Operand 2nd Operand Register R3 2 3 BYTES 0 1 COMPARE FWD3 BYTE BYTE Main Storage CC Setting: If R3 bytes = FWD3 -- 0 If R3 bytes < FWD3 -- 1 If R3 bytes > FWD3 -- 2 Concepts

  35. Topic: Compare Instructions Unit: Comparing and Branching Compare Logical Characters Long Instruction Compare Logical Long (CLCL): RR Format – Register to Register • This instruction is analogous to the Move Long instruction (MVCL). Like Move Long, both operands must • specify even numbered GPRs using the Compare Logical Long (CLCL) instruction, which, in each case • represent even-odd register pairs. The even numbered registers contain the addresses of the two operands. • The odd numbered registers contain the length of the operands, in their low order 24 bits. The high order byte • of R2+1 contains the padding byte. CLCL R2,R4 1st Operand 2nd Operand EVEN – ODD REGISER PAIR EVEN – ODD REGISER PAIR R2 (EVEN) R2 + 1 (ODD) R1 (EVEN) R2 + 1 (ODD) Address of OP2 Length of OP2 Address of OP1 Length of OP1 COMPARE COMPARE If Lengths are not = the shorter one is extended with PAD Characters CC Setting - Comparison Continued… Concepts

  36. Topic: Compare Instructions Unit: Comparing and Branching Compare Logical Characters Long Instruction (cont’d) • The comparison proceeds left to right and stops • when an inequality is found, or when the end of • the longer operand is reached. If the operation • terminates because of an inequality, the even • numbered registers point to the first unequal • byte. The odd register contains the original • lengths, less the number of equal bytes. CLCL Comparison: OP1 @1000 A B C D E F G H I J 16,777,215 Bytes @2000 A B C D X Y Z W K L OP2 = = = = < Stops at First Inequality Concepts

  37. Topic: Compare Instructions Unit: Comparing and Branching Compare Logical Long – An Example set up regs for clcl compare fields total field length less length minus equal bytes save count of equal bytes • To find out how many 100 byte fields called DATA1 and DATA2 are initially equal, you could use the code • shown above. LM R2,R5,INITCOMP CLCLR2, R4 LH R6, =H ‘100’ SR R6,R5 STH R6,EQBYTES . . . DC A(DATA1) DC F’100’ DC A(DATA2) DC F ‘100’ DS H INITCOMP EQBYTES Concepts

  38. Topic: Compare Instructions Unit: Comparing and Branching Are We on Track? • Assume R3 contains X'FFFFFF40' and FLD1 contains X'00004000'. Match the instructions with the condition codes that they would set. • 1. C R3,FLD1 A. 0 • 2. CL R3,FLD1 B. 2 • 3. CLM R3, 1, FLD1+2 C. 1 Review

  39. Topic: Compare Instructions Unit: Comparing and Branching Are We on Track? • Complete the following program to compare two 3000 byte fields. • L R4,=A(FLD1) • L R5,=F'3000' • L R6,=A(FLD2) • L R7,=F'3000' • _________________ Review

  40. Topic: Compare Instructions Unit: Comparing and Branching Glossary • Logical Comparison – Based on true or false alternatives as opposed to arithmetic calculations of numeric values. For example, a logical expression is one that, when evaluated, has a single outcome, either true or false. • Half Rounding – Rounds the quotient up to the next higher integer if the remainder is equal to or greater than half the divisor. • Analogous – A signal having the property of continuously varying its strength or quantity. Glossary

  41. Topic: Compare Instructions Unit: Comparing and Branching Topic Summary • Now that you have completed this topic, you should be able to: • Understand Numeric and Logical comparisons • Describe the various kinds of Compare Instructions and their functions Summary

  42. UNIT Comparing and Branching Topics: • Decision Making in Assembler • Compare Instructions • Branching • Building Structured Constructs

  43. Topic: Branching Unit: Comparing and Branching Topic Objectives • At the end of this topic, you will be able to: • Describe Branch on Condition instruction • Describe Extended Mnemonic Branch instructions Introduction

  44. Topic: Branching Unit: Comparing and Branching Branch on Condition Instruction • What is the Branch on Condition Instruction? • The way you implement conditional execution in • Assembler Language is with the Branch on • Condition (BC) Instruction. This instruction tests • the current setting of the condition code, using a • mask field in the instruction. • If the mask field corresponds to the setting of the • condition code, then the next instruction to be • executed is the one at the address specified as • the second operand of Branch on Condition. If • there is no correspondence, then execution • proceeds sequentially with the instruction • following Branch on Condition. Branch on Condition BC MASK Corresponds To Condition Code YES 2nd Operand of BC NO Next Sequential Instruction Concepts

  45. Topic: Branching Unit: Comparing and Branching The Mask Field • The mask field is 4 bits in length, allowing 16 • possible values. The condition code is 2 bits long, • allowing 4 possible values. The 4 bits of the mask • correspond to the 4 possible condition values. • If the mask value is 8, the Branch on Condition • instruction tests for a CC setting of zero. If the CC • = 0, the branch is taken, otherwise normal • sequential execution occurs. Mask Field: Condition Code Setting 0 1 2 3 Corresponding Mask Bit 0 1 2 3 Mask Value 8 4 2 1 BIT Value 8 4 2 1 X X X X 0 1 2 3 MASK BIT (4 BITS) BIT Position Continued… Concepts

  46. Topic: Branching Unit: Comparing and Branching The Mask Field (cont’d) • Mask values can be any value in the range of 0 to • 15. A mask value of 7 (4+2+1) tests if the CC is • 1 or 2 or 3. If so, the branch is taken. Otherwise it • is not. • Any combination of condition codes can be tested • in a single Branch on Condition instruction. A • mask value of 15 tests if the CC is 0 or 1 or 2 or 3. • Since the CC must be one of these values, this • constitutes an unconditional branch. Mask Values: MASK = 710 DECIMAL = 01112 BINARY CC = 1 CC = 2 CC = 3 Concepts

  47. Topic: Branching Unit: Comparing and Branching BC – An Example • When using the Branch on Condition (BC) • instruction the first operand of BC specifies a • mask, not a GPR. If the bit in the mask • corresponding to the current value of the condition • code is on, then the address specified as the • second operand replaces the next instruction • address in the PSW. If not, the normal sequential • instruction sequencing occurs. • For example: BC 8,EQRTN • If the condition code is zero, branch to EQRTN. • Otherwise, continue with the next instruction after • the BC. Branch on Condition (BC): RX Format – Register to Indexed Storage BC 8, EQRTN 1st Operand 2nd Operand 8 EQRTN MASK ADDRESS TO BRANCH BC If CC = 0 Branch to EQRTN If CC is (1 or 2 or 3) Continue to Next Instruction CC Setting – Condition Code is Unchanged Continued… Concepts

  48. Topic: Branching Unit: Comparing and Branching BC – An Example (cont’d) • EQRTN would be a label identifying the location in • your program that you wanted to branch to. Often • Assembler Language programmers put branch • labels on an instruction that does nothing. • EQRTN EQU * • This instruction equates the label EQRTN to the • current value of the location counter. This is the • value of EQRTN regardless, so the instruction • really does nothing. The reason you set up labels • this way is to ensure ease in maintenance. • Suppose you put the label on a machine • instruction as follows: • EQRTN LR R2,R3 EQRTN LR R7,R2 LR R2,R3 Add New Instruction 2 Instructions Change Continued… Concepts

  49. Topic: Branching Unit: Comparing and Branching BC – An Example (cont’d) • Later on, if you want to add an instruction at the • beginning of EQRTN but before the LR, you • would need to add a new instruction with the label • EQRTN, and then delete the label from the LR • instruction. If the label is on a do nothing • instruction, your original code looks like this: • EQRTN EQU * • LR R2,R3 • To add a new instruction, you simply insert it in • between the EQU and the LR instruction, as • shown on the right. EQRTN EQU * LR R7,R2 LR R2,R3 New Instruction Just addition – No change to existing Concepts

More Related