SAR
Instruction
SAR
(shift arithmetic right) instruction performs a right arithmetic shift on its destination operand. SAR
differs from SHR
in one important way: SAR
uses the sign bit to fill leftmost vacated bits. In this way, positive and negative values retain their signs.
SAR — Shift Arithmetic Right |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
SAR
instruction. Halving odd numbers such as 5 and 7 generates 2 and 3, respectively, and -5 and -7 generates -3 and -4, respectively.
Shift Negative Right | Shift Arithmetic Right | Shift Arithmetic Right |
.data value SDWORD -27 .code shr value, 03 mov eax, value call WriteInt |
.data value SDWORD -27 .code sar value, 03 mov eax, value call WriteInt |
.data value SDWORD 27 .code sar value, 03 mov eax, value call WriteInt |
Output | Output | Output |