BT汇编指令

8

我有关于bt汇编指令的问题。我提供了一部分书籍来提供背景信息。请看最后一个例子,bt Testme, bx。为什么要复制TestMe + 8?难道不应该复制TestMe + 65吗?

非常感谢您的帮助!

6.6.4.2 The Bit Test Instructions: BT, BTS, BTR, and BTC

On an 80386 or later processor, you can use the bt instruction (bit test) to test a single bit. Its second operand specifies the bit index into the first operand. Bt copies the addressed bit into the carry flag. For example, the instruction

  bt  ax, 12

copies bit twelve of ax into the carry flag.

The bt/bts/btr/btc instructions only deal with 16 or 32 bit operands. This is not a limitation of the instruction. After all, if you want to test bit three of the al register, you can just as easily test bit three of the ax register. On the other hand, if the index is larger than the size of a register operand, the result is undefined.

If the first operand is a memory location, the bt instruction tests the bit at the given offset in memory, regardless the value of the index. For example, if bx contains 65 then

  bt  TestMe, bx

will copy bit one of location TestMe+8 into the carry flag. Once again, the size of the operand does not matter. For all intents and purposes, the memory operand is a byte and you can test any bit after that byte with an appropriate index. The actual bit bt tests is at bit position index mod 8 and at memory offset effective address + index/8.

2个回答

12
当书中说“地址为TestMe+8的第一个比特”,其中的“8”是指以字节为单位的地址偏移量。每个字节有64位,所以第65个比特是在TestMe后的8字节中的第一个比特。
  • TestMe处的字节有7..0比特
  • TestMe+1处的字节有15..8比特
  • TestMe+2处的字节有23..16比特
  • ...
  • TestMe+8处的字节有71..64比特
因此,“65”指的是地址为TestMe+8的字节中的“比特1”(从右边数第二个)。

3

bt TestMe, bx 其中bx包含65,是在TestMe的地址上方8个字节(64位加1)处的访问。它不会复制那里的字节,只会将该字节中的第二位(到进位标志CF)复制。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接