Search This Blog

Wednesday, January 2, 2013

;Q.2 Write a Program to find factorial
; Assume input from memory directly

data segment
     number dw 05h ; input number
     fact dw 00h   ; factorial of number..
ends

code segment
start:
    ; set data segment register
    mov ax, data
    mov ds, ax                        
    mov ax, 01h    ; init AX to 1 for multiplication
    mov bx, number ; move number into BX           
repeat:
    mul bx
    dec bx
    jnz repeat;  fact = n(n-1)(n-2).....
                                       
    mov fact, ax ; copy result into fact
                                       
    ; end of factorial finding
   
    mov ax, 4c00h ; exit to operating system.
    int 21h       ; 21 is DOS interrupt ......... value is ax determines operation
ends

end start ; set entry point and stop the assembler.

No comments:

Post a Comment