Stack Manipulation

Stack manipulation is again similar to that of O'caml. One can load values to the accumulator from the stack and to specific locations in the stack from the accumulator. Manipulation between stack elements is much more limited, though there are a few special instructions which alter the stack only (for instance, the rev instruction). Return values from functions are normally placed on the stack.

One interesting safety feature of BMD VM is the special treatment of the stack frame. Like the O'caml VM, function calls are set up by pushing the return address onto the stack. This creates a new stack frame record. However, normal pop operations cannot pop this return address. So, one cannot destroy the stack by merely trying to step out of the stack without returning properly.



Mason Smith 2008-06-11