Program for finding factorial

Can any one post me a program for finding the factorial of a given number using 8086 Microprocessor. i am new for assembly language and curious to learn more.....

my mail id :


  • [code]geti macro
    local exit,get
    xor bx,bx
    mov dx,bx
    mov cx,00ah
    push bx
    ;Read character
    mov ah,01h
    int 21h
    xor ah,ah
    pop bx
    ;If enter stop
    cmp al,0dh
    jz exit
    sub al,30h
    ;Multply By 10
    push ax
    mov ax,bx
    mul cx
    mov bx,ax
    pop ax
    add bx,ax
    jmp get
    mov ax,bx

    puti macro buffer
    local exit,put
    mov bx,0ah
    lea si,buffer
    add si,06h
    mov BYTE PTR [si],'$'
    xor dx,dx
    dec si
    div bx
    add dl,30h
    mov [si],dl
    cmp ax,0h
    jnz put

    mov dx,si
    mov ah,09h
    int 21h


    puts macro msg
    push ax
    push dx
    mov dx,offset msg
    mov ah,09h
    int 21h
    pop dx
    pop ax

    data segment
    msg1 db 0dh,0ah,"Enter Number : $"
    msg2 db 0dh,0ah,"Factorial : $"
    buff db 20 dup(?)
    data ends

    assume cs:code,ds:data
    code segment
    mov ax,data
    mov ds,ax
    puts msg1
    push ax
    puts msg2
    pop ax
    mov cx,ax
    dec cx
    jz over
    xor dx,dx
    re:mul cx
    loop re
    puti buff
    mov ah,4ch
    int 21h
    code ends
    end start

    This program is simple and finds upto 8 or 9! above which the 16 bit register overflows.
    [link=][/link] has a more elaborate code for finding upto 255 factorial (roughly 500 digits)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion