Emperor Napoleon Posted May 5, 2013 Report Share Posted May 5, 2013 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 More sharing options...
alvieboy Posted May 5, 2013 Report Share Posted May 5, 2013 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 More sharing options...
Emperor Napoleon Posted May 5, 2013 Author Report Share Posted May 5, 2013 Sweet, thanks. Makes sense. I guess a compiler cant know ahead of time when a pointer would become unaligned and emit the code for such an acces. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.