Given a 32 bit decimal number in %ecx and %edx, when trying to shift left and right each copy of the original number using shl and shr then moving the carry (the bit that was just cut) to a 8 bit register ah and al to compare if equal, I wrote:
movl $32, %esi #counter
xor %eax, %eax
.LOOP:
shl %ecx
setb %ah
shr %edx
setb %al
cmp %ah, %al
jnz .np
decl %esi
jnz .LOOP
What am I doing wrong?
You are comparing 2 numbers from opposite sides. Your program continues looping while
ecx[i] == edx[32-i]. So what you’re actually doing is checking whetherecxcontains an inverted value (i.e. with reordered bits) ofedx. E.g., it will return true forecxwith value0x200000andedxwith value0x400.