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

problem with casting for arm compiler

Hi all
I have a strange problem when I'm trying to cast buffers by arm compiler.
Here an example:

char* pbuf;
...
unsigned short val = *((unsigned short*)(pbuf+3));


When I compile this code, my generated assembly code uses LDRH,STRH. Then because my pbuf+3 is not multiple of 2 and those 2 instruction can only work with even value addresses, processor hangs up.
What I should to do that compiler generates a code that works in all cases?

Regards

Parents
  • you can always use pointers to a char, and assemble your value step by step. but any way, your processor should not hang in case of an un-aligned access (ARM7 and Cortex M). The LDR/STR instructions have a specific behavior when working with un-aligned addresses. refer to your assembly manual, but in any case it is not a good idea!

Reply
  • you can always use pointers to a char, and assemble your value step by step. but any way, your processor should not hang in case of an un-aligned access (ARM7 and Cortex M). The LDR/STR instructions have a specific behavior when working with un-aligned addresses. refer to your assembly manual, but in any case it is not a good idea!

Children
No data