1

I have done movdqu [dst], xmm0 but I keep getting errors, however this works:

mov esi, dst
movdqu [esi], xmm0

Why is that? And how can I use direct memory write?

Thank you.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Mathew Kurian
  • 5,949
  • 5
  • 46
  • 73
  • 1
    Did you define "dst" as a 128 bit item to the assembler? – Ira Baxter Dec 29 '13 at 03:33
  • In this case dst is a void*. Not sure what you mean. – Mathew Kurian Dec 29 '13 at 03:36
  • The x86 assemblers I am used to (MASM) insists that the size of the register entity, and the storage location to which it is assigned, be clearly the same size, or you get an assembly time error. I don't know what the item declaration is for a 128 bit item, but to do "mov [dst],ebx" you either have have to have declared dst as DWORD, or write "mov DWORD PTR[dst],ebx" to tell the assembler to treat the effective address as a DWORD entity. I assume an analog is true for xmm registers. – Ira Baxter Dec 29 '13 at 03:40
  • @IraBaxter I tried that but it still doesn't work for some reason. – Mathew Kurian Dec 29 '13 at 03:42
  • Tell us what assembler you are using, or if you are using inline assembly please give context including the host language code in which it is inlined, and also how you are calling it. – Ray Toal Dec 29 '13 at 03:42
  • You tried *what*, specifically for data type qualification? "void*" won't cut it for two reasons: a) it isn't compatible with 128 bit items, b) is sure as heck isn't assembly source code. – Ira Baxter Dec 29 '13 at 03:44
  • I just did `movdqu dword ptr[dest], xmm1;` with C++ assembly on 64 bit machine from visual studio 2013. I am new to this as you can probably already see. – Mathew Kurian Dec 29 '13 at 03:45
  • Sigh. Some uncharitable people might think you aren't doing your share of the homework, here. "dword ptr" is for 32 bit items; read my response carefully. You'll actually need to *read* the assembler manual to find out what to use for 128 bit items. – Ira Baxter Dec 29 '13 at 03:46
  • 1
    @IraBaxter Why is that I dont have to specify the size when I load `dst` into `esi` and then use `[esi]` for the `movdqu`? I looked and it said to use `xmmword ptr` which also fails. – Mathew Kurian Dec 29 '13 at 03:48
  • I can't answer *why*; I can only guess that the MASM designers decided that storing an item of known size (e.g., a register) indirect through a register pointer, made it clear enough. They could have decided that you needed the type qualifier in that case, too. So the decision seems arbitrary to me. You still have to honor it. Dunno why "xmmword ptr" fails, if indeed that is the correct size type designation; my experience is with 32 bit assembly code. I suggest you show the specific code you wrote, and the specific error you got, and let others provide the final answer. – Ira Baxter Dec 29 '13 at 04:08
  • Are you sure that your version of MASM supports SSE2? (or maybe you have to have a command line flag to enable those instructions?) – Alexis Wilke Dec 29 '13 at 04:48
  • @AlexisWilke I am new to this. I am using visual studio 2013, can you please explain it in terms of that. – Mathew Kurian Dec 29 '13 at 05:04
  • According to this forum post you may actually need some include so the instructions get recognized: http://masm32.com/board/index.php?topic=1438.0 – Alexis Wilke Dec 29 '13 at 05:14
  • There is also the .XMM instruction: http://msdn.microsoft.com/en-us/library/sk9wezsb.aspx – Alexis Wilke Dec 29 '13 at 05:16
  • In MASM, `mov esi, dst` is the same as `mov esi, [dst]`, this this load is an extra level of indirection, not something you can do with one store instruction. A `movdqu` store (or any addressing mode) needs the components in registers, not memory. If `dst` is actually another register somehow, then you just need the right size override like `oword ptr` or `xmmword ptr`, whichever MASM wants. – Peter Cordes Jun 28 '21 at 18:07

1 Answers1

1

If you are trying to move the 128 bits of memory starting at address dst into xmm0 you can do the following in MASM. (I have not used MASM since the early 1990s, but from what I remember this should work):

movdqu oword ptr dst, xmm0

You might also try

movdqu dst, xmm0

I think the issue here is that in most assemblers you would use brackets to denote the value of a variable, but in MASM you do not!

In the case of

mov esi, dst
movdqu [esi], xmm0

the brackets are required because esi is not a variable; it is a register.

Ray Toal
  • 86,166
  • 18
  • 182
  • 232
  • Bummer. If I had MASM I could probably get it to work. I'm sure there is _some_ type specifier you can use, because the instruction specification does not prohibit direct memory references! I know how to do this in other assemblers; I could add a NASM and GCC solution to my answer it that would help. For MASM, `oword` looked promising. Sorry. – Ray Toal Dec 29 '13 at 04:17
  • @RayToai Thats absolutely fine. Would it be faster if I load directly into xmm versus loading into register and then into xmm? I am just curious here. – Mathew Kurian Dec 29 '13 at 04:18
  • I edited my answer because I think I figured it out for MASM. See if it works for you this way. I had to dig up [my old assembler notes](http://cs.lmu.edu/~ray/notes/x86assembly/). I found the idea in the "Differences section" near the bottom of the page. – Ray Toal Dec 29 '13 at 04:27
  • @RayToai Hate to be the bearer of bad news, but it still doesn't work for some reason. – Mathew Kurian Dec 29 '13 at 04:34
  • 2
    I believe the prefix is xmmword not oword. – Raymond Chen Dec 29 '13 at 04:46
  • @mk1 Next thing to try is `xmmwordptr` which was suggested in the comments to your question (and which Raymond Chen just pointed out). You might have tried it with brackets earlier. I got this working, BTW, in NASM, where the brackets are used. Just saying. – Ray Toal Dec 29 '13 at 04:48
  • @RayToal I have no clue then why its not working for me then. I did with brackets and without brackets. I also used the `xmmword ptr` not `xmmwordptr` which it says is not supported. – Mathew Kurian Dec 29 '13 at 05:06
  • @mk1: Why did you check this as the "correct" answer, if it doesn't work for you ? – Ira Baxter Jan 02 '14 at 08:41
  • @IraBaxter For the effort, its the least I can do. But, I do see it as misguiding so I will remove it. – Mathew Kurian Jan 02 '14 at 09:48
  • 1
    For the record, NASM uses `oword` and doesn't recognize `xmmword`. GAS uses `xmmword ptr`. [Unable to compile assembly code with xmmword operand-size using nasm](https://stackoverflow.com/q/67819051). AFAIK, nothing uses `xmmwordptr` (without a space). Also, all assemblers accept `movdqu [esi], xmm0` with xmm0 implying the operand-size. (Or any other way of specifying a destination operand, unless you're using MASM and need a size override because of some symbol name magically implying an operand-size, then you might actually need `xmmword ptr`) – Peter Cordes Jun 03 '21 at 09:54