问题描述
eax和ebx是32位寄存器。 a []和b []数组有4个字符和32位数据。我可以在每个寄存器中单独设置数组的每个索引,例如mov eax,a [1]。
但是我想将所有4个数组'a'的字符设置为eax寄存器。重要的是序列。我想设置这两个寄存器而不对数组内容序列进行任何更改。例如,第一个数组是[0] ='a',a [1] ='b',a [2] ='c',a [3] ='d',eax寄存器必须为abcd 。我怎么能这样做?
我尝试过:
eax and ebx are 32 bits registers. a[] and b[] arrays have 4 chars and 32 bits data. i can separately set each index of array in each register for example mov eax,a[1].
but I wanna set all 4 chars of array 'a' to eax register. the important thing is the sequence. I want to set those two registers without any changes in the arrays content sequence. for example first array is a[0]='a',a[1]='b',a[2]='c',a[3]='d' and the eax register must be as "abcd". how can I do that?
What I have tried:
<pre lang="c++">
int _tmain()
{
char b[4],a[4];
b[0]='A',b[1]='T',b[2]='C',b[3]='G';
a[0]='A',a[1]='T',a[2]='C',a[3]='G';
__asm
{
movzx eax,a[1] //here i want to load all 4 char of a
movzx ebx,b[1] //here i want to load all 4 char of b
}
getchar();
return 0;
}
推荐答案
MOV EAX,BYTE PTR [addr]
如果要从字节数组加载32位值,请告诉编译器他必须加载32位字(未经测试但应该这样做):
If you want to load a 32 bit value from a byte array, tell the compiler that he has to load 32 bit words (untested but should do it):
__asm
{
mov eax,DWORD PTR [a]
mov ebx,DWORD PTR [b]
}
请注意在这两种情况下使用 MOVZX
在源和目的地大小相同时没有任何意义。
同时进行了测试。使用 DWORD PTR
按预期工作,而使用转换指针不起作用(加载寄存器的地址为a32或b32)。
[/ EDIT ]
Note that in both cases using MOVZX
makes no sense when source and destination have the same size.
Have tested it meanwhile. Using DWORD PTR
works as expected while using a casted pointer does not work (loads register with address of a32 resp. b32).
[/EDIT]
eax和ebx是32位寄存器。 a []和b []数组有4个字符和32位数据。我可以在每个寄存器中单独设置数组的每个索引,例如mov eax,a [1]。
eax and ebx are 32 bits registers. a[] and b[] arrays have 4 chars and 32 bits data. i can separately set each index of array in each register for example mov eax,a[1].
首先,你应该尝试更换
first of all, you should try to replace
movzx eax,a[1] //here i want to load all 4 char of a
movzx ebx,b[1] //here i want to load all 4 char of b
by
by
movzx eax,a[0] //here i want to load all 4 char of a
movzx ebx,b[0] //here i want to load all 4 char of b
因为数组是0的基础C ++。
because arrays are 0 based in C++.
如何设置eax寄存器,内联汇编C ++
How to set eax register in, inline assembly C++
否则,你的问题是什么使用此代码?
otherwise, what is your problem with this code ?
这篇关于如何在内联汇编C ++中设置eax寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!