Intel Microcontroller Microscope & Magnifier User Manual


 
4-9
PROGRAMMING CONSIDERATIONS
4.2.3.4 Indirect Addressing with the Stack Pointer
You can also use indirect addressing to access the top of the stack by using the stack pointer as
the WORD register in an indirect reference. The following instruction uses indirect addressing
with the stack pointer:
PUSH [SP] ; duplicate top of stack
; SP SP +2
4.2.4 Indexed Addressing
Indexed addressing calculates an address by adding an offset to a base address. There are three
variations of indexed addressing: short-indexed, long-indexed, and zero-indexed. Both short- and
long-indexed addressing are used to access a specific element within a structure. Short-indexed
addressing can access up to 255 byte locations, long-indexed addressing can access up to 65,535
byte locations, and zero-indexed addressing can access a single location. An instruction can con-
tain only one indexed reference; any remaining operands must be direct references.
4.2.4.1 Short-indexed Addressing
In a short-indexed instruction, you specify the offset as an 8-bit constant and the base address as
an indirect address register (a WORD). The following instructions use short-indexed addressing.
LD AX,12H[BX] ; AX MEM_WORD(BX+12H)
MULB AX,BL,3[CX] ; AX BL
×
MEM_BYTE(CX+3)
The instruction LD AX,12H[BX] loads AX with the contents of the memory location that resides
at address BX+12H. That is, the instruction adds the constant 12 (the offset) to the contents of BX
(the base address), then loads AX with the contents of the resulting address. For example, if BX
contains 1000H, then AX is loaded with the contents of location 1012H. Short-indexed address-
ing is typically used to access elements in a structure, where BX contains the base address of the
structure and the constant (12H in this example) is the offset of a specific element in a structure.
You can also use the stack pointer in a short-indexed instruction to access a particular location
within the stack, as shown in the following instruction.
LD AX,2[SP]
4.2.4.2 Long-indexed Addressing
In a long-indexed instruction, you specify the base address as a 16-bit variable and the offset as
an indirect address register (a WORD). The following instructions use long-indexed addressing.
LD AX,TABLE[BX] ; AX MEM_WORD(TABLE+BX)
AND AX,BX,TABLE[CX] ; AX BX AND MEM_WORD(TABLE+CX)