正确理解 LEAL (Load Effective Address) 指令

LEAL: leal S, D    ->    D ← &S

在 CSAPP (Computer Systems: A Programmer’s Perspective) 中,对 LEAL 指令用作简单算术运算的情况,给出了一个例子:

For example, if register %edx contains value x, leal 7(%edx,%edx,4), %eax will set register %eax to 5x + 7.

正确理解逻辑为:

1. 设%edx的值为x

2. 7(%edx,%edx,4) 为变质寻址,目标内存地址为5x+7

3. 设储存在地址5x+7的值为y。然而LEAL并不寻址,它只取y的地址。y的地址即为5x+7。因此,LEAL的左操作数为5x+7

CSAPP描述为:

It has the form of an instruction that reads from memory to a register, but it does not reference memory at all. Its first operand appears to be a memory reference, but instead of reading from the designated location, the instruction copies the effective address to the destination.

4. LEAL将y的地址,5x+7,赋给%eax

至此,LEAL实现了简单算术功能。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 原文: GCC-Inline-Assembly-HOWTO 1. 简介(Introduction.) 1.1 Co...
    桂糊涂阅读 9,991评论 1 5
  • 我的思念像细雨后的春草一样拔节生长 我的牵挂像檐前的雨帘一样如丝如网 纤细怅惘的心弦 不成调的琴声中 依然萦绕你模...
    万道我为法阅读 2,338评论 0 0
  • 处暑悄然至,天长杳无迹。 蒸蒸热气散,悠悠凉风起! 午间摇素扇,凌晨添薄衣。 莫愁华叶衰,流年秋声里!
    逸塵居士阅读 1,703评论 0 0