了解汇编代码

时间:2014-09-11 22:03:05

标签: assembly

   0x08048d02 <+0>: push   %ebp
   0x08048d03 <+1>: mov    %esp,%ebp
   0x08048d05 <+3>: push   %esi
   0x08048d06 <+4>: push   %ebx
   0x08048d07 <+5>: sub    $0x30,%esp       //minus 48 to esp
   0x08048d0a <+8>: lea    -0x20(%ebp),%eax     //eax = first element in the array

   0x08048d0d <+11>:    mov    %eax,0x4(%esp)       //
   0x08048d11 <+15>:    mov    0x8(%ebp),%eax       //input?
   0x08048d14 <+18>:    mov    %eax,(%esp)      //esp = eax
   0x08048d17 <+21>:    call   0x804914a <read_six_numbers>

   0x08048d1c <+26>:    cmpl   $0x0,-0x20(%ebp)     // first int compare to 0

   0x08048d20 <+30>:    jns    0x8048d27 <phase_2+37>   //if not negative, jump

   0x08048d22 <+32>:    call   0x8049108 <explode_bomb> // < 0

   0x08048d27 <+37>:    mov    $0x1, %ebx       //set ebx = 1
   0x08048d2c <+42>:    lea    -0x20(%ebp),%esi     //set esi to the address of the first element of the array
   0x08048d2f <+45>:    mov    -0x4(%esi,%ebx,4),%eax   //eax = esi + ebx * 4 - 4
   0x08048d33 <+49>:    sub    %ebx,%eax        //ebx  = ebx - eax
   0x08048d35 <+51>:    cmp    %eax,(%esi,%ebx,4)   //eax = (esi + ebx * 4)

   0x08048d38 <+54>:    je     0x8048d3f <phase_2+61>

   0x08048d3a <+56>:    call   0x8049108 <explode_bomb>

   0x08048d3f <+61>:    add    $0x1,%ebx        //ebx = 2;
   0x08048d42 <+64>:    cmp    $0x6,%ebx        //if (ebx < 6)
   0x08048d45 <+67>:    jne    0x8048d2f <phase_2+45>   //do the loop again.

   0x08048d47 <+69>:    add    $0x30,%esp       //add 48 to esp.
   0x08048d4a <+72>:    pop    %ebx
   0x08048d4b <+73>:    pop    %esi
   0x08048d4c <+74>:    pop    %ebp
   0x08048d4d <+75>:    ret   

我有上面的汇编代码,目标是不达到“explode_bomb”。 我评论了我的工作,似乎需要6个数字并检查它们。我发现他们有一个for循环所以下一个数字总是等于前一个数字* 4 - 4,所以我尝试了类似的东西 x,4x-4,4(4x-4)等......其中x> 0但它不起作用。有人能指出这里的问题是什么吗?谢谢你的帮助!

1 个答案:

答案 0 :(得分:1)

啊,再次炸弹了。还没见过这个阶段;)

您似乎对mov -0x4(%esi,%ebx,4),%eaxcmp %eax,(%esi,%ebx,4)感到困惑。算术适用于指针,而不是值。基本上,第一个是array[i-1],第二个是array[i]ebxi(数组索引),esi是基地址。乘以4是因为每个元素的长度为4个字节。

因此,循环就是这样的:

for(i = 1; i != 6; i++)
{
    if (array[i - 1] - i != array[i]) explode_bomb();
}

第一个元素可以是任何大于或等于零的数字,因为这样的可能解决方案是0-1-3-6,{{1 },-10