Hello!
Yes, this seems like an option...
I had thought of this, but didn't like the idea of repeating N times the
increment code.
But, the way you put it seems feasible in an elegant way.
I'll try it. At least, I understand it, which is more than I can say of
those tricky BCD conversion routines! 8)
My ugliest problem here, is the comparison with the constant. Feels
quite cumbersome to be
subtracting values just to check if the value is equal...
Thanks,
Nuno Pedrosa.
Byron A Jeff wrote:
{Quote hidden}>
> >
> > Hello!
> >
> > I need to implement some 24 bits and a 32 bits counter in my
> > application, in Assembly.
> > I'm not ready yet to go into PIC C.
> >
> > I have seen 16bit to BCD, from John Payson, but I couldn't find a way to
> > expand it
> > to 24 bit and 32 bits.
> >
> > Does anyone have such routines?
> >
> > I know I could use division by 10 and module 10, but if there's a more
> > efficient way, I would prefer it.
>
> The most efficient way is to count in packed BCD. It'll take 4 bytes for
> 24 bits (up to 16000000 and change) and 5 bytes for 32 bits.
>
> Here's how to count in packed BCD:
>
> 1) Start at the lowest byte. Add 1.
> 2) If the low nybble is A, do a BCD adjust by adding 6 to it.
> 3) If the high nybble is A, do another BCD adjust by adding h'60' to it.
> 4) Do the next higher byte if the carry is set.
>
> So for example if you have
> 00001999
> (note that this is 4 consecutive bytes in hexidecimal representing packed BCD)
> and you add 1
> 0000199A
> Since the low nybble is A, adjust by adding 6
> 000019A0
> Since the high nybble is A, adjust by adding 60
> 00001900
> Since the carry is set goto the next byte and add 1 to it.
> 00001A00
> Since the low nybble is A, adjust by adding 6
> 00002000
> And voila! there's the incremented value.
>
> Off the cuff is seems that using FSR/INDF and a tight loop could get this done
> fairly efficiently since the adjustment process is the same for each nybble
>
> Hope this helps,
>
> BAJ
--
---- ~~~~~~~ ------- Nuno Filipe Freitas Pedrosa
-- ~~~~ ~~ ----- SIEMENS S.A. Portugal TEL: +351 1 4242454
- ~~~~ ~~ ---- Nuno.Pedrosa
KILLspamicn.siemens.de
- ~~~~ ~~ ---- "MSWindows - Best run on a SlideShow"
=======================================================================