You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
addrmods<br />
@ P. Klimo<br />
October 2005<br />
<strong>Addressing</strong> Modes – 8086 Examples<br />
Register:<br />
Examples:<br />
Operand value(s) in registers.<br />
MOV AL, BL ( no operand only opcode)<br />
ADD AX, BX<br />
Immediate :<br />
Examples:<br />
Operand value present in the instruction.<br />
MOV AX, 63 ( 16 bit operand)<br />
ADD AL, 63 (8 bit operand)<br />
Direct:<br />
Examples:<br />
Operand offset address (with respect to DS) given in the<br />
instruction.<br />
MOV AX,[13AF], ADD AX,[87FD] (all operands are 16 bit addresses)<br />
Register Indirect:<br />
Operand offset given in a CPU register.<br />
Registers used are BX (B register) , SI (source index),<br />
DI( destination index) or BP (base pointer).<br />
BP holds offset with respect to SS, but SI, DI and BX<br />
refer to DS.<br />
Examples: MOV [BX], AX , ADD AX, [SI] ( no operands, only opcodes)<br />
Direct Indexed Address:<br />
Operand offset given by a sum of a value held in either<br />
SI or DI registers and a constant displacement specified<br />
as an operand.<br />
Examples:<br />
MOV AX, [SI + 064F], ADD AX, [DI + 23EF]<br />
A typical application would be to access arrays using displacement as the pointer to<br />
the start of the array and the register value as an array index :<br />
my_array<br />
10 DB 'I', 'N', 'T', 'E', 'L', ' ', '8', '0', '8', '6'<br />
MOV SI, 7<br />
MOV AL, [SI + my_array];<br />
AL holds my_array[7] which is '0'<br />
1
addrmods<br />
@ P. Klimo<br />
October 2005<br />
Base Relative:<br />
Operand offset given by a sum of a value held in either<br />
BX or BP registers and a constant offset specified as an<br />
operand.<br />
A typical application would be to access various structures containing a variable size<br />
elements, using the register value as the pointer to the start of the structure and the<br />
displacement to pint at the start of the element within the structure.<br />
Example:<br />
; Constant definitions<br />
name EQU 0<br />
height EQU 20<br />
age EQU 30<br />
; Structure Definition with initial data<br />
my_details 20 DB "Paul Klimo" ; name (element)<br />
10 DB "2.3 m " ; height (element)<br />
5 DB '2', '1' ; age (element)<br />
; Data for other structures (may be not initialized)<br />
his_details 35 DB ??<br />
her_details 35 DB ??<br />
; This code retrieves the age of the person as a string of 2 ASCII letters held in AX<br />
MOV BX, my_details<br />
CALL get_age<br />
;point to base of structure<br />
;call subroutine that<br />
;returns with ASCII age<br />
;string in AX<br />
..... ; do something with it<br />
ADD BX, 35<br />
CALL get_age<br />
...<br />
; next customer, please<br />
; Subroutine (procedure) get_age<br />
; Get two bytes at offset age into the start of array pointed by BX<br />
get_age MOV AL, [BX + age+1] ; AL has low ASCII of age<br />
MOV AH, [BX + age] ; AH has high ASCII of age<br />
RET<br />
2
addrmods<br />
@ P. Klimo<br />
October 2005<br />
Base Indexed:<br />
Operand offset given by the sum of BX or BP with<br />
either SI or DI plus a constant displacement.<br />
Typical application would be accessing two dimensional arrays:<br />
; This extract reads the numbers stored in the specified row<br />
; variable declaration<br />
row DB 3 ; read data from this row<br />
column DB 2 ; and column<br />
; Data for a 4x3 array<br />
my_array DB 1, 2, 3, 4<br />
DB 5, 6, 7, 8<br />
DB 9, A, B, C<br />
; the code<br />
; Calculates offset to my_array : 4*(row-1) + (column-1) and<br />
; loads the byte it finds there into AL<br />
access_my_array MOV BX, row ; BX will hold row offset<br />
MOV DI, column ; DI column<br />
DEC DI<br />
; column-1<br />
DEC BX ; row -1<br />
SHL BX<br />
; 2*(row-1)<br />
SHL BX<br />
; 2(*2*(row-1))<br />
MOV AL, [my_array+ DI + BX] ; AL holds value A<br />
.....<br />
3