Texas Instruments MSC1210 manual Adjusting Accumulator for BCD Addition DA

Models: MSC1210

1 324
Download 324 pages 20.97 Kb
Page 221
Image 221

Adjusting Accumulator for BCD Addition (DA)

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, 00H. The decimal digits 09 are represented in BCD as 09H. The decimal digits 10, however, are represented in BCD as 10H—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, 09H jumps to 10H.

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 25H. 38H + 25H = 5DH. 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 5DH will result in the accumulator being adjusted to 63H, 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.

8052 Assembly Language

16-27

 

Page 221
Image 221
Texas Instruments MSC1210 manual Adjusting Accumulator for BCD Addition DA