`leal(%rdi,%rdi),%eax`有什么作用?

时间:2019-03-06 05:43:34

标签: assembly x86 att

#include <stdio.h>

int f(int x) {
    return x * FACTOR;
}
int main() {
    int x=1;
    printf("%d\n", f(x));
    return 0;
}

对于上述程序,如果我使用clang -g -S -DFACTOR=2进行编译。我得到以下输出。

似乎以下两条指令与乘法x * 2有关。但是我不明白他们如何计算乘法。有人可以帮忙解释一下吗?谢谢。

    leal    (%rdi,%rdi), %eax
...
    movl    $2, %esi
...
Ltmp0:
    ##DEBUG_VALUE: f:x <- $edi
    .loc    1 6 11 prologue_end     ## main.c:6:11
    leal    (%rdi,%rdi), %eax
    .loc    1 6 2 is_stmt 0         ## main.c:6:2
    popq    %rbp
    retq
...
Ltmp2:
    ##DEBUG_VALUE: main:x <- 1
    .loc    1 10 2 prologue_end     ## main.c:10:2
    leaq    L_.str(%rip), %rdi
    movl    $2, %esi
    xorl    %eax, %eax
    callq   _printf
    .loc    1 11 2                  ## main.c:11:2
    xorl    %eax, %eax
    popq    %rbp
    retq

0 个答案:

没有答案
相关问题