modified HOF to use the stack instead of registers.