Arrays and Addressing Modes
Arrays and Addressing Modes
CS 272
Sam Houston State University
Dr. Tim McGuire
Arrays
Arrays whose elements share a common initial value are defined using the DUP
pseudo-op
It has the form:
o repeat_count DUP (value)
gamma dw 100 DUP(0)
o sets up an array of 100 words, with each entry initialized to 0
delta db 212 DUP(?)
o sets up an array of 212 uninitialized bytes
Three forms:
o Immediate data -- stored directly in machine code
example: mov ax,5 ; 5 is an immediate value
immediate operands are always source operands
o Register data -- held in processor registers
example: add ax,bx
o Memory data -- held in memory
processor calculates the 16-bit effective address
Memory-Addressing Modes
Direct mov ax, count
Register-indirect mov ax, [bx]
Base mov ax, [record + bp]
Indexed mov ax, [array + si]
Base-indexed mov ax, [recordArray + bx + si]
String lodsw
I/O Port in ax, dx
Segment Override
Register indirect mode references for bx, si, or di are usually relative to ds
To change this, use a segment override:
o mov ax, es:[bi]
Segment overrides can also be used with based and indexed modes.
An override occupies a byte of machine code which is inserted just before the
affected instruction
Register-Indirect Mode
Example
Another example
bx=1000h, si=2000h, di=3000h, [1000h]=1BACh, [2000h]=20FEh,
[3000h]=031Dh
W dw 10,20,30,40,50,60,70,80,90,10
We have seen the use of the WORD and BYTE pseudo-ops to remove type
ambiguity
The LABEL pseudo-op is another way of working with data of various types
Example:
Syntax of an operand
Replace the lowercase letters in the string to uppercase using index addressing
mode
W dw 10,20,30,40,50,60,70,80,90,10
Based and indexed addressing mode is often used for array and string
processing
Based-indexed addressing mode can be used for two dimensional arrays
We will discuss these in greater detail later
lea ax,data
and
However,
Two-Dimensional Arrays
Suppose A is a 5x7 word array stored in row-major order. Write code to clear
row 2.