| View previous topic :: View next topic |
| Author |
Message |
Csimbi I post too much
Reputation: 98
Joined: 14 Jul 2007 Posts: 3375
|
Posted: Sat Jul 02, 2011 6:07 pm Post subject: What is the best way to set a memory location to a double? |
|
|
This is what I want to achieve:
| Quote: | | mov [eax+10], (double)1000 |
I guess I would load the integer 1000 to XMM0, then I would use this:
| Code: | | movq [eax+10], xmm0 |
but how do I save the XMM0, load the int into XMM0 and restore XMM0 efficiently?
Thank you.
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8585 Location: 127.0.0.1
|
Posted: Sat Jul 02, 2011 10:35 pm Post subject: |
|
|
Write a code cave to do all that if you want to 'save' the value before overwriting it. Or just directly write to the address and not overwrite xmm0 at all and remove the original instruction.
_________________
- Retired. |
|
| Back to top |
|
 |
Csimbi I post too much
Reputation: 98
Joined: 14 Jul 2007 Posts: 3375
|
Posted: Sun Jul 03, 2011 4:00 pm Post subject: |
|
|
| Wiccaan wrote: | | Write a code cave to do all that if you want to 'save' the value before overwriting it. Or just directly write to the address and not overwrite xmm0 at all and remove the original instruction. |
I think you're missing the point.
There's no such instruction as:
| Code: | | mov [eax+10], (double)1000 |
What is the most efficient way of implementing the instruction above (pluy, push and pop XMM0? What do you type in auto-assembler (the actual code)?
Thank you.
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8585 Location: 127.0.0.1
|
Posted: Sun Jul 03, 2011 7:20 pm Post subject: |
|
|
You'll need to look into floating point instructions then.
FIST / FISTP would probably be the ones you need mainly. I'm not at all an expert with the FPU instructions so I can't really help much other then suggesting you check into them.
_________________
- Retired. |
|
| Back to top |
|
 |
Freiza Grandmaster Cheater
Reputation: 22
Joined: 28 Jun 2010 Posts: 662
|
Posted: Mon Jul 04, 2011 2:51 am Post subject: |
|
|
i am not sure what is your requirement but I think this is what you want'
CVTTSD2SI r32, xmm/m64
example: CVTTSD2SI eax, xmm0
It will convert and Truncate to int
|
|
| Back to top |
|
 |
Geri Moderator
Reputation: 112
Joined: 05 Feb 2010 Posts: 5627
|
Posted: Mon Jul 04, 2011 10:00 am Post subject: |
|
|
This would add 5 (in double) to another double value every time when the code is executed.
| Code: | alloc(boostinc,8)
boostinc:
dq (double)5
newmem: //this is allocated memory, you have read,write,execute access
fld qword ptr [esi+00003CF8]
fadd qword ptr [boostinc]
fstp qword ptr [esi+00003CF8] |
As for simply using for "mov [blabla],(double)5":
| Code: | alloc(boostinc,8)
boostinc:
dq (double)5
newmem: //this is allocated memory, you have read,write,execute access
fld qword ptr [boostinc]
fstp qword ptr [esi+00003CF8] |
This code would convert an integer value from an address into double, but again, you need to define the value so it is basically the same solution but you define the number in integer and it is converted by fild.
| Code: | fild qword ptr [whatever_integer_value_on_an_address]
fstp qword ptr [esi+00003CF8] |
And if you want to push/pop XMM0, well I don't know if there is a legit instruction for that (on 32-bit), but you could just allocate 8 bytes, use movsd to move the values from XMM0 to the allocated address and push the values from the address in 2 pieces (4-4 bytes) as if they were 2 different values. I have never tried it, but in theory, there is nothing wrong with it (except the fact that it is pretty complicated for a seemingly easy task). I don't put values in the stack when I modify a code, so I have never tried. I would just leave it on an allocated address for storage if it is needed. I don't know how many programs are passing double values into 32-bit stack, but if they do, I am sure they split the value in 2 pieces.
_________________
|
|
| Back to top |
|
 |
Csimbi I post too much
Reputation: 98
Joined: 14 Jul 2007 Posts: 3375
|
Posted: Tue Jul 05, 2011 8:29 am Post subject: |
|
|
@Freiza
There is a double in XMM0, that's what I need to 'patch'.
Thanks for the reply though.
@Geri
Just what the doctor ordered!
Thank you!
|
|
| Back to top |
|
 |
|