简体   繁体   English

汇编语言为C代码?

[英]Assembly language to C code?

I'm trying to figure out what this block of assembly code is doing: 我试图找出这个汇编代码块正在做什么:

mystery:
.LFB0
    testl   %edi, %edi
    je      .L3
    subq    $8, %rsp
    shrl    $2, %edi
    call mystery
    addq    $1, %rax
    jmp     .L2
.L3:
    movl    $l, %eax
    ret
.L2:
    addq    $8, %rsp
    ret

So far I have this as the C code: 到目前为止,我将此作为C代码:

long mystery(unsigned n){
    if(n==0)
       return 1;

And I get that there is a recursive function going on here while n!=0 but I don't understand what the %rsp register is doing 而且我知道这里有一个递归函数,而n!= 0但是我不明白%rsp寄存器在做什么

Here's my guess: 这是我的猜测:

#include <inttypes.h>

int64_t mystery(int32_t n) {
    if (n == 0) {
        return 1;
    }

    return 1 + mystery(n / 4);
}

I don't know what the $l is in the line: 我不知道$l在行中是什么:

movl    $l, %eax

so my above solution assumes it's a typo for $1 . 所以我的上述解决方案假设这是$1的拼写错误。 Enlighten me. 开导我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM