Hi, I recently started programming with inline assembly (I use Visual C++), but I have found a bug that I cannot solve.
Why does it give an error?
// C language
unsigned char array[] = {1, 2, 3, 4, 5, 6, 7};
// Assembly
__asm
{
XOR CL,CL
MOV AL,array[0] ; ok
MOV AL, array+2 ; ok
MOV AL,array[CL] ; ERROR!!!
}
The error is -> "error C2403: 'CL' : register must be base/index in 'second operand'".
I tested it many times and I found that the only way to make it work is to use ECX register as index! Why?
If I use ANY OTHER register it will not compile (as above) or it will give a Fatal Error if I use another EXX register (as EAX or EBX).
The problem is that on my program I have a "nested for loop" and so I can't use just 1 counter (ECX), but I need 2 of them and they must be BYTE register (as CL/CH) because the array variable is a char. Any idea?
Thank you very much!
Luke
P.S: any better idea on how to write effective inline nested loop?