-2

I'm having trouble understanding what exactly ror and shl do in assembly. I see the definitions, e.g. ror: rotates bits to the right and back into high-order bit on the left.

but what does that mean? I just can't wrap my head around it. like if

mov eax, 0x12345678
mov ebx, eax
ror ebx, 16

what happens?

Syntactic Fructose
  • 18,936
  • 23
  • 91
  • 177

1 Answers1

1
mov eax, 0x12345678
mov ebx, eax
ror ebx, 16

What happens is that the low 16 bits of EBX are swapped with the high 16 bits of EBX. The value in EBX will be 0x56781234.

All kinds of shifts are performed 1 bit at a time. The 16 defines how many times the CPU repeats the process of shifting all the bits of EBX to the right. With each shift bit[0] is replicated in the carry flag and at the same time fills the now vacant bit[31].

Fifoernik
  • 9,779
  • 1
  • 21
  • 27