watcom内联汇编出错“非法使用寄存器”

时间:2013-11-11 02:50:09

标签: c inline-assembly watcom

我使用Open Watcom IDE V1.9,目标环境是DOS-16bit,图像类型是exe。 target 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是怎么回事,我检查了开放的watcom用户指南, 但在“在线汇编语言”一节中,没有关于为什么的信息 我收到了这个错误。 有什么建议吗?

1 个答案:

答案 0 :(得分:1)

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