Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
8xC196EA microcontroller user's manual.1998.pdf
Скачиваний:
52
Добавлен:
23.08.2013
Размер:
8.29 Mб
Скачать

PROGRAMMING CONSIDERATIONS

3.2.3.3Extended Indirect Addressing with Autoincrement

The extended load and store instructions can also use indirect addressing with autoincrement. The only difference is that the register containing the indirect address must be a word-aligned 24-bit register to allow access to the entire address space. The following instructions use extended indirect addressing with autoincrement:

ELD

AX,[EX]+

; AX MEM_WORD(EX)

 

 

; EX EX + 2

ELDB

AL,[EX]+

; AL MEM_BYTE(EX)

 

 

; EX EX + 1

EST

AX,[EX]+

; MEM_WORD(EX) AX

 

 

; EX EX + 2

ESTB AL,[EX]+

; MEM_BYTE(EX) AL

;EX EX + 1

3.2.3.4Indirect 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

3.2.4Indexed 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 shortand long-indexed addressing are used to access a specific element within a structure. Short-indexed addressing can access up to 256 byte locations, long-indexed addressing can access up to 65,536 byte locations, and zero-indexed addressing can access a single location. An instruction can contain only one indexed reference; any remaining operands must be direct references.

3.2.4.1Short-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)

3-9

8XC196EA USER’S MANUAL

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 12H (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 addressing 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]

3.2.4.2Long-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)

ST

AX,TABLE[BX]

;

MEM_WORD(TABLE + BX) AX

ADDB

AL,BL,LOOKUP[CX]

;

AL

BL

+ MEM_BYTE(LOOKUP + CX)

The instruction LD AX, TABLE[BX] loads AX with the contents of the memory location that resides at address TABLE+BX. That is, the instruction adds the contents of BX (the offset) to the constant TABLE (the base address), then loads AX with the contents of the resulting address. For example, if TABLE equals 4000H and BX contains 12H, then AX is loaded with the contents of location 4012H. Long-indexed addressing is typically used to access elements in a table, where TABLE is a constant that is the base address of the structure and BX is the scaled offset (n × element size, in bytes) into the structure.

3.2.4.3Extended Indexed Addressing

The extended load and store instructions can use extended indexed addressing. The only difference from long-indexed addressing is that both the base address and the offset must be 24 bits to support access to the entire address space. The following instructions use extended indexed addressing. (In these instructions, OFFSET is a 24-bit variable containing the offset, and EX is a double-word aligned 24-bit register containing the base address.)

ELD

AX,OFFSET[EX]

; AX

MEM_WORD(EX+OFFSET)

ELDB

AL,OFFSET[EX]

;

AL

MEM_BYTE(EX+OFFSET)

EST

AX,OFFSET[EX]

;

MEM_WORD(EX+OFFSET) AX

3-10

Соседние файлы в предмете Электротехника