Professional Documents
Culture Documents
Assignment No. 10
Title: Write x86 ALP to find the factorial of a given integer number on a command line by using
recursion. Explicit stack manipulation is expected in the code.
Working Environment:
1. CPU – Core 2 Duo, 64bit with 2.3 GHz clock frequency
2. OS – Fedora 18, 64bit
Tools:
A recursive procedure is one that calls itself. There are two kind of recursion:
i) Direct
ii) Indirect.
In direct recursion, the procedure calls itself and in indirect recursion, the first procedure calls a second
procedure, which in turn calls the first procedure.
Recursion could be observed in numerous mathematical algorithms.
For example, consider the case of calculating the factorial of a number. Factorial of a number is given
by the equation −
Most compilers implement recursion using stacks. When a method is called the compiler pushes the
arguments to the method and the return address on the stack and then transfers the control to the
method. When the method returns, it pops these values off the stack. The arguments disappear and
the control returns to the return address
SE Computer Engineering 2019 Course
Algorithm:
1. Start.
2. Create the text file & write the input data into it and save.
3. Initialize required variables in .data section
4. Declare required variables in .bss section
5. Define macros to display message/data and accept numbers
6. In .text section, display msg "*****Program to find Factorial of a number***** "
7. Display msg "Enter the number : "
8. if(num==1)
9. Display "Factorial is : 0000001"
10. Else
11. call fact_proc (Goto step 14)
12. Exit
13. Stop
14. fact_proc Algorithm:
if (num===1)
{
call Calculate_proc
}
else
{
move 1 into Accumulator
}
Return (goto step 11)
Calculation Procedure:
i) num=num-1
ii) call fact_proc
iii) num=num+1
iv) Content of Accumulator * num
v) Return
Conclusion: Thus we find the factorial of a given integer number on a command line by using
recursion.