简体   繁体   English

nasm汇编堆栈上的存储限制

[英]nasm assembly limit of storage on the stack

I am writing a program to print out a 32-bit number, and I was thinking of storing each digit on the stack, to make use of its last-in-first-off functionality. 我正在编写一个打印出32位数字的程序,我正在考虑将每个数字存储在堆栈中,以利用其先进先出功能。 This arose the question, could I store 32 digits on the stack? 这就出现了问题,我可以在堆栈上存储32位数字吗?

My question is, how many digits of information could I store on the stack? 我的问题是,我可以在堆栈中存储多少位信息? What is the limit of the number of things I can push onto the stack? 我可以推入堆栈的数量限制是多少? Could I store 64 digits? 我可以存储64位数字吗? 128? 128? A number of arbitrary length? 一些任意长度?

Thanks in advance, 提前致谢,

Rileyh Rileyh

Depends a tiny bit on the OS and a bit more on the linker you use, but you should be fine. 取决于操作系统上的一小部分,以及您使用的链接器上的更多内容,但您应该没问题。 It's common to allocate a stack of a megabyte or more by default, so 128 bytes is nothing. 默认情况下,分配一个兆字节或更多的堆栈是很常见的,因此128个字节不算什么。 Just make sure you reset the stack pointer before you return, and everything should be fine. 只需确保在返回之前重置堆栈指针,一切都应该没问题。

You can typically tell the linker to allocate a stack of a certain size as well, if you find you need more than you get by default. 如果您发现需要的数量超过默认值,则通常可以告诉链接器分配一定大小的堆栈。

It's not actually nasm dictating this, more the linker that you use. 它实际上没有nasm使唤这一点,更多的是你用连接器。 All nasm does is create object files which can be linked together. 所有nasm都是创建可以链接在一起的目标文件。

If you are using the ld linker from Linux, you'll most likely find that your default stack is 2M. 如果您使用Linux的ld链接器,您很可能会发现您的默认堆栈是2M。

So, no, 32 bytes is not really going to have a massive impact on that and, even if you run out of stack, you can use something like ld --stack 4194304 to bump it up. 所以,不,32字节实际上不会对它产生巨大的影响,即使你用完了堆栈,你也可以使用像ld --stack 4194304这样的东西ld --stack 4194304它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM