The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Terminate and stay resident (TSR) is a DOS technique in which a program ends its initial run and returns control to its parent while keeping selected code and data in memory. That retained portion can later provide a service or respond to an event. In MS-DOS, the documented method is Interrupt 21h, function 31h.
What does TSR stand for?
TSR stands for terminate and stay resident. “Terminate” means the program’s initial execution ends and control returns to the program that started it. “Stay resident” means a chosen part of the program remains allocated in memory rather than being released with the rest of the running program.
| # | Preview | Product | Price | |
|---|---|---|---|---|
| 1 |
|
DOS For Dummies | $12.15 | Buy on Amazon |
| 2 |
|
Advanced MS-DOS Programming: The Microsoft Guide for Assembly Language and C Programmers | $7.47 | Buy on Amazon |
| 3 |
|
Running MS-DOS | $318.02 | Buy on Amazon |
| 4 |
|
Running MS-DOS: Qbasic | $6.67 | Buy on Amazon |
As an Amazon Associate I earn from qualifying purchases.
The term is associated with DOS programs. It does not mean the program continues running continuously in the background: its resident code is reached later through an interrupt handler or another entry point.
How does a TSR work?
- Install: The program initializes and may register an interrupt handler or another way for later code to reach it.
- Keep the resident portion: It calls a DOS termination service that returns control to its parent while retaining a specified amount of memory.
- Respond later: A subsequent interrupt, software call, or other documented entry point transfers control to the retained code.
The setup code and the resident code need not occupy the same amount of memory. A program can leave only the portion needed for its later work resident.
#1 Best Overall
How MS-DOS terminates a program but keeps it in memory
INT 21h function 31h
MS-DOS documents INT 21h function 31h as the terminate-and-stay-resident service. The calling program sets AH to 31h, places its return code in AL, and specifies the number of memory paragraphs to retain in DX. The service ends the running program, passes the return code to its parent, and keeps the specified memory resident. The Assembly Language Help reference for INT 21h function 31h describes the inputs and behavior; Microsoft’s MASM 6.1 Programmer’s Guide (1992) identifies function 31h as an MS-DOS service invoked through Interrupt 21h.
These are historical MS-DOS interfaces. For a new implementation, consult documentation for the specific DOS version or environment you intend to support rather than assuming low-level behavior is identical everywhere.
Rank #2
- Used Book in Good Condition
INT 27h
INT 27h is an older terminate-and-stay-resident method. Microsoft’s MASM 6.1 guide says it is present in the MS-DOS versions covered by that guide, but warns that Microsoft could not guarantee future support and did not recommend relying on it. That is a historical recommendation about the DOS interface, not a statement about support in present-day operating systems.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsWhat were TSR programs used for?
TSRs could provide services to other programs or respond to events without being loaded from disk for each use. Microsoft’s MS-DOS Programmer’s Reference, Including Version 5 (1991) gives PRINT.EXE as an example: it remains resident to maintain a print queue and provide functions other programs can call. A Microsoft KnowledgeBase article on TSRs in assembly, last modified January 12, 1989, describes a timer-interrupt example. The Programmer’s WorkBench TSR glossary entry also mentions pop-up utilities.
Rank #3
What distinguishes one TSR from another?
When discussing TSR implementations, the useful differences are technical rather than product comparisons:
Quick Recap
Rank #4
- Used Book in Good Condition
- Termination call: INT 21h function 31h or the older INT 27h.
- Memory retained: how much memory, and which portion of the program, remains resident.
- Activation method: an interrupt handler, software interrupt, or another documented entry point.
- Purpose: a service for other programs, device support, or an interactive utility.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

