68k:将 0x100 添加到 9 位寄存器并执行 BEQ.s - 这有什么意义?

逆向工程 拆卸 部件 摩托罗拉
2021-06-22 09:54:19

在我当前的项目中,我发现了这样的代码:

move.w  (0xFFFC0C).l, d0 | read SCSR
andi.w  #0x100, d0       | add 256 to d0
beq.s   location         | branch if LSB = 0x00

我无法理解这个片段。我猜作者试图检查 UART 的状态,但是当 SCSR 最多可包含 9 位时,它如何实现andi.wbeq.s达到目的?

在此处输入图片说明

1个回答

不是加。它是binary 和 operation,在转换为 C 时,代码如下所示:

d0 = readSCSR(); // move.w  (0xFFFC0C).l, d0 | read SCSR
if (d0 & 0x100) 
//andi.w  #0x100, d0       | not add, but AND 256 to d0
//beq.s   location         | branch if LSB = 0x00
{
    // do whatever needed
}
location: // else branch to location