memory - understanding the use of stacks in programming language implementation -


i going through paper(probably famous one, on implementation of dialect of scheme new ,the paper abdulaziz ghuloum ).

this got hint of when , how stacks used during execution of program .but on further reflection got bit confused , thought of clearing out here .

so understanding use stacks when want save local variables , values of registers can use registers "eax" carry on computation needs done separately ,and won't loose earlier values stored in register .

so example have c code snippet following :

function mult(int , int k ) {    return(a*k); }  void main () { int a,b,c,d;   = + b ;   b = b + c;   c  = mul( b,d); } 

so in above code snippet when main function executed stack space allocated . during first code instruction , "eax" register utilized store new value of "a" obtained after addition. second code instruction adding "b" , "c", need "eax" register again doing overwrite value of "a" stored in "eax". such save value of "a" in location in stack , proceed our addition . , when reach code line calls function "mul" , have stack created function "mul" , first pushed values in stack address of next instruction . push latest computed value in main function stack created , push values of arguments being passed function "mul" in stack meant , carry on computations in function mul in similar manner. understanding of state of affairs correct ? besides , have following 2 related questions :

  1. how addresses base pointers of stack assigned .i mean how decided should stack of first function start , should 1 second function begin ? there rule fixed amount of size allocated each stack , let's "n" number of memory cells , next stack begins @ "address in base pointer of first stack " + "n * memory size of each memory cell " ?

    1. when need change value of local variable , place updated value in location corresponding in stack need pop out values pushed after ,place them in separate location , place updated value , push popped out values 1 one stack ?

    thanks in advance. please correct understanding wheresoever wrong .


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -