Commodore 128 Programmer's Reference Manual page 151

Hide thumbs Also See for 128:
Table of Contents

Advertisement

n
n
n
n
n
MACHINE LANGUAGE ON THE COMMODORE 128
141
Because of the way this program segment is written, a branch can occur only once, the
first time through the loop.
Under relative addressing, the first byte of the instruction is the op-code and the
second is the operand, representing an offset of a number of memory locations. The
location to branch back to is not interpreted as an absolute address but an offset relative to
P|
the location of the branch instruction in memory.
' i
The offset ranges from -128 through 127. If the condition of the branch is met,
the offset is added to the program counter and the program branches to the address in
r^
memory.
I [
In the example in Figure 5-8, notice that the operand in the branch instruction is
only one instruction past the label START. The operand START is interpreted by the
p-1
computer as an offset of three bytes backward in memory since the DEC instruction use
j
2 bytes and the BEQ op-code uses one byte. The 8502 can only branch forward 127
bytes and branch backward by 128 bytes.
fmm>
If you enter the machine-language monitor and disassemble the machine-language
\
code, you'll see how the computer represents a branch instruction operand as in part (B)
of Figure 5-8. The symbolic code in part (C) operand field represents the operands as
absolute addresses but the assembled hexadecimal code to the left in part (B) of the op
code stores the operand using one byte, a number plus or minus the address of the
branch instruction. The largest number for a forward branch is $7F. A backward branch
is represented by hex numbers greater than $80. When you are within the machine-
p
language monitor, subtract the operand offset from 255 ($FF) to find the actual value of
I j
the negative offset. In this case $FF minus 3 equals $FC, which is the operand in the
branch instruction in part (B) of Figure 5-8.
Here are some examples of relative addressing branch instructions:
INSTRUCTION
BEQ
BNE
BCC
HEX OP-CODE
$F0
$D0
$90
MEANING
Branch on result Equal to 0
Branch on result Not Equal to 0
Branch on Carry Clear
INDEXED ADDRESSING MODES
The Commodore 128 has two special-purpose registers: the X and Y index registers.
In indexing addressing modes, index registers modify an address by adding their
contents to a base address to arrive at the actual or effective address. For example,
here's a program segment that illustrates the importance of address modification, using
the X and Y index registers:

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents