Get me outta here!

Sunday, May 7, 2023

Logical Shifting COA

 

SHR stands for "Shift Right" and it is used to shift the bits in a register or memory location to the right. When a number is shifted to the right using SHR, the least significant bit (LSB) is replaced by a zero, and the most significant bit (MSB) is shifted out and lost. The other bits are shifted to the right by the specified number of positions. For example, the instruction "SHR AL, 1" will shift the bits in the AL register to the right by 1 position. SAR stands for "Shift Arithmetic Right" and it is used to shift the bits in a register or memory location to the right while preserving the sign bit. When a number is shifted to the right using SAR, the least significant bit (LSB) is replaced by a zero, and the most significant bit (MSB) is shifted out and lost. However, unlike SHR, SAR preserves the sign bit by shifting it into the vacated MSB position. This ensures that the sign of the number is preserved after the shift. For example, the instruction "SAR BL, 1" will shift the bits in the BL register to the right by 1 position while preserving the sign bit.

SHL stands for "Shift Left" and it is used to shift the bits in a register or memory location to the left. When a number is shifted to the left using SHL, the most significant bit (MSB) is replaced by a zero, and the least significant bit (LSB) is shifted out and lost. The other bits are shifted to the left by the specified number of positions. For example, the instruction "SHL AX, 1" will shift the bits in the AX register to the left by 1 position. SAL stands for "Shift Arithmetic Left" and it is also used to shift the bits in a register or memory location to the left. The operation performed by SAL is identical to SHL, and both instructions can be used interchangeably. The only difference is that the Intel documentation recommends using SAL when performing arithmetic shifts, to emphasize that the sign bit is shifted along with the other bits. IN summary, the main difference between SHL and SAL is that SHL performs a logical shift, while SAL performs an arithmetic shift. However, in practice, the two instructions are identical and can be used interchangeably for left shifts.

ROL: The ROL instruction performs a left rotation of the bits in a register or memory location. Each bit is shifted one position to the left, with the carry flag being shifted into the least significant bit (LSB) and the most significant bit (MSB) being shifted into the carry flag. This effectively shifts all bits one position to the left, including the carry flag. For example, the instruction "ROL AL, 1" will rotate the bits in the AL register one position to the left.• ROR: The ROR instruction performs a right rotation of the bits in a register or memory location. Each bit is shifted one position to the right, with the carry flag being shifted into the most significant bit (MSB) and the least significant bit (LSB) being shifted into the carry flag. This effectively shifts all bits one position to the right, including the carry flag. For example, the instruction "ROR BH, 1" will rotate the bits in the BH register one position to the right. Both ROL and ROR are circular shifts, which means that the shifted bits are rotated around to the opposite end of the register or memory location. The carry flag plays a key role in this operation, as it is shifted into the least significant bit (LSB) during a left rotation and into the most significant bit (MSB) during a right rotation.



0 comments:

Post a Comment