Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
}
Posted
Updated 2-Aug-18 12:05pm
Comments
Richard MacCutchan 3-Aug-18 4:12am    
Why? As soon as that code is passed then the registers will be used for other purposes, as decided by the compiler.

The compiler knows that the arrays are of type char and generates a
MOV EAX,BYTE PTR [addr]

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):
C++
__asm
{
    mov eax,DWORD PTR [a]
    mov ebx,DWORD PTR [b]
}

Or cast the char array pointers to DWORD pointers:
uint32_t* a32 = reinterpret_cast<uint32_t*>(a);
uint32_t* b32 = reinterpret_cast<uint32_t*>(b);
__asm
{
    mov eax,a32[0]
    mov ebx,b32[0]
}
Note that in both cases using MOVZX makes no sense when source and destination have the same size.

[EDIT]
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]
 
Share this answer
 
v2
Quote:
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
C++
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
C++
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

because arrays are 0 based in C++.
Quote:
How to set eax register in, inline assembly C++

otherwise, what is your problem with this code ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900