Functions

Function is a smaller part of the software which is used for a perticular operation and returns a value the the function that is called it, or not.

Likewise, a function might require a parameter or set of parameters as a input.

A function can call sub-functions also called sub-routines in order to break down a complex algorithm.

Having said that, it becomes obvious that when a function is called, something changes in the execution flow of the program. Instructions in memory are executed one after another, and s we noted in the previous chapter the instruction pointer (IP) aiways points to the memory- location of the next instruction to be executed:

Having said that, it becomes obvious that when a function is called, something changes in the execution flow of the program.

Instructions in memory are executed one after another, and as we noted in the previous chapter, the instruction pointer (1P) always points to the memory location of the next instruction to be executed.

So, when the program needs to call a function and trafisfer execution flow o that function,the program needs a way to remember where execution left off.

“This is required in order for the program to be able o continue once the function is complete: to feturn and continue executing the next instruction after the one that transferred the execution to the function.

‘Also, that function may need a set of parameters in afder to ‘operate properly, and in addition to this we might wantto preserve some register values in order o be able o retrieve them once we exit the function.

“This is where the procedure stack comes into play - also known as “the stack'.

‘The stack is a reserved memory area inside a specific segment called the stack segment, which is dentified by the segment selector inside the SS register.

“The term ‘reserved s used i this case in order to indicate: ts special use during program execution

Last updated