Hello everyone. I haven't started to write the program yet but I have the guidelines to make it. They are :

Write a function in assembly language called “factorial” with the following prototype:

integer factorial(integer n)

Pre-Conditions:

“n” is an integer (positive or negative)

“n” has been passed in as a parameter via the stack.

Postconditions: Let the register EAX return the answer.

EAX will either be

a positive number (meaning a valid answer was found)

a -1 representing an error of “n” being negative

or a “-2” represent an overflow (ie an answer too large to be accommodated by 32 bits)

(NOTE: No input or output should happen inside of “factorial”, only the math operations and the returning of a answer via EAX)

Explanation of Factorial

Given an integer “n” the function should find the factorial of that integer. In other words the function should simulate the “n!” on your calculator. The factorial function (n!) means find the product of all numbers from 1 up to “n.”

For example:

3!=1 x 2 x 3 = 6 4! = 1 x 2 x 3 x 4 = 24

Important notes:

Factorials are only defined for positive numbers. So if your function is passed a negative number let your function return a “-1” representing an error code.

By definition the factorial of “0” is “1” (0! = 1)

Check for “overflow.” Factorial gets large very quickly.

For example:

8!= 1x2x3x4x5x6x7x8=40320

If “n” generates an overflow then let your function return a “-2” representing an “overflow” errorcode.

How to test your function:

Call your function from a main program. In the main program prompt the user to enter an integer (positive or negative). Then pass this integer (n) as a parameter (using the stack) to your factorial function. Your factorial function should then return its answer via EAX.

OUTPUT the following in MAIN

Based on the value of EAX, display either:

The factorial of “n” is #### (i.e. a EAX contain a valid answer)

The factorial of “-n” is undefined (i.e. EAX contains a “-1”)

Or

The factorial of “n” cannot be computed accurately because it’s answer has caused an overflow (i.e. EAX contains a “-2”).

Now i'm not too sure on how to do this so if somebody could give me some guidelines that'd be great. Thanks a lot!