Luben Hristov
   
Reged: Oct 26 2003
Posts: 24
Loc: UK
|
|
Hello,
Again this damn assembler....
if defined global static variables
static unsigned char keys_A, keys_B, keys_D, imagePORTA, imagePORTB, imagePORTD;
and then I have this fragment in the code
...........
keys_A = 0x66;
keys_B = 0x66; // not optimized
keys_D = 0x66; // not optimized
imagePORTA = 0; // not compiled
imagePORTB = 0; // not compiled
imagePORTD = 0; // not compiled
signal16 = 0; // not compiled
Disable_Ints(); // disable INTERRUPTS
#asm
.....
#endasm
by some crazy reason I don't see setting the variable to ZERO - in the list file the code for them is just missing.
I agree that all changes of signal16 and other variables are made in the assembler section, where the compiler has no scope what happens and maybe this is the root of problem.
In addition I see that the fisrt 3 instructions are compiled with unoptimezed code - every time ACC is loaded with 0x66 and the loaded into variable, instead loading once the ACC and moving the content 3 times to variables.
here is the output in LST file
274 00A9 0F66 mov a,102
275 00AA 40A2 mov [_keys_A],a
276 ;test.C: 47: _keys_B = 0x66;
277 00AB 0F66 mov a,102
278 00AC 40A3 mov [_keys_B],a
279 ;test.C: 48: keys_D = 0x66;
280 00AD 0F66 mov a,102
281 00AE 40A1 mov [_keys_D],a
282 ;test.C: 59: _emi=0;
283 00AF 340B clr [intc0].0
as you see there is missing code .... 4 commands are not translated at all.
Some suggestions?
Best regards
Luben Hristov
Edited by Luben Hristov (Fri May 13 2005 05:33 AM)
|
Luben Hristov
   
Reged: Oct 26 2003
Posts: 24
Loc: UK
|
|
I found that if I move the variable to local / auto variable and everything works. That means that the problem is accessing the global static variables from assembler code.
Further investigation revealed that if the compiler don't see any change of the variable in the C section (asm section is invisible), then it optimizes the code and removes the initial settings of the variables.
I got many different error messages just by using/not using the variables in C section. At the end I made some simple section, where all variables were somehow changing each other, that ensured the compiler that the variables are needed.
So, seems that if you mix C and ASM you should be aware that if in the C section there is no use of some variable, the consequence could be:
- could not define the var names for assembler section (yields errors)
- could remove all initial settings of the variables (no erros) ... it's nasty case.
Proposal - one pargma to switch ON/OFF the optimization in some places will be very useful. Actually all these effects are caused from the optimization.
Regards
Luben Hristov
Edited by Luben Hristov (Fri May 13 2005 09:46 AM)
|
C.J. Prins
Reged: Jun 08 2005
Posts: 3
Loc: Nijkerk, The Netherlands
|
|
Instead of turning optimization on/off, I think you could better declare your variables as 'volatile .....' . In this way, the compiler will not optimize this variable, because it takes into account that this variable could have been changed by e.g. interrupt routines or, as in your case, assembly lines.
Greetings from The Netherlands, from a very satisfied customer, using the Hi-Tech C-compiler for Hitachi H8/300H series.
|
|