简体   繁体   English

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

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

Suppose an arbitrary data register contains the value '000E0015'. 假设任意数据寄存器包含值“ 000E0015”。 How can I copy the first 4 bits (000E) to another data register? 如何将前4位(000E)复制到另一个数据寄存器?

You need to provide more information for a good answer. 您需要提供更多信息才能获得良好的答案。

First, 000E0015 is a 32 bit value. 首先,000E0015是32位值。 The "first four" bits could mean the most significant bits, the 0 that leads it. “前四个”位可能意味着最高有效位,即领先于此的0。 Or it could mean the lowest four bits, the 5. Or you could mean what you typed- the 000E- which is the first sixteen bits (each four bit group is called a 'nibble'). 或者它可能意味着最低的4位,即5。或者您可能意味着键入的内容-000E-即前16位(每个四位组称为“半字节”)。

Second, what is your desired end state? 其次,您想要的最终状态是什么? If you begin with 000E0015 in a register, and you have XXXXXXXX in the destination register, do you want it to be 000EXXXX, preserving the values? 如果您在寄存器中以000E0015开头,并且目标寄存器中有XXXXXXXX,您是否希望它为000EXXXX,并保留这些值? Are you ok with it being 000E0000? 您认为它是000E0000吗? Or do you want the register to be something like 0000000E? 还是您想要寄存器为0000000E之类的东西?

I will assume, until you state otherwise, that you would like the second register to get the 000E, as you state. 我将假设,除非您另外声明,否则您希望第二个寄存器按照您的声明获得000E。 In that case, assuming you begin in d0 and want to go to d1: 在这种情况下,假设您从d0开始并想转到d1:

move.l  d1,d0
swap    d1   

This will first copy the entire 32 bit register to d1, then it will swap the words. 这将首先将整个32位寄存器复制到d1,然后将交换字。 d1 will contain 0015000E. d1将包含0015000E。 If you wanted to clear them, you could AND d1 with 0000FFFF. 如果要清除它们,则可以将d1与0000FFFF进行与。 If you wanted them to contain whatever they did before, you could first prepare the 0000000E in an intermediate register, then clear the low bits by ANDing with FFFF0000, then bring in the 0000000E from the intermediate register with an OR- but I'm not quite sure what you need exactly. 如果希望它们包含以前做的任何事情,则可以先在中间寄存器中准备0000000E,然后通过与FFFF0000进行与运算来清除低位,然后使用OR-从中间寄存器中引入0000000E,但我不是非常确定您到底需要什么。

You are wanting the most significant word, not 1st 4 bits, so the most significant 16 bits of the 32 bit value. 您想要的是最高有效字,而不是前4位,因此需要32位值中的最高有效16位。 There are a few ways you could do this. 有几种方法可以做到这一点。 If you are only going to deal with that word as a word and ignore anything else in the data register then you could use swap safely. 如果您只打算将该单词作为一个单词来处理,而忽略数据寄存器中的其他任何内容,则可以安全地使用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

After this d1 will contain #$0015000E so if you address it only as a word you will access purely the $000E portion of the data register. 在此之后,d1将包含#$ 0015000E,因此,如果仅以字寻址,则将纯粹访问数据寄存器的$ 000E部分。

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

Now, if you are planning to use the rest of the data register, or perform operations with or on this that will extend beyond the 1st word, you need to make sure that the upper word is clear. 现在,如果您打算使用其余的数据寄存器,或对此进行扩展到第一个字以外的操作,则需要确保高位字是清楚的。 You can do this easily enough, 1st instead of using swap, use lsr.l 您可以很容易地做到这一点,首先使用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

You cannot use lsr.l #16,d1 as the immediate value of lsX.l is limited to 8, but you can specify up to 32 in another register and perform the operation that way. 您不能使用lsr.l#16,d1,因为lsX.l的立即数限制为8,但是您可以在另一个寄存器中最多指定32,然后以这种方式执行操作。

A cleaner (IMHO) way (unless you were repeating this operation multiple times) would be to use AND to clean up the register after the swap. 较干净的(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

This will remove all bits from the d1 register that do not fit in with the logical mask. 这将从d1寄存器中删除所有不适合逻辑掩码的位。 IE bit is set true in both d1 and the pattern specified ($ffff) IE位在d1和指定的模式($ ffff)中都设置为true

Finally, what I think might be the most efficient and cleanest way of performing this task would be to use clr and swap. 最后,我认为执行此任务的最有效,最简洁的方法是使用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

Hope those are of some help ? 希望这些对您有所帮助? :) :)

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

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