0

I have two similar issues when handling arrays when defined in the asm and when passed from c++ to asm. The code works fine inline but I need to separate them from the cpp into an asm file. The compiler may not throw an error or warning but the end result is random each run and should be constant like it was when inline.

The below code works when used in MMX (movq mm6,twosMask_W) but I need the equivalent for SSE2. I thought that this would work but I appear to be incorrect.

.data
align 16
twosMask_W qword 2 dup(0002000200020002h)
.code
...
movdqa xmm6,oword ptr twosMask_W
...

The second issue is when I pass my thresh128 array from C++ to asm (again for SSE2):

//C++
uint64_t thresh128[2];
thresh128[0] = ((thresh-1)<<8)+(thresh-1);
thresh128[0] += (thresh128[0]<<48)+(thresh128[0]<<32)+(thresh128[0]<<16);
thresh128[1] = thresh128[0];
sendToASM(thresh128)

//ASM
;There are more parameters that utilize the registers but not listed.
receivedFromCPP proc thresh:qword
public receivedFromCPP
...
movdqu xmm4,oword ptr thresh
...

I've tried having thresh as an oword parameter in the procedure but it yielded no results. I'm sure I've got some syntax or parameter type wrong. Any help would be greatly appreciated.

Note: Compiled using MASM in VS2013 for x86.

Elegant
  • 143
  • 2
  • 15
  • Keep in mind that you can't pass arrays as parameters: they decay to pointers. You're showing very little code, but this could be an issue. – zneak Mar 07 '15 at 19:55
  • I'm using the uint64 array to act as a uint128 when it's passed, it will be a pointer but I should be able to access it correctly. I could provide more code but ultimately I'm just looking for the proper way to pass the "uint128" to asm. When it was inline it worked by simply using `movdqu xmm4,thresh128` which instantly grabbed the C++ array and used it without issue. – Elegant Mar 07 '15 at 20:03

1 Answers1

0

Well, I tested the first part and it seems to work - so I cannot say anything related to this particular issue.

Concerning the second problem: you seem to pass a 64 bit qword on the stack in 32 bit mode (where is no direct opcode for 64 bit PUSHes) so it would be 2 PUSHes...

receivedFromCPP proc thresh:qword

but are expecting a pointer to a 128 bit value on the stack:

movdqu xmm4,oword ptr thresh

Also keep in mind the little-endianess of x86 - depending on how the compiler chooses to PUSH the 2*64bit-array it may be different from a little-endian-value resulting in seemingly random values.

EDIT: Because the stack grows upside-down, a 128 bit value has to be PUSHed in reverse order for referencing it by EBP.

zx485
  • 28,498
  • 28
  • 50
  • 59
  • I updated my code to reflect how the array values are reversed but am still having issues. It's strange that having this code inline causes no issues... – Elegant Mar 09 '15 at 21:04
  • just reverse the two uint64_t as they are already little endian: `uint64_t temp = thresh[1]; thresh[1] = thresh[0]; thresh[0] = temp; ` Without a disassembly of both code versions it's hard to tell what's wrong. – zx485 Mar 10 '15 at 08:13