Colin,
Yes, you've discovered a bug in shift right operation...
I'll fix it shortly.
I dunno, why it generates such a long code, but I'll check.
gcc actually thinks, that
if(a) a= 0 ;
else a = 1;
can be done better with shifts.
~d
On Wednesday 06 March 2002 18:39, Colin Domoney wrote:
> Hi
>
> I have the following code segment whose purpose is to toggle an LED every
> time the watchdog timer interrupt occurs:
>
> interrupt(WDT_VECTOR) WatchdogHandler(void)
> {
> static char st = 0;
>
> IFG1 &= ~WDTIFG;
>
> if (st)
> {
> LED1_ON();
> }
> else
> {
> LED1_OFF();
> }
>
> st = !st;
>
> IE1 = (IE1 | WDTIE);
> }
>
> The problem I am seeing is that the static 'st' variable is not being
> inverted correctly. The assembler code produced with -01 is:
>
> 71:watchdog.c **** st = !st;
> 140 .stabn 68,0,71,.LM11-WatchdogHandler
> 141 .LM11:
> 142 0028 5C42 0000 mov.b &st.0, r12
> 143 002c 4C93 tst.b r12
> 144 002e 0234 jge .Leaq33
> 145 0030 7CE3 inv.b r12
> 146 0032 5C53 inc.b r12
> 147 .Leaq33:
> 148 0034 7C53 add.b #llo(-1), r12
> 149 0036 4C11 rra.b r12
> 150 0038 4C43 clr.b r12
> 151 003a 4C10 rrc.b r12
> 152 003c C24C 0000 mov.b r12, &st.0
>
> If I watch the memory location where 'st' is stored (it is 0x200 on my app,
> I checked by disassembling the output ELF file) I can see that it gets
> inverted correctly from 0x00 to 0x80 the first time around the loop but
> then is always left at 0x80 and never inverted again to 0x00. If I write
> the above explicitly ie.
> if (st)
> st = 0;
> else
> st = 1 (or 0x80, whatever as long as it isn't 0x00)
> my handler behaves as expected ie. the LED is toggled.
>
> If I build the same code with -O0 (optimisations off) I get this:
> 149 .stabn 68,0,71,.LM11-WatchdogHandler
> 150 .LM11:
> 151 0036 C143 0200 mov.b #llo(0), 2(r1)
> 152 003a C293 0000 tst.b &st.0
> 153 003e 0220 jne .L5
> 154 0040 D143 0200 mov.b #llo(1), 2(r1)
> 155 .L5:
> 156 0044 D241 0200 mov.b 2(r1), &st.0
> which is a lot more compact and works correctly !
>
> I am using a MSP430F149 and a fairly (a week or two old) build of the
> MSP430GCC. Any comments ? What command line options do people typically use
> with msp430-gcc ie. in terms of optimisations, etc. I guess for now I will
> use -O0
>
> Regards.
>
> Colin
>
> ---------------------------------------------------------------------------
>------ Colin Domoney
> Digital Hardware Design Engineer
> NCipher, Jupiter House, Station Road, Cambridge, CB1 2JD
> e-mail: [email protected]
> Telephone: +44-1223-723630
>
> _______________________________________________
> Mspgcc-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
--
*********************************************************************
("`-''-/").___..--''"`-._ (\ Dimmy the Wild UA1ACZ
`6_ 6 ) `-. ( ).`-.__.`) Enterprise Information Sys
(_Y_.)' ._ ) `._ `. ``-..-' Nevsky prospekt, 20 / 44
_..`--'_..-_/ /--'_.' ,' Saint Petersburg, Russia
(il),-'' (li),' ((!.-' +7 (812) 314-8860, 5585314
*********************************************************************