How I can increase size of stack in assembly (NASM OS X intel64)

I used .STACK 4096 before section .data but return this error

error: attempt to define a local label before any non-local labels

 error: parser: instruction expected

Please guide me.

Dani AI

Generated

Short answer for : NASM does not use the old MASM/TASM-style stack directive from DOS/Windows assemblers. NASM expects you to reserve data with resb/resq or use its preprocessor stack-related macros for local labels; it does not provide a .STACK source directive that changes the process/thread stack mapped by the OS. That is why the assembler/parser rejected the line. (nasm.us)

If the goal is a larger process (main-thread) stack on Mac OS X / macOS, set it at link time. The Mach-O linker accepts -stack_size (default is 8MB); when invoking gcc/clang pass it through the linker with -Wl. The argument is a hex number and should be an even multiple of the VM page size (usually 4096). Example (16MB):

gcc -o myprog myprog.o -Wl,-stack_size,0x1000000

Use the system linker docs for exact syntax and alignment rules. ()

Other practical options (sometimes preferable): raise the runtime soft limit for the stack with setrlimit(RLIMIT_STACK) (or launch from a shell with a larger ulimit -s), or when creating additional threads set each thread’s stack size with pthread_attr_setstacksize. For large automatic buffers prefer heap allocation (malloc/mmap) instead of pushing big frames onto the stack. These approaches avoid fragile large stack frames and are how most macOS programs handle big allocations. (developer.apple.com)

Troubleshooting tips: check ulimit -s to see shell-imposed limits, make sure the -stack_size value is page-aligned (4096 bytes on Intel macs), and assemble for the proper output format (e.g., nasm -f macho64) before linking. If problems persist, show the exact assemble and link command lines and the linker error output for more targeted help. ()

This is dependant on a number of things, but from this it looks like you can just flag the linker.

May I ask why you're trying to change the stack size? Generally speaking, there is a way around increasing the stack size.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.