user8240761
user8240761

Reputation: 995

How to access an element of an array in Assembly?

The documentation says:

(Index ∗ Scale) + Displacement ⎯ This address mode offers an efficient way to index into a static array when the element size is 2, 4, or 8 bytes. The displacement locates the beginning of the array, the index register holds the subscript of the desired array element, and the processor automatically converts the subscript into an index by applying the scaling factor.

Can Base be used instead of Displacement to specify the beginning of the array:

Base + (Index ∗ Scale)

Upvotes: 0

Views: 6076

Answers (1)

fuz
fuz

Reputation: 93152

base, index, scale, and displacement are just the names for the four parts of a memory operand. You are free to use each part for whatever purpose you like. For example, to fetch the n+k-th entry of an array, you might use something like this:

mov al, [array + ebx + ecx]

where n is stored in ebx and k is stored in ecx. In This case, the “base” is really used as an index into the array and so is the “index” part.

Upvotes: 1

Related Questions