
190 Compilers – Principles and Practice
addressing within the called function. The call arguments are available at (BP) + 4, (BP) + 6 and
(BP) + 8. The return address is at (BP) + 2 and the caller’s BP is at (BP).
The actions within the called function are:
1. Push BP: the caller’s BP is saved in the stack;
2. Copy SP to BP: set up the current frame (base) pointer;
3. Do whatever computation for this function, but do not disturb BP;
4. Pop BP, the caller’s BP restored;
5. Return from this function. Note that the return address will be at TOS.
The relevant code in function test(), assuming that it does not use any local variables, is:
test:
pushw ...