## How to do a MATH in ASM script in CE? (addition, subtraction, division, multiplication)

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
MartaLabieniec
Expert Cheater
Posts: 236
Joined: Sat Oct 06, 2018 3:19 pm
Reputation: 104

### How to do a MATH in ASM script in CE? (addition, subtraction, division, multiplication)

Hello Guys.

I have very big problem - I don't know how to properly do a MATH in CE script.

I want to DIVIDE by 2 the VALUE which I will write in the script.

I have a function: mulss xmm0,[ebp+104]

EBP+104 is having the value which I am interested in FLOAT type. If I will write script like that:

Code: Select all

``````mov [ebp+104],(float)200
mulss xmm0,[ebp+104]``````
I will add 200 into EBP+104 but the result of my hacking is displayed in the game as: 400 - because the game multiplies itself by the value of two.

So doesn't matter what I will write, the result will be always the same = if I will write 100, I will get result of 200 ; if I will write a 150, I will get the result of 300 ; if I will write a 200, I will get the result of 400.... and so on & son.

How to properly write a script to do a Math without me?

I just want to write for example 300 value and then see this 300 value in my game (not 600).

I made a screenshot from BACK & TRACE:

I was trying to do something like these:

Code: Select all

``````alloc(newmem,2048)
globalalloc(dupa,4)
label(returnhere)
label(originalcode)
label(exit)

newmem: //this is allocated memory, you have read,write,execute access

originalcode:
push eax
push edx
push ebx
mov ebx,[dupa]
mov [ebp-14],ebx
pop ebx
mov edx,[ebp-14]
mov eax,[edx]
push ebx
mov ebx,#2
div ebx
mov [ebp-14],eax

mulss xmm0,[ebp-14]
pop edx
pop ebx
pop eax``````
by after activating script - the game is crashing. What is wrong? I did this by reading this tutorial ---> https://wiki.cheatengine.org/index.php? ... VFFUBCjhN8

I don't know what is wrong and why it is crashing my game after activation.

Best Regards.
Marta.

DrummerIX
ViP
Posts: 1654
Joined: Wed Mar 22, 2017 6:15 pm
Reputation: 1745

### Re: How to do a MATH in ASM script in CE? (addition, subtraction, division, multiplication)

If I'm understanding what you want to do, just mov the float value to xmm0 without doing the multiplication the game is doing.

Code: Select all

``````alloc(newmem,2048)
globalalloc(dupa,4)
label(returnhere)
label(originalcode)
label(exit)

newmem: //this is allocated memory, you have read,write,execute access
movss xmm0,[dupa]

originalcode:
// Do Nothing here because you don't want to multiply
jmp returnhere

dupa:
dd (float)200
``````

MartaLabieniec
Expert Cheater
Posts: 236
Joined: Sat Oct 06, 2018 3:19 pm
Reputation: 104

### Re: How to do a MATH in ASM script in CE? (addition, subtraction, division, multiplication)

I did like you wrote but it was wrong because the game was still multiplying the value with 2 so it wasn't working.

But I FIXED IT!

I read some info about XMM registers and I did something like that:

Code: Select all

``````alloc(newmem,2048)
globalalloc(dupa,4)
globalalloc(hey,4)
label(returnhere)
label(originalcode)
label(exit)

newmem: //this is allocated memory, you have read,write,execute access
movss xmm0,[dupa]
divss xmm0,[hey]

originalcode:
// Do Nothing here
jmp returnhere

hey:
dd 2``````
And now is perfectly working! I have DUPA outside the script and I am writing value in FLOAT, for example 200 and thanks to HEY, now in the game I can also see 200 value, not like earlier 400.

When I was reading this tutorial --> https://wiki.cheatengine.org/index.php? ... VFFUBCjhN8 I probably wrong understand it because I was thinking that [ebp+104] has an address generating with every new opening of the game - I understood like that thanks to this tutorial which I posted the link.

Now I know that I can do MATH with XMM registers only?

Chucky
Expert Cheater
Posts: 51
Joined: Thu Mar 08, 2018 4:01 pm
Reputation: 14

### Re: How to do a MATH in ASM script in CE? (addition, subtraction, division, multiplication)

MartaLabieniec wrote:
Fri Jul 12, 2019 9:40 am
Now I know that I can do MATH with XMM registers only?
Nope.
SSE and AVX (1,2). Even CUDA.

MartaLabieniec
Expert Cheater
Posts: 236
Joined: Sat Oct 06, 2018 3:19 pm
Reputation: 104

### Re: How to do a MATH in ASM script in CE? (addition, subtraction, division, multiplication)

Can you share any tutorials or examples to study and learn?

### Who is online

Users browsing this forum: No registered users