如何在Assembly中访问数组的元素? [英] How to access an element of an array in Assembly?

查看:61
本文介绍了如何在Assembly中访问数组的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档说:

(Index ∗ Scale) + Displacement ⎯ 当元素大小为 2 时,这种地址模式提供了一种索引静态数组的有效方法,4 或 8 个字节.位移定位数组的开头,索引寄存器保存所需数组元素的下标,并且处理器自动将下标转换为索引通过应用比例因子.

(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.

可以使用Base代替Displacement来指定数组的开头:

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

Base + (Index ∗ Scale)

推荐答案

base、index、scale、displacement 只是内存四个部分的名称操作数.您可以自由地将每个部分用于您喜欢的任何目的.例如,要获取数组的第 n+k 个条目,您可以使用以下内容:

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]

其中 n 存储在 ebx 中,k 存储在 ecx 中. 在这种情况下,"base"实际上用作数组的索引,索引"部分也是如此.

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.

这篇关于如何在Assembly中访问数组的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆