# Linux Kernel Module Cheat
The perfect emulation setup to study and develop the <<linux-kernel>> v5.9.2, kernel modules, <<qemu-buildroot-setup,QEMU>>, <<gem5-buildroot-setup,gem5>> and x86_64, ARMv7 and ARMv8 <<userland-assembly,userland>> and <<baremetal-setup,baremetal>> assembly, <<c,ANSI C>>, <<cpp,C++>> and <<posix,POSIX>>. <<gdb>> and <<kgdb>> just work. Powered by <<about-the-qemu-buildroot-setup,Buildroot>> and <<about-the-baremetal-setup,crosstool-NG>>. Highly automated. Thoroughly documented. Automated <<test-this-repo,tests>>.

### 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