How functions work in low level ?

 BY USING PROCESSOR REGISTERS

    Arguments that we pass to functions and results given by functions are nothing but parameters and the exchange of these data is called parameter passing. Parameter passing can be done by processor registers, processor stack, or by using memory stack.

    What we will do is we will use registers 2,3,4,5 for parameter passing and data manipulation, but this is good when we require fewer parameters but when the number of parameters increases we cant use processor registers as these registers are limited. 






BY USING PROCESSOR STACK

    The address of the start of the array and the number of elements in the array are pushed in the stack and adding function is called when adding a function called this function computes the sum and places the result on the stack.
    
    As the subroutine uses 4 registers it needs to save the content of these 4 registers somewhere so it pushes the content of all 4 registers on the stack computes the sum and stores the sum in a place where starting address is stored in the stack. After that contents of all registers are restored and the return is called.

Comments

Popular posts from this blog

3 MAPPING TECHNIQUES

VIRTUAL MEMORY

ADJACENT MATRIX