Hi experts!
I want to use ldr/str or ldm/stm to copy memory not aligned 4bytes.
I know their input address should be aligned by 4 bytes.
but is there any solution to use ldr/str or ldm/stm though src or dst isn't aliged 4byte by modifing following code?
void wordcopy(unsigned char *dst, unsigned char *src, int num) {loop: LDR r3,[r1]; STR r3,[r0]; SUBS r2,r2,#1; BNE loop; BX lr;}
To enhance Martin's reply slightly:
In the very beginning of your routine, make a check on the lowest 2 bits on both source and destination.
If the bits match on both source and destination, use a 32-bit copy with a ramp-up.
If bit 0 on source differs from bit 0 on destination, you may benefit from byte-copy; you also have the option to use shifts, but the code will be large.
If bit 1 on source differs from bit 1 on destination, you may benefit from halfword-copy, but the penalty for copying misaligned halfwords is not so bad, so you may want to do a full 32-bit copy there.
Hint: Use the EOR instruction followed by a LSLS#30 to check if the low two bits match.
View all questions in Cortex-A / A-Profile forum