Branching and Loops
Jumping Jump instruction causes a change in the program flow to any location within the addressable range of the processor. ORG $0200 0200 86 AC LDAA #$AC 0202 7E 02 0B JMP STORE 0205 4F CLRA 0206 5F CLRB 0207 7F 02 00 CLR $0200 020A 47 ASRA 020B B7 02 50 STORE STAA $0250 020E 7E 02 0E END JMP END
Jump ORG $0200 0200 86 AC LDAA #$AC 0202 7E 02 0B JMP $020b 0205 4F CLRA 0206 5F CLRB 0207 7F 02 00 CLR $0200 020A 47 ASRA 020B B7 02 50 STAA $0250 020E 7E 02 0E JMP $020e
Branching and Relative Address Mode Branch instructions differ from the jump instructions in that they do not supply the absolute address of the next instruction.
Branching and Relative Address Mode BCC BCS BEQ BMI BNE BPL BVC BVS BHS BLO
Branching and Relative Address Mode ORG $0200 0200 96 AC LDAA $AC 0202 2A 05 BPL POS 0204 B7 02 51 STAA $0251 0207 20 03 BRA END 0209 B7 02 50 POS STAA $0250 020C 20 FE END BRA END
Destination address calculation Problem: Calculate the destination address (DA) for each of the following branch instructions. ADDRESS MACHINE CODE SOURCE CODE 0200 20 6C BRA PAST O1F7 20D3 BRA LOOP 063A 20 9B BRA AGAIN
RELATIVE ADRESS (rr) CALCULATION Calculate the relative address (rr) for each of the following branch instuctions a. ORG $0200 0200 96 AC LDAA $AC 0202 2A ?? BPL POS 0204 B7 02 51 STAA $0251 0207 20 ?? BRA END 0209 B7 02 50 POS STAA $0250 020C 20 ?? END BRA END
RELATIVE ADRESS (rr) CALCULATION ORG $0300 0300 96 AC LDAA $AC 0302 9B AD ADDA $AD 0304 29 ?? BVS ERROR 0306 25 ?? BCS CARRY 0308 B7 02 01 STAA $0201 030B 20 ?? BRA END 030D 86 01 CARRY LDAA #$01 030F B7 02 50 STAA $0250 0312 20 ?? BRA END 0314 CC FF FF ERROR LDD #$FFFF 0317 FD 02 50 STD $0250 031A 20 ?? END BRA END
Compare Instructions CMPA CMPB CPD CPX CPY CBA
Test Instructions TSTA TSTB TST
IF-THEN-ELSE ORG $0200 LDAA $03FA BPL PAST NEGA PAST STAA $03FA
WHILE AND UNTIL LOOPS
TIMING LOOPS $0200 LDX #100 LOOP DEX BNE LOOP
TIMING LOOPS LDAA #30 STAA $1000 LDAA #00 STAA $1001 BACK DEC $1001 ORG $0200 LDAA #30 STAA $1000 LDAA #00 STAA $1001 BACK DEC $1001 BNE BACK DEC $1000