0

How could I convert a movq SSE2 instruction into a simple code snippet which I could later patch into the original EXE which cointained? Please if you could provide sample direct instructions to be used as a replacement "template", so much the better!

I am mostly interested in writing such template-based replacement into my CodeBlocks project using C mostly, so I'd prefer it to be inline ASM form. That way I could programatically patch the subst into original instructions which are 5-byte long with an ASM call to the inline piece of code within the same C I'm using to patch the EXE (rest of the code already written).

I know the question sounds a bit more general than you'd like maybe, but any insight will be appreciated. Thanks in advance!

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
MSC
  • 1
  • does this help: https://stackoverflow.com/questions/3852909/movq-assembly-function – Daniel A. White Feb 19 '21 at 18:14
  • Just to clarify: in the case in which I had say an `movq %xmm0, [some memory location]` (this is CodeBlocks in Linux), I got it when the XMM0 reg was 0, e.g. `xor %eax, %eax` and then patch it over two consecutive DWORDS at that location. But what if there's significant value charged previously in XMMn? How can I "discharge" the value into "normal" registers to drop afterwards into memory? (sorry I know quite my way in x86 standard ASM but had no experience previously with SSE/SSE2...) – MSC Feb 19 '21 at 18:22
  • @DanielA.White thanks, not sure if applicable.Are there any standard way of halving so to speak a `movq`into two halves that would execute in SSE2-less CPU? Do I need to use standard registers in the way? Is there any SSE2-less "write half of XMMn into DWORD" that I could use twice for the current loaded FP value? I'm confused because I've seen some other SSE (not 2 I guess) instructions that the CPU treats & executes normally. It's just a couple of movq's in the original code that I'm bothered with! (this is compiled code, if I had the source I could recompile with SSE2-less swtich/es...) – MSC Feb 19 '21 at 18:29

1 Answers1

1

With only MMX/SSE, the options are limited.

A movq from memory eg movq xmm4, [edx] may be emulated with:

xorps xmm4, xmm4
movlps xmm4, [edi]

A movq to memory eg movq [edx], xmm5 may be emulated with:

movlps [edx], xmm5
harold
  • 61,398
  • 6
  • 86
  • 164