Basic Addressing Modes Information
We have load and store instructions to get data to and from
memory. To make certain types of programming easier, such as accessing
an array of data, the HC11 supports several different addressing modes,
or ways of accessing memory locations.
-
Inherent: The locations of data are implied by the instruction name
-
Example: ABA, which adds register B to A, implies the registers in the
instruction name
-
Note: no operands are needed to indicate memory to work with or constant value to load.
-
Immediate: The actual data is located in memory immediately following
the instruction's opcode
-
Format: the instruction name is followed by a constant value or label with
a
# sign in front.
-
Example: LDAA #22 generates two bytes of machine code $86 $16, where the
second byte is equivalent to decimal 22, the constant to be loaded into
the A register.
-
Extended: The address of the data is located in memory immediately
following the instruction's opcode
-
Format: the instruction name is followed by a label that is in the
assembly program somewhere, or is followed by a constant value, without
a
# sign.
-
Example: LDAA param2, where param2 is a label in the program
-
Example: LDAA $ff32, which means load the byte at $ff32 into the A register
-
Direct: A one-byte address of the data is located immediately following
the opcode. This is the low-order byte of the address. The high order byte
is assumed to be $00
-
Format, same as extended, except that labels and addresses must begin with
RAM (High byte is always $00)
-
Example, LDAA $43, which means load the byte at $0043 into the A register
-
This is somewhat redundant, given that Extended addressing can do the same
thing,
but it is more efficient because only one byte of addressing is fetched
-
Remember: our RAM is all located in the "direct" area!
-
Relative: The value in the operand is computed from the relationship
between where you are currently in the code in memory to where you are
going to, the label.
-
Format: the instruction name followed by a 8 bit value that indicates the
distance to move (add to PC) from where currently in code.
-
Example: BEQ 05 branches 6 memory locations forward from the memory location
where the value $05 is located (adds $05 to the current PC value)
-
Example: BRA fe branches 1 memory locations backwards from the memory location
where the value $fe is located (adds $fe, subtracts 2,
to the current PC value)
-
The relative address value is in two's complement form so it can only indicate
a change of -128 memory locations backwards and +127 memory locations forwards.
-
Indexed (not responsible for yet): The value in an index register
(X or Y) is added to an
offset value, which provides the final effective address of the data.
-
Format: the instruction name followed by a value,register pair
-
Example: LDAA var,X loads the byte found at address (X+var) into register
A
-
The offset is a positive 1-byte value, so it is limited to values from
0 to 255
Ok, we've concentrated on load/store instructions, but the HC11 actually
kind-of cheats. It allows memory accesses on most any form of instruction.
So, the addressing modes apply to many, many instructions.