| View previous topic :: View next topic |
| Author |
Message |
++METHOS I post too much
Reputation: 92
Joined: 29 Oct 2010 Posts: 4197
|
Posted: Mon Feb 07, 2022 7:12 pm Post subject: Add Fixed Number to Float Value? |
|
|
I am trying to add (float)3 on top of the elevation value, but I am not sure how to do it.
For example, this will not work:
| Code: | mov rdx,[elevation_value]
add rdx,(float)3 // I want to take the elevation_value and add float 3 to it
mov [rdi+78],rdx // [rdi+78] contains vertical coordinate
|
This code appears to overwrite rdx with (float) 3 instead of adding it on top of elevation_value for some reason.
To clarify, if elevation_value is (float)100, then I want to be able to add 3 on top of it, so that it becomes (float)103 before it gets loaded into the vertical coordinate value.
How to do this properly?
Thanks.
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25831 Location: The netherlands
|
Posted: Mon Feb 07, 2022 7:26 pm Post subject: |
|
|
probably something like:
| Code: |
alloc(value3,4)
...
value3:
dd (float)3
...
movss xmm1,[elevation_value]
addss xmm1,[value3]
movss [rdi+78],xmm1
|
or
| Code: |
mov rdx,[elevation_value]
{$ccode ev=rdxf}
ev=ev+3.0f
{$asm}
mov [rdi+78],rdx
|
_________________
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 |
|
 |
++METHOS I post too much
Reputation: 92
Joined: 29 Oct 2010 Posts: 4197
|
Posted: Tue Feb 08, 2022 5:00 am Post subject: |
|
|
You are awesome, DB. Thank you very much.
By the way, the first solution worked, but the second one did not work for some reason.
Thanks so much.
|
|
| Back to top |
|
 |
Csimbi I post too much
Reputation: 97
Joined: 14 Jul 2007 Posts: 3337
|
Posted: Tue Feb 08, 2022 7:33 am Post subject: |
|
|
| Code: | push (float)3.0
addss xmm1,[rsp]
add rsp,8 |
?
If the value is always the same, allocating that and using that address directly like DB suggested is faster.
I.e.
| Code: |
addss xmm1,[myvalue]
|
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25831 Location: The netherlands
|
Posted: Tue Feb 08, 2022 4:21 pm Post subject: |
|
|
| Quote: |
By the way, the first solution worked, but the second one did not work for some reason.
|
Right, there is an issue with the XXXf reg notation in ccode (picks the wrong reg)
for now should be able to do:
| Code: |
{$ccode ev=rdx}
float *evfix=(float*)&ev;
*ev=*ev+3.0f
{$asm}
|
_________________
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 |
|
 |
++METHOS I post too much
Reputation: 92
Joined: 29 Oct 2010 Posts: 4197
|
Posted: Tue Feb 08, 2022 4:29 pm Post subject: |
|
|
| Thank you, Csimbi and Dark Byte. I really appreciate everyone's help.
|
|
| Back to top |
|
 |
|