Understanding stack frame of function call in C/C++? -


i new c/c++ , assembly lang well. basic question. trying understand how stack frames built , variables(params) pushed stack in order?. search results showed that....compiler of c/c++ decides based on operations performed within function. e.g if function suppose increment value 1 of passed int param , return (similar ++ operator) put ..the param of function , local variable within function in registers , perform addition ....wondering register used returned/pass value ?....how references returned? .....difference b/w eax, ebx,ecx , edx.

requesting book/blog/link or kind of material understand registers,stack , heap references used/built , destroyed during function call's....and how main function stored? in advance

your question borderline here. programmers better place.

a book understand concepts of stack etc might queinnec's lisp in small pieces (it explains quite stack lisp). also, sicp book read.

d.knuth's books , mmix read.

read wikipedia call stack page.

in theory, no call stack needed, , languages , implementations (e.g. old sml/nj) did not use stack (but allocated call frame in garbage collected heap). see a.appel's old paper garbage collection can faster stack allocation (and learn more garbage collection in general).

usually c , c++ implementations have stack (and use hardware stack). c local variables might not have stack location (because have been optimized, or kept in register). sometimes, stack location of c local variable may change (the compiler use 1 call stack slot occurrences, , call stack slot other occurrences of same local variable). , of course temporary values may compiled local variables (so stay in register, on in 1 stack slot one, etc....). when optimizing compiler weird tricks variables.

on old machines ibm/360 or ibm z/series, there no hardware stack; stack used c compiler software convention (e.g. register dedicated usage, without specific hardware support)

think execution (or interpretation) of recursively defined function (like old factorial naively coded). read recursion (in general, in computer science), primitive recursive functions, lambda calculus, denotational semantics, stack automaton, register allocation, tail calls, continuations, abi, interrupts, posix signals, sigaltstack(2), getcontext(2), longjmp(3)etc.... etc...

read books computer architecture. in practice, call stack important several hardware resources (including stack pointer register, call frame base pointer register, , perhaps hidden machinery e.g. cache related) dedicated on common processors.

you @ intermediate representations used gcc compiler. use -fdump-tree-all or gcc melt probe. if looking @ generated assembly sure pass -s -fverbose-asm gcc command.

see linux assembly howto.

i gave lot of links. difficult answer better, because have no idea of background.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -