mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
x86 asm: move rotation and bit instructoins in from x86-assembly-cheat
This commit is contained in:
57
README.adoc
57
README.adoc
@@ -12378,6 +12378,63 @@ Bibliography:
|
||||
* link:userland/arch/x86_64/or.S[OR]
|
||||
* link:userland/arch/x86_64/xor.S[XOR]
|
||||
|
||||
=== x86 shift and rotate instructions
|
||||
|
||||
<<intel-manual-1>> 5.1.5 "Shift and Rotate Instructions"
|
||||
|
||||
* link:userland/arch/x86_64/shl.S[SHL and SHR]
|
||||
+
|
||||
SHift left or Right and insert 0.
|
||||
+
|
||||
CF == the bit that got shifted out.
|
||||
+
|
||||
Application: quick unsigned multiply and divide by powers of 2.
|
||||
* link:userland/arch/x86_64/sal.S[SAL and SAR]
|
||||
+
|
||||
Application: signed multiply and divide by powers of 2.
|
||||
+
|
||||
Mnemonics: Shift Arithmetic Left and Right
|
||||
+
|
||||
Keeps the same sign on right shift.
|
||||
+
|
||||
Not directly exposed in C, for which signed shift is undetermined behavior, but does exist in Java via the `>>>` operator. C compilers can omit it however.
|
||||
+
|
||||
SHL and SAL are exactly the same and have the same encoding: https://stackoverflow.com/questions/8373415/difference-between-shl-and-sal-in-80x86/56621271#56621271
|
||||
* link:userland/arch/x86_64/rol.S[ROL and ROR]
|
||||
+
|
||||
Rotates the bit that is going out around to the other side.
|
||||
* link:userland/arch/x86_64/rol.S[RCL and RCR]
|
||||
+
|
||||
Like ROL and ROR, but insert the carry bit instead, which effectively generates a rotation of 8 + 1 bits. TODO application.
|
||||
|
||||
=== x86 bit and byte instructions
|
||||
|
||||
<<intel-manual-1>> 5.1.6 "Bit and Byte Instructions"
|
||||
|
||||
* link: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]
|
||||
....
|
||||
* link:userland/arch/x86_64/btr.S[BTR]
|
||||
+
|
||||
Do a BT and then set the bit to 0.
|
||||
* link:userland/arch/x86_64/btc.S[BTC]
|
||||
+
|
||||
Do a BT and then swap the value of the tested bit.
|
||||
* link:userland/arch/x86_64/setcc.S[SETcc]
|
||||
+
|
||||
Set a a byte of a register to 0 or 1 depending on the cc condition.
|
||||
* link:userland/arch/x86_64/test.S[TEST]
|
||||
+
|
||||
Like <<x86-binary-arithmetic-instructions,CMP>> but does AND instead of SUB:
|
||||
+
|
||||
....
|
||||
ZF = (!(X && Y)) ? 1 : 0
|
||||
....
|
||||
|
||||
=== x86 control transfer instructions
|
||||
|
||||
<<intel-manual-1>> 5.1.7 "Control Transfer Instructions"
|
||||
|
||||
Reference in New Issue
Block a user