The carry added well the add operation automatically adds the carry
166 Programming the 65816
The comparison operation—is VALUEl equal to VALUE2, for example—is implemented on the 65x, as on most processors, as an implied subtraction. In order to compare VALUEl to VALUE2, one of the values is subtracted from the other. Clearly, if the result is zero, then the numbers are equal.
This kind of comparison can be made using the instructions you already know, as Fragment 9.5 illustrates. In this fragment, you can see that the branch to TRUE will be taken, and the INC VAL instruction never executed, because $1234 minus $1234 equals zero. Since the results of subtractions condition the z flag, the BEQ instruction (which literally means "branch if result equal to zero"), in this case, means "branch if the compared values are equal."
REP | 9 | 167 | ||
---|---|---|---|---|
#$30 | 16-bit registers | |||
LONGA | ON | |||
|
LONGI | ON |
0 0 0 2
0002 9C1200 | TRUE | STZ | ||
---|---|---|---|---|
0005 A93412 | LDA | |||
0008 38 | SEC |
|
|
|
0009 E93412 | SBC | |||
OOOC F003 | BEQ | |||
INC | ||||
OOOE EE1200 | ||||
0 0 1 1 60 | RTS | |||
0 0 1 20 0 0 0 |
|
DS |
|