HOME

TheInfoList



OR:

In programming, a spot of a
function Function or functionality may refer to: Computing * Function key, a type of key on computer keyboards * Function model, a structured representation of processes in a system * Function object or functor or functionoid, a concept of object-oriente ...
or subroutine is the location (line of code) where the function is called (or may be called, through
dynamic dispatch In computer science, dynamic dispatch is the process of selecting which implementation of a polymorphic operation (method or function) to call at run time. It is commonly employed in, and considered a prime characteristic of, object-oriented ...
). A call site is where zero or more
arguments An argument is a statement or group of statements called premises intended to determine the degree of truth or acceptability of another statement called conclusion. Arguments can be studied from three main perspectives: the logical, the dialectic ...
are passed to the function, and zero or more return values are received.


Example

// this is a function ''definition'' function sqr(x) function foo()


Assembler example

IBM/360 The IBM System/360 (S/360) is a family of mainframe computer systems that was announced by IBM on April 7, 1964, and delivered between 1965 and 1978. It was the first family of computers designed to cover both commercial and scientific applic ...
or
Z/Architecture z/Architecture, initially and briefly called ESA Modal Extensions (ESAME), is IBM's 64-bit complex instruction set computer (CISC) instruction set architecture, implemented by its mainframe computers. IBM introduced its first z/Architecture ...
* (usually) external call.... R13 usually points to a save area for general purpose registers beforehand * and R1 points to a list of addresses of parameters (if any) LA R1,=A(B) point to (address of) variable 'B' L R15,=A(SQR) Load pointer (address constant) to separately compiled/assembled subroutine BALR R14,R15 Go to subroutine, which returns - usually at zero displacement on R14 * internal call (usually much smaller overhead and possibly 'known' parameters) BAL R14,SQR Go to program label and return In some occasions, return is an efficient method of indicating success or failure. return may be accomplished by returning at +0 or +4,+8, +12, etc. requiring a small
branch table In computer programming, a branch table or jump table is a method of transferring program control ( branching) to another part of a program (or a different program that may have been dynamically loaded) using a table of branch or jump instruction ...
at the return point - to go directly to process the case (as in HLL Switch statement). BAL R14,SQR Go to program label and return (using offset on R14 as return address) B FAIL (RET+0) - SOMETHING WRONG * (RET+4) - O.K. Conventionally however, a return code is set in R15 (0=OK, 4= failure, or similar ..) but requiring a separate instruction to test R15 or use directly as a branch index.


See also

* Function inlining * Subroutine


References

Subroutines {{Compu-lang-stub