开发者

How to call DOS Interrupts within a C/C++ program using Inline Assembly?

开发者 https://www.devze.com 2022-12-28 01:02 出处:网络
I need to call some DOS interrupts (Services) from a C/C++ program, I tried the following inline asm code:

I need to call some DOS interrupts (Services) from a C/C++ program, I tried the following inline asm code: (Read a character)

int main()
{
asm(
 "movb $0x01, %ah;"
 "int $0x21"
 );
system("PAUSE");
}

But it did not work ! I would like to know what have i done wrong here ! Also if there is an开发者_Python百科other way to call dos interrupts ! Thank You !


You can only use DOS interrupts from DOS programs, so to make this work, you'd need a really ancient C++ compiler like Visual C++ 1.0 or 1.5, or Turbo C++/Borland C++ up through something like 4.5 or possibly 5.0. Then you'd have to fix your assembly code -- what you've written looks like AT&T syntax, but all the DOS compilers of which I'm aware use Intel syntax. There is one semi-exception to that: djgcc. This an ancient version of gcc that runs under a DOS extender, so it uses AT&T syntax, and still supports a set of DOS-like interrupts (though you're really using the DOS extender, not DOS per se).

Even then, the program would only run on a system that supports DOS programs (and Microsoft is quickly dropping that from windows -- e.g., it's absent in all the x64 versions of Windows).

DOS has been obsolete long enough that writing new code for it doesn't make sense. If you want to read a key like that, write a Windows program, and use something like ReadConsoleInput instead.

Edit: Okay, if you really want to do this, the obvious way would be to pick a DOS extender and port a current version of gcc to it. The other possibility would be to pick a compiler like OpenWatcom or Digital Mars that's still maintained and already ported to a DOS extender.


You may need an x86 emulator like DOSBox to run this code under Windows XP.

0

精彩评论

暂无评论...
验证码 换一张
取 消