خرید بک لینک

Vote count: 0

I've written some code (main in c, subprogram in assembly x86) to calculate the binomial coefficient recursively and print out all the binomial coefficients with n=10, restricted by m<=n.

My problem is that I'm getting a segfault on compile.

Segmentation fault (core dumped)

Here's the main program:

#include <stdio.h>

unsigned int result,m,n,i;
unsigned int binom(int,int);
int main(){

n=10;


for (i=0; i<n+1;i++){
printf("i=%d | %d n", i, binom(n,i) );
}

retu;


}

And the recursive sub program:

    .text
    .globl  binom

binom: 
    mov     $0x00, %edx     #for difference calculation
    cmp     %edi, %esi          #m=n?
    je      equalorzero         #jump to equalorzero for retuing of value 1
    cmp     $0x00, %esi         #m=0?
    je      equalorzero     
    cmp     $0x01, %esi         #m=1?

    mov     %esi,%edx
    sub     %edi, %edx
    cmp     $0x01, %edx         # n-m = 1 ?
    je      oneoronedifference  

    jmp     otherwise

equalorzero:
    add     $1, %eax            #retu 1
    ret 

oneoronedifference:
    add     %edi, %eax          #retu n
    ret

otherwise:
    sub     $1, %edi            #binom(n-1,m) 
    call    binom       
    sub     $1, %esi            #binom(n-1,m-1)
    call    binom

asked 36 secs ago

- - , .
.

برچسب: نویسنده: استخدام کار تاريخ: شنبه 26 تير 1395 ساعت: 10:50

صفحه بندی