CS-220, Section 90, Week 8
R. Eckert

INDIRECT ADDRESSING--

Use index registers (SI, DI) and/or base registers (BX, BP) as pointers to memory.
These registers should contain the offset part of an address.

Most General Format:   Displacement[IndexReg][BaseReg]
Alternate form:        Displacement[IndexReg+BaseReg]
Alternate form:        [IndexReg+BaseReg+Displacement]

The Displacement and/or IndexReg and/or BaseReg are optional.

The offset of the operand is obtained by adding the contents of the Base Register 
(if present), the contents of the Index Register (if present), and the Displacement
(if present).

The displacement may be either a symbol or an immediate value.

EXAMPLES OF INDIRECT ADDRESSING--

Assume the following data segment:

                                data    segment
0000    12 34                   x       db      12h, 34h                
0002    05 07 02 04             y       db      5,7,2,4
0006    08 01 03 06 09          z       db      8,1,3,6,9
                                data    ends

        mov     si,3            ;si=3
        mov     di,1            ;di=1
        mov     bx,2            ;bx=2
        mov     al,[si]         ;offset=3, al=07
        mov     ah,3[di]        ;offset=3+1=4, ah=02
        mov     cl,[bx][si]     ;offset=2+3=5, cl=04
        mov     ch,z[bx]        ;offset=z+2=6+2=8, ch=03
        mov     dl,y[bx][si]    ;offset=y+2+3=2+2+3=7, dl=01    
        mov     dh,y+4[bx+di]   ;offset=y+4 + 2 + 1 = 2+4 + 2 + 1 = 9, dh=6



SIMPLE I/O ON A PC--

The DOS operating system provides many I/O services through
software interrupt 21h. As we'll see later, software interrupts
are, in many ways like calls to far procedures. The instruction

   INT 21h

transfers control to the operating system and requests that it
perform a service for the calling program. The service requested
is determined by the "function number" which should be placed in
AH register.

Some common DOS services:

AH=1 ==> Single Character Keyboard input with echo to screen.
ASCII code of first key pressed will be in AL register after the int 21h.
The character will appear at the current cursor location on the screen.

Example:        mov   ah,1
                int     21h
                ;the ASCII code of first key pressed is now in al

AH=2 ==> Single Character output to the screen.
ASCII code of character to be displayed should be placed in DL register.
After the int 21h, the character in DL will appear at the current cursor
location on the screen. The cursor is then moved to the next screen position.

Example:        mov     ah,2
                mov     dl,'A'
                int     21h
                ;An 'A' will be displayed on the screen.