Hi all,
I have this neat little SRAM Test:
register unsigned char *p_val,*p_sav,i,sav; register unsigned char val; register signed char h; /* test all locations with 0x55, 0xAA and complement of address value */ p_val=((unsigned char *)(SRAM_START_ADR)); sav = *p_val; *p_val = 0x55; i = *p_val; if (i!=0x55) { return TEST_FAIL; } *p_val = 0xAA; i = *p_val; if (i!=0xAA) { return TEST_FAIL; } val = ~((unsigned char)p_val); *p_val = val; i = *p_val; if (i != val) { return TEST_FAIL; } *p_val=sav; }
(I know, the for loop is missing in the example. :wink: )
When compiling with -O0, everything is ok, but when compiling with i.e. -Os, the asm output is
ce: 80 e0 ldi r24, 0x00 ; 0 d0: 90 e0 ldi r25, 0x00 ; 0
I know it is because I save the Ram value, change it to 55 and AA and read it, compare it and than write back the saved RamValue. For sure, the compiler will think: "Who the hell wrote this. I will delete all the shit and do nothing!!"
But now, how to tell the compiler that he has to do the write 55 and AA and read and compare stuff to make me happy.
First idea is to put the RAM test into a seperate C-File and give it the compile flag -O0, second is to write the ram-test in Assember or take the -O0 compiled Assemblercode and put it as inline assembler into my c-file?!
Any other suggestions?
Baldrian