This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
We use Code Composer 4.02, but this problem is general. If I allocate a memory array that for some reason ends up crossing a 64K boundary, the memset() function bombs the wraparound part of the memory segment. I am using LARG memory model. If I write the code using a "for" loop, then it works fine.
Looking inside the string.h I find the memset function as an inline function. It looks OK.
If I then open an assembler window and analyze the generated code, I se:
MOV T0,*AR3+
but I expected something like:
MOV T0,*XAR3+
PS: We use a 5509A DSP, with external memory.
Terje,
2nd question first. When you use *AR3, you get the address represented by the AR3 bits plus the 7 extended address register bits. You only need to use the XAR indicator when you load the register to set the correct page.
This actually leads to your first problem. When you fill the data using a for loop, when you cross the boundary, your array is then actually non-contiguous. i.e. say you are on data page 4, when you write to address 0x04FFFF and then increment your data pointer, the next value gets written to 0x040000 (not 0x050000).
I'm not too familiar with the way that memset works, but I suspect that there is some checking that occurs to ensure that you don't cross a 64K boundary.
regards,
Dan
First, as Dan says, in "MOV T0, *AR3+" the full 23-bit address in the XAR3 is used in the addressing calculation. It is something of an inconsistency in the assembly language that "ARn" rather than "XARn" is used in these address modes.
The problem is that the address register-modifying address modes on 5509A such as auto-increment, indexed, etc only do a 16-bit add, so they wraparound at 64K boundaries. The compiler generates these address modes and relies on the linker to reject data sections that try to cross a 64K boundary. Thus, no standard-conforming C program will have a problem with this wraparound behavior. However, if the C source that results in one of these address modes is not based on the address of a C-allocated entity (like an array), but instead uses a computed value that is not an address inside a C entity (typically just some numeric literal value) it is possible to encounter the wraparound behavior.
The code written using a for loop probably worked because it did not happen to use auto-increment or indexed addressing. If you need to do memset across a boundary then stick with your specialized version that handles this case.
Paul, Dan,
Great answers, this explans my problem and Ti's earlier replay that a C5505 or equal DSP would NOT se this problem...