# Linux Kernel Module Cheat

### 29.7. x86 bit and byte instructions

Intel 64 and IA-32 Architectures Software Developer’s Manuals Volume 1 5.1.6 "Bit and Byte Instructions"

- userland/arch/x86_64/bt.S: BT

  Bit test: test if the Nth bit a bit of a register is set and store the result in the CF FLAG.

      CF = reg[N]

- userland/arch/x86_64/btr.S: BTR

  Do a BT and then set the bit to 0.

- userland/arch/x86_64/btc.S: BTC

  Do a BT and then swap the value of the tested bit.

- userland/arch/x86_64/setcc.S: SETcc

  Set a byte of a register to 0 or 1 depending on the cc condition.

  Bibliography: https://stackoverflow.com/questions/1406783/how-to-read-and-write-x86-flags-registers-directly/30952577#30952577

- userland/arch/x86_64/popcnt.S: POPCNT

  Count the number of 1 bits.

- userland/arch/x86_64/test.S: TEST

  Like CMP but does AND instead of SUB:

      ZF = (!(X && Y)) ? 1 : 0