fixed register saving and stack overflow checking