Sorry if this is obvious
Don't know if this applies, but notice that if you're doing multiple
digit hex numbers, it's not enough to just convert the hex nibbles to
their BCD equvalents if what you want is to end up with actual BCD
Suppose you've got a two digit hex number. You've got a 1's place
and a 16's place. If you simply convert that 16's place hex digit
to BCD you end up with (sort of) BCD coded hex. You'll need to multiply
it by 16 to get the BCD.
C0 in HEX which is 192 in decimal
if you only convert the high nibble to it's BCD equvalent you get
120 in BCD (or "BCD coded hex")
You have to multiply that 12 by 16
"Jim Knight" <(EMail Removed)> wrote in message news:<(EMail Removed)>...
> Gary,
> Thanks. Appreciate the clear instructions even someone like me can
> understand. Guess I should be able to write a routine that does this and
> then just call the routine whenever the original code is operating in
> Decimal mode.
>
> Again thanks.
>
> Jim Knight
> "Gary Kato" <(EMail Removed)> wrote in message
> news:(EMail Removed)...
> > >Is it difficult to explain how you would do this conversion in a system
> > >(ST7) that only works in Hex?
> > >
> >
> > No, not difficult. All you really need to do is to look at what happens to
> one
> > nibble. This assumes you added two legal BCD values together into a sum.
> >
> > First, you need to detect when the nibble goes beyond 9. So, what do you
> do?
> > Try an example:
> >
> > 1001 9
> > 0001 1
> > 1010 10(hex) Illegal BCD
> >
> > What we want is 10hex. To get this, we need to subtract 10(hex) from this
> > nibble and add 1 to the next higher nibble. If we are looking at the least
> > significant nibble of a byte, we see that this means adding 16 to
> increment the
> > high nibble. So, +1610 = +6. We come out with this general rule:
> >
> > 1. If the low 4 bits of the sum are > 9, add 6 to sum.
> >
> > But we have to take another case into account. What if the low nibble of
> the
> > sum is legal BCD, but there was a carry from the low nibble to the high
> during
> > our binary addition? Example:
> >
> > 01001 9
> > 01001 9
> > 10010 12(hex) = 18 decimal
> >
> > What we want is 18(hex). We need to add 6 to the sum to make it right.
> Which
> > leads to our next rule:
> >
> > 2. If there was a carry from low nibble to high, add 6 to the sum.
> >
> > Fortunately, the ST7 has a carry bit to show a carry from the high nibble,
> and
> > a halfcarry bit to show a carry from the low nibble to the high nibble.
> >
> > I'll leave BCD subtraction to you, though you probably don't need that.
> >
> >
> >
