Modifying array elements with inline assembly

最后都变了- 提交于 2019-12-01 21:39:12

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!