大会 - 如何修改堆栈大小? [英] Assembly - How to modify stack size?

查看:428
本文介绍了大会 - 如何修改堆栈大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在汇编编程新手,我使用的使用内存堆栈push和pop指令。
那么,什么是堆栈默认大小,如何修改它,什么是限制,如果它的大小?

I am a newbie in assembly programming and I am using push and pop instructions that use the memory stack. So, What is the stack default size, How to modify it and What is the limit if its size?

推荐答案

不管装(以下简称装载机)的的程序到内存中,并通过控制它,决定了在内存堆栈位置,以及有多少空间可用于堆栈。

Whatever loaded ("the loader") your program into memory, and passed control to it, determines where in memory the stack is located, and how much space is available for the stack.

它通过加载堆栈指针,通常使用的 MOV ESP的简单技巧这样做,... 之前调用指令/跳转到您的code。那么你的程序使用提供的堆栈区。

It does so by the simple artifice of loading the stack pointer, typically using a MOV ESP, ... instruction before calling/jumping to your code. Your program then uses the stack area supplied.

如果你的程序使用过多,会写入超出分配的堆栈区的末端。这是一个程序错误,因为过去年底的内存可能被分配在应用一些其他的目的。写在其他内存很可能会改变程序行为(例如,错误)时内存被使用,并且发现错误的原因很可能是困难的(人想当然地认为堆栈不损坏程序数据和副反之亦然)。

If your program uses too much, it will write beyond the end of the allocated stack area. This is a program bug, because the memory past the end may be allocated for some other purpose in the application. Writing on that other memory is likely to change the program behavior (e.g., "bug") when that memory gets used, and finding the cause of that bug is likely to be difficult (people assume that stacks don't damage program data and vice versa).

如果您的应用程序要使用更大的栈,一般你所要做的就是分配自己的领域,你就足够大了,做一个MOV ESP,......你自己到堆栈设置到所选的位置。您如何分配的面积取决于在其中运行的执行环境。 (你要尊重ESP约定:必须是4的倍数,应被初始化为一个高速缓存行的底部,通常是有用的初始化到虚拟存储器页的底部)

If your application wants to use a larger stack, generally all you have to do is allocate your own area, large enough for your purposes, and do a MOV ESP, ... yourself to set the stack to the chosen location. How you allocate an area depends on the execution environment in which you run. (You need to respect ESP conventions: must be a multiple of 4, should be initialized to the bottom of a cache line, often useful to initialize to the bottom of virtual memory page).

它通常是当交换协议栈,以节省ESP由装载机提供的旧值,并且控制权返回给装载机/来电/ OS之前ESP恢复到原来的值是一个好主意。同样的,你应该释放不再被使用的扩展堆栈空间。

It is generally a good idea when "switching" stacks to save the old value of ESP provided by the loader, and restore ESP to that old value before returning control to the loader/caller/OS. Likewise, you should free the extended stack space no longer being used.

如果你知道的堆栈空间,你需要提前量这个方案会奏效。在实践中,这是相当困难,以猜测(如果你code的递归算法,巢深可以是不可能的)。所以,你可以选择一个真正庞大的数字大于你需要(益),也可以使用一个有条理的交换机堆叠时,它很清楚,它需要更多的程序。
见<一href=\"http://stackoverflow.com/questions/1016218/how-does-a-stackless-language-work/1053159#1053159\">How做了无堆栈语言文字工作?更多的讨论。

This scheme will work if you know the amount of stack space you need in advance. In practice, this is rather hard to "guess" (and may be impossible if your code has a recursive algorithm that nests deeply). So you can either pick a really huge number bigger than you need (ick) or you can use an organized approach to switch stacks when it is clear to the program that it needs more. See How does a stackless language work? for more discussion.

这篇关于大会 - 如何修改堆栈大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆