Hi All, I've been lurking on this board for about 12 months now, but this is my first post... I have traced a memory corruption problem to a single assembler statement. The statement is the first statement in the Keil printf() function. The invocation of the printf() function is this: printf("\n"); From my limited knowledge of the XC161's segmented addressing, I can't figure out why the Keil C compiler is generating the assembler that it has. Please refer to this image during the following description: 68.178.219.18/.../printf_segment_problem.png From what I can tell the assembler statement that was just executed: MOV [-R0],R12 is moving the contents of register R12 (0x0BF2) to the absolute address 0x80BFE. It is using DPP2 to calculate that absolute address as follows (correct me if I'm wrong): DPP2 = 0x20 = 100000 + 0x8BFE & 0x3FFF = 0x0BFE = 00101111111110b = 100000b 00101111111110b = 10000000101111111110b = 0x80BFE My hardware has 512K of RAM memory located at address 0x80000. NDATA is (I presume) indexed using DPP2 which puts the 16K of near data at 0x80000. After compiling the code I can see in the *.M66 file that: - NDATA is located at 0x80000..0x8004E - HDATA is located at 0x80050 through to 0x87A6F. I have an 8192 byte array declared, it is located by the compiler/linker at: 0x80050..0x8204F My question is this: Why does the compiler produce code in the printf() function that writes to memory address 0x80BFE which is in the middle of my array. Or if there is no answer to the "why" question, then what can I do to stop this memory overwritting from occuring. I guess it probably has something to do with the memory model and near data definitions. For what it's worth I have selected the HLarge memory model and 16K near RAM and 16K near ROM. There is probably a lot more info I can provide. If you can help and need more info just tell me what info you need and I'll get it. Regards (and thanks in advance, this has had me stumped for 2 days now). Paul