0

I am doing my school project: dynamic MASM assembler library in Visual Studio, that implements CaesarCipher's method. Everything worked fine, when I was using console application. When I created Windows Forms UI, MMX functions started to cause errors.

MMX functions - the problem of my project. I see no point of usage it in my project, but one of things I have to do is to use MMX code, even though its useless.

In console that worked fine:

movq mm1, mm0

In Forms Application it causes generic error.

user1678401
  • 55
  • 1
  • 7

1 Answers1

5

Using an MMX instruction will cause the FPU to switch to MMX mode (sort of, it's not really a mode), which means that all 8 FPU registers will become valid and ready for use by MMX instructions. Using an x87 instruction while in this state can easily fail, all the FPU stack slots are filled so loading anything will cause an FPU stack overflow. In a console program it can easily be the case that no x87 instructions were used at all, so it wasn't a big problem to leave the FPU in that state, but windows forms uses some x87 instructions and they assumed there would be space on the FPU stack as usual.

You can empty the FPU stack after using MMX by using the emms instruction.

harold
  • 61,398
  • 6
  • 86
  • 164
  • At least the sysv abi mandates fpu stack to be empty upon entry into a function, I assume microsoft does it too even though I couldn't find a document explicitly stating this. The [most relevant msdn article](https://msdn.microsoft.com/en-us/library/ha59cbfz.aspx) only talks about function exit, not entry. – Jester Nov 13 '15 at 13:42
  • 1
    @Jester I've found [an other source](http://www.agner.org/optimize/calling_conventions.pdf) that says it must be empty on entry as well (as I would expect), but I haven't been able to find Microsoft saying this directly – harold Nov 13 '15 at 14:03