Presentation is loading. Please wait.

Presentation is loading. Please wait.

Physics 413 Chapter 4 A Fork in the Road LDAB # $ 13 here :ADDA # $ 24 DEC B BNE here WAI BNE is the new instruction. Branch if not equal to zero.

Similar presentations


Presentation on theme: "Physics 413 Chapter 4 A Fork in the Road LDAB # $ 13 here :ADDA # $ 24 DEC B BNE here WAI BNE is the new instruction. Branch if not equal to zero."— Presentation transcript:

1

2 Physics 413 Chapter 4

3 A Fork in the Road LDAB # $ 13 here :ADDA # $ 24 DEC B BNE here WAI BNE is the new instruction. Branch if not equal to zero.

4 Branch Address Calculation LDAB # $ 13C6 13 here :ADDA # $ 248B 24 DEC B5A BNE here26 ?? WAI3E

5 Backward and Forward FFGo back 1 step FEGo back 2 steps FBGo back 5 steps 80Go back 128 steps 01Go forward 1 step 05Go forward 5 steps 7FGo forward 127 steps

6 Branch Address Calculation LDAB # $ 13C6 13 here :ADDA # $ 248B 24 DEC B5A BNE here26 FB WAI3E Note: PC (Program Counter) is pointing at the next instruction so count backward from 3E. Incidentally, CPU uses the Z - bit (zero flag) in CCR to ascertain whether accumulator B is indeed zero.

7 Branches Galore MnemonicDescription of Criteria BCCBranch if Carry Clear BCSBranch if Carry Set BEQBranch if Equal to Zero BNEBranch if Not Equal to Zero BRABranch Always Note: Familiarize yourself with other related instructions like JMP, BSR, and JSR

8 Dare to Compare ! here:LDAA # $ E3 CMPA $ 50 BNE here WAI Temperature sensor reading is stored at memory location 0050 and compared with a danger limit of E3.

9 Delay Loop Subroutine here:JSR DELAY LDAA # $ E3 CMPA $ 50 BNE here WAI. DELAY: LDX # $ FFFF AGAIN : DEX BNE AGAIN RTS

10 Indexed Addressing Mode LDX # $ 0050 CLRA up :ADDA $ 00, X INX CPX # $ 0070 BNE up WAI Program adds numbers stored in memory locations 0050 through 006F. Index register is a “pointer” which is incremented. The offset, 00, can be changed if necessary.

11 Push and Pull PSHAA M SP SP - 1 SP PULASP + 1 SPM SP A

12 Predict the Outcome! PSHA PSHB PULA PULB

13 Solution Congratulations, if you said the contents of A and B will be swapped and, perhaps more importantly, the value of the stack pointer will be restored to its original value before this program segment was run. 00D6 00D5 00D4 00D3

14 Detailed Explanation Suppose that SP was pointing at 00D6 (stack). PUSHA stores A into 00D6. Then PUSHB stores B into 00D5. At this point SP = 00D4. Then PULA pulls 00D5 (which contains B) and stores it into A. Finally, PULB pulls 00D6 (which contains A) and stores it into B. We end up swapping A and B. At this point SP = 00D6, its original value. 00D6 00D5 00D4 00D3


Download ppt "Physics 413 Chapter 4 A Fork in the Road LDAB # $ 13 here :ADDA # $ 24 DEC B BNE here WAI BNE is the new instruction. Branch if not equal to zero."

Similar presentations


Ads by Google