Home > Back-end >  What is the difference between `MOV AX,4C00H INT 21H` and `INT 20H`?
What is the difference between `MOV AX,4C00H INT 21H` and `INT 20H`?

Time:07-19

I know that both of those terminate the program, but why use MOV AX,4C00H INT 21H when I could just do INT 20H?

CodePudding user response:

  • The int 20h DOS.TerminateProgram interrupt and its operationally identical sibling mov ah, 00h int 21h DOS.TerminateProgram function were present in DOS version 1. They both rely on the CS segment register pointing at the segment that contains the ProgramSegmentPrefix aka PSP.
  • The mov ax, 4C??h int 21h DOS.TerminateWithReturnCode function was introduced with DOS version 2. This new function allows returning an exit code to the parent process, and does not rely on having CS point at the PSP.

Function 4Ch is the preferred way to terminate a program in DOS versions 2 and better. However, if you don't care about returning an exit code, you can just use the int 20h interrupt and shave off a few byte. You don't have to worry about having CS point at the PSP either since DOS versions 2 will silently make your int 20h act as if it was a mov ax, 4C00h int 21h sequence with an exit code of 0.

Ultimately though you have to find out for yourself if the above is true. All sorts of emulators/environments could implement it in their own ways. I believe DEBUG.EXE differentiates between the two...

  • Related