Assembly - shr instruction turn on carry flag?
16,363
shr AL, 1
moves all of the bits in AL
right one place.
The original rightmost bit is shifted out of the AL
register into the carry flag (and the new leftmost bit is set to 0). For example:
+------------------------+ +------------------------+
| 1 0 0 1 0 1 0 1 | | 0 1 1 0 0 1 0 0 |
+------------------------+ +------------------------+
\ \ \ \ \ \ \ \ or \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
+------------------------+ CF +------------------------+ CF
|(0) 1 0 0 1 0 1 0 | 1 |(0) 0 1 1 0 0 1 0 | 0
+------------------------+ +------------------------+
In your comment on another answer:
My book gives the next example: Before shift: AL = 10101110 ; shr AL, 1 ; After shift: 01011100, CF = 1 ; Is it mistake?
If that's what it says, then yes. That's a left shift (shl AL, 1
), not a right shift: the bits in AL
have all been moved left by one place, and the carry flag has been set to the bit that was shifted out of the left-hand end.
Author by
Adam Sh
Updated on June 09, 2022Comments
-
Adam Sh almost 2 years
I saw the next code:
shr AL, 1 jnc bit_0
I don't understand when the carry flag is turn on due to shr instrucrion?
Thanks