Commodore 128 Programmer's Reference Manual page 166

Hide thumbs Also See for 128:
Table of Contents

Advertisement

156
COMMODORE 128
with an 8563 register number, into the 8563 address register. The BIT instruction places
L>
bit 7 of location $D600 into the negative flag in the 8502 status register. The BPL
instruction branches to the BIT instruction in location $185B as long as the value of the
\ /
negative flag is equal to 0. To the 8563 chip, this means the data is not yet valid and
Jf
cannot be written to or read from until bit 7 is set. This loop continues until the value of
bit 7 is 1, then it is transferred to the negative flag. The result now becomes negative
so the branch is skipped and control is passed to the next instruction in memory, which
j j
stores the data into the 8563 data register. Refer to Chapter 10, Writing to an 8563
U>
Register for an expanded version of this program.
REGISTER TRANSFER INSTRUCTIONS
|j
Register transfer instructions move a value from one register (A, X, or Y) to another.
This instruction is useful since it only requires one byte of memory and saves the
("/
programmer the trouble of loading the value from one register and storing it in another.
[J
The 8502 microprocessor has the following six register transfer instructions:
TAX—Transfer contents of accumulator to X index register
j j
TAY—Transfer contents of accumulator to Y index register
U
TSX—Transfer the contents of the stack pointer to X index register
TXA—Transfer the contents of X index register to the accumulator
i
;
TYA—Transfer the contents of the Y index register to the accumulator
! ;
TXS—Transfer the contents of the X register to the stack pointer
The TXS and TSX instructions transfer values from the X index register to the
j J
stack pointer and vice versa. This is useful if you need to take a value off the stack
U
temporarily, in a mathematical operation (for example, to operate on it and then replace
it on the stack). Another use is to take a value off the stack, place it in the X register for
s~ j
temporary storage, add a new value on the stack, and then place the old value back on
j I
top. This could be the case when you need to sort values in ascending order.
SHIFT AND ROTATE INSTRUCTIONS
The shift and rotate instructions manipulate the bits of the accumulator or memory.
Following are the shift and rotate instructions used by the 8502 family of microprocessors:
jj
ASL—Shift the whole byte one bit to the left
^
LSR—Shift the whole byte one bit to the right
ROL—Rotate the whole byte one bit to the left
j >
ROR—Rotate the whole byte one bit to the right
L)
SHIFT INSTRUCTIONS
, j
The shift instructions are useful when evaluating the value of a single bit at a time in a
[ \
series of bits that control your program. For example, a joystick read routine is an
example that calls for the shift instruction. Locations $DC00 and $DC01 control the
joystick direction (bits 0-3), and the joystick fire button (bit 4). One way to evaluate
I j
these values is to shift them to the right. This causes the value to be passed to the carry
L)

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents