Forum Discussion
Altera_Forum
Honored Contributor
19 years agoAs I experienced, the nios processor is ONLY able to read 16 Bit Words from 2 byte aligned memory and 32 Bit words from 4 byte aligned memory.
So one needs to be very carefull with doing memcpy on structures. For example, if your structure contains any INT or FLOAT and you copy it to an unaligned address, all reads and write will automatically cut address bit 0 or bit 0 and 1 on read and write access. try this simple testprogramm, to see what the proccessor is doing...#include <stdio.h>
int main()
{
short bufs= {0x1122,0x3344,0x5566,0x7788};
int bufi= {0x11223344,0x55667788};
int *pi;
short *ps;
// Test Byte Displacement on 4byte load instruction
pi=bufi;
printf("pi : %x: %x\n",pi,*pi);
pi=(void*) ((int)pi+1);
printf("pi+1 : %x: %x\n",pi,*pi);
pi=(void*) ((int)pi+1);
printf("pi+2 : %x: %x\n",pi,*pi);
pi=(void*) ((int)pi+1);
printf("pi+3 : %x: %x\n",pi,*pi);
pi=(void*) ((int)pi+1);
printf("pi+4 : %x: %x\n",pi,*pi);
// Test Byte Displacement on 2byte load instruction
ps=bufs;
printf("ps : %x: %x\n",ps,(int)*ps);
ps=(void*) ((int)ps+1);
printf("ps+1 : %x: %x\n",ps,(int)*ps);
ps=(void*) ((int)ps+1);
printf("ps+2 : %x: %x\n",ps,(int)*ps);
ps=(void*) ((int)ps+1);
printf("ps+3 : %x: %x\n",ps,(int)*ps);
ps=(void*) ((int)ps+1);
printf("ps+4 : %x: %x\n",ps,(int)*ps);
return 0;
} I received this output: pi : 7ffffcc: 11223344
pi+1 : 7ffffcd: 11223344
pi+2 : 7ffffce: 11223344
pi+3 : 7ffffcf: 11223344
pi+4 : 7ffffd0: 55667788
ps : 7ffffc4: 1122
ps+1 : 7ffffc5: 1122
ps+2 : 7ffffc6: 3344
ps+3 : 7ffffc7: 3344
ps+4 : 7ffffc8: 5566 Wonderfull, isn't it? http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/mad.gif This took me HOURS to find out...