Saturday, September 10, 2011

TASM Program Source Code to Find Factorial of a Number

The TASM Assembly Program given below can be used to find the factorial of a number.The Complete Source Code is given below.Check it out and do respond to the post if you have any doubts.
 readnum macro num  
     mov ah,01h  
     int 21h  
     sub al,'0'  
     mov bh,0ah  
     mul bh  
     mov num,al  
     mov ah,01h  
     int 21h  
     sub al,'0'  
     add num,al  
 printstring macro msg  
     mov ah,09h  
     mov dx,offset msg  
     int 21h  
 data segment  
     cr equ 0dh  
     lf equ 0ah  
     msg1 db 'enter the number',cr,lf,'$'  
     msg2 db 'the factorial is','$'  
     num db ?  
     result db 20 dup('$')  
     data ends  
 code segment  
     assume cs:code,ds:data  
        mov ax,data  
        mov ds,ax  
        printstring msg1  
        readnum num  
        mov ax,01h  
        mov ch,00h  
        mov cl,num  
        cmp cx,00  
        je skip  
       mov dx,00  
       mul cx  
       loop rpt1  
       mov si,offset result  
       mov bl,[si]  
       call hex2asc  
       printstring msg2  
       printstring result  
       mov ah,4ch  
       mov al,00h  
       int 21h  
       hex2asc proc near  
       push ax  
       push bx  
       push cx  
       push dx  
       push si  
       mov cx,00h  
       mov bx,0ah  
       mov dx,00  
       div bx  
       add dl,'0'  
       push dx  
       inc cx  
       cmp ax,0ah  
       jge rpt2  
       add al,'0'  
       mov [si],al  
 rpt3:pop ax  
       inc si  
       mov [si],al  
       loop rpt3  
       inc si  
       mov al,'$'  
       mov [si],al  
       pop si  
       pop dx  
       pop cx  
       pop bx  
       pop ax  
       hex2asc endp  
       code ends  
 end start  

No comments:

Post a Comment

Which is the Best Photo Watermarking Software

Photo Theft is becoming more and more common in the web with the outburst of social websites like Facebook,Google Plus and Image sharing se...