Describe Returning Values From Subroutines?
Return from Subroutine : To return from a subroutine is to return execution of code to the point it was before the subroutine was called. Usually a subroutine is called by ‘CALL‘ instruction. At each CALL instruction, the IP and CS of the next instruction is pushed into the stack, before control is transferred to procedure. At the end of the procedure ‘RET’ instruction must be executed. RET is used o return from a subroutine previously called by CALL. When it is executed, the previously stored content if the IP and CS are retrieved into the CS, IP registers from stack and the execution of the main program continues further. Therefore given that calling a subroutine pushes the current address PC+2 onto stack. Returning from a subroutine will return execution at the address calculated by the topmost two bytes of the stack. The most significant byte is popped off the stack first, followed by the least significant byte. Address of the RET is loaded from the stack. After the RET is executed, the stack and its pointers are modified accordingly.