How MS-DOS 6.22 Processes Ctrl+C in Loops

In MS-DOS 6.22, processing keyboard shortcuts like Ctrl+C during program execution depends on a combination of BIOS hardware interrupts, DOS input/output polling, and the state of the system's BREAK setting. Because MS-DOS is a single-tasking operating system without native preemptive multitasking, a running program retains full control of the CPU, meaning the operating system cannot forcibly interrupt an execution loop to handle Ctrl+C unless the program makes a DOS system call or explicitly polls for input. When detected, the operating system invokes a dedicated software interrupt, INT 23h, to terminate the program or execute a custom exit routine.

Hardware and BIOS Input (INT 09h)

When a user presses Ctrl+C, the keyboard controller issues hardware Interrupt Request 1 (IRQ 1), which routes to the BIOS handler at INT 09h. The BIOS detects the scan codes, determines that the Ctrl key is depressed alongside the "C" key, and generates the ASCII control character 03h (ETX, or End of Text).

The BIOS places this 03h code into the circular keyboard buffer in the BIOS Data Area (BDA) at memory address 0040:001Eh. At this stage, the loop in the running application continues unabated; the keystroke sits in the buffer until software reads or checks it.

DOS Polling via INT 21h Functions

MS-DOS 6.22 inspects the keyboard buffer through its primary API, INT 21h. By default, DOS does not run background processes to monitor the keyboard buffer. Instead, it checks for Ctrl+C only when an active application executes standard console input/output functions, such as:

  • Character Input (INT 21h, Function 01h)
  • Character Output (INT 21h, Function 02h)
  • Direct Console I/O (INT 21h, Function 06h, depending on sub-parameters)
  • Display String (INT 21h, Function 09h)
  • Buffered Input (INT 21h, Function 0Ah)

If an application loop performs any of these standard display or keyboard calls, the internal DOS routines inspect the incoming character. If it detects 03h, DOS intercepts the execution flow instead of returning the character to the program.

The Role of BREAK=ON vs. BREAK=OFF

If a program loop does not perform console I/O—such as a loop that processes file blocks, performs raw calculations, or communicates over serial ports—the standard Ctrl+C check never occurs. To mitigate this, MS-DOS 6.22 uses the BREAK command.

  • BREAK=OFF (Default): DOS only checks for Ctrl+C during standard character device operations (console, printer, and auxiliary ports). A CPU-bound loop or a pure file-read loop will completely ignore Ctrl+C.
  • BREAK=ON: DOS checks the keyboard buffer whenever an application makes almost any INT 21h system call, including disk read/write functions (Function 3Fh/40h), file open/close routines, and process management services.

Even with BREAK=ON, if a loop executes strictly within CPU registers and memory without calling INT 21h services, MS-DOS 6.22 cannot process Ctrl+C, resulting in an un-interruptible loop that requires a hardware reset.

Invoking the Ctrl+C Handler (INT 23h)

Once MS-DOS identifies 03h during an eligible system call, it initiates the following sequence:

  1. Output Echo: DOS prints ^C to standard output to notify the user.
  2. Triggering INT 23h: DOS transfers control to the address stored in Interrupt Vector 23h (the DOS Control-C Exit Address).
  3. Default Action: The default INT 23h handler in COMMAND.COM terminates the running program, releases allocated memory, flushes standard buffers, and returns control to the DOS prompt.
  4. Custom Handling: Programs can intercept and hook INT 23h prior to entering a loop. This allows software to ignore the abort command, complete cleanup operations, or present a confirmation prompt (such as "Terminate batch job (Y/N)?") before yielding control back to the operating system.

Ctrl+C versus Ctrl+Break

While visually similar, MS-DOS treats Ctrl+Break differently from Ctrl+C. When Ctrl+Break is pressed, the BIOS INT 09h handler detects the dedicated Break key scan code and immediately fires BIOS Interrupt 1Bh. The BIOS sets a flag byte in the BDA and clears the keyboard buffer.

When MS-DOS detects the INT 1Bh flag during a system call, it immediately forces an INT 23h abort, even in situations where a standard Ctrl+C character might have been delayed behind other keystrokes queued in the buffer.