与16的按位AND(或TEST)如何测试第5位? [英] How does a bitwise AND (or TEST) with 16 test the 5th bit?

查看:136
本文介绍了与16的按位AND(或TEST)如何测试第5位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的学院关于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

假设aAL,而b16:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆