Commodore 128 Programmer's Reference Manual page 162

Hide thumbs Also See for 128:
Table of Contents

Advertisement

152
COMMODORE 128
U
This program segment essentially performs the following mathematical operation:
U>
(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
J
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.
)
LOGICAL INSTRUCTIONS
u
(AND, EOR, AND 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
| j
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
) j
illustration of this concept:
U
Memory address = 10001010
| /
Accumulator
= 11110010
jj
Result of AND
= 10000010
As noted, the result of an AND operation is (true) 1, only if the two operands are
L)
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
^ i
l's are equal to 1. The rest of the bits are equal to zero since no other bit positions in
jj
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:
,
f
If one of the operands equals 1, the resulting Boolean value equals 1.
LJ
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. Here's
j
an illustration.
!—'
Contents of Memory Address = 10101001
j
Contents of Accumulator
= 10000011
L.
Result of the OR operation
= 10101011
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
I J
equal 1, the result is zero. This suggests the following general rule:
(j

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents