| View previous topic :: View next topic |
| Author |
Message |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Mon Nov 14, 2016 11:43 am Post subject: (ASM) ROL and ROR? |
|
|
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 |
|
 |
ParkourPenguin I post too much
Reputation: 154
Joined: 06 Jul 2014 Posts: 4754
|
|
| Back to top |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Mon Nov 14, 2016 12:49 pm Post subject: |
|
|
| 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.
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 |
|
 |
Dark Byte Site Admin
Reputation: 473
Joined: 09 May 2003 Posts: 25909 Location: The netherlands
|
Posted: Mon Nov 14, 2016 12:56 pm Post subject: |
|
|
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 |
|
 |
ParkourPenguin I post too much
Reputation: 154
Joined: 06 Jul 2014 Posts: 4754
|
Posted: Mon Nov 14, 2016 12:59 pm Post subject: |
|
|
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 |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Mon Nov 14, 2016 1:01 pm Post subject: |
|
|
| 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.
|
|
| Back to top |
|
 |
|