How to Use the STACKS= Setting in the CONFIG.SYS File (84300)

The information in this article applies to:
    Microsoft MS-DOS operating system 3.1
    Microsoft MS-DOS operating system 3.2
    Microsoft MS-DOS operating system 3.21
    Microsoft MS-DOS operating system 3.3
    Microsoft MS-DOS operating system 3.3a
    Microsoft MS-DOS operating system 4.0
    Microsoft MS-DOS operating system 4.01
    Microsoft MS-DOS operating system 5.0
    Microsoft MS-DOS operating system 5.0a
    Microsoft MS-DOS operating system 6.0
    Microsoft MS-DOS operating system 6.2
    Microsoft MS-DOS operating system 6.21
    Microsoft MS-DOS operating system 6.22

This article was previously published under Q84300


Mysterious hangs or failures can occur when a hardware routine does not have enough storage space to perform its job. To avoid this problem, MS-DOS versions 3.2 and later provide additional storage space for the interrupt-handling code whenever a hardware interrupt occurs. This is done by changing the current storage area (called a "stack," because it is a place to stack information temporarily) to a new storage area provided by MS-DOS.

By default, nine of these stacks, each 128 bytes in size, are provided. The number and size of stacks can be increased using the CONFIG.SYS STACKS=n,m command, where n is the number of stacks and m is the size of each stack in bytes.

Changing the current stack takes time. It was discovered that changing the stack can slow the system enough that some programs, particularly high-speed communications programs, will fail. To avoid this problem, MS-DOS versions 3.3 and later allow disabling the stack swapping by specifying 0 stacks of 0 bytes in size (STACKS=0,0).

Because the STACKS= command affects hardware- and configuration-dependent code, it can have unpredictable effects.


    If a "stack overflow" or "exception error 12" (stack exception) error occurs, increasing the number and size of stacks specified in CONFIG.SYS may solve the problem (for example, STACKS=18,256).

    Note: STACKS= only affects hardware interrupts. If the stack being overflowed (trying to store too much information) is internal to an application, this will probably not solve the problem.
    If the command STACKS=0,0 is in the CONFIG.SYS file and any instability occurs (including, but not limited to, printing problems and system hangs), remove the STACKS= command temporarily and test.
    If the command STACKS=n,m is in CONFIG.SYS and problems occur (including, but not limited to, serial port problems), remove it temporarily and test. If problems continue and the system is an AT class machine, set STACKS=0,0; if the system is a PC, PC XT, or PC Convertible, set STACKS=9,128.


Beginning in MS-DOS version 3.2, MS-DOS added code to swap the stack whenever an asynchronous hardware interrupt occurs, before passing control to the original interrupt handler. (Interrupt vectors 02H, 08-0EH, 70H, and 72-77H, corresponding to IRQs 0-15.) Before MS-DOS 3.2, interrupt handlers received control with the stack set to that of whatever program or device driver was executing when the interrupt occurred. Thus, if a program stack is nearly full and a hardware interrupt occurs, random and unpredictable behavior will result (typically a system hang).

Beginning in MS-DOS 3.3, the STACKS=0,0 line was added. This setting disables MS-DOS stack switching (thus returning MS-DOS stack behavior to that of MS-DOS versions 3.1 and earlier). That is, interrupts are processed using whichever stack happens to be loaded at the time of the interrupt. Because MS-DOS doesn't manage any stacks, less memory is required when 0,0 is specified. In addition, less time is required to handle interrupts because no code to swap stacks is executed. A negative aspect is that the same behavior that motivated support for stack swapping can occur (that is, system hangs and other random behavior as the stack overflows).

If stack switching is enabled, MS-DOS ensures nested interrupts do not get the same stack. Upon completion of the interrupt processing, the stack is released so that MS-DOS may use it for a future interrupt.

Ranges for n and m in STACKS=n,m

    MS-DOS 3.1 and earlier have no support for swapping of stacks
    MS-DOS 3.2 and later support values in range N=8-64, M=32-512
    MS-DOS 3.3 added support for 0,0, which is equivalent to behavior in 3.1 and earlier.

Default Values for STACKS

    MS-DOS versions earlier than 3.2 do not support STACKS; behavior is equivalent to STACKS=0,0 on MS-DOS 3.3 and later.
    MS-DOS 3.2 always defaults to STACKS=9,128.
    MS-DOS 3.3 and later use special case codes that check for PC, PC XT, and PC Convertible. If any of these is detected, STACKS defaults to 0,0. Otherwise, STACKS defaults to 9,128.


If a system is experiencing random hangs or strange behavior and STACKS=0,0 is in the CONFIG.SYS file, this should be considered a prime suspect and removed. Conversely, some hardware that requires extremely fast interrupt processing may require STACKS=0,0 to operate properly. If you are having trouble with a high-speed communications or real-time program, try setting STACKS=0,0. If you have a program that worked correctly with MS-DOS 3.1 or earlier and you cannot get it to work with MS-DOS 3.2 or later, set STACKS=0,0.

Error Messages

If stack switching is enabled and MS-DOS runs out of free stacks, the following message will be displayed:

FATAL : Internal Stack Failure, System Halted.
If the above message is displayed, try a higher number for n in STACKS=n,m. If you experience random hangs or other strange behavior, try increasing the m value in STACKS=n,m.

Programming Notes

If you are hooking interrupts with the MS-DOS get/set interrupt vector services, stack switching will not be done before your interrupt handler gets control. Any stack switching necessary must be done by your interrupt handler.


"Microsoft MS-DOS Encyclopedia," page 805

"Microsoft MS-DOS User's Guide and Reference," version 5.0 pages 250, 284, and 570

"Microsoft Systems Journal," July 1991; Vol. 6, No 4; pages 25-26

"Microsoft MS-DOS Programmer's Reference," version 5.0, pages 109-110

Modification Type: Major Last Reviewed: 5/12/2003
Keywords: KB84300