I use the Open Watcom IDE V1.9, and Target Environment is DOS-16bit,image type is exe. target cpu is 80386.
Here is my source code:
#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
}
}
when i make it, I got this:
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
Well, but I cannt see how Line28 is wrong, I checked the open watcom user guide, but in section "In-line Assembly Language", there are no information about Why I got this error. Any suggestion?
You can't use ax register of 80x86 processor in 16-bit mode to access memory locations, or at least not in this way. Try to use one of the index register instead, like si or di, for that