Thursday, February 10, 2011

Factorial


%OUT-------------------------------------------------------------------------
%OUT- Factorial of a number (upto 5)
%out- input: Enter the Number
%out- output: The computed factorial
%out – author: Ayon and Ariyam
%OUT-------------------------------------------------------------------------

if1
include macrolib.lby
endif

.model small
.stack
.data
msg db "Enter value (<=05h): ","$"
error_str db " INPUT VALUE GREATER THAN 5!!","$"
str1 db " Factorial of ","$"
str2 db " is ","$"

.code
factorial proc
showmsg msg
input
push ax
cmp al,05h ;check if value greater than 5
ja error
mov ah,00h
mov cx,ax
dec cx
lp: mul cl
loop lp
pop bx ;get the original inout
push ax ;save the result
mov bh,bl
showmsg str1
output
showmsg str2
pop ax
mov bh,al
output
jmp done
error: showmsg error_str ;show error statement
done: exit
factorial endp
end factorial

No comments:

Post a Comment

Do you think this information useful or was not up to the mark? Comment if you have any advices or suggestions about the post.