What is the need of using two different stacks in same program? How does trap change the current stack of program from user stack to kernel stack? How does it come back to user
It's operating system dependent. The reason to have it is basic security of the operating system. It's by careful design of the operating system itself. For instance some processors have Kernel, Executive, Supervisor and User stacks.