You are on page 1of 2

name nCr page 60,80 title computation of nCr using recursion .model small .stack 64 .data n db 4 r db 2 res db ? .

code main: mov ax,@data mov ds,ax mov al,n mov bl,r call ncr int 3

ncr proc cmp al,bl je p8 cmp bl,0 je p8 cmp bl,1 je p10 ;if r=1 then ncr=n ;if r=0 then ncr=1 ;if n=r then ncr=1

dec al cmp bl,al je p9 push ax push bx call ncr pop bx pop ax dec bl push ax push bx call ncr pop bx pop ax ret p8: inc res ret p9: p10: inc res

;n-1 ;if r=n-1 then ncr=n

;(n-1)Cr ; ;

; ; ; ;(n-1)C(r-1)

add res,al ret align 16

ncr endp end main

You might also like