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 


Need help dividing 16bit registers

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
Homtaro
How do I cheat?
Reputation: 0

Joined: 02 Apr 2022
Posts: 5

PostPosted: Fri Feb 03, 2023 4:49 pm    Post subject: Need help dividing 16bit registers Reply with quote

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
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4702

PostPosted: Fri Feb 03, 2023 5:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Fri Feb 03, 2023 6:06 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Homtaro
How do I cheat?
Reputation: 0

Joined: 02 Apr 2022
Posts: 5

PostPosted: Sat Feb 04, 2023 1:15 am    Post subject: Reply with quote

Thanks for the information, you guys are lifesavers.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4702

PostPosted: Sat Feb 04, 2023 2:59 am    Post subject: Reply with quote

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
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