Reputation: 1
I am currently testing various methods of speeding up my code using x86 assembler. I've been able to access 1D arrays in the past but 2D arrays seem to be completely different!
I'm using two for loops which I've created in assembly and have moved 'x' into the ECX register and 'y' into the EDX register.
I've also loaded the effective address of the array into EBX by using this:
lea ebx,dword ptr [slimeTrail]
Now what I want to do is use the loops to isolate a character and move it into the AL register by using:
movsx al,byte ptr [ebx + (ecx * sizeX) + edx]
where sizeX is the width.
However, the errors I am getting are
error C2404: 'edx' : illegal register in 'second operand'
and
error C2425: '*' : non-constant expression in 'second operand'
I've checked the Intel manuals and don't seem to be getting there. Have I missed something basic?
Upvotes: 0
Views: 1342
Reputation: 62048
You need to learn addressing of memory operands.
In 32-bit mode you're typically limited to using one of the following as the address of a memory operand in a single instruction:
Your ebx + (ecx * sizeX) + edx
is neither of the above.
If sizeX
is neither of 1, 2, 4 and 8, you must multiply ecx
by it using either mul
or imul
or some other equivalent operation (consisting of several instructions) and add the product to ebx
or edx
and after that you can do mov al,byte ptr [ebx + edx]
.
Btw, movsx al, ...
makes no sense is probably invalid. A simple mov
will do.
Upvotes: 1