Change an array's value in x86 assembly (embedded in C++)
Solution 1
The arrayOfLetters
value is equivalent to a pointer. So, your assembly code might need to be:
mov temp, 'X'
mov al, temp
mov edx, arrayOfLetters
mov [edx], al
In the above code, edx
is loaded with the address of arrayOfLetters
. Then the last instruction stores the al
byte into the address pointed to by edx
.
Solution 2
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
}
VV.
Updated on June 04, 2022Comments
-
VV. almost 2 years
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...