Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How to Negate XMM Register?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Mon Jan 31, 2022 4:51 am    Post subject: How to Negate XMM Register? Reply with quote

Having trouble with this one.

I have this code segment:

Code:
sub rsp,#20
movdqu [rsp],xmm0
movss xmm0,[speed_lmodifier]         ///////////Need to be able to negate custom input here
movss [rsp+10],xmm0
movss xmm0,[rsp+10]
addss xmm0,[rdi+70]
movss [rdi+70],xmm0
movdqu xmm0,[rsp]
add rsp,#20


The [speed_lmodifier] is being used for custom/user input, and occurs multiple times throughout the script. In some places, the value needs to be positive, and in other places, the value needs to be negative.

I have tried doing this many different ways that I can think of, but nothing I have done is working 100% as it should.

Thanks.
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 55

Joined: 01 Oct 2008
Posts: 943

PostPosted: Mon Jan 31, 2022 6:28 am    Post subject: This post has 1 review(s) Reply with quote

If there is a near memory that can store a float value -1,
Code:

...
movss    xmm0,[MinusOne] /// MinusOne stored (float)-1
mulss    xmm0,[speed_lmodifier]
addss    xmm0,[rdi+70]
movss    [rdi+70],xmm0
...

else may need an extra register
Code:

...
mov      eax,(float)-1
movd   xmm0,eax /// use rax & movq for double
mulss    xmm0,[speed_lmodifier]
addss    xmm0,[rdi+70]
movss    [rdi+70],xmm0
...

there should be other ways.

_________________
- Retarded.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25298
Location: The netherlands

PostPosted: Mon Jan 31, 2022 7:40 am    Post subject: This post has 2 review(s) Reply with quote

if you're lazy
Code:

{$ccode val=XMM0.0}
val=-val;
{$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
View user's profile Send private message MSN Messenger
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Mon Jan 31, 2022 11:37 am    Post subject: Reply with quote

panraven wrote:

Code:

...
mov      eax,(float)-1
movd   xmm0,eax /// use rax & movq for double
mulss    xmm0,[speed_lmodifier]
addss    xmm0,[rdi+70]
movss    [rdi+70],xmm0
...
-Thank you. This works. When I tried this before, it did not work. I realized that I needed to remove some lines.
I cannot +rep you yet, but I will not forget.



Dark Byte wrote:
Code:

{$ccode val=XMM0.0}
val=-val;
{$asm}
-Thank you. How to implement? Does this have to wrap the specific xmm0 register that I am trying to manipulate, or is val used as a variable?

I appreciate everyone's help. Thank you.
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1055
Location: 0x90

PostPosted: Mon Jan 31, 2022 12:24 pm    Post subject: This post has 1 review(s) Reply with quote

++METHOS wrote:

Dark Byte wrote:
Code:

{$ccode val=XMM0.0}
val=-val;
{$asm}
-Thank you. How to implement? Does this have to wrap the specific xmm0 register that I am trying to manipulate, or is val used as a variable?

I appreciate everyone's help. Thank you.


Like this for example:
Code:

...
newmem:
sub rsp,#20
movss xmm0,[speed_lmodifier]         ///////////Need to be able to negate custom input here

{$ccode val=XMM0.0}
val=-val;
{$asm}

movss [rsp+10],xmm0
movss xmm0,[rsp+10]
addss xmm0,[rdi+70]
movss [rdi+70],xmm0
movdqu xmm0,[rsp]
add rsp,#20
...


Val is just an arbitrary name for something you recognise. It is essentially giving the xmm0 register an identifier which can be used within the scope of the in-line block.
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Mon Jan 31, 2022 12:39 pm    Post subject: Reply with quote

Thanks. So, the code is only executed where it is placed and is no longer applied throughout? In other words, wherever it is placed is basically like doing the following:

Code:
neg xmm0


or

Code:
mulss xmm0,-1


Thanks for your help.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25298
Location: The netherlands

PostPosted: Mon Jan 31, 2022 12:47 pm    Post subject: This post has 1 review(s) Reply with quote

yes, unlike lua blocks ccode (and luacode) blocks execute only when the code reaches that point
_________________
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
View user's profile Send private message MSN Messenger
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4307

PostPosted: Mon Jan 31, 2022 1:09 pm    Post subject: This post has 1 review(s) Reply with quote

Compilers will produce an xorps instruction:
Code:
// float negate(float f) {
//     return -f;
// }
negate:
  xorps xmm0,[.LC0]
  ret

align 4 CC
.LC0:
  dd 80000000


See this post for more information and examples on luacode and ccode:
https://forum.cheatengine.org/viewtopic.php?t=618134

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Tue Feb 01, 2022 1:32 pm    Post subject: Reply with quote

Thank you all for your help. I really appreciate it.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites