0

假设任意数据寄存器包含值“000E0015”。如何将前 4 位 (000E) 复制到另一个数据寄存器?

4

2 回答 2

3

您需要提供更多信息才能获得好的答案。

首先,000E0015 是一个 32 位的值。“前四”位可能意味着最高有效位,即引导它的 0。或者它可能表示最低的四位,即 5。或者您可能表示您键入的内容 - 000E - 即前十六位(每个四位组称为“半字节”)。

其次,你想要的最终状态是什么?如果您在寄存器中以 000E0015 开头,并且在目标寄存器中有 XXXXXXXX,您是否希望它为 000EXXXX,并保留这些值?你可以接受它是 000E0000 吗?还是您希望寄存器类似于 0000000E?

除非您另有说明,否则我将假设您希望第二个寄存器获得 000E,正如您所说。在这种情况下,假设您从 d0 开始并想要转到 d1:

move.l  d1,d0
swap    d1   

这将首先将整个 32 位寄存器复制到 d1,然后交换字。d1 将包含 0015000E。如果你想清除它们,你可以 AND d1 与 0000FFFF。如果您希望它们包含之前所做的任何事情,您可以首先在中间寄存器中准备 0000000E,然后通过与 FFFF0000 进行与运算来清除低位,然后使用 OR- 从中间寄存器中引入 0000000E,但我不是很确定你到底需要什么。

于 2016-10-13T05:05:40.397 回答
2

您想要的是最高有效字,而不是第一个 4 位,因此需要 32 位值的最高有效 16 位。有几种方法可以做到这一点。如果您只想将该词作为一个词处理并忽略数据寄存器中的任何其他内容,那么您可以安全地使用交换。

move.l #$000E0015,d0   ; so this example makes sense :)
move.l d0,d1  ; Move the WHOLE value into your target register
swap d1   ; This will swap the upper and lower words of the register

在此 d1 之后将包含 #$0015000E,因此如果您仅将其作为一个字来寻址,您将仅访问数据寄存器的 $000E 部分。

move.w d1,$1234  ; Will store the value $000E at address $1234

现在,如果您打算使用数据寄存器的其余部分,或对其执行超出第一个字的操作,则需要确保高位字清晰。你可以很容易地做到这一点,第一次而不是使用交换,使用 lsr.l

move.l #$000E0015,d0   ; so this example makes sense :)
move.l d0,d1  ; Move the WHOLE value into your target register
moveq  #16,d2  ; Number of bits to move right by
lsr.l  d2,d1  ; Move Value in d1 right by number of bits specified in d2

您不能使用 lsr.l #16,d1 因为 lsX.l 的立即数限制为 8,但您可以在另一个寄存器中指定最多 32 并以这种方式执行操作。

一种更清洁(恕我直言)的方式(除非您多次重复此操作)是在交换后使用 AND 清理寄存器。

move.l #$000E0015,d0 ; so this example makes sense :)
move.l d0,d1         ; Move the WHOLE value into your target register
swap   d1            ; This will swap the upper and lower words of the register
and.l  #$ffff,d1     ; Mask off just the data we want

这将从 d1 寄存器中删除所有不适合逻辑掩码的位。IE 位在 d1 和指定的模式中都设置为真 ($ffff)

最后,我认为执行此任务的最有效和最干净的方法可能是使用 clr 和 swap。

move.l #$000E0015,d0 ; so this example makes sense :)
move.l d0,d1         ; Move the WHOLE value into your target register
clr.w  d1            ; clear the lower word of the data register 1st
swap   d1            ; This will swap the upper and lower words of the register

希望这些有帮助吗?:)

于 2016-11-09T12:21:14.823 回答