All mathematical operations are performed within the arithmetic logic unit (ALU)
and stored in the accumulator. It is considered a temporary mathematical work area. For
example, you want to add two numbers, 2 + 3. First, load the accumulator with the 2.
Next add 3 with the ADC mnemonic. Now, you want to perform another operation. You
must store the answer from the accumulator into a RAM location before you perform the
next math operation. If you don't, your original answer is erased.
The accumulator is so important that it has an addressing mode of its own. All the
instructions using this mode pertain specifically to the accumulator. The following three
sample instructions pertain solely to the accumulator in its own addressing mode:
LDA - LOAD accumulator with memory
STA - STORE the accumulator in memory
ADC - ADD contents of memory to the accumulator
Details on all of the accumulator addressing commands are given later in this chapter.
TH E X A N D Y IN D E X REGISTERS
The second most used registers are the X and Y index registers. These index registers are
used primarily to modify an address by adding an index within a machine-language
instruction. They also can be used as temporary storage locations or to load values and
store them in RAM like the accumulator.
When modifying an address, the contents of the index registers are added to an
original address, called the base address, to find an address relative to the base address.
The resulting address yields the effective address— i.e., the location where a data value
is stored or retrieved. The effective address is acted upon by machine-language instruc
tions. For example, you want to place the value 0 in locations 1024 through 1034. In
BASIC, here's how you do it:
10 FOR I = 1024 to 1034
20 POKE 1,0
30 NEXT
Here's how you do it in symbolic machine language by using the X or Y index
register. NOTE: Don't worry if you don't understand all of the following instructions. They
are discussed fully in the TYPES OF INSTRUCTIONS section, later in this chapter.
LDA #$00
TAX
START
STA $0400,X
INX
CPX #$0B
BNE START
BRK
* = In the machine-language monitor the symbolic label START is not allowed, so it
would appear as an absolute address reference (eg; $183B).
M ACHINE LANGUAGE ON THE COMMODORE 128
Load the Accumulator with 0
Transfer the contents of Accumulator (0) to X
Register.
Store contents of Accumulator in address $0400 + X
Increment the X register
Compare the X register with $0B (11 decimal)
If X register does not equal 11 branch to START.
Stop
129
Need help?
Do you have a question about the 128 and is the answer not in the manual?