【问题标题】:watcom inline assembly got error "Illegal use of register"watcom 内联汇编出现错误“非法使用寄存器”
【发布时间】:2013-11-11 02:50:09
【问题描述】:

我使用的是Open Watcom IDE V1.9,目标环境是DOS-16bit,图像类型是exe。 目标cpu是80386。

这是我的源代码:

#include <stdio.h>

void getITV(int n);
unsigned int ITV[16];

void main()
{
    int i=0;
    for(i=0;i<16;i++){
        getITV(i);
        printf("%x   ",ITV[i]);
    }
    printf("\n");
}

void getITV(int n)
{
    int*  address ;
    n = n * 2;
    address     = (int*) ( (int)ITV + n );
    __asm{
        push es
        push ax
        push bx
        mov ax,0
        mov es,ax
        mov ax,n
        mov bx,es:[ax]            --<this line is the one create error>--
        mov word ptr [address],bx
        pop bx
        pop ax
        pop es
    }
}

当我成功时,我得到了这个:

cd D:\watcom-project\dumpIVT
wmake -f D:\watcom-project\dumpIVT\dumpIVT.mk -h -e -a D:\watcom-project\dumpIVT\getCS.obj
wcc getCS.c -i="C:\WATCOM/h" -w4 -e25 -zq -od -d2 -3 -bt=dos -fo=.obj -mm
getCS.c(28): Error! E1156: Assembler error: 'Illegal use of register'
Error(E42): Last command making (D:\watcom-project\dumpIVT\getCS.obj) returned a bad status
Error(E02): Make execution terminated
Execution complete

好吧,但我看不出 Line28 有什么问题,我查看了 open watcom 用户指南, 但在“内联汇编语言”部分中,没有关于为什么的信息 我得到了这个错误。 有什么建议吗?

【问题讨论】:

    标签: c inline-assembly watcom


    【解决方案1】:

    您不能在 16 位模式下使用 80x86 处理器的 ax 寄存器来访问内存位置,或者至少不能以这种方式。尝试使用其中一个索引寄存器,例如 si 或 di,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多