Texas Instruments MSC1210 User Manual

Page 221

Advertising
background image

Adjusting Accumulator for BCD Addition (DA)

16-27

8052 Assembly Language

16.26 Adjusting Accumulator for BCD Addition (DA)

DA A is a very useful instruction if you are doing BCD-encoded addition.

BCD stands for binary coded decimal, and is a form of expressing two decimal
digits in a single 8-bit byte. When any 8-bit value is expressed in hexadecimal,
it can be expressed as a number between 00 and FF. Obviously, it is possible
to express all normal decimal numbers between 0 and 99 in hexadecimal for-
mat so that, printed as hexadecimal, they appear to be decimal numbers.

For example, the decimal digits 00 are represented in BCD as, not surprisingly,
00

H

. The decimal digits 09 are represented in BCD as 09

H

. The decimal digits

10, however, are represented in BCD as 10

H

—but note that 10

H

is actually 16

(decimal). That is because in BCD, the hex values A, B, C, D, E, and F are not
used. Thus, 09

H

jumps to 10

H

.

This is all fine and good, but what happens when adding two BCD numbers
together? For example, what happens when adding 38 to 25? Obviously, in
normal decimal math, 38 + 25 = 63. Ideally, doing the same addition on BCD
encoded values would have the same result.

However, 38 encoded as BCD is 38h and 25 encoded as BCD is 25

H.

38

H

+ 25

H

= 5D

H

. Obviously the result no longer looks like a decimal value—and

that is not surprising because BCD does not use the values A, B, C, D, E, and
F.

What DA A does is automatically adjusts the accumulator after the addition of
two BCD values. In the previous example, executing DA A when the accumula-
tor holds 5D

H

will result in the accumulator being adjusted to 63

H

, thereby fix-

ing our rather strange addition.

The details of how DA A works and why are not extremely important to this tuto-
rial and would tend to confuse things rather than explain them. If planning on
doing BCD addition, please investigate this instruction further. For the majority
that will not be doing BCD addition, you can safely ignore this instruction.

Advertising