Dos interrupts 2h function

Hi, everyone!
Dos interrupts 2h function can ouput a character to screen.
mov ah , 02h
mov dl , 'A'
int 21h
On the other hand, we can directly "write" a character to screen.
mov ax , 0b800h
mov es , ax
xor bx , bx
mov al , 'A'
mov ah , 07h
mov es:[bx] , ax
What's the difference between this two ways, or the relationship of them? And how does Dos interrupts work?


  • [color=Blue]Directly writing is faster than INT 21h.
    However, INT 21h writes to a current video page and your direct code writes to page zero. So, if you need to directly write to a few pages at once - you need more code in your direct code sample.

    To find out how INT 21h works in that case - simply trace into the call "INT 21h" with a debugger and see what's there.
  • In addition to using the various DOS functions and writing directly to video memory, there are also various Video BIOS (INT 10h) functions.

    There are two big advantage to using DOS functions (besides the fact that it handles the video pages automatically, as asmguru stated). The first is that DOS will "translate" various characters (like tab, carriage return, and line feed) appropriately, giving you some control over where the characters are displayed when you are doing line-oriented output. Putting a Carriage-return character directly into video memory will NOT move the cursor at the beginning of the line -- it will simply display a funny-looking character.

    The other advantage to using DOS functions is that it handles output redirection appropriately (that is, you can tell DOS to redirect your output to something other than the screen, e.g., to NUL or to a file).

    In general, if you are simply writing "status" messages or simple character output, you should ALWAYS use the DOS functions, even though they may be slower. Use video BIOS calls if you are not using line-oriented output. Writing directly to video memory should only be done if the Video BIOS doesn't do what you want, or if speed is a major concern. Writing directly to video memory can cause all kinds of compatibility problems.
  • Thanks a lot for your replies. I tried to trace into DOS interrupts, but failed. I think maybe trace flag is cleared immediately when we call "INT 21h". So I checked the interrupt vector of "INT 21h" and found the code of "INT 21h" according to the vector. But it confused me. I need some time to figure out how DOS interrupts works.
    If anybody has a better way to trace into DOS interrupts, please let me know. Thanks!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!