繁体   English   中英

68K汇编,如何复制数据寄存器的前4位

[英]68K Assembly, how to copy the first 4 bits of a data register

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

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

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

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

我将假设,除非您另外声明,否则您希望第二个寄存器按照您的声明获得000E。 在这种情况下,假设您从d0开始并想转到d1:

move.l  d1,d0
swap    d1   

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

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

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而不是使用swap

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)中都设置为true

最后,我认为执行此任务的最有效,最简洁的方法是使用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

希望这些对您有所帮助? :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM