Tag Archives: assembly language program to find factorial of a number

COMPUTE nCr USING RECURSION PROCEDURE – Assembly Language Program

.MODEL SMALL

.STACK

.DATA
N DW 5
R DW 4
NCR DW 1
msg db “The nCr is :$”

.CODE
MOV AX,@DATA
MOV DS,AX
MOV BX,N
INC BX
MOV CX,R
CALL NCP
lea dx,msg
mov ah,09h
int 21h
mov ax,ncr
call ascii
MOV AH,4CH
INT 21H

NCP PROC NEAR
CMP CX,00H
JE L1
PUSH CX
DEC CX
CALL NCP
MOV AX,BX
POP CX
SUB AX,CX
MUL NCR
DIV CX
MOV NCR,AX
L1: RET
NCP ENDP

ASCII PROC NEAR
MOV BX,AX
AND AX,0F000H
MOV AL,AH
MOV CL,4
SHR AL,CL
CALL DISP
MOV AX,BX
AND AX,0F00H
MOV AL,AH
SHR AL,CL
CALL DISP
MOV AX,BX
AND AL,0F0H
SHR AL,CL
CALL DISP
MOV AX,BX
AND AL,0FH
CALL DISP
RET
ASCII ENDP

DISP PROC NEAR
CMP AL,0AH
JB SKIP
ADD AL,7
SKIP: ADD AL,30H
MOV DL,AL
MOV AH,02
INT 21H
RET
END