Problem with word / dword - access...
2004-02-10 by lpc2100@web.de
Hello,
i have a problem with word / dword - access when the address is not even / devideable through 4. When i let run the below program i get the following output:
00 01 02 03 04 05 06 07 08 09
0100 0001 0302 0003 0504 0005 0706 0007 0908 0009
03020100 00030201 01000302 02010003 07060504 04070605 05040706 06050407 0B0A090
8 080B0A09
First line is fine, because it is byte access, filled the array with increasing numbers.
Second line: On word access all accesses on even addresses are wrong. Why is the ARM hardware not correcting this or at least detecting it (throwing an exception), so you know there is something wrong ?
Third line: dword (4 Bytes) seems to ignore below 2 bits, only rotating... is it really as it should be ?
I found it during porting a software to LPC2106, and it costs me hours to find the wrong values. And i am still not sure if i have catched all the problems.
Have a look at the following example:
(Pay attention, i have cut out not relevant parts, but i hope you can still see my problem)
int main(void)
{
unsigned char bytearray[256];
unsigned char *charptr;
unsigned short *wordptr;
unsigned long *dwordptr;
int i;
// Init cut out here...
for(i = 0;i < 256; i++) bytearray[i] = i;
for(i = 0;i < 10; i++)
{
charptr = (unsigned char *)&bytearray[i];
DebugPutString(" ");
DebugPutBYTE(*charptr);
}
DebugPutString("\r\n\r\n");
for(i = 0;i < 10; i++)
{
wordptr = (unsigned short *)&bytearray[i];
DebugPutString(" ");
DebugPutWORD(*wordptr);
}
DebugPutString("\r\n\r\n");
for(i = 0;i < 10; i++)
{
dwordptr = (unsigned long *)&bytearray[i];
DebugPutString(" ");
DebugPutDWORD(*dwordptr);
}
while(1);
}
______________________________________________________________________________
Erdbeben im Iran: Zehntausende Kinder brauchen Hilfe. UNICEF hilft den
Kindern - helfen Sie mit! https://www.unicef.de/spe/spe_03.php