Return statement ================ In computer programming, a return statement causes execution to leave the current subroutine and resume at the point in the code immediately after the instruction which called the subroutine, known as its return address. The return address is saved by the calling routine, today usually on the process's call stack or in a register. Return statements in many programming languages allow a function to specify a return value to be passed back to the code that called the function. In computer programming, a return statement causes execution to leave the current subroutine and resume at the point in the code immediately after the instruction which called the subroutine, known as its return address. The return address is saved by the calling routine, today usually on the process's call stack or in a register. Return statements in many programming languages allow a function to specify a return value to be passed back to the code that called the function. ==Syntax== Return statements come in many shapes. The following syntaxes are most common: In some assembly languages, for example that for the MOS Technology 6502, the mnemonic "RTS" (ReTurn from Subroutine) is used. ==Yield statements== Cousin to return statements are yield statements: where a return causes a subroutine to terminate, a yield causes a coroutine to suspend. The coroutine will later continue from where it suspended if it is called again. Coroutines are significantly more involved to implement than subroutines, and thus yield statements are less common than return statements, but they are found in a number of languages. ==Call/return sequences== A number of call/return sequences are possible depending on the hardware instruction set, such as the following: The CALL instruction pushes address of the next instruction on the stack and branches to the specified address. The RETURN instruction pops the return address from the stack into the instruction pointer and execution resumes at that address. (Examples: x86, PDP-11) In architectures such as the Motorola 96000, the stack area may be allocated in a separate address space known as the Stack Memory Space, distinct from the main memory address space. The NEC μPD7720 also features a stack with its own separate address space. The CALL instruction places address of the next instruction in a register and branches to the specified address. The RETURN instruction sequence places the return address from the register into the instruction pointer and execution resumes at that address. (Examples: IBM System/360 and successors through z/Architecture, most RISC architectures) The CALL instruction places address of the next (or current ) instruction in the storage location at the call address and branches to the specified address+1. The RETURN instruction sequence branches to the return address by an indirect jump to the first instruction of the subroutine. (Examples: IBM 1130, SDS 9XX, PDP-8) ==See also== Return type Exit status ==Notes== ==References== REFERENCES ---------- BIBLIOGRAPHY (BibTeX) -------------------- @article{ref0, title = {Return statement}, url = {https://encyclopegia.org/a/return-statement} } BIBLIOGRAPHY (RIS) ------------------- TY - JOUR TI - Return statement UR - https://encyclopegia.org/a/return-statement ER - CITE THIS ARTICLE ---------------- Cite this article: Return statement Derived from: https://en.wikipedia.org/w/index.php?oldid=1359237580 Licence: CC BY-SA 4.0 Snapshot: enwiki-001359237580 Permalink: /a/return-statement