本文介绍了理解函数的调用栈帧C / C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的C / C ++和汇编郎为好。
    这也可能是非常基本的问题。
    我想了解栈帧是如何构建的,哪些变量(PARAMS)被推以什么顺序堆叠?
    一些搜索结果表明,.... C / C ++编译器做出决定基于一个函数内执行的操作。对于例如,如果功能是假设由通过INT参数和返回(类似于++运算符),这将令的功能和局部变量的所有..the参数函数中的寄存器和执行另外的1只增加值。 ...不知道哪寄存器用于返回/传值?......怎么都引用返回? .....差的B / W EAX,EBX,ECX和EDX。

I am new to C/C++ and assembly lang as well. This could also be very basic question. I am trying to understand how stack frames are built and which variables(params) are pushed to stack in what order?. Some search results showed that....compiler of C/C++ decides based on operations performed within a function. for e.g if the function was suppose to just increment value by 1 of the passed int param and return (similar to ++ operator) it would put all ..the param of the function and local variable within the function in registers and perform addition ....wondering which register is used for returned/pass by value ?....how are references returned? .....difference b/w eax, ebx,ecx and edx.

请求书/博客/链接或任何一种材料,了解寄存器,栈和堆引用用于/内置,并在函数调用的破坏....怎么也主要功能是存储?
在此先感谢

Requesting for a book/blog/link or any kind of material to understand registers,stack and heap references are used/built and destroyed during function call's....and also how main function is stored?Thanks In Advance

推荐答案

您的问题是边缘在这里。 可能是一个更好的地方。

Your question is borderline here. programmers could be a better place.

一本好书,了解栈等的概念可能是Queinnec的(它解释得很好堆栈是什么Lisp的)。此外,
 是一本好书,。

A good book to understand the concepts of stack etc might be Queinnec's Lisp In Small Pieces (it explains quite well what a stack is for Lisp). Also, SICP is a good book to read.

的书和的也是很好看的。

D.Knuth's books and MMIX is also a good read.

请仔细阅读维基百科的页。

Read carefully Wikipedia Call stack page.

在理论上,不需要调用堆栈,和一些语言和实现(例如旧SML / NJ)没有使用任何栈(但分配在垃圾收集堆中的呼叫帧)。见A.Appel的旧纸更快(和了解的一般)。

In theory, no call stack is needed, and some languages and implementations (e.g. old SML/NJ) did not use any stack (but allocated the call frame in the garbage collected heap). See A.Appel's old paper Garbage Collection Can be Faster than Stack Allocation (and learn more about garbage collection in general).

通常C和C ++编译器有一个堆栈(通常使用硬件堆栈)。一些C局部变量可能没有任何栈位置(因为它们已被优化,或者被保存在一个寄存器)。有时,一个C局部变量的栈位置可能会改变(编译器会使用一段出现一个呼叫堆栈槽,并且对于相同的局部变量的其他事件另一呼叫堆栈槽)。当然一些临时值可被编译像本地变量(所以留在寄存器中,对在一个堆栈槽,然后又一个,等...)。当优化编译器可以做怪异的招数与变数。

Usually C and C++ implementations have a stack (and often use the hardware stack). Some C local variables might not have any stack location (because they have been optimized, or are kept in a register). Sometimes, the stack location of a C local variable may change (the compiler would use one call stack slot for some occurrences, and another call stack slot for other occurrences of the same local variable). And of course some temporary values may be compiled like your local variables (so stay in a register, on in one stack slot then another one, etc....). When optimizing the compiler could do weird tricks with variables.

想想递归定义函数的执行(或跨pretation)(像好老的阶乘的天真codeD)。阅读关于(一般的的,,的,,的,中, ABI ,的,,的,的,的等....等等...

Think about the execution (or interpretation) of a recursively defined function (like the good old factorial naively coded). Read about 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 also books about Computer Architecture. In practice, the call stack is so important that several hardware resources (including the stack pointer register, often the call frame base pointer register, and perhaps hidden machinery e.g. cache related) are dedicated to it on common processors.

您也可以看看由GCC编译器使用的中间再presentations。然后使用 -fdump树,所有或。如果看生成的程序集一定要 -S -fverbose-ASM 传递给你的 GCC 命令。

You could also look at the intermediate representations used by the GCC compiler. Then use -fdump-tree-all or the GCC MELT probe. If looking at the generated assembly be sure to pass -S -fverbose-asm to your gcc command.

又见。

这篇关于理解函数的调用栈帧C / C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 07:27