如何调用DOS中使用内联汇编一个C / C ++程序中的中断? [英] How to call DOS Interrupts within a C/C++ program using Inline Assembly?

查看:233
本文介绍了如何调用DOS中使用内联汇编一个C / C ++程序中的中断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!
我需要调用从C / C ++程序的一些DOS中断(服务),我尝试了下面的内联汇编code:
(读取一个字符)

  INT的main()
{
ASM(
 MOVB $ 0×01,%啊;
 INT $ 0×21
 );
系统(暂停);
}

但它没有工作!我想知道我做了什么错在这里!此外,如果有另一种方式来调用DOS中断!
谢谢!


解决方案

您只能使用DOS,从DOS程序中断,所以,使这项工作,你需要一个非常古老的C ++编译器像Visual C ++ 1.0或1.5,或的Turbo C ++ / Borland的C ++向上穿过像4.5或5.0可能。然后,你就必须解决您的装配code - 你写的是什么样子AT& T公司的语法,但所有的DOS的编译器我知道采用Intel语法。有一个半例外情况:djgcc。这GCC的一个古老的版本,一个DOS扩展下运行,所以它使用AT& T公司的语法,而且还支持一组类似DOS中断的(虽然你真的使用DOS扩展,而不是DOS本身)

即使这样,该程序将只支持DOS程序(和微软正在快速下探,从窗户 - 例如,它在Windows中的所有x64版本不存在)的系统上运行。

DOS已经过时了足够长的时间,编写新的code它没有意义。如果你想读这样的键,编写Windows程序,使用类似的 ReadConsoleInput 来代替。

编辑:好吧,如果你真的想这样做,明显的方法是选择一个 DOS扩展和端口的当前版本的GCC它。另一种可能性是挑选像 OpenWatcom 或的数字火星这仍然维持并已经移植到的 DOS扩展

everyone ! 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 another 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.

这篇关于如何调用DOS中使用内联汇编一个C / C ++程序中的中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆