Is there a way of modifying specific array elements with inline assembly ?
int move[2];
I'm looking to change move[0]
and move[1]
in __asm
.
I am a novice with assembly coding, mainly stick to C++, and there is probably a very simple answer.
So far I've attempted to move move[1]
into registers, move the number I want to change it to into another, and then move one into the other. I have managed to get it to compile but it doesnt actually work.
You can use something like MOV array[TYPE array * index], value;
, for example:
#include <stdio.h>
int main(int argc, char **argv) {
int foo[] = {1, 2, 3};
printf("%d\n", foo[0]);
printf("%d\n", foo[1]);
printf("%d\n", foo[2]);
__asm {
MOV foo[TYPE foo * 0], 11;
MOV foo[TYPE foo * 1], 22;
MOV foo[TYPE foo * 2], 33;
};
printf("%d\n", foo[0]);
printf("%d\n", foo[1]);
printf("%d\n", foo[2]);
return 0;
}
TYPE
will return the size of one element of the array. The output:
1
2
3
11
22
33
来源:https://stackoverflow.com/questions/21369405/modifying-array-elements-with-inline-assembly