user1502256
user1502256

Reputation:

Move [eax+4] in VS

I can't compile this, how should I move [eax+4] to y in Visual Studio?

float x, y, z;

__asm
{
    mov x,      eax
    mov y,      [eax+4]
    mov z,      [eax+8]
}

EDIT:

Error 1 error C2424: '+' : improper expression in 'second operand'

Upvotes: 0

Views: 883

Answers (3)

Sedat Kapanoglu
Sedat Kapanoglu

Reputation: 47660

You're using eax as a pointer, so storing that bit-pattern into float x seems unlikely. Perhaps you meant to copy 3 floats from memory at [eax+0], +4, and +8?

@RaymondChen is right, you can use a temporary register to transfer it. The obvious choice is to pick ECX or EDX as a temporary; those along with EAX are call-clobbered so using them won't force the compiler to save/restore them in the function containing your asm block.

Even though the values are float, you can copy them with 32-bit integer registers instead of through XMM0 or an x87 register; you're not doing FP math on them.

mov   ecx, [eax]
mov   x, ecx            // you probably want this, not  mov x, eax
mov   ecx, [eax+4]
mov   y, ecx
mov   ecx, [eax+8]
mov   z, ecx

If you knew x and y were contiguous, you could copy 8 bytes at once with an XMM register.

Upvotes: 3

Natascha Koschkina
Natascha Koschkina

Reputation: 11

float x, y, z;

__asm
{
    mov x,      eax
    push        eax
    mov eax,    [eax+4]
    mov y,      eax
    pop         eax
    mov eax,    [eax+8]
    mov z,      eax
}

Upvotes: -2

Raymond Chen
Raymond Chen

Reputation: 45173

The MOV instruction cannot move memory to memory. Check your favorite assembly language reference for more details on the rules for each instruction. If something is not explicitly listed as permitted, then it is not allowed. You can't just make up stuff. Processors are very picky.

Upvotes: 10

Related Questions