【问题标题】:68K Assembly, how to copy the first 4 bits of a data register68K汇编,如何复制数据寄存器的前4位
【发布时间】:2016-10-13 04:36:25
【问题描述】:

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

【问题讨论】:

  • 前 4 位为 0,您显然想要高 16 位

标签: assembly 68000 easy68k


【解决方案1】:

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

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

其次,您想要的最终状态是什么?如果您在寄存器中以 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,但我不是很确定你到底需要什么。

【讨论】:

  • 现在,已经 20 年了,但不应该是 move.l d0, d1 吗?很确定 68K 使用右侧的目的地。
【解决方案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 并以这种方式执行操作。

一种更清洁的 (IMHO) 方式(除非您多次重复此操作)是在交换后使用 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

希望这些有帮助吗? :)

【讨论】:

    猜你喜欢
    • 2013-01-10
    • 2020-06-07
    • 1970-01-01
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    • 2014-05-25
    • 1970-01-01
    • 2019-03-11
    相关资源
    最近更新 更多