Assembly Recursion
Arecursion procedure is one that calls itself. There are two kinds of recursion: direct and indirect. In direct recursion, the procedure calls itself and in indirect recursion, the first procedure calls a second procedure, which in turn, cal s 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:
For example: factorial of 5 is 1 x 2 x 3 x 4 x 5 = 5 x factorial of 4 and this can be a good example of showing a recursive procedure. Every recursive algorithm must have an ending condition i.e., the recursive calling of the program should be stopped when a condition is fulfilled. In the case of factorial algorithm the end condition is reached when n is 0.
The following program shows how factorial n is implemented in assembly language. To keep the program simple, we will calculate factorial 3.