Explain how the jsr and rts instructions are involved with s
Explain how the jsr and rts instructions are involved with subroutines. Specifically, explain how
the stack pointer is involved with all this
Solution
A subroutine is a section of code which performs a specific task,
 usually a task which needs to be executed by different parts of the program
 Its a specialized program module that may be called upon many times during the
 course of execution of program
 Like,mathematical functions, such as square root (sqrt)
 Because a subroutine can be called from different places in a program, you cannot get
 out of a subroutine with an instruction such as jmp label
 because you would need to jump to different places depending upon which section of
 the code called the subroutine.
 
 Stack applications are to store return addresses during subroutine executions .
 When one wants to call the subroutine, the code has to save the addres where the
 subroutine should return to. It does this by saving the return address on the stack.
 Its to control the transfer of data into or ourt of computer uses an externally generated signal
 called interrupt.
 This is done automatically for you when you get to the subroutine by
 using JSR (Jump to Subroutine)instruction. This instruction pushes the address of the
 instruction. All subroutines must end with either the instruction RTS(return from subroutine)
 or RTR(return and restore condition stores)following the JSR instruction on the stack
 After the subroutine is done executing its code, it needs to return to the address saved
 on the stack.This is done automatically when you return from the subroutine by
 using RTS (Return from Subroutine) instruction. This instruction pulls
 the return address off the stack and loads it into the PC.

