x86 Assembly

Moderators: None (Apply to moderate this forum)
Number of threads: 4563
Number of posts: 16029

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Dos interrupts 2h function Posted by YRQ on 12 Jun 2010 at 8:35 AM
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?
Report
Re: Dos interrupts 2h function Posted by AsmGuru62 on 12 Jun 2010 at 2:01 PM
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.
Report
Re: Dos interrupts 2h function Posted by Bret on 13 Jun 2010 at 7:29 AM
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.
Report
Re: Dos interrupts 2h function Posted by YRQ on 14 Jun 2010 at 12:13 AM
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!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.