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 


(ASM) ROL and ROR?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Mon Nov 14, 2016 11:43 am    Post subject: (ASM) ROL and ROR? Reply with quote

I have two questions.

First, the concept of ROL/ROR. For example, if "al = 01010101",
1) After "rol al,1", does al equal "10101010"?

2) After "rol al,2", does al equal "01010101"?

Second, what's the purpose of ROL/ROR? Can someone translate it into C++? Is it some kind of arithmetic operation?


Thanks a lot.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 154

Joined: 06 Jul 2014
Posts: 4754

PostPosted: Mon Nov 14, 2016 12:10 pm    Post subject: Reply with quote

https://en.wikipedia.org/wiki/Circular_shift
_________________
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
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Mon Nov 14, 2016 12:49 pm    Post subject: Reply with quote

ParkourPenguin wrote:
https://en.wikipedia.org/wiki/Circular_shift


Thanks for the link. Please take a look at the question below if you have time. Smile


If al holds 8, an integer, it is "00001000" in binary. After "rol al,1", it becomes "00010000", which is 16, right? My question is, what's the purpose of using ROL ? Why not just use multiplication, like multiply al with 2?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 473

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

PostPosted: Mon Nov 14, 2016 12:56 pm    Post subject: Reply with quote

multiply is slower than a simple rotate (of course smart cpu's usually detect multiplications by factors of two and turn it into a shift internally anyhow)

Also, for multiplication I recommend shl as it just adds a 0 instead of using a bit that could roll over.

ROL is usually used for encryption or obfuscation uses (e.g some games rotate by 12 just to make things harder to find)

_________________
Tools give you results. Knowledge gives you control.

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

Joined: 06 Jul 2014
Posts: 4754

PostPosted: Mon Nov 14, 2016 12:59 pm    Post subject: Reply with quote

In that specific example, bitwise operations are generally simpler, easier, and faster than arithmetic operations. When multiplying by powers of 2, I'd use shl: using mul just seems stupid to me when there's a bitwise operator that can do it faster, and rol makes less sense semantically since bits that overflow would roll over.

For other examples, use Google. e.g.:
http://stackoverflow.com/a/19912005

_________________
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
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Mon Nov 14, 2016 1:01 pm    Post subject: Reply with quote

Dark Byte wrote:
multiply is slower than a simple rotate (of course smart cpu's usually detect multiplications by factors of two and turn it into a shift internally anyhow)

Also, for multiplication I recommend shl as it just adds a 0 instead of using a bit that could roll over.

ROL is usually used for encryption or obfuscation uses (e.g some games rotate by 12 just to make things harder to find)


Oh, got it! Then I think the game I am trying to hack uses ROL to encrypt numbers, because every ROL is followed by a ROR somewhere later in the code. Thanks for pointing that out, Dark Byte. Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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