I am trying to understand how the SHL instruction sets the OF and CF flag, for the most part I understand how it happens but one particular example I can't wrap my mind around.
Consider the following case:
; RAX == 0x18F2086424981487
SHL RAX, 0x22
After this the flag status is the following:
OF == 0, CF == 0
Ill explain my logic when approaching this.
CF is always the last bit pushed out of destination so in that case 0x18F2086424981487 << 0x21
has a most significant bit of 0 meaning that on the next shift the 0 will be pushed out, setting CF to 0, so far so good.
Regarding OF (from SHL reference):
The OF flag is affected only on 1-bit shifts. For left shifts, the OF flag is set to 0 if the most-significant bit of the result is the same as the CF flag (that is, the top two bits of the original operand were the same); otherwise, it is set to 1.
From this I understand that if CF == 0
and the most significant bit of the result (here 0x18F2086424981487 << 0x22
so the most significant bit is 1) are equal then OF = 0
. But in this case CF == 0
and the most significant bit is 1 therefore CF = 1
.
Where have I gone wrong?
EDIT:
I have read the OF is only affected on 1-bit shifts but how do you explain:
; RAX == 0xABECFF1297783575
SHL RAX, 0x78
Outputting:
CF == 1, OF == 1
From my understanding the SHL instruction is just treated as a loop of value << 1
until the counter is exhausted, meaning that OF will be set for the last shift.