View previous topic :: View next topic |
Author |
Message |
Homtaro How do I cheat?
Reputation: 0
Joined: 02 Apr 2022 Posts: 5
|
Posted: Fri Feb 03, 2023 4:49 pm Post subject: Need help dividing 16bit registers |
|
|
So I got back into cheat engine and encountered a problem:
I dont know optimal way to divide registers such as ax,cx etc.
Right now I'm working on script dividing ax in following code:
Code: |
sub cx,ax
mov eax,[esp+08]
|
I could use shr, but I want more precise control, something like using div,[something].
Also if there is good website\guide with such information so I dont ask dumb questions in future, a link would be great.
Any help is appreciated.
|
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4702
|
Posted: Fri Feb 03, 2023 5:29 pm Post subject: |
|
|
I'd recommend using floating point math so you can divide by a fractional amount: 1.5 for example.
Code: | ...
alloc(newmem,4096)
label(divisor)
newmem:
movzx eax,ax
cvtsi2sd xmm0,eax
divsd xmm0,[divisor]
cvttsd2si eax,xmm0
code:
sub cx,ax
mov eax,[esp+08]
jmp return
newmem+800:
divisor:
dq (double)1.5
... |
See any x86-64 instruction set reference manual for information on instructions. Intel has official PDFs on their website, but there are more accessible mirrors:
https://www.felixcloutier.com/x86/
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25796 Location: The netherlands
|
Posted: Fri Feb 03, 2023 6:06 pm Post subject: |
|
|
You don't have to use floats if you don't want to.
e.g. divide by 1.5: first multiply the value by 10 and then divide it by 15
_________________
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 |
|
 |
Homtaro How do I cheat?
Reputation: 0
Joined: 02 Apr 2022 Posts: 5
|
Posted: Sat Feb 04, 2023 1:15 am Post subject: |
|
|
Thanks for the information, you guys are lifesavers.
|
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4702
|
Posted: Sat Feb 04, 2023 2:59 am Post subject: |
|
|
Fixed point math is also an option, albeit quite obscure:
Code: | // divides by 1.5
movzx eax,ax
imul rax,rax,AAAAAAAC
shr rax,32 | I had to fiddle with a compiler to get this. I'm just pointing out that this exists: don't actually use this in anything.
The benefit of using a float / double is it's easy for the user to change it in the address list. Just use registersymbol to make it accessible.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
|