This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ldm/stm with not aligned 4byte

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;
}

Parents
  • LDM/STM only support aligned addresses.

    LDR/STR can be used with unaligned addresses, as long as the target addresses are marked as Normal and that alignment checking isn't enabled.

    You didn't mention which processor/architecture you are targeting. For A class, the translation tables that define whether an address is Normal or Device.  For R and M class, it's the MPU (if present).

    The other option is to test in the passed in pointers.  Do a number of byte load/stores until you get an aligned address, then do LDM/STM, and finish with more byte load/stores if needed.

    EDIT: Typo

Reply
  • LDM/STM only support aligned addresses.

    LDR/STR can be used with unaligned addresses, as long as the target addresses are marked as Normal and that alignment checking isn't enabled.

    You didn't mention which processor/architecture you are targeting. For A class, the translation tables that define whether an address is Normal or Device.  For R and M class, it's the MPU (if present).

    The other option is to test in the passed in pointers.  Do a number of byte load/stores until you get an aligned address, then do LDM/STM, and finish with more byte load/stores if needed.

    EDIT: Typo

Children
No data