How to trigger DOS interrupts in a C / C ++ program using Inline Assembly?
I need to call some DOS (Services) interrupts from a C / C ++ program, I tried the following inline asm code: (Read character)
int main()
{
asm(
"movb $0x01, %ah;"
"int $0x21"
);
system("PAUSE");
}
But it didn't work! I would like to know what I did wrong here! Also if there is another way to call dos interrupts! Thanks!
a source to share
You can only use DOS interrupts from DOS programs, so you'll need a really old C ++ compiler like Visual C ++ 1.0 or 1.5, or Turbo C ++ / Borland C ++ with whatever to do this job. something like 4.5 or maybe 5.0. Then you have to fix the assembly code - what you wrote looks like AT&T syntax, but all DOS compilers I know of use Intel syntax. There is one semi-exception: djgcc. This is an ancient version of gcc that runs under the DOS expander, so it uses AT&T syntax and still supports a set of DOS-like interrupts (although you are indeed using the DOS expander and not DOS per se).
Even then, the program will only run on a system that supports DOS programs (and Microsoft is quickly dropping this out of windows - for example, it is missing from all x64 versions of Windows).
DOS is outdated long enough that it doesn't make sense to write new code for it. If you want to read such a key, write a Windows program and use instead ReadConsoleInput
.
Edit: Okay, if you really want to do this, the obvious way would be to select the DOS extender and port the current version of gcc to it. Another possibility is to choose a compiler like OpenWatcom or Digital Mars , which is still supported and already ported to the DOS expander .
a source to share