In a certain computer system, there is special instruction implemented to call subroutines. The instruction is
JSR Reg.Sub
Microsequence: Temp ← Sub
SP ← (SP)+2
(SP) ← (Reg)
Reg ← (PC)
PC ← (Temp)
Where
- Temp is an internal CPU register
- Sub is calling routine address specification
- Reg is any register in the system
- SP is stack pointer
- PC is program counter
- (SP) refers to the contents of SP.
The system supports indirect addressing and autoincrement addressing modes. PC can be used as a link register. Sub field in the JSR instruction allows any operand specification, including the use of stack pointer along with some addressing modes.
Explain how you would implement co-routine using the JSR instruction. Show the control flow diagram and the contents of the stack before and after the call.