与16的按位AND(或TEST)如何测试第5位? [英] How does a bitwise AND (or TEST) with 16 test the 5th bit?
问题描述
在我的学院关于8086汇编的文档中,以下示例:
TEST AL, 16 ; tests the 5th bit's state
给定 TEST指令做什么,这完全正确吗?它基于AL & 16
设置标志.那如何测试第五位?
注意:AL以前没有提到的值,只是这里显示的值,所以我认为这在一般情况下必须有效.
16
十进制是10000
二进制.请注意,右边的第五位已设置,并且它是唯一的第五位.
TEST
是按位与.按位与运算的结果是,两个原始值中均存在1
的位置都具有1
的值.例如:
a = 1010 1110
b = 0110 1011
a AND b = 0010 1010
假设a
是AL
,而b
是16
:
AL = xxxx xxxx
16 = 0001 0000
AL AND 16 = 000y 0000
如果AL的第五位是0
,结果可以是0
,或者如果AL
的第五位是1
,结果可以是16
.例如,如果使用TEST
指令的结果的指令是有条件的跳转(例如JNZ),则实际上它会测试"是否设置了AL
的第五位并根据结果进行操作./p>
更精确地说,结果是间接使用的-仅设置各种标志.在这种情况下,ZF
标志是相关的.根据按位与运算的结果,如果结果为0
,则将ZF
设置为0
;如果结果不是0
,则将其设置为1
.
In my College's documentation on 8086 Assembly is the following example:
TEST AL, 16 ; tests the 5th bit's state
Is this at all correct given what the TEST instruction does? It sets flags based on AL & 16
. How does that test the 5th bit?
NOTE: there's no previously mentioned value to AL, just exactly what's shown here, so I assume this has to work in the general case.
16
in decimal is 10000
in binary. Notice the fifth bit from the right is set, and that it is the only one.
TEST
is bitwise AND. The result of a bitwise AND operation is a value that has 1
's wherever there was a 1
in both original values. For example:
a = 1010 1110
b = 0110 1011
a AND b = 0010 1010
Supposing a
was AL
and b
was 16
:
AL = xxxx xxxx
16 = 0001 0000
AL AND 16 = 000y 0000
The result can be either 0
, if the fifth bit of AL is 0
, or it can be 16
, if the fifth bit of AL
is 1
. If the instruction using the result of the TEST
instruction was, for example, a conditional jump, like JNZ, then it does in fact 'test' if the fifth bit of AL
is set and acts according to the result.
To be more precise, the result is used indirectly – only various flags are set. In this case, the ZF
flag is relevant. Depending on the result of the bitwise AND operation, ZF
is either set to 0
if the result was 0
or it is set to 1
if the result was not 0
.
这篇关于与16的按位AND(或TEST)如何测试第5位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!