What is the mathematical equivalent of turning left?

I am trying to decrypt some assembly code, which includes several left-handed rotations of an 8-bit binary number.

For reference, code:

lab: rol dl,1 rol dl,1 dec ecx jnz lab 

dec and jnz not a problem, but you need to show that 2 rol are executed several times.

What I'm trying to do is calculate the mathematical equivalent of this code, like a formula. Of course, I am not looking for a complete formula to tell me all the code, but I would like to know if there is a formula that gives the equivalent (in denar) of one left rotation.

I tried to figure this out with a pair of different numbers, but I don’t see the connection between the two results. For example: if the start number is 115, it is displayed as 220, but if the start number is 99, it is displayed as 216.

+4
source share
2 answers

Given your sample results, I assume that we treat the 8-bit quantity as unsigned.

7 least significant bits are shifted to the left, multiplying this part of the number by 2; and a high order bit is exchanged for the beginning.

Thus, (x % 128) * 2 + (x / 128) using the usual integer div / mod operators.

+8
source

Offset of the byte containing the number X by one bit (position) to the left is equal to multiplying the number X by 2:

x <1 <==> x = x * 2

-2
source

All Articles