检查我对简单装配的理解

时间:2014-07-27 20:01:49

标签: assembly x86

我自己组装大会并正在进行一些练习。我在C中对此代码的解释是否正确?我想我的一切都是正确的,除了潜在的底部位。

 push %ebp
 mov  %esp,%ebp
 sub  $0x10,%esp
 movl $0x0,-0x4(%ebp)
 mov  0xc(%ebp),%eax
 add  $0x4,%eax
 mov  (%eax),%eax
 cmp  0x8(%ebp),%eax
 jle  .L1
 mov  0xc(%ebp),%eax
 mov  (%eax),%eax
 sub  $0x7,%eax
 mov  %eax,-0x4(%ebp)
 .L1:
 mov  0x8(%ebp),%eax
 shl  $0x5,%eax
 add  %eax,-0x4(%ebp)
 mov  -0x4(%ebp),%eax
 leave  
 ret

我的解释:

此功能有两个参数:parameter_1和* parameter_2

int a = 0;

if (parameter_2 + 4 =< parameter_1) {

    a = parameter_2 - 7;

} else {

a = (parameter_1 * 32) + a // shifting to the right by 5 would be like 2 * 5?, or is it just divided by 5?

}

1 个答案:

答案 0 :(得分:2)

MinGW-GCC没有优化产生恰好你的汇编代码:

int func (int a, int b[])
{
    int c = 0;
    if (b[1] > a)
    {
        c = b[0] - 7;
    }
    c += (a * 32);
    return c;
}