Search code examples
unixassemblystackgnu-assembler

Do I need to initialize stack in GAS?


Hallo! Currently I'm learning basics of assembly. Earlier I was using TASM and Intel-syntax. There I had to initialize stack in some ways. But now I'm using GNU Assembler and AT&T syntax. I looked through lots of examples and saw no any declaration/initialization of stack. I wonder if I have to do it? Or, may be, it's made without my help here? If is so, how exactly is it initialized automatically? Are there risks to rub important info in data-segment? I didn't also notice any directives concerning stack.

Thanks for your answers beforehand! Oh, one more thing: are there any good books concerning programming in ASM (GAS) for Unix-like systems?


Solution

  • An OS with Virtual Memory handles the stack somewhat differently than how an OS without Virtual Memory handles it.

    • No VM (e.g. DOS, µClinux !MMU): you reserve some physical space for the stack. In DOS it depends on the memory model you use, for larger memory models you will allocate some memory and point SS (the stack segment) to it. In µClinux you will save the stack size in a field of the executable file format's header, see the bFLT format for an example.
    • VM → the stack grows dynamically, up to a configurable limit (see ulimit -s on Linux). Since each process has its own virtual address space, there is a lot of space between the stack and any other mapped virtual memory area.