我一直在学习汇编,我有一个问题。教科书中给出了以下示例:
Assume that the printer data port is memory-mapped to address 0FFE0h and the printer status port is bit zero of memory-mapped port 0FFE2h. The following code waits until the printer is ready to accept a byte of data and then it writes the byte in the L.O. byte of ax to the printer port:
0000: mov bx, [FFE2] 0003: and bx, 1 0006: cmp bx, 0 0009: je 0000 000C: mov [FFE0], ax . . . . . .
The first instruction fetches the data at the status input port. The second instruction logically ands this value with one to clear bits one through fifteen and set bit zero to the current status of the printer port. Note that this produces the value zero in bx if the printer is busy, it produces the value one in bx if the printer is ready to accept additional data. The third instruction checks bx to see if it contains zero (i.e., the printer is busy). If the printer is busy, this program jumps back to location zero and repeats this process over and over again until the printer status bit is one.
为什么我们必须执行第二条指令,and bx, 1
?我们不能直接转到 cmp bx, 0
吗?
此外,您能否澄清或改写“第二条指令在逻辑上将该值与 1 相加,以清除位 1 到 15,并将位 0 设置为打印机端口的当前状态”?我现在不明白这意味着什么,因为英语不是我的母语。
谢谢你
最佳答案
状态字节的位字段可能包含其他位中的其他标志。在这种情况下,您只对位 0(最低有效位)感兴趣,因此您通过将值与 1 相加来忽略其余位,然后针对 0 测试该值。
关于c - 测试状态位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7236884/