Chap 10
Chap 10
Chap 10
• One‐Dimensional Arrays
• Addressing Modes
1
One‐Dimensional Array A
2
One‐Dimensional Array
W DB 10, 20, 30, 40, 50, 60
*Address of the array variable is called base address of array
4
The DUP Operator
• The DUP (duplicate) is used to define arrays whose elements
share a common initial value.
• Format:
DUP (value)
5
Location of Array Elements
•The address of an array element can be specified by
adding a constant to the base address
– If A is an array & S is the size of every element in bytes
6
Example
Exchange 4th and 10th element of an [word]array:
MOV AX, W + 6
XCHG W+18, AX
MOV W+6, AX
7
Addressing Modes
• The way an operand is specified
8
ADDITIONAL ADDRESSING MODES
Four additional addressing modes to address memory
operands indirectly:
9
Register Indirect Mode
Offset address of the operand is contained in a register.
Register acts like a pointer to the memory location
[register]
The register is BX, SI, DI, or BP
1
0
Examples
MOV AX, SI
; AX = 0100h
1
1
Your turn . . .
Suppose that,
BX contains 1000h Offset 1000h contains 1BACh
SI contains 2000h Offset 2000h contains 20FEh
DI contains 3000h Offset 3000h contains 031Dh
where the above offsets are in the data segment addressed by DS.
Hints: exchange the 1st and Nth words, the 2nd and (N-1)th word
and so on.
1
4
Based and Indexed Addressing Mode
•Operand’s offset address is obtained by adding a number
called displacement to the contents of a register
1
5
Based and Indexed Addressing Mode
• [register + displacement]
• [displacement + register]
• [register] + displacement
• displacement + [register]
• displacement[register]
• [register]displacement
1
7
Example
Rework the last example by using based mode.
1
8
Your turn . . .
Suppose that ALPHA is declared as
ALPHA DW 0123H, 0456h, 0789h, 0ABCDh
in the segment addressed by DS.
Suppose also that,
BX contains 2, Offset 0002 contains 1084h
SI contains 4, Offset 0004 contains 2BACh
DI contains 1
Tell which of the following instructions are legal. If legal, give the source
offset address and the result or number moved.
Source offset Number moved
a. MOV AX, [ALPHA+BX] ALPHA+2 0456h
b. MOV BX, [BX+2] 2+2 = 4 2BACh
c. MOV CX, ALPHA[SI] ALPHA+4 0789h
d. MOV AX, –2[SI] –2+4 = 2 1084h
e. MOV BX, [ALPHA+3+DI] ALPHA+4 0789h
f. MOV AX, [BX] 2 Illegal form of source operand
g. ADD BX, [ALPHA+AX] Illegal source register 1
9
PTR OPERATOR
• Operands of instruction must be of the same type
2
0
Accessing the STACK
• When BP specifies the offset address, SS supplies the segment
number
• BP may be used to access elements of the stack
MOV BP, SP
MOV AX, [BP]
MOV BX, [BP + 2]
MOV CX, [BP + 4]
2
1
Home Assignment
2
2
Based Indexed Addressing Mode
2
3
Based Indexed Addressing Mode
2
4
Based Indexed Addressing Mode
• W is a word variable
• BX contains 2
• SI contains 4