function to square using a stack