You are currently offline, waiting for your internet to reconnect

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

This article was previously published under Q84300
This article has been archived. It is offered "as is" and will no longer be updated.
Mysterious hangs or failures can occur when a hardware routine doesnot have enough storage space to perform its job. To avoid thisproblem, MS-DOS versions 3.2 and later provide additional storagespace for the interrupt-handling code whenever a hardware interruptoccurs. This is done by changing the current storage area (called a"stack," because it is a place to stack information temporarily) to anew storage area provided by MS-DOS.

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

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

Because the STACKS= command affects hardware- andconfiguration-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 stackwhenever an asynchronous hardware interrupt occurs, before passingcontrol to the original interrupt handler. (Interrupt vectors 02H,08-0EH, 70H, and 72-77H, corresponding to IRQs 0-15.) Before MS-DOS3.2, interrupt handlers received control with the stack set to that ofwhatever program or device driver was executing when the interruptoccurred. Thus, if a program stack is nearly full and a hardwareinterrupt 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 settingdisables MS-DOS stack switching (thus returning MS-DOS stack behaviorto that of MS-DOS versions 3.1 and earlier). That is, interrupts areprocessed using whichever stack happens to be loaded at the time ofthe interrupt. Because MS-DOS doesn't manage any stacks, less memoryis required when 0,0 is specified. In addition, less time is requiredto handle interrupts because no code to swap stacks is executed. Anegative aspect is that the same behavior that motivated support forstack swapping can occur (that is, system hangs and other randombehavior as the stack overflows).

If stack switching is enabled, MS-DOS ensures nested interrupts do notget the same stack. Upon completion of the interrupt processing, thestack 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.

Troubleshooting Notes

If a system is experiencing random hangs or strange behavior andSTACKS=0,0 is in the CONFIG.SYS file, this should be considered aprime suspect and removed. Conversely, some hardware that requiresextremely fast interrupt processing may require STACKS=0,0 to operateproperly. If you are having trouble with a high-speed communicationsor real-time program, try setting STACKS=0,0. If you have a programthat worked correctly with MS-DOS 3.1 or earlier and you cannot getit 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, thefollowing message will be displayed:
FATAL : Internal Stack Failure, System Halted.
If the above message is displayed, try a higher number for n inSTACKS=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 vectorservices, stack switching will not be done before your interrupthandler gets control. Any stack switching necessary must be done byyour 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
3.0 3.00 3.0a 3.00a 3.1 3.10 3.2 3.20 3.21 3.22 3.3 3.30 3.3a 3.30a 4.0 4.00 4.0a 4.00a 5.00 5.00a 6.00 6.20 6.21 6.22 overview 9,256 explanation swap swapping switch switching tshoot printing printscreen

Article ID: 84300 - Last Review: 12/04/2015 09:14:51 - Revision: 2.0

Microsoft MS-DOS 3.1, Microsoft MS-DOS 3.2 Standard Edition, Microsoft MS-DOS 3.21 Standard Edition, Microsoft MS-DOS 3.3 Standard Edition, Microsoft MS-DOS 3.3a, Microsoft MS-DOS 4.0 Standard Edition, Microsoft MS-DOS 4.01 Standard Edition, Microsoft MS-DOS 5.0 Standard Edition, Microsoft MS-DOS 5.0a, Microsoft MS-DOS 6.0 Standard Edition, Microsoft MS-DOS 6.2 Standard Edition, Microsoft MS-DOS 6.21 Standard Edition, Microsoft MS-DOS 6.22 Standard Edition

  • kbnosurvey kbarchive KB84300