Saturday, 9 August 2014

8086 program to find factorial of a number

This is an 8086 program to print out the factorial of a number. If you have any doubts please let me know.
.MODEL SMALL
.DATA
MSG DB 0AH,0DH,'ENTER THE NUMBER: ','$'
MSG2 DB 0AH,0DH,'FACTORIAL: ','$'
NEW DB 0AH,0DH,24H
.CODE
START:
MOV AX,@DATA
MOV DS,AX

LEA DX,MSG
MOV AH,09H
INT 21H

MOV AH,01H
INT 21H


LEA DX,MSG2
MOV AH,09H
INT 21H

MOV CL,AL
MOV CH,00H
SUB CX,30H
CMP CX,00H
JE ZERO

MOV AX,0001H
AGAIN:
MUL CX
LOOP AGAIN
JMP DISPLAY

ZERO: MOV AX,0001H
DISPLAY:    
   MOV BX, 000AH  
   MOV DX, 0000H  
   MOV CX, 0000H  
   
L1:  MOV DX, 0000H  
   DIV BX    
   PUSH DX    
   INC CX    
   CMP AX, 00H  
   JNE L1  
   
L2:  POP DX    
   ADD DX, 30H    
   MOV AH, 02H    
   INT 21H    
   LOOP L2
   LEA DX,NEW
   MOV AH,09H
   INT 21H      

.EXIT
END START

No comments:

Post a Comment