5.9. 5.9 Recursion
Recursion occurs when a procedure calls itself. The following, for example, is a recursive procedure:
procedure Recursive; begin Recursive; Recursive(); end Recursive;
Of course, the CPU will never return from this procedure. Upon entry into Recursive, this procedure will immediately call itself again and control will never pass to the end of the procedure. In this particular case, runaway recursion results in an infinite loop.[96]
[96] Well, not really infinite. The stack will overflow and Windows or Linux will raise an exception at that point.
Like a looping structure, recursion requires a termination condition in order to stop infinite recursion. Recursive could be rewritten with a termination condition as follows:
procedure ...
Get Art of Assembly Language, 1st Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.