【问题标题】:Understanding ATT Assembly Language了解 ATT 汇编语言
【发布时间】:2013-02-01 16:09:02
【问题描述】:

C 版:

int arith(int x, int y, int z)
{
    int t1 = x+y;
    int t2 = z*48;
    int t3 = t1 & 0xFFFF;
    int t4 = t2 * t3;
    return t4;
}

同一程序的ATT汇编版本:

x 在 %ebp+8,y 在 %ebp+12,z 在 %ebp+16

movl   16(ebp), %eax    
leal   (%eax, %eax, 2), %eax   
sall   $4, %eax      // t2 = z* 48... This is where I get confused
movl   12(%ebp), %edx   
addl   8(%ebp), %edx
andl   $65535, %edx
imull  %edx, %eax

除了左移之外,我了解它在程序的所有点上所做的一切。

我假设它会向左移动 4 次。这是为什么呢?

谢谢!

编辑:我也明白我困惑的部分等同于 C 版本的 z*48 部分。

我不明白的是,左移 4 次如何等同于 z*48。

【问题讨论】:

  • 左移 4 位本质上是乘以 16。

标签: c assembly x86 att


【解决方案1】:

您错过了leal (%eax, %eax, 2), %eax 行。应用一些数学,汇编代码如下:

一个:= x a := a + 2*a // a = 3*x a := a * 2^4 // a = x * 3*16

【讨论】:

    猜你喜欢
    • 2018-04-12
    • 1970-01-01
    • 2010-12-24
    • 1970-01-01
    • 2014-10-07
    • 1970-01-01
    • 2013-01-17
    • 2013-09-04
    相关资源
    最近更新 更多