AsAssembly · Lesson 4 of 10
Arithmetic & Logic
The CPU can add, subtract, multiply, divide, and do bitwise operations. Every result updates the FLAGS register — a set of bits that record whether the result was zero, negative, overflowed, etc. Branches read those flags.
✦ Tip
Bit manipulation tricks that compilers know and you should too: `x & (x-1)` clears the lowest set bit, `x & (-x)` isolates the lowest set bit, `x | (x-1)` sets all bits below the lowest set bit, `(x >> 63)` extracts the sign bit of a 64-bit value. These appear constantly in optimized code.
Bit manipulation tricks that compilers know and you should too: `x & (x-1)` clears the lowest set bit, `x & (-x)` isolates the lowest set bit, `x | (x-1)` sets all bits below the lowest set bit, `(x >> 63)` extracts the sign bit of a 64-bit value. These appear constantly in optimized code.