您可以使用 AND 操作清除位。
for each bit index `i`
result[i] = boolean_and(first[i], second[i])
.--------- commonly associated symbol for the operation
|
& 1 0 <- first argument
-------
1 | 1 0 <- result
0 | 0 0
^--------- second argument
Run Code Online (Sandbox Code Playgroud)
一个字节的例子:
00101100
00111010
&
00101000
Run Code Online (Sandbox Code Playgroud)
因此,您可以使用此操作来屏蔽和翻转寄存器中的位区域。传入一个常量作为第二个参数,它的位翻转了你想要跟上的。
x86 mnemonic: AND a, b
operation: a = a & b
Run Code Online (Sandbox Code Playgroud)
除非您还没有理解,否则这是如何做到的:
AND eax, 0xfffffffc
Run Code Online (Sandbox Code Playgroud)
AL 是 EAX 寄存器的最低字节部分,因此您可以这样做。
这是二进制 -> 十六进制转换表:
0000 | 0
0001 | 1
0010 | 2
0011 | 3
0100 | 4
0101 | 5
0110 | 6
0111 | 7
1000 | 8
1001 | 9
1010 | a
1011 | b
1100 | c
1101 | d
1110 | e
1111 | f
Run Code Online (Sandbox Code Playgroud)
哦,如果你想成为一个自尊的、熟悉汇编的程序员,你应该从脑后记住这一点。
另请阅读 OR 和 XOR 位运算。
mat*_*thk -3
and al, 0xFD
Run Code Online (Sandbox Code Playgroud)
使其适应您正在使用的汇编器:gas、nasm、masm ...
编辑:实际上是这样and al, 0xFC,但你明白了
| 归档时间: |
|
| 查看次数: |
17216 次 |
| 最近记录: |