Sometimes by rotating a number right we obtain the same number.
eg. 01010101 (85) can be rotated by 2,4,6 places to get the same number.what are the number of times we can rotate a number by different bits to get the same number? For this I wrote the following code:
extern printf ; the C function to be called
SECTION .data ; Data section
msg: db "The number of possible rotations are : %d",10,0
inta1: dd 1234567 ; integer 1234567
num: dd 1431655765
SECTION .text ; Code section.
global main ; "C" main program
main:
mov eax, [num]
mov ecx,32
mov ebx,0
mov edx,eax
.loop:
dec ecx
cmp ecx,1
jl .exit
ror eax,1
cmp edx,eax
jne .loop
inc ebx
jmp .loop
.exit:
push ebx
push dword msg
call printf
add esp, 8
Output for above code:
The number of possible rotations are : 15
When num: 858993459
Output:
The number of possible rotations are : 7
.
Although I get correct answers for 32 bit numbers, I am not able to use a non-32 bit in place of num in the same code to get the correct answer.
eg When I use num :85,
I get the output:
The number of possible rotations are : 0
But it should have been 3
Maybe it is because of padding by zeros in the first remaining bits.(Not sure, Just assuming)
How do I use the same set of registers to display the value of possible rotations for a non-32 bit number too?