本文介绍了大会 - JS与JA指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我们的目标是为我写出对应于此装配C code:

So the goal is for me to write out the C code that corresponds to this assembly :

0:  85 f6                   test   %esi,%esi
2:  78 13                   js     17 <part3+0x17>
4:  83 fe 07                cmp    $0x7,%esi
7:  77 14                   ja     1d <part3+0x1d>
9:  8d 0c f5 00 00 00 00    lea    0x0(,%rsi,8),%ecx
10: 48 d3 ff                sar    %cl,%rdi
13: 48 89 f8                mov    %rdi,%rax
16: c3                      retq
17: b8 00 00 00 00          mov    $0x0,%eax
1c: c3                      retq
1d: b8 00 00 00 00          mov    $0x0,%eax
22: c3                      retq

我有点困惑,因为第一个循环测试%ESI寄存器结束第二循环结束了。

I am a little confused because the first loop testing the %esi register ends before the second loop ends.

时的if语句比较%ESI至7的第一个循环内的第二次?或者这是一个如果,否则,如果情??

Is the second if statement comparing %esi to 7 inside the first loop? or is this a if , else if situation??

推荐答案

让我总结一下,什么已经说过

Let me sum up, what's already been said

0:  85 f6                   test   %esi,%esi
2:  78 13                   js     17 <part3+0x17>

这是如果(ESI℃下)转到17;

this is " if (esi < 0) goto 17; "

4:  83 fe 07                cmp    $0x7,%esi
7:  77 14                   ja     1d <part3+0x1d>

这是如果(ESI> 7)转到1D;

this is " if (esi >7) goto 1d; "

9:  8d 0c f5 00 00 00 00    lea    0x0(,%rsi,8),%ecx

CX = 8 * RSI//不是很明显它的只是一个乘法)

"cx = 8*rsi" // not that obvious it's "just" a multiplication)

10: 48 d3 ff                sar    %cl,%rdi

RDI >> CL; //没有CX,但CX是安全的,是&LT; = 7 * 8,所以这是相同的
    13:48 89 F8 MOV%RDI,RAX%
    16:C3 retq

rdi >> cl; // not cx, but cx is safe to be <= 7*8, so that's the same 13: 48 89 f8 mov %rdi,%rax 16: c3 retq

返回RDI;

17: b8 00 00 00 00          mov    $0x0,%eax
1c: c3                      retq

17返回0

1d: b8 00 00 00 00          mov    $0x0,%eax
22: c3                      retq

1D:另一个返回0

1d: another "return 0"

所以C- code是:

so the C-Code is:

{
    if (esi < 0) return 0;
    if (esi > 7) return 0;
    return rdi >> ( 8 * rsi );
}

PS:2返回0(第17和1D)表示他们不会在一个组合的如果
PSS:有C code的显然不是编译优化:P

PS: the 2 "return 0" (17 and 1d) indicate they're NOT combined in one "if"PSS: there C Code was obviously not compiled with optimization :P

这篇关于大会 - JS与JA指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 21:10