Howdy, Stranger!

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

Categories

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 : jeganfernando2000@yahoo.com

Comments

  • digitalpbkdigitalpbk Member Posts: 1
    [code]geti macro
    local exit,get
    xor bx,bx
    mov dx,bx
    mov cx,00ah
    get:
    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
    add bx,ax
    ;redo
    jmp get
    exit:
    mov ax,bx
    endm

    puti macro buffer
    local exit,put
    mov bx,0ah
    lea si,buffer
    add si,06h
    mov BYTE PTR [si],'$'
    put:
    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

    endm

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

    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
    start:
    mov ax,data
    mov ds,ax
    puts msg1
    geti
    push ax
    puts msg2
    pop ax
    mov cx,ax
    dec cx
    jz over
    xor dx,dx
    re:mul cx
    loop re
    over:
    puti buff
    mov ah,4ch
    int 21h
    code ends
    end start
    [/code]

    This program is simple and finds upto 8 or 9! above which the 16 bit register overflows.
    [link=http://digitalpbk.blogspot.com/2008/11/masm-assembly-factorial-program-big.html]http://digitalpbk.blogspot.com/2008/11/masm-assembly-factorial-program-big.html[/link] has a more elaborate code for finding upto 255 factorial (roughly 500 digits)
Sign In or Register to comment.