我怎样才能得到 int 0x16 的值?

How I can get the value of int 0x16?

我的 C 代码中有这个内联汇编程序:

asm volatile ("mov %ah, 01\n"
              "int [=10=]x16\n");

此代码是 getch()

的汇编版本

它有效,但现在我想获取返回此内联汇编程序的值(具体来说,我想知道 returns 中断 16h 的关键)。

我该怎么做?

编辑:我正在使用 C 和 DosBox 制作 MS-DOS COM 文件。目前一切正常,除了我现在遇到的问题。

完整代码:

asm (".code16gcc\n"
     "call  dosmain\n"
     "mov   [=11=]x4C,%ah\n"
     "int   [=11=]x21\n");

static void print(char *string)
{
    asm volatile ("mov   [=11=]x09, %%ah\n"
                  "int   [=11=]x21\n"
                  : /* no output */
                  : "d"(string)
                  : "ah");
}

int dosmain(void)
{

    int a;
    asm volatile ("mov %%ah, 0\n"
                  "int [=11=]x16\n"
                   : "=r"(a));

    print(a);
    print("Hello, World!\n$");
    return 0;
}

但是很不错 "buffer overflow?"

你有一个工具链问题。

您使用的 GCC 版本是 32 位编译器。在顶部插入 asm(".code16gcc") 指令会更改汇编器的行为以允许使用 32 位指令,但是 不会 让 GCC 知道在实模式。结合您用来生成 .com 二进制文件的(未知的,可能不正确的)步骤,结果将是一个无法运行的可执行文件。

如果要构建 DOS 可执行文件,请使用针对此环境的工具链,例如 OpenWatcom