I'm compiling my code with gcc and looking at the assembly, what is this code exactly doing?
shrl $20, %edx
leal (%edx,%eax), %eax
sarl 1, %eax
Say that the variable X is at the edx register, and Y is at eax and both are (32-bit int). What is going on here??
I know 'shrl $20, %edx' is shifting %eax right 20 bits, so is same as: eax/(2^20) and then sarl is the same so 'sarl 1, %eax' = eax/(2^1). Is that right, and if so what does leal do?
Assuming that sarl 1, %eax
is really supposed to be sarl $1, %eax
, then the whole thing equates to:
x = ((unsigned int) x) >> 20;
y = (x + y) >> 1
The leal
instruction means: eax = eax + edx
. This link might be useful to you, as well as this one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With