Linux x64 Assembly Tutorial 6: Shifting Bits

Опубликовано: 27 Март 2026
на канале: Creel
4,927
78

In this video we'll look at the shift instructions SHL, SHR and SAL. They're often used for fast multiplication and division of integers, but they also have many other uses.

SHL is shift left, it shifts the bits left and fills the vacant spots with 0. SHR is shift right, it shifts bits right and fills the vacant bits on the left with 0's. SAR is shift arithmetic right, it's the same SHR only it fills the vacant spots on the left with whatever the original sign bit was (the left most bit is the sign bit in a signed integer!).

SAR is supposed to be used for signed division of a register or memory by a power of 2, SHR is meant for unsigned division of integers by powers of 2.

At the end there's a challenge, you have to reverse, or mirror, the bits of an unsigned char. It's trickier than it sounds!