Google

May 18, 2008

Effective addresses

Effective Addresses

Most memory data accessing in the 86 family is accomplished via
the mechanism of the effective address. Wherever an effective
address specifier "eb", "ew" or "ed" appears in the list of 8086
instructions, you may use a wide variety of actual operands in
that instruction. These include general registers, memory
variables, and a variety of indexed memory quantities.

GENERAL REGISTERS: Wherever an "ew" appears, you can use any of
the 16-bit registers AX,BX,CX,DX,SI,DI,SP, or BP. Wherever an
"eb" appears, you can use any of the 8-bit registers
AL,BL,CL,DL,AH,BH,CH, or DH. For example, the "ADD ew,rw" form
subsumes the 16-bit register-to-register adds; for example, ADD
AX,BX; ADD SI,BP; ADD SP,AX.

MEMORY VARIABLES: Wherever an "eb", "ew", or "ed" appears, you
can use a memory variable of the indicated size: byte, word, or
doubleword. Variables are typically declared in the DATA
segment, using a DW declaration for a word variable, or a DB
declaration for a byte variable. For example, you can declare
variables:

DATA_PTR DW ?
ESC_CHAR DB ?

then you can load or store these variables:

MOV ESC_CHAR,BL ; store the byte variable ESC_CHAR
MOV DATA_PTR,081 ; initialize DATA_PTR
MOV SI,DATA_PTR ; load DATA_PTR into SI for use
LODSW ; fetch the word pointed to by DATA_PTR

Alternatively, you can address specific unnamed memory locations
by enclosing the location value in square brackets; for example,

MOV AL,[02000] ; load contents of location 02000 into AL

Note that A86 discerned from context (loading into AL) that a
BYTE at 02000 was intended. Sometimes this is impossible, and
you must specify byte or word:

INC B[02000] ; increment the byte at location 02000
MOV W[02000],0 ; set the WORD at location 02000 to zero

6-2

INDEXED MEMORY: The 86 supports the use of certain registers as
base pointers and index registers into memory. BX and BP are the
base registers; SI and DI are the index registers. You may
combine at most one base register, at most one index register,
and a constant number into a run time pointer that determines the
location of the effective address memory to be used in the
instruction. These can be given explicitly, by enclosing the
index registers in brackets:

MOV AX,[BX]
MOV CX,W[SI+17]
MOV AX,[BX+SI+5]
MOV AX,[BX][SI]5 ; another way to write the same instr.

Or, indexing can be accomplished by declaring variables in a
based structure (see the STRUC directive in Chapter 9):

STRUC [BP] ; NOTE: based structures are unique to A86!
BP_SAVE DW ? ; BP_SAVE is a word at [BP]
RET_ADDR DW ? ; RET_ADDR is a word at [BP+2]
PARM1 DW ? ; PARM1 is a word at [BP+4]
PARM2 DW ? ; PARM2 is a word at [BP+6]
ENDS ; end of structure
INC PARM1 ; equivalent to INC W[BP+4]

Finally, indexing can be done by mixing explicit components with
declared ones:

TABLE DB 4,2,1,3,5
MOV AL,TABLE[BX] ; load byte number BX of TABLE

You might be also interested in:

::Interfacing pic microcontroller with LCD
:: Serial Port interfacing with atmega
:: TCP/IP on PIC 18 series

No comments: