如何使用Inline Assembly在C / C ++程序中调用DOS中断? [英] How to call DOS Interrupts within a C/C++ program using Inline Assembly?

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

问题描述

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

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

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

解决方案

你只能使用DOS程序的DOS中断, d需要一个真正古老的C ++编译器,如Visual C ++ 1.0或1.5,或Turbo C ++ / Borland C ++通过类似4.5或可能5.0。然后你必须修复你的汇编代码 - 你写的看起来像AT& T语法,但我知道的所有DOS编译器使用英特尔语法。有一个半异常:djgcc。这是一个古老版本的gcc运行在DOS扩展,所以它使用AT& T语法,并仍然支持一组DOS类中断(虽然你真的使用DOS扩展,而不是DOS本身)。

即使如此,程序只能在支持DOS程序的系统上运行(而微软正在迅速从Windows中删除它 - 例如,它在所有x64版本的Windows )。



DOS已经过时了,为它编写新代码没有意义。如果你想读这样的密钥,写一个Windows程序,并使用像

编辑:好的,如果你真的想要这样做,显而易见的方式是选择 DOS扩展程序,并移植当前版本的gcc到它。另一种可能性是选择一个类似于 OpenWatcom 数字火星,仍然维护并已移植到 DOS extender


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.

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

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