修改与内联汇编数组元素 [英] Modifying array elements with inline assembly

查看:476
本文介绍了修改与内联汇编数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有修改特定的数组元素与内联汇编的一种方式?

Is there a way of modifying specific array elements with inline assembly ?

int move[2];

我期待改变移动[0] 移动[1] __ ASM 。结果
我用汇编编码新手,主要是坚持到C ++,大概有一个很简单的答案。结果
到目前为止,我试图移动移动[1] 到寄存器,将我想要将其更改为到另一个数字,然后移动一成其他。我设法得到它的编译,但它不实际工作。

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.

推荐答案

您可以使用类似 MOV阵列[类型数组*指数]值; ,例如:

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

这篇关于修改与内联汇编数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆