Find limit of recursion: Difference between revisions
m
→{{header|Z80 Assembly}}
Puppydrum64 (talk | contribs) (added section for Z80 Assembly) |
Puppydrum64 (talk | contribs) |
||
Line 3,249:
=={{header|Z80 Assembly}}==
Unlike the 6502, the Z80 has a 16-bit stack pointer that is fully relocatable. Therefore, the limit of recursion technically depends on how much RAM you have
To give the maximum limit, we'll say that there is only one variable (we need one to store the stack pointer), and the entire address space of the CPU exists and is in RAM (i.e. 64k of RAM, including the beginning vector table, program code, and stack space, no address mirroring. Also we'll assume there is no "video memory" or anything not intended for a specific purpose.) A byte count of each line of code is also provided.
(For a more realistic example see this task's entry for 8080 Assembly.)
<lang z80>org &0000
Line 3,276:
* The <code>CP</code> instruction only compares the accumulator to an 8 bit register, so to compare HL to BC we actually have to subtract them. If the result is zero, they were the same to begin with.
* If they're different, then the act of pushing AF clobbered the stack pointer we backed up in step 1. This means recursion is at its limit, so quit looping and halt the CPU.
=={{header|zkl}}==
|