2.5.2 Cooperative Programs cooperation>

To prevent corruption of code and data, MS-DOS programs must run cooperatively. To ensure cooperation, programmers should use the following guidelines:

Use only the memory and resources owned by the program. Since MS-DOS provides no memory protection, it cannot prevent a program from writing to memory it does not own. Unfortunately, writing to memory owned by MS-DOS, by device drivers, or by other programs can corrupt code or data and cause the system to fail.

Check for invalid pointers and out-of-bounds indexes. Programs must check the addresses they use, to prevent unintentionally writing to unallocated memory. In particular, programs must not write to memory beyond the end of any allocated block, since doing so may destroy data belonging to another program or corrupt structures MS-DOS uses to manage memory.

Do not leave interrupts disabled. Programs should not disable interrupts unless they need to carry out operations that must not be interrupted, such as changing the stack registers. If a program disables interrupts, it should complete the task and reenable the interrupts as quickly as possible.

Do not switch the operating mode of the central processing unit (CPU). MS-DOS runs in real mode. Programs that switch to other modes, such as protected mode, effectively disable MS-DOS.