Reply by Martin Griffith February 22, 20082008-02-22
On Fri, 22 Feb 2008 21:53:28 +0100, in comp.arch.embedded Arlet Ottens
<usenet+5@c-scape.nl> wrote:

>Martin Griffith wrote: > >> I'm trying to convert CBFalconer's bin to BCD for an 8051 >> >> http://cbfalconer.home.att.net/download/dubldabl.txt >> >> 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 >> http://es.geocities.com/mart_in_medina/doubledabl.c > >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
Reply by Arlet Ottens February 22, 20082008-02-22
Martin Griffith wrote:

> I'm trying to convert CBFalconer's bin to BCD for an 8051 > > http://cbfalconer.home.att.net/download/dubldabl.txt > > 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 > http://es.geocities.com/mart_in_medina/doubledabl.c
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 by CBFalconer February 22, 20082008-02-22
Martin Griffith wrote:
> > I'm trying to convert CBFalconer's bin to BCD for an 8051 > > http://cbfalconer.home.att.net/download/dubldabl.txt > > 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?
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]: <http://cbfalconer.home.att.net> Try the download section. -- Posted via a free Usenet account from http://www.teranews.com
Reply by Martin Griffith February 22, 20082008-02-22
On Fri, 22 Feb 2008 11:28:43 -0800, in comp.arch.embedded "John Speth"
<johnspeth@yahoo.com> wrote:

>> I'm trying to convert CBFalconer's bin to BCD for an 8051 >> >> http://cbfalconer.home.att.net/download/dubldabl.txt >> >> 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 >> http://es.geocities.com/mart_in_medina/doubledabl.c > >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
Reply by John Speth February 22, 20082008-02-22
> I'm trying to convert CBFalconer's bin to BCD for an 8051 > > http://cbfalconer.home.att.net/download/dubldabl.txt > > 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 > http://es.geocities.com/mart_in_medina/doubledabl.c
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 by Martin Griffith February 22, 20082008-02-22
I'm trying to convert CBFalconer's bin to BCD for an 8051

http://cbfalconer.home.att.net/download/dubldabl.txt

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
http://es.geocities.com/mart_in_medina/doubledabl.c

</ homework>

Thanks


martin