位运算与移位指令
掌握 x86 中的位操作:学习用于掩码、切换标志位和快速乘法的 AND、OR、XOR、NOT,以及移位和循环移位指令。
位运算与移位指令 是 CoddyKit 上的免费 Assembly Language & x86 Low-Level Systems Programming 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Assembly Language & x86 Low-Level Systems Programming 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Assembly Language & x86 Low-Level Systems Programming 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Why Bit Operations?
Low-level code constantly manipulates individual bits: setting flags, packing fields, masking, and fast math. x86 provides dedicated bitwise and shift instructions.
AND for Masking
AND keeps only the bits set in both operands, the standard way to mask out unwanted bits.
and eax, 0x0F ; keep low nibbleOR for Setting Bits
OR forces specific bits to 1 while leaving others unchanged.
or eax, 0x80 ; set bit 7XOR for Toggling
XOR flips bits where the mask is 1. A famous idiom zeroes a register quickly:
xor eax, eax ; eax = 0NOT for Inversion
NOT flips every bit (ones complement).
not eaxLogical Shift Left (SHL)
SHL shifts bits left, filling with zeros. Each shift left multiplies an unsigned value by two.
shl eax, 1 ; eax = eax * 2Logical Shift Right (SHR)
SHR shifts right with zero fill, dividing an unsigned value by powers of two.
shr eax, 2 ; unsigned eax / 4Arithmetic Shift (SAR)
SAR shifts right but preserves the sign bit, so it divides signed values correctly.
sar eax, 1 ; signed eax / 2Rotate Instructions
ROL and ROR rotate bits around, wrapping the bit that falls off back in on the other side, used in hashing and crypto.
rol eax, 4Bit Test Instructions
BT copies a chosen bit into CF so you can test it, while BTS/BTR test and set/reset it.
bt eax, 3 ; CF = bit 3 of eaxCommon Idioms
Handy patterns:
xor reg, regto zeroshl/shrfor power-of-two mathand reg, maskto extract fields
Quick Check
Test your understanding of bit operations.
Recap
You learned bitwise and shift instructions:
- AND mask, OR set, XOR toggle, NOT invert
- SHL/SHR for unsigned power-of-two math
- SAR preserves sign for signed division
- ROL/ROR rotate; BT tests a bit into CF
用 AI 导师学习 Assembly — 免费
在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。
- 课程
- 12
- 课程
- 48
常见问题解答
「位运算与移位指令」课时是免费的吗?
是的 — 「位运算与移位指令」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Assembly Language & x86 Low-Level Systems Programming 课程的其余内容,请升级到 CoddyKit PRO。 Assembly Language & x86 Low-Level Systems Programming 课程共包含 4 节课。
「位运算与移位指令」这节课中我会学到什么?
掌握 x86 中的位操作:学习用于掩码、切换标志位和快速乘法的 AND、OR、XOR、NOT,以及移位和循环移位指令。 你通过在浏览器中直接运行的动手代码来练习 Assembly Language & x86 Low-Level Systems Programming,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Assembly Language & x86 Low-Level Systems Programming 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Assembly Language & x86 Low-Level Systems Programming 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「位运算与移位指令」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Assembly Language & x86 Low-Level Systems Programming 课中编写并运行代码吗?
能。每节 Assembly Language & x86 Low-Level Systems Programming 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。