Commodore 128 Programmer's Reference Manual page 160

Hide thumbs Also See for 128:
Table of Contents

Advertisement

150
COMMODORE 128
U
COMPARE INSTRUCTIONS
°
The Commodore 128 has three compare instructions that check the contents of a register
)
with the contents of memory. A compare operation can be used to determine which
[_
instructions to execute as a result of a conditioned value. The compare instructions are:
CMP
f |
CPX
U
CPY
The CMP instruction compares the contents of the accumulator with the contents
j
of the specified address in the instruction. Compare instructions essentially subtract
^
memory from a register value but change neither—they just set status flags. CPX
compares the contents of the X register with the specified address. CPY compares the
r j
contents of the Y register with the specified memory location.
M
All three instructions have versions that will operate in immediate, zero-page and
absolute addressing modes. This means you can compare the contents of a register
(A,X, or Y) with the contents of a zero-page location, any other address above zero page,
j
or against a constant. Here's an example:
^
LDX#$00
LDA #$00
ONE
STA $DF,X
U
INX
CPX #$0A
\ j
BNE ONE
U
The preceding program segment stores 0's in 10 consecutive memory addresses
starting at $DF. The first instruction loads the X register with 0, the second loads 0 into
] J
the accumulator. The third instruction stores 0 in location $DF plus the contents of the X
Lj
register. The fourth instruction increments the X register. The fifth instruction compares
the contents of the X index register with the constant $0A (10 decimal). If the contents
\ ~*
of the X register does not equal $0A, the program segment branches back to the store
jj
instruction specified by the label ONE. After the loop cycles ten times, the X register
and the constant $0A are equal. Therefore the processor does not take the branch
and the program continues with the instruction immediately following BNE.
\
You can compare the value of a register with the contents of an absolute memory
U
address. Here's the same example as above using the contents of a memory address
instead of a constant:
/
LDA #$0A
J
STA $FB
LDX #$00
i j
LDA #$00
I I
ONE
STA $DF,X
°
INX
CPX$FB
I j
BNE ONE
J

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents