简体   繁体   English

ARMv7-M汇编:寄存器中未对齐的字节替换?

[英]ARMv7-M assembly: unaligned byte replacement in registers?

Suppose we have three destination registers, r5, r6, and r7, and consider them to be an array of 12 bytes: 假设我们有三个目标寄存器r5,r6和r7,并认为它们是12个字节的数组:

r5={a, b, c, d} r6={e, f, g, h} r7={i, j, k, l}

What I'd like to do is read eight bytes {0, 1, 2, 3, 4, 5, 6, 7} from a given memory location, and copy them into the three destination registers to give 我想做的是从给定的存储位置读取八个字节{0, 1, 2, 3, 4, 5, 6, 7} ,然后将它们复制到三个目标寄存器中,以得到

r5={a, 0, 1, 2} r6={3, 4, 5, 6} r7={7, j, k, l}

In other words, I'd like to replace bytes 1-8 of of the array in r5-r7 with the eight bytes read from ROM. 换句话说,我想用从ROM读取的八个字节替换r5-r7中数组的字节1-8。

I can do this in six instructions: 我可以通过六个指令来做到这一点:

ldrd    r0, r1, [r3]
bfi     r5, r0, #8, #24
ubfx    r6, r0, #24, #8
bfi     r6, r1, #8, #24
bfc     r7, #0, #8
orr     r7, r7, r1, lsr #24

Can it be done in fewer? 可以用更少的时间完成吗? Assume the absence of floating-point unit. 假设没有浮点单元。

(Background: this is part of a blitting routine, several pixel patterns are read from memory and composited into a set of registers which is then written to a display buffer with stmia .) (背景:这是绘图程序的一部分,从内存中读取几个像素图案,并合成到一组寄存器中,然后使用stmia将其写入显示缓冲区。)

I'm hesitant to post the following, because it doesn't solve the problem as posed - it assembles the output in memory rather than in the registers. 我很犹豫地发布以下内容,因为它不能解决所提出的问题-它将输出组装在内存中而不是在寄存器中。

But for what it's worth: 但是对于它的价值:

r5,r6,r7 - abcdefghijkl      (as per the question)
r3       - input array ptr   (as per the question)
r2       - output array ptr

                        r5   r6   r7    [r3]         r0    r1        [r2]
                        abcd efgh ijkl  01234567
ldrd    r0, r1, [r3]                                 0123  4567      ------------
str     r5, [r2, #0]                                                 abcd-------- 
str     r7, [r2, #8]                                                 abcd----ijkl 
str.w   r0, [r2, #1]                                                 a0123---ijkl 
str.w   r1, [r2, #5]                                                 a01234567jkl

Note that: 注意:

  • The three output words are assembled in four writes to memory, two of which are unaligned. 这三个输出字以四次写入内存的方式组合在一起,其中两个未对齐。
  • The two str instructions are 16-bit encodings. 这两个str指令是16位编码。

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

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