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?

I guess in your rush to spam multiple message boards
http://www.tek-tips.com/viewthread.cfm?qid=1382444&page=1
with the same question, that you couldn't be bothered with simple courtesy of reading the posting guidelines on any of them.
http://www.daniweb.com/forums/announcement125-3.html

Yes, you are completely right...
The problem is that I have less than 2 days to finish the project for my Computer Science school and when I posted that, I was really running mad (I worked for so many days and moreover it was 03:00 of night here in Italy!!!), so I decided to find an Assembly forum to ask for help! I still don't understand why it does not compile :'( , I really need help...

I am very sorry :(
Luke

P.S: since I can no more edit my first post, here the is the code (for the problem, look at the first post):

//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!!!
}

using VC++ 2005 express

int main()
{
unsigned char array[] = {1, 2, 3, 4, 5, 6, 7};
 
// Assembly
__asm
{
    MOV AL,array[0] ; ok
    MOV AL,array+2 ; ok
    lea ebx, array
    MOV AL, [ebx] ; ok
}
This article has been dead for over six months. Start a new discussion instead.