我新的編程,和我開始閱讀一本書就明白了基本面。我無法理解下面的彙編代碼是如何工作的:它計算一個數字的階乘。我已經對我能理解的說明添加了評論 - 顯然我錯過了一些東西。怎麼做這個遞歸函數的工作
.section .data
.section .text
.globl _start
.globl factorial
_start:
pushl $4
call factorial
popl %ebx
movl %eax, %ebx
movl $1, %eax
int $0x80
factorial:
pushl %ebp # push the base pointer
movl %esp, %ebp # copy the stack pointer to the base pointer
movl 8(%ebp), %eax # move the value 4 to %eax
cmpl $1, %eax # compare it to 1
je end_factorial # jump to end_factorial if it's equal
decl %eax # else decrease the value by 1
pushl %eax # push the decreased value in the stack
call factorial # this means that it should start again (?)
popl %ebx # that's the part that i don't understand
incl %ebx # when are these lines excuted? since it
imul %ebx, %eax # keeps starting from the top, until the value
# of %eax is 1 then, it jumps to end_factorial
end_factorial:
movl %ebp, %esp
popl %ebp
ret`
哪一部分難以理解?哪部分不起作用? – Hodrobond
該程序的工作原理,我不明白的唯一部分是遞歸函數階乘,以及它如何計算,並感謝迴應 – ech0