views:

44

answers:

1

Given a number, this program computes the factorial, but it no long works with number bigger than 9

.section .data
.section .text
.globl _start

_start:
pushl $10
movl %eax, %ebx

call func
addl $4, %esp  
movl %eax, %ebx

movl $1, %eax
int $0x80

.type func,@function

func:
    pushl %ebp
    movl %esp, %ebp
    movl 8(%ebp), %eax
    cmpl $1, %eax
    je fim_loop
    decl %eax
    pushl %eax
    call func
    movl 8(%ebp), %ebx
    imull %ebx, %eax

    fim_loop:
        movl %ebp, %esp
        popl %ebp
        ret

after compile and run the program, echo $? should return the result, but this is returning 0 instead of the right result, do anyone know what's wrong with this code?

+1  A: 

seems the exit value of a program is limited in size, I think the highest value is 255, so I should use sys_write or something from libc

killown
Would you mind post the final code?
jyzuz