Upload
clementine-henderson
View
212
Download
0
Embed Size (px)
Citation preview
Physics 413Chapter 4
A Fork in the Road
LDAB # $ 13here : ADDA # $ 24
DEC BBNE here WAI
BNE is the new instruction. Branch if not equal to zero.
Branch Address Calculation
LDAB # $ 13 C6 13here : ADDA # $ 24 8B 24
DEC B 5ABNE here 26 ?? WAI 3E
Backward and Forward
FF Go back 1 stepFE Go back 2 stepsFB Go back 5 steps80 Go back 128 steps01 Go forward 1 step05 Go forward 5 steps7F Go forward 127 steps
Branch Address Calculation
LDAB # $ 13 C6 13here : ADDA # $ 24 8B 24
DEC B 5ABNE here 26 FB WAI 3E
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.
Branches Galore
Mnemonic Description of Criteria
BCC Branch if Carry Clear
BCS Branch if Carry Set
BEQ Branch if Equal to Zero
BNE Branch if Not Equal to Zero
BRA Branch AlwaysNote: Familiarize yourself with other related instructions like JMP, BSR, and JSR
Dare to Compare !
here: LDAA # $ E3CMPA $ 50BNE hereWAI
Temperature sensor reading is stored at memory location 0050 and compared with a danger limit of E3 .
Delay Loop Subroutine
here: JSR DELAYLDAA # $ E3CMPA $ 50BNE hereWAI
.
.
.DELAY: LDX # $ FFFFAGAIN : DEXBNE AGAINRTS
Indexed Addressing Mode
LDX # $ 0050CLRA
up : ADDA $ 00, XINXCPX # $ 0070BNE upWAI
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.
Push and Pull
PSHA A MSP SP - 1 SP
PULA SP + 1 SP MSP A
Predict the Outcome!
PSHAPSHBPULAPULB
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
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