adiroot

Bug report: HC12 Compiler 5.0.35 will erroneously inline routines with assembly code

Discussion created by adiroot on Sep 24, 2010
Latest reply on Sep 29, 2010 by CompilerGuru

HC12 Compiler 5.0.35 will erroneously inline routines with assembly code.

 

We switched from version 5.0.21  to 5.0.35 of the HC12 compiler.  A C routine that had assembly code in it was not inlined by compiler 5.0.21.  However, 5.0.35 did inline the routine, and did so poorly, resulting in a bug (stack mixup causing variable values to be written in the wrong place).

 

Here's the C code:

 

#pragma INLINE
char SpiByteExchange(register unsigned char cDataToSend)
{
   while (SPI1SR_SPTEF == 0);
   asm STAB SPI1DR;
   while (SPI1SR_SPIF == 0);
   return SPI1DR;
}

 

Here's the assembly from compiler 5.0.35:

Options : -C++f -Cf -Cni -CpEPAGE -CpGPAGE -CpPPAGE -CpRPAGE -CPUHCS12X -DSDRX -F2 -Lasm=%n.lst -Lasmc=aepv -Ldf=predef.h -Lm=d:\SDRX\text\SDRX.dep -Ml -Onu -Onf -Oi=c0 -OnB -Onbt -Onca -Oncn -One -OnP=abcdefghijklmnpqrtu -Ont= -TuCD4LD4LLD4uE -ViewHidden -W1 -WErrFileOff -WmsgNu=abcde -WmsgSd1106 -WmsgSd1435 -WOutFileOn

  513:    SpiByteExchange(0xff);
  c6ff         [1]     LDAB  #255
  6b8c         [2]     STAB  12,SP
  4f0020fc     [4]     BRCLR _SPI1SR,#32,*+0 ;abs = 0012
  5b00         [2]     STAB  _SPI1DR
  4f0080fc     [4]     BRCLR _SPI1SR,#128,*+0 ;abs = 0018
  d600         [3]     LDAB  _SPI1DR

Outcomes