Das erstellen und aufrufen-Funktion in x86 Assembler (AT&T-syntax)

Bitte geben Sie mir ein sehr einfaches Beispiel von erstellen einer Funktion und Aufruf in x86 Assembler (AT&T-syntax). Actaully, ich bin versucht, zu erstellen eine Funktion, die berechnet factorial einer Zahl. Dies ist, was ich getan habe :

#include<syscall.h>
#include<asm/unistd.h>
# Calculates Factorial, Argument is passed through stack
.text
.global _start
_start:
    pushl $5       #factorial of this value will be calculated
    call Fact
    movl %eax, %ebx #eax contains the result, Result is the return val of the program
    movl $1, %eax
    int $0x80
    ret
Fact:
    popl %ebx     #Return address
    popl %edx
    movl $1, %ecx #Will be used as a counter
    movl $1, %eax #Result(Partial & complete) will be stored here
    LOOP:
        mul %ecx
        inc %ecx
        cmp %ecx, %edx
        jle LOOP
    pushl %ebx    #Restore the return address
    ret

Ich bin immer Segmentation Fault Fehler, wieder und wieder. Ich bin mit GAS auf Ubuntu.

InformationsquelleAutor batman | 2012-09-03
Schreibe einen Kommentar