View previous topic :: View next topic |
Author |
Message |
sir-gunny Advanced Cheater
Reputation: 0
Joined: 15 Mar 2012 Posts: 81
|
Posted: Mon Oct 15, 2012 3:46 am Post subject: add [ecx+94],(float)50000 dont work! Why? |
|
|
Hi.
I want to add (float)50000 to [eax] with this asm:
add [ecx+94],(float)50000
But it dont work.
If i use mov, it writes the value perfect.
how can I add (float) 50000 to eax?
|
|
Back to top |
|
 |
mgr.inz.Player I post too much
Reputation: 222
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Mon Oct 15, 2012 6:02 am Post subject: |
|
|
You wrote, "add to [eax]"
solution 1:
add [eax],(float)50000
Then you wrote, "add to eax"
solution 2:
add eax,(float)50000
_________________
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25794 Location: The netherlands
|
Posted: Mon Oct 15, 2012 6:19 am Post subject: |
|
|
ADD doesn't work with a floating point addition
I usually use ADDSS
I guess the usual fpu instructions can be used as well, but I find them more complex to use than sse
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
sir-gunny Advanced Cheater
Reputation: 0
Joined: 15 Mar 2012 Posts: 81
|
Posted: Mon Oct 15, 2012 10:40 am Post subject: |
|
|
Hi Dark Byte.
If i use addss [edx+000000C4],(float)50000, i get an error: This instruction can't be compiled.
Whats wrong?
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25794 Location: The netherlands
|
Posted: Mon Oct 15, 2012 11:29 am Post subject: |
|
|
the problem with addss (and other sse instructions) is that it must use a xmm register as destination and a memory address or other xmm register as source. No direct assignments either
so try something like this:
Code: |
sub esp,#20 //allocate 20bytes for local storage (original xmm0 register(16) and temp float value(4))
movdqu [esp],xmm0 //save xmm0 (128 bit register, so 16 bytes)
mov [esp+10],(float)50000 //prepare an address with the float value 50000
movss xmm0,[esp+10] //write the float value into xmm0 (note that the upper bits of xmm0 will get erased by doing this, which is why we use movdqu to save it and not movss)
addss xmm0, [edx+c4] //increase xmm0 (50000.0) with the float value at edx+c4
movss [edx+c4],xmm0 //write the result of the calculation to edx+c4
movss xmm0,[esp] //restore with original
add esp,#20 //free local variable space
|
I haven't really tested it, but this is the general gist of it
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
sir-gunny Advanced Cheater
Reputation: 0
Joined: 15 Mar 2012 Posts: 81
|
Posted: Mon Oct 15, 2012 12:31 pm Post subject: |
|
|
YEA!!! It works!!!
Dark Byte you are the godfather of ASM and GameHack!!!
Big THX
|
|
Back to top |
|
 |
mgr.inz.Player I post too much
Reputation: 222
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Mon Oct 15, 2012 1:12 pm Post subject: |
|
|
uhm, sorry, I though it was integer. I just made quick reply too quick.
Btw. there are other ways. For example I used for other games where values were floats but they have always integer values.
And there is e.g.:
movss [edi+04],xmm0
and I want [edi+04] to be 5000 bigger, I use this
push eax
cvttss2si eax,xmm0
add eax,(int)5000
cvttsi2ss xmm0,eax
pop eax
movss [edi+04],xmm0
_________________
|
|
Back to top |
|
 |
|