I would like to iterate over two unsigned char arrays and manipulate the values in array1 with the values in array2 like this:
point one register to array1
point second register to array2
the arrays are the same length
get the value at array1[0]; get the value at array2[0]; XOR array1[0] with array2[0] and repeat until the end of the array.
This will go in a C++ DLL which will be used by a C# program.
Is this possible?
THANKS!!
RON
Yes, it's possible. What have you coded so far? Please post it here.
#include "stdafx.h"
#include <windows.h>
void Xor(int counter, unsigned char *b1, unsigned char *b2)
{
__asm
{
lea si,b1
mov ebx,b2
xor cx,cx
L1 :
mov eax, [ebx]
xor [si],al
inc si
inc ebx
inc ecx
cmp ecx, counter
jne L1
}
}
int _tmain(int argc, _TCHAR* argv[])
{
using byte = unsigned char;
byte array1[4];
byte array2[4];
for (int i = 0; i < 4; i++)
{
array1[i] = 5+i*i;
array2[i] = 6+i*i*i;
}
Xor(4, array1, array2);
Xor(4, array1, array2);
return 0;
}
"si" and "cx" are 16-bit registers, but we are in the 32-bit world. I've modified your code a little bit, and added some testing. Check \Masm32\help\opcodes.chm for lodsb and stosb.
void Xor(int counter, unsigned char *b1, unsigned char *b2)
{
__asm
{
pushad
mov esi, b1
mov edi, b2
xor ecx, ecx
L1:
lodsb
xor al, [edi]
stosb
inc ecx
cmp ecx, counter
jne L1
popad
}
}
int main(int argc, char* argv[])
{
unsigned char array1[4];
unsigned char array2[4];
for (int i = 0; i < 4; i++)
{
array1[i] = 5+i*i;
array2[i] = 6+i*i*i;
}
for (int i = 0; i < 4; i++) printf("%i ", array2[i]);
printf("\n");
Xor(4, array1, array2);
for (int i = 0; i < 4; i++) printf("%i ", array2[i]);
printf("\n");
Xor(4, array1, array2);
for (int i = 0; i < 4; i++) printf("%i ", array2[i]);
printf("\n");
return 0;
}
YES, that was perfect. THANKS!!!!!!!!!!! :biggrin:
I posted an error i got but it is my faul; doing something incorrect. Apologies.!