简体   繁体   中英

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. This arose the question, could I store 32 digits on the stack?

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? 128? A number of arbitrary length?

Thanks in advance,

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. 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. All nasm does is create object files which can be linked together.

If you are using the ld linker from Linux, you'll most likely find that your default stack is 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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