Does the ZPUino support unaligned pointer access?


Emperor Napoleon

Recommended Posts

From a little googling I have learned that the ZPU in general does not support unaligned memory accesses.

 

My question is, will the ZPUino compiler generate the correct code to access the data pointed here correctly?

 

I suspect it does not... would that be considered a bug?

 

The reason for this is I am doing some data structure packing/unpacking. Im porting this code from an ARM and it seemed ok there!

 

Thanks, and please let the emperor know if he is really just losing his mind.

 

 

 

        uint8_t output_buf [64];
       uint8_t * buf_ptr= output_buf;
          
       *buf_ptr = '1';
       buf_ptr++;
       *(unsigned *)buf_ptr = 0;//Unaligned access.
 
Link to comment
Share on other sites

No, unaligned accesses are not supported, like in most RISC processors.

 

You should use something like shift+add if you are required to do so.

 

similar to this:

void store_u32(unsigned char *dest, uint32_t value){  *dest++=(value>>24);  *dest++=(value>>16);  *dest++=(value>>8);  *dest=value;}
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.