Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS 020 Assembly Programming Chapter 13 - Branching and Looping With Registers © John Urrutia 2012, All Rights Reserved.5/27/20121.

Similar presentations


Presentation on theme: "CIS 020 Assembly Programming Chapter 13 - Branching and Looping With Registers © John Urrutia 2012, All Rights Reserved.5/27/20121."— Presentation transcript:

1 CIS 020 Assembly Programming Chapter 13 - Branching and Looping With Registers © John Urrutia 2012, All Rights Reserved.5/27/20121

2 Objectives Syntax & Use of RR & RX Branch instructions Looping structures Infinite loops & ABENDs Syntax & Use of LOAD and LOAD ADDRESS instructions © John Urrutia 2012, All Rights Reserved.25/27/2012

3 Branch in all of its’ forms The Branch instruction allows us to alter the execution of instructions. The Branch can refer to a label, a register or an indexed register, all of which resolve to an address within your program domain (hopefully). We have already seen the use of B and BR which are extended mnemonics of the BC and BCR instructions B ranch – Unconditional ( BC 15,ADDRESS) B ranch R egister – Unconditional ( BCR 15,R1) B ranch C ondition – Conditional Based on Condition Code © John Urrutia 2012, All Rights Reserved.35/27/2012

4 Branch in all of its’ forms There are a total of 8 Branch instructions: © John Urrutia 2012, All Rights Reserved.45/27/2012 MnemonicFormatOperands BCRXM1,D2(X2,B2) BCRRRM1,R2 BCTRXR1,D2(X2,B2) BCTRRRR1,R2 BALRXR1,D2(X2,B2) BALRRRR1,R2 BXHRSR1,R3,D2(B2) BXLERSR1,R3,D2(B2)

5 Branch in all of its’ forms BC & BCR use a mask to interrogate the condition code Extended mnemonics are easier to use instead of mask values © John Urrutia 2012, All Rights Reserved.55/27/2012 MnemonicFormatOperands BCRXM1,D2(X2,B2) BCRRRM1,R2 Mnemonic BHBLBEBNHBNLBNE BHRBLRBERBNHRBNLRBNER

6 Branch in all of its’ forms BCT - Branch On Count Used for looping structures based on the a number of times to loop. R1 – Register to decrement and test Operand 2 is set to the label or address of the next instruction to execute. © John Urrutia 2012, All Rights Reserved.65/27/2012 MnemonicFormatOperands BCTRXR1,D2(X2,B2)

7 Branch in all of its’ forms BCT - Branch On Count Upon Execution R1 is decremented by 1. If the value of R1 is zero the instruction that follows is executed If the value of R1 is not zero the instruction specified by Operand 2 is execute © John Urrutia 2012, All Rights Reserved.75/27/2012 MnemonicFormatOperands BCTRXR1,D2(X2,B2)

8 Branch in all of its’ forms BCTR - Branch On Count Register Used for looping structures based on the a number of time to loop. R1 – Register to decrement and test R2 – is set to the address of the next instruction to execute. © John Urrutia 2012, All Rights Reserved.85/27/2012 MnemonicFormatOperands BCTRRRR1,R2

9 Branch in all of its’ forms For BCT & BCTR R1 – Register to decrement is treated as an unsigned 32 bit number. If the value is set to 1 No Branching Occurs If the value is set to 0 Branching Occurs until zero is reached! Operand 2 or R2 – is set to the address of the next instruction to execute if R1 is not zero. For BCTR only – if the value of R2 is zero no branching occurs © John Urrutia 2012, All Rights Reserved.95/27/2012

10 Load and Test Register The purpose of the LTR instruction is to validate the contents of a register. R1 – is set to the value of R1 Based on R1 value the condition code is set R2 remains unchanged Both Operands R1 and R2 can be the same register. Use the extended mnemonics to branch © John Urrutia 2012, All Rights Reserved.105/27/2012 Mnemonic BPBMBZ BPRBMRBZR

11 Load and Test Register The Load and Test Register instruction Copies the sending Register, Operand 2 to the receiving Register, Operand 1. © John Urrutia 2012, All Rights Reserved.115/27/2012

12 Load VS Load Address These two instructions can be quite confusing and can cost you hour and hours of debugging time! Load - stores the data identified by Operand 2 into the Register of Operand 1 Load Address – stores the Address of Operand 2 into the Register of Operand 1 Similar concept of passing by value or by reference respectively. Load Address – also allows us to use relative addressing within our domain © John Urrutia 2012, All Rights Reserved.125/27/2012

13 Load VS Load Address Lets look at the difference. © John Urrutia 2012, All Rights Reserved.135/27/2012

14 Load VS Load Address Delimited Variable length fields – Exercise Lets assume we have a record format that contains the following. FRSTNAME – 1 to 16 characters LASTNAME – 2 to 30 characters MIDLNAME – 1 to 16 characters Each of these fields is delimited with a comma. We want to store each of these in fixed length fields left justified and pad them on the right with blanks. How can we find the end of each delimited field? © John Urrutia 2012, All Rights Reserved.145/27/2012

15 Load VS Load Address Our fixed length fields are FRSTOUT – 16 characters LASTOUT – 30 characters MIDLOUT – 16 characters Use a loop to process each byte in the variable field looking for a comma. © John Urrutia 2012, All Rights Reserved.155/27/2012


Download ppt "CIS 020 Assembly Programming Chapter 13 - Branching and Looping With Registers © John Urrutia 2012, All Rights Reserved.5/27/20121."

Similar presentations


Ads by Google