bt 汇编指令
我对 bt
汇编指令有疑问。我摘录了书中的部分内容以提供背景信息。请参阅最后一个示例,bt Testme, bx
。为什么会复制 TestMe+8
?它不应该复制 TestMe+65
吗?
非常感谢您的帮助!
6.6.4.2 位测试指令:BT、BTS、BTR 和 BTC
在 80386 或更高版本的处理器上,可以使用 bt 指令(位 test)来测试单个位。它的第二个操作数指定位索引 进入第一个操作数。 Bt 将寻址位复制到进位中 旗帜。例如指令
<前><代码> bt 斧头,12将 ax 的第 12 位复制到进位标志中。
bt/bts/btr/btc 指令仅处理 16 或 32 位操作数。 这不是指令的限制。毕竟,如果你想 测试 al 寄存器的第三位,您可以轻松测试位 三个斧头寄存器。另一方面,如果索引较大 大于寄存器操作数的大小,结果未定义。
如果第一个操作数是内存位置,则 bt 指令测试 内存中给定偏移量处的位,无论其值是多少 指数。例如,如果 bx 包含 65,则
<前><代码> bt TestMe,bx将把 TestMe+8 位置的第一个位置复制到进位中 旗帜。再次强调,操作数的大小并不重要。对于所有人 意图和目的,内存操作数是一个字节,您可以测试 该字节之后的任何位都有适当的索引。实际位bt 测试位于位位置索引 mod 8 和有效内存偏移处 地址+索引/8。
I have quesetion about bt
assembly instruction. I have excerpted part of book to provide context. Please see last example, bt Testme, bx
. Why does that copy TestMe+8
? Shouldn't it copy TestMe+65
?
Very much thank you for help!
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 instructionbt 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 thenbt 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当书上说“位置
TestMe+8
的位一”时,“8
”指的是地址偏移,以字节为单位。 8 个字节中有 64 位,因此第 65 位是 TestMe 之后的 8 个字节中的一位。TestMe
处的字节具有位 7..0TestMe+1
处的字节具有位 15..8TestMe+2
处的字节具有位 23..16TestMe+8
处的字节具有位 71..64因此“65”指的是地址处字节的“位 1”(从右数第二个)
测试我+8
。When the book says "bit one of location
TestMe+8
", the "8
" refers to an address offset, which is measured in bytes. There are 64 bits in 8 bytes, so the 65th bit is bit one of 8 bytes pastTestMe
.TestMe
has bits 7..0TestMe+1
has bits 15..8TestMe+2
has bits 23..16TestMe+8
has bits 71..64So "65" refers to "bit 1" (the second counting from the right) of the byte at address
TestMe+8
.bt TestMe, bx
其中 bx 包含65
是超出TestMe
地址的 8 个字节(64 位加 1)的访问。它不会复制该字节,仅复制该字节中的第二位(复制到进位标志 CF)。bt TestMe, bx
where bx contains65
is an access 8 bytes (64 bits plus 1) beyond the address ofTestMe
. It doesn't copy the byte there, only the second bit in that byte (to the carry flag, CF).