Ich bin neu in der Programmierung, und ich fange an, ein Buch darüber zu lesen, um die Grundlagen zu verstehen. Ich konnte nicht verstehen, wie der folgende Assembler-Code funktioniert: Er berechnet den Faktor einer Zahl. Ich habe Kommentare zu den Anweisungen hinzugefügt, die ich verstehen kann - klar, dass mir etwas fehlt.wie funktioniert diese rekursive Funktion
.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`
Welchen Teil haben Sie Schwierigkeiten zu verstehen? Welcher Teil funktioniert nicht? – Hodrobond
das Programm funktioniert, der einzige Teil, den ich nicht verstehe, ist die rekursive Funktion Fakultät, und wie es berechnet, und danke für die Antwort – ech0