Debugging loops question

I'm trying to convert CBFalconer's bin to BCD for an 8051

formatting link

the first example, and I'm stuck, it almost works.

I get quite confused by loops like this

My version gives 10, 1000, 1000 instead of 10, 0101, 0101

Any hints on debugging things like this?

my code(?) is here

formatting link

Thanks

martin

Reply to
Martin Griffith
Loading thread data ...

You're code looks like it's 100% portable ANSI C. Therefore, try to debug it using your favorite ANSI C compiler and debugger on a desktop. You don't even need a debugger - printf can be a powerful debugging tool. If it doesn't work on your desktop (taking into account data sizes), it'll never work on your target. Does it work on your desktop?

JJS

Reply to
John Speth

I'm using the Raisonance compiler for the 8051, and stepping through it. I spent 3 hours trying to figure out what was wrong. It's me....

I'll put some printf's in, hand have another go at the weekend. I always come to grief when a for loop and bit shifting come together.

martin

Reply to
Martin Griffith

I haven't looked at your code. Just a thought - are you using signed chars to hold the various items? If so, retype them to unsigned char.

--
 [mail]: Chuck F (cbfalconer at maineline dot net) 
 [page]: 
            Try the download section.
Reply to
CBFalconer

You should only do the +3 correction _before_ a shift. In your code, the correction is done after a shift. This works fine, except in the last iteration where the correction isn't followed by a shift.

Reply to
Arlet Ottens

Thank you thank you thank you

martin

Reply to
Martin Griffith

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.