Assembly 汇编程序中的这段代码是做什么的?

Assembly 汇编程序中的这段代码是做什么的?,assembly,Assembly,我得到了下面的代码,现在试着去理解它 数组指向一个足够大的内存,在.bss中,代码用0预初始化 1 fib : file format elf 32−i386 2 3 Disassembly of section.text : 4 5 0 x08048080 <start>: 6 0 x08048080 : mov eax , 0x80490d0 <array> 7 0 x08048085 : push eax 8 0 x08048086 : mov eax , 0 x3

我得到了下面的代码,现在试着去理解它

数组指向一个足够大的内存,在.bss中,代码用0预初始化

1 fib : file format elf 32−i386
2
3 Disassembly of section.text :
4
5 0 x08048080 <start>:
6 0 x08048080 : mov eax , 0x80490d0 <array>
7 0 x08048085 : push eax
8 0 x08048086 : mov eax , 0 x3
9 0 x0804808b : push eax
10 0 x0804808c : call 0 x8048098 <fib>
11 0 x08048091 : pop eax
12 0 x08048092 : pop eax
13 0 x08048093 : jmp 0 x80480c1 <Lend>
14
15 0 x08048098 <fib>:
16 0 x08048098 : mov ebx , [esp+0x8]
17 0 x0804809c : mov ecx , 0 x2
18 0 x080480a1 : xor edx , edx
19 0 x080480a3 : mov [ebx] , edx
20 0 x080480a5 : mov eax , 0x1
21 0 x080480aa : mov [ebx+0x4] , eax
22 0 x080480ad : jmp 0 x080480ba <Lloop_cond>
23
24 0 x080480b2 <Lloop >:
25 0 x080480b2 : push eax
26 0 x080480b3 : add eax , edx
27 0 x080480b5 : mov [ebx+ecx∗4] , eax
28 0 x080480b8 : pop edx
29 0 x080480b9 : inc ecx
30
31 0 x080480ba <Lloop_cond>:
32 0 x080480ba : cmp ecx , [esp+0x4]
33 0 x080480be : jle 0x080480b2 <Lloop>
34 0 x080480c0 : ret
35
36 0 x080480c1 <Lend>:
37 0 x080480c1 : mov ebx , 0 x0 ; Exit code 0 = success
38 0 x080480c6 : mov eax , 0 x1 ; Select System call exit
39 0 x080480cb : int 0 x80 ; System call
40
41 Disassembly of section.bss :
42
43 0 x080490d0 <array>:
44 . . .
1fib:文件格式elf 32−i386
2.
3节的分解。文本:
4.
5 0 x0804800:
6 0 X0804800:mov eax,0x80490d0
7 0 x08048085:推送eax
8 0 x0804086:mov eax,0 x3
9 0 x0804808b:推送eax
10 0 X080408C:致电0 x8048098
11 0 x08048091:pop eax
12 0 x08048092:pop eax
13 0 x08048093:jmp 0 x80480c1
14
15 0 x08048098:
16 0 x08048098:mov ebx[esp+0x8]
17 0 x0804809c:mov ecx,0 x2
18 0 x080480a1:xor edx,edx
19 0 x080480a3:mov[ebx],edx
20 0 x080480a5:mov eax,0x1
21 0 x080480aa:mov[ebx+0x4],eax
22 0 x080480ad:jmp 0 x080480ba
23
24 0 x080480b2:
25 0 x080480b2:推送eax
26 0 x080480b3:添加eax、edx
27 0 x080480b5:mov[ebx+ecx∗4] ,eax
28 0 x080480b8:pop edx
29 0 x080480b9:inc ecx
30
31 0 x080480ba:
32 0 x080480ba:cmp ecx[esp+0x4]
33 0 x080480be:jle 0x080480b2
34 0 x080480c0:ret
35
36 0 x080480c1:
37 0 x080480c1:mov ebx,0 x0;退出代码0=成功
380x080480c6:mov-eax,0x1;选择系统调用退出
39 0 x080480cb:int 0 x80;系统调用
40
41.bss节的拆卸:
42
43 0 x080490d0:
44 . . .
它要求或需要我提供我的想法,但我担心这会使人困惑,而不是带来好处。
谢谢你的建设性帮助

该函数被称为
fib
,它正在生成一个Fibonacci序列数组。工作主体按照标签
Lloop
后面的几个说明完成

Lloop:
    push eax                ; save current term
    add eax , edx           ; add previous term
    mov [ebx+ecx*4] , eax   ; write to array
    pop edx                 ; retrieve previous term for next loop
    inc ecx                 ; loop control and array index

Lloop_cond:
    cmp ecx , [esp+0x4]     ; end test
    jle Lloop               ; repeat
    ret                     ; done

剩下的就交给你了。

所以已经给出了正确的答案,这个问题的原因可能不太清楚,但我也需要进行组装,这是一个有趣的练习

我的反向工程fib归结为以下功能:

void fib_simple(int* array, int n)
{
    int i, j, tmp;
    int count = 2;

    array[0] = i = 0;
    array[1] = j = 1;

    for (count = 2; count <= n; count++) {
        tmp = j;
        j = array[2] = i + j;
        i = tmp;
    }
}
void fib_simple(int*数组,int n)
{
int i,j,tmp;
整数计数=2;
数组[0]=i=0;
数组[1]=j=1;

对于(count=2;count我注意到,几年前,这个问题在一所德国大学里被用作一个答案。如果没有你的想法和你目前对代码的理解,或者你不理解的某个特定问题,那么你现在就出现在要求我们做你的家庭作业。@MichaelPetch这似乎是从字面上抄袭过来的。@从你链接的PDF来看。@MichaelPetch如果你非常擅长研究,那么你也知道目前德国有假期,假期期间没有家庭作业,因此我问你是因为我想知道,不是因为我需要对下一个家庭作业发表好的评论。但不管怎样。通常情况下,你不会得到有用的评论(甚至不谈论答案),但有时这些评论仍然足以进行逆向工程,并理解事物是如何工作的。在你的问题中,你说“这要求或需要我提供我的想法,”。我要求你提供你的想法。编辑你的问题,告诉我们你学到了什么,你认为一些代码在做什么,如果你对代码有一个具体的问题,你不理解,你可以问。无论是否在度假都不相关。这是几年前的考试问题/家庭作业的准确副本,我会我不认为让学生做这类问题的所有工作对学生来说特别有用,因为这不会让学生自己思考啊。绿色的勾号很快被取消,取而代之的是否决票。太好了!我已经在页面顶部回答了问题,并注释了代码的重要部分。这是什么你期待吗?你在这里不会得到感激或感谢。但不管怎样。我感谢你的回答。我使用它,重新编辑我的问题,并用我的评论标记我的进度。那么你为什么撤销绿色勾号?你期待一个完全的逆向工程吗?这里的人真的在乎吗?我不期望对代码进行完整的解释,那就是疯狂+有点粗鲁。一个“基本”的想法或代码的目的,你可以在一行评论中写出来的东西,实际上已经足够了。我喜欢这个问题,并且或多或少为自己解决了它,因为已经给出了正确的答案,OP理解了这个问题。我的帖子不仅仅提供了想法,而且直接解决了家庭作业。(不完全是这么说的)
void fib(int* array, int n)
{
    int ecx, edx, tmp;

    /* mov ebx , [esp+0x8]; ebx is the array */
    /* mov ecx , 0x2; ecx is a counter, starting from 2 */
    ecx = 2;

    /* xor edx, edx  ; set edx to zero     */
    edx = 0;

    /* mov [ebx], edx; set array[0] to edx */
    array[0] = edx;

    /* mov eax , 0x1 */
    eax = 1;

    /* mov [ebx+0x4] , eax */
    array[1] = 1;

    /* The while loop condition is checked with a loop condition:
    <Lloop_cond>:          ; place to jump back to every iteration
    cmp ecx , [esp+0x4]    ; compare to n
    jle 0x080480b2 <Lloop> ; if ecx <= n, jump to loop
    */
    while (ecx <= n) {
        /*
        This is the inner loop
        <Lloop >:
        */

        /* push eax; eax is temporarily saved to stack */
        tmp = eax;

        /* add eax, edx */
        eax += edx;

        /* mov [ebx+ecx∗4], eax */
        array[ecx] = eax;

        /* pop edx */
        edx = tmp;

        /* inc ecx */
        ecx++;
    }

    /* ret */
    return;
}