Está en la página 1de 3

@ P.

Klimo 2002

Examples on the Use of 8086/88 Addressing Modes


Register: Operand value(s) in registers.

Examples: MOV AL, BL , ADD AX, BX Immediate : Examples: Operand value present in the instruction. MOV AX, 04563, ADD AL,A5

Direct: Examples:

Operand offset address (with respect to DS) given in the instruction. MOV AX,[13AF], ADD AX,[87FD]

Register Indirect:

Operand offset given in a CPU register. Registers used are BX (B register) , SI (source index), DI( destination index) or BP (base pointer). BP holds offset with respect to SS, but SI, DI and BX refer to DS.

Examples:

MOV [BX], AX , ADD AX, [SI]

Direct Indexed Address:

Operand offset given by a sum of a value held in either SI or DI registers and a constant displacement specified as an operand.

Examples:

MOV AX, [SI + 064F], ADD AX, [DI + 23EF]

A typical application would be to access arrays using displacement as the pointer to the start of the array and the register value as an array index : my_array 10 DB 'I', 'N', 'T', 'E', 'L', ' ', '8', '0', '8', '6' MOV SI, 7 MOV AL, [SI + my_array]; AL holds my_array[7] which is '0'

@ P. Klimo 2002

Base Relative:

Operand offset given by a sum of a value held in either BX or BP registers and a constant offset specified as an operand.

A typical application would be to access various structures containing a variable size elements, using the register value as the pointer to the start of the structure and the displacement to pint at the start of the element within the structure. Example: ; Constant definitions name height age

EQU 0 EQU 20 EQU 30 ; name (element) ; height (element) ; age (element)

; Structure Definition with initial data my_details 20 DB "Paul Klimo" 10 DB "2.3 m " 5 DB '2', '1' ; Data for other structures (may be not initialized) his_details 35 DB ?? her_details 35 DB ??

; This code retrieves the age of the person as a string of 2 ASCII letters held in AX MOV BX, my_details CALL get_age ..... ADD BX, 35 CALL get_age ... ; Subroutine (procedure) get_age get_age MOV AL, [BX + age+1] MOV AH, [BX + age] RET ; AL has low ASCII of age ; AH has high ASCII of age ; point to base of structure ; ASCII age string into AX ; do something with it ; next customer, please

@ P. Klimo 2002

Base Indexed:

Operand offset given by the sum of BX or BP with either SI or DI plus a constant displacement.

Typical application would be accessing two dimensional arrays: ; This extract reads the numbers stored in the specified row ; variable declaration row ; Data for a 4x3 array my_array DB 3 ; read data from this row

3 DB 1, 2, 3, 4 3 DB 5, 6, 7, 8 3 DB 9, 0Ah, 0Bh, 0Ch

; the code access_my_array

MOV AL, row DEC AL SHL AL SHL AL MOV SI, AL MOV DI, 00 MOV AL, [my_array+ SI + DI] INC DI MOV AL, [my_array+SI +DI] .....

; < Calculates ; < row offset = ; < (row-1)*4 ; SI holds row offset ; DI holds column # ; AL = 9 ; next column, please ; AL = Ah

También podría gustarte