如何通过x86程序集访问int数组中的元素?
我当前的代码显示了我要做什么:
int arr[3]{0,6,8};
__asm
{
mov eax, [arr+1*4] // access value "6" in the array and put it in eax
}
eax显示一个“ 0F5CA9A1”,而不是6
最佳答案
以下代码可在VS 2013上完美运行:
int array[] = { 10, 20, 30 };
int idx0, idx1, idx2;
__asm {
mov eax, [array + 0 * 4]
mov idx0, eax
mov eax, [array + 1 * 4]
mov idx1, eax
mov eax, [array + 2 * 4]
mov idx2, eax
}
printf("%d %d %d\n", idx0, idx1, idx2);
输出:
10 20 30
关于c - 如何通过x86程序集访问int数组中的元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24025293/