From: Maarten B. <sou...@ds...> - 2013-01-19 11:24:03
|
Hello Vincent, The reason for this behaviour is that SDCC turns polling and then clearing a bit/sbit into an atomic action (using JBC). This is very useful when the bit is a semaphore or is set inside an interrupt handler. Maarten > Hi. > > I'm looking at asm generated for the following loop (8051, a CYCFX2LP > actually) with sdcc 3.1.0#7066: > > __sbit __at 0x98+1 TI; > void main() { > while (!TI); > TI = 0; > } > > I get this: > > 00101$: > jbc _TI,00115$ > sjmp 00101$ > 00115$: > > Wouldn't it be more efficient, for such bit polling loop, to use instead: > > 00101$: > jnb _TI,00101$ > clr _TI > > The first version polls _TI every 7 cycles. > The second version polls _TI every 4 cycles. > If _TI is set on loop entry, the first version exits after 4 cycles while > the > second exits after 6 cycles. I believe it's sane to assume this is an > unlikely > event, so it shouldn't matter too much. > > Regards, > -- > Vincent Pelletier |