NEC ELECTRONICS GLOBAL
nec electronics global
HOME
APPLICATIONS
PRODUCTS
TECHNOLOGY
SUPPORT
BUY ONLINE
NEWS & EVENTS
ABOUT US
header
GO
AdvancedParametric
SITE MAP CONTACT US

Decimal calculations with microcontrollers (78K0, 78K0S, 78K0R)

Contents

    
FAQ-ID = 78cor-nnnn
0001: Decimal calculations with microcontrollers (78K0, 78K0S, 78K0R)
78cor
-0001
Decimal calculations with microcontrollers (78K0, 78K0S, 78K0R)
Q1
Is the decimal adjust instruction used when performing conversion from binary to decimal in a microcontroller?
A1
Yes. The decimal adjust instruction is used to convert the result of binary addition/subtraction to decimal.
Is this information useful for you ?
Q2
I set the binary value to register A and performed decimal adjust instruction, but was not able to obtain a correct result.
A2
The decimal adjust instruction is not for converting binary values to decimal values. To convert binary values to decimal values, a conversion program must be used.
Is this information useful for you ?
Q3
Please tell me how to use the decimal adjust instruction?
A3
The decimal adjust instruction is used to obtain correct results of decimal addition or subtraction. When adding (or subtracting) decimal values, first calculate them by binary addition (subtraction). Next, adjust the result with the decimal adjust instruction to obtain the correct decimal result.
For example, when calculating 19 + 17, the addition itself is processed as a binary addition. The addition result is 30. This number itself is not a strange number in the decimal system, but in the case of this addition, carry from the lower 4 bits occurs. In the decimal system, carry is done at 10, but in this case, carry occurs at 16. By performing decimal adjustment here, 6 is added to the lower 4 bits and the result, 36, is the correct decimal addition result.



Decimal adjustment is thus performed for adjusting the value and a carry/borrow at every four bits. This must always be executed immediately after each addition/subtraction.

Coffee Break
Decimal adjustment is done using the contents of register A, a carry flag and an auxiliary carry flag. Actual adjustment is performed by dividing the contents of register A into higher four bits and lower four bits (this division is done for each decimal number digit). In the case of addition, either when the result value is A to F or when carry occurs (when carry or auxiliary carry is set), 6 is added to the four bits (or else, 0 is added). The result is reflected to register A and the carry flag.
Since the addition is executed between the same degits of decimal numbers, [addition result = A to F] and [carry] never occur simultaneously.

For details about decimal adjustment, refer to Sample arithmetic operation program for CPUs that do not have a decimal adjust instruction.
Is this information useful for you ?
Q4
The 78K0R/Kx3 microcontroller does not have a decimal adjust instruction. Can decimal adjustment not be performed in these products?
A4
Yes, it can perform decimal adjustment. The 78K0R/Kx3 microcontroller has a decimal correction circuit for this purpose.
As can be seen from the above operation example, decimal adjustment is done by adding or subtracting a adjustment value depending on the calculation result (carry or borrow at every four bits and value). In other words, the same result can be obtained by generating the adjustment value according to the calculation result and then adding or subtracting that adjustment value.
Thus, the same decimal adjustment result can be obtained without the decimal adjust instruction, and this is why the decimal adjust instruction has been deleted from the instruction set of the 78K0R.

Coffee Break
There are a number of decimal calculation methods. In terms of instructions, the use of decimal addition and decimal subtraction instructions is one approach, and the use of adjustment is another one. In the majority of cases, decimal adjustment is employed.
The 8080 family, the first generation of 8-bit microprocessors, used decimal adjust instructions for addition only, and performing subtractions in decimal required quite a lot of processing. Subsequent microprocessors that improved this point provided a flag indicating whether addition or subtraction was performed, enabling both addition and subtraction with one adjust instruction. This latter version was clearly easier to use, but since the former version was used in the market, the latter version gained little acceptance due to compatibility issues. Later, the Z80 was launched and the improved design featuring an additional flag became common. The method adding a flag was born from the need to be able to continue using existing software. Free from the constraint of existing software, the approach of the current 78K0 employing a adjust instruction for addition and a adjust instruction for subtraction allows a simpler configuration because it does not require the use of extra flags.
Is this information useful for you ?
back to top  
(2008/01)









































 LEGAL  RSS Feeds       © 1995-2008  NEC Electronics Corporation