我新的编程,和我开始阅读一本书就明白了基本面。我无法理解下面的汇编代码是如何工作的:它计算一个数字的阶乘。我已经对我能理解的说明添加了评论 - 显然我错过了一些东西。怎么做这个递归函数的工作
.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