How to access C arrays from assembler for Windows x64?

Posted by 0xdword32 on Stack Overflow See other posts from Stack Overflow or by 0xdword32
Published on 2010-03-18T12:46:15Z Indexed on 2010/03/18 12:51 UTC
Read the original article Hit count: 343

Filed under:
|
|
|
|

I've written an assembler function to speed up a few things for image processing (images are created with CreateDIBSection).

For Win32 the assembler code works without problems, but for Win64 I get a crash as soon as I try to access my array data.

I put the relevant info in a struct and my assembler function gets a pointer to this struct. The struct pointer is put into ebx/rbx and with indexing I read the data from the struct.

Any idea what I am doing wrong? I use nasm together with Visual Studio 2008 and for Win64 I set "default rel".

C++ code:

struct myData {
  tUInt32 ulParam1;
  void* pData;
};

CallMyAssemblerFunction(&myData);

Assembler Code:

Win32:

...
  push ebp;
  mov ebp,esp
  mov ebx, [ebp + 8]; pointer to our struct
  mov eax, [ebx]; ulParam1
  mov esi, [ebx + 4]; pData, 4 byte pointer

  movd xmm0, [esi];
...

Win64:

...
  mov rbx, rcx; pointer to our struct
  mov eax, [rbx]; ulParam1
  mov rsi, [rbx + 4]; pData, 8 byte pointer

  movd xmm0, [rsi]; CRASH!
...

© Stack Overflow or respective owner

Related posts about c++

Related posts about assembler