152
COMMODORE 128
This program segment essentially performs the following mathematical operation:
(10 + 4 )- 6 + 10= 18.
The first instruction clears the carry bit. The second instruction loads the accumu
lator with $0A (10 decimal). The third instruction stores the value in address $FB for
later use. The fourth instruction adds the constant $04 to the value already in the
accumulator. The SBC instruction subtracts the constant $06 from the contents of the
accumulator. The next instruction, ADC $FB, adds the contents of memory location
$FB to the contents of the accumulator. The resulting value (18($ 12)) of all the
mathematical operations is stored in address $FD.
LO GICAL IN STRUCTIO NS
(A N D , EOR, A N D ORA)
These instructions operate on the contents of a memory address and a register. The AND
operation is a binary (Boolean) algebra operation having two operands that can result in
one of two values, 0 or 1. The only way an AND operation can result in a 1 is if both
the operands equal 1; otherwise the result is 0. For example, the two operands are the
contents of a specified memory address and the contents of the accumulator. Here's an
illustration of this concept:
Memory address = 10001010
Accumulator
Result of AND
As noted, the result of an AND operation is (true) 1, only if the two operands are
equal to 1; otherwise the result is 0. Notice bit 7 (high-order bit) equals 1 because both
bit 7 's in the operands are 1. The only other resulting bit equal to 1 is bit 1, since both bit
l 's are equal to 1. The rest of the bits are equal to zero since no other bit positions in
both operands are equal to 1. A 1 and a 0 equals 0, as does a 0 and a 0.
The Boolean OR works differently. The general rule is:
If one of the operands equals 1, the resulting Boolean value equals 1.
For example, the two operands are the contents of a specified memory address and
the contents of the accumulator. Each individual bit can be treated as an operand. H ere's
an illustration.
Contents of Memory Address = 10101001
Contents of Accumulator
Result of the OR operation
For all the bit positions that equal one in either operand, the resulting value of that
bit position equals 1. The result is 1 if either operand or both operands are equal to 1.
The exclusive OR works similarly to the OR operation, except if both operands
equal 1, the result is zero. This suggests the following general rule:
= 11110010
= 10000010
= 10000011
= 10101011
Need help?
Do you have a question about the 128 and is the answer not in the manual?