汇编 AND 指令和 C++ 等效吗?

Ima*_*rys -2 c++ assembly

解决了。​​感谢您的帮助,在网上看到了一个非常好的例子...但是是谷歌搜索引擎上的最后几页~~

我正在通过谷歌搜索阅读一些关于组装的在线教程,但我似乎无法弄清楚当他们显示 AND 指令时他们的意思。

有人可以向我解释它的用法吗?其等效的 C++ 运算符是什么?

我也无法理解运算符“!”是什么意思。在c++中用于。

提前致谢。

Cod*_*key 5

按位与,表示将一个操作数的每一位与另一操作数的相应位进行比较,如果两者都为 1,则将结果设置为 1,否则将结果设置为 0。因此,考虑将这两个字节组合在一起:

  00000011
& 00000101
----------
  00000001
Run Code Online (Sandbox Code Playgroud)

结果中仅设置了最低位,因为只有该位位置的操作数均为 1。

在 Intel x86 汇编语言中,您可以使用“and”运算符来实现此目的:

mov    eax, [op1]   ; eax is a register
and    eax, [op2]   ; now eax is the bitwise 'and' of the two.
mov    [result], eax
Run Code Online (Sandbox Code Playgroud)

在 C++ 中

unsigned result = op1 & op2;
Run Code Online (Sandbox Code Playgroud)

逻辑和工作方式不同。我们不是对每一位进行“与”操作,而是使用这样的约定:如果值为零则为“假”,如果不为零则为“真”。这是高级语言的约定,不是汇编语言的概念。所以在 x86 中我们有:

    mov    eax, [op1]
    test   eax, eax  ; Test if eax is zero by anding it with itself.
    jz     isfalse   ; just to isfalse if the first operand is false

    mov    eax, [op2]
    test   eax, eax
    jnz    istrue

isfalse:
    mov    [result], 0
    jmp    done
istrue:
    mov    [result], 1

done:
    ...
Run Code Online (Sandbox Code Playgroud)

此处此代码使用的约定是 0 表示 false,1 表示 true。

C++ 的等价物是:

boolean result = op1 && op2;
Run Code Online (Sandbox Code Playgroud)