ronaldmaas wrote
Implementing a function [header] is defined as:
g:
repeat nVars times:
push 0
Does this mean that the assembler code loops round nVars times, generating commands to push 0 onto the stack, or does it mean the assembler needs to generate asm code to loop round nVars times?
...
or use asm code to loop round, store nVars in a temp register, and loop round in the asm code until the temp register becomes 0, and the required number of push 0 has been performed.
You can do it either way, what matters is what the Hack machine state is at the end of the header code.
If your translator loops calling writePush("const", 0) you end up with longer code; if your translator writes code that loops, you end up with shorter code that runs a bit slower.
You can write shorter linear code by eliminating extra SP increments. Write all the zeros, then add
nVars to SP.
My translator chooses between these options based on
nVars so that it writes the shortest code.
--Mark