Debugging loops question

Feb 22, 2008 5 Replies

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


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

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

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.

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.

Thank you thank you thank you

martin

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required