added function to store registers to stack.