Bcd Correction Circuit Operation - NEC 78K0R/KE3 User Manual

16-bit single-chip microcontrollers
Table of Contents

Advertisement

25.3 BCD Correction Circuit Operation

The basic operation of the BCD correction circuit is as follows.
(1) Addition: Calculating the result of adding a BCD code value and another BCD code value by using a
BCD code value
<1> The BCD code value to which addition is performed is stored in the A register.
<2> By adding the value of the A register and the second operand (value of one more BCD code to be added)
as are in binary, the binary operation result is stored in the A register and the correction value is stored in
the BCDADJ register.
<3> Decimal correction is performed by adding in binary the value of the A register (addition result in binary)
and the BCDADJ register (correction value), and the correction result is stored in the A register and CY
flag.
Caution The value read from the BCDADJ register varies depending on the value of the A
An example is shown below.
Examples 1: 99 + 89 = 188
MOV A, #99H
ADD A, #89H
ADD A, !BCDADJ
Examples 2: 85 + 15 = 100
MOV A, #85H
<R>
ADD A, #15H
ADD A, !BCDADJ
Examples 3: 80 + 80 = 160
MOV A, #80H
ADD A, #80H
ADD A, !BCDADJ
682
CHAPTER 25 BCD CORRECTION CIRCUIT
register when it is read and those of the CY and AC flags. Therefore, execute the
instruction <3> after the instruction <2> instead of executing any other instructions. To
perform BCD correction in the interrupt enabled state, saving and restoring the A
register is required within the interrupt function. PSW (CY flag and AC flag) is restored
by the RETI instruction.
Instruction
A Register
; <1>
; <2>
; <3>
Instruction
A Register
; <1>
; <2>
9AH
; <3>
Instruction
A Register
; <1>
; <2>
; <3>
User's Manual U17854EJ9V0UD
CY Flag
AC Flag
99H
22H
1
88H
1
CY Flag
AC Flag
85H
0
00H
1
CY Flag
AC Flag
80H
00H
1
60H
1
BCDADJ
Register
1
66H
0
BCDADJ
Register
0
66H
1
BCDADJ
Register
0
60H
0

Advertisement

Table of Contents
loading

Table of Contents