Dealing with non-aligned data

Hello,

A colleague of mine, while processing some binary data, transfered a RAM memory address to a function. That address was not even (ARM7 architecture) so the LDR instruction behaved exactly as the assembly manual specifies it should in case of a misaligned address - round in the address + some more shift magic, which created a memory access off by 1 byte. My question is: Is there a way to deal with this runtime error in advance?

Parents
  • What exactly was this supposed to do anyway? Copy the function code to some place?

    First of all, the reason the function address is odd, is that the LSB is used to distinguish ARM from Thumb functions.

    The function in question was most likely a Thumb function. You could just clear the LSB of the function address to get the real function address. If it has to be assembler, use LDRH/STRH to copy instructions, since the worst case is half word aligned addresses.

    Without more input, this is all I can say.

    Regards
    Marcus
    http://www.doulos.com/arm/

Reply
  • What exactly was this supposed to do anyway? Copy the function code to some place?

    First of all, the reason the function address is odd, is that the LSB is used to distinguish ARM from Thumb functions.

    The function in question was most likely a Thumb function. You could just clear the LSB of the function address to get the real function address. If it has to be assembler, use LDRH/STRH to copy instructions, since the worst case is half word aligned addresses.

    Without more input, this is all I can say.

    Regards
    Marcus
    http://www.doulos.com/arm/

Children
More questions in this forum