-1

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

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

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

我也无法理解运算符“!” 在 c++ 中用于。

提前致谢。

4

1 回答 1

4

按位与,意味着您将一个操作数的每一位与另一个操作数的相应位进行比较,如果它们都是 1,则将结果设置为 1,否则设置为 0。所以考虑这两个字节并在一起:

  00000011
& 00000101
----------
  00000001

结果中仅设置了最低位,因为只有该位位置的操作数都是 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

在 C++ 中

unsigned result = op1 & op2;

逻辑和工作方式不同。我们使用一个约定,如果它为零,则为“假”,如果不是,则为“真”,而不是对每个位进行 and-ing。这是高级语言的约定,不是汇编语言的概念。所以在 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:
    ...

这里代码使用了 0 为假,1 为真的约定​​。

C++ 等价物是:

boolean result = op1 && op2;
于 2013-08-04T01:19:50.800 回答