Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change an array's value in x86 assembly (embedded in C++)

I am messing around with assembly for the first time, and can't seem to change the index values of an array. Here's the method I am working on

int ascending_sort( char arrayOfLetters[], int arraySize )
 {
   char temp;

__asm
    {

   //???
      }
}

And these are what I tried

mov temp, 'X'
mov al, temp
mov arrayOfLetters[0], al

And this gave me an error C2415: improper operand type

so I tried

mov temp, 'X'
mov al, temp
mov BYTE PTR arrayOfLetters[0], al

This complied, but it didn't change the array...

like image 506
VV. Avatar asked Dec 07 '25 15:12

VV.


1 Answers

When you have a parameter or varaible that is an array, it is actually a pointer to the first element of the array. You have to deference that pointer in order to change the data that it points to. For example:

__asm
{
mov eax, arrayOfLetter
mov [eax], 0x58
}

Or, more generically:

__asm
{
mov eax, arrayOfLetter
mov [eax+index], 0x58
}
like image 122
Remy Lebeau Avatar answered Dec 10 '25 04:12

Remy Lebeau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!