[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with confirmation on a small bit of assembly?



Tristan Mumford <xtristan.xmumford@xgmail.xcom> wrote:

> Just thought you'd like to know I did find the bug. If I have the time I'll
> fix it tomorrow. It was in that for...loop too.
> 
> After applying a liberal dose of printfs that spit out data to anything
> which may be called around when it jams up I tracked it. It just sails on
> past 0 and wraps around, spitting the contents of memory at the poor
> SL811HS all through its memory map. Correct me of I'm wrong but even though
> I was silly and used an unsigned 8 bit int, it still should have stopped at
> 0, right?

If you use an unsigned int and are testing for "greater than or equal to
zero" as a loop termination, the loop will go on forever. It is not
possible for an unsigned int to be less than zero. After decrementing
from 0, it will be 0xFF (or 0xFFFF), which is greater than zero.

If the compiler did produce code which stopped, that would be a bug.

You have to use a signed int if your loop termination condition is the
zero-to-minus-1 crossing.

-- 
David Empson
dempson@actrix.gen.nz