Download BBC Microcomputer Advanced User Guide

Transcript
5.11
Relative addressing
The 6502 instruction set contains 8 branch instructions which
cause a jump if a certain condition is met. In the example above
a BNE instruction is used to cause the loop to be executed again
if the loop index (Y register) does not equal 0. These branch
instructions can only be used with relative addressing. If the
condition of the branch is satisfied the byte following the
branch instruction is added to the program counter as an 8 bit
two's complement number. This method of relative addressing
allows a branch forward 127 bytes or back 128 bytes from the
program counter value after the branch instruction has been
executed. The calculation of the relative branch value is
normally quite transparent to the programmer using the BASIC
assembler. When writing in assembly language the
programmer follows the branch instruction with a label or
absolute address and the assembler performs the necessary
calculations. The use of relative addressing will only become
apparent when a label or absolute address is specified outside
the relative addressing range. When this occurs the assembler
will flag an ‘Out of range’ error to the user. OPT 0 is used to
suppress this error from forward references on the first
assembler pass.
40