DAA 命令 (Decimal Adjust for Addition) |
オペコード | 構文 | アドレッシングモード | バイト数 | 命令サイクル | 注 |
---|---|---|---|---|---|
DF
|
DAA A
|
Accumulator
|
1
|
3
|
|
; DAA Sample ; Calculate 25 + 49 (= 74) in decimal. CLRC ; ***-*-** MOV A, #$25 ; ***-*-*c ADC A, #$49 ; n**-*-zc A: 25 First, add two numbers in hexadecimal. DAA A ; nv*-h-zc A: 6E Then, execute DAA instruction. *** ; nv*-h-zc A: 74 ;DAA instruction runs following operations in this case. ;1. Since low nibble is 0xE > 0x9, adds 0x6 to accumulator. 0x6E + 6 = 0x74 ;2. Since high nibble is 0x7 < 0xA and carry flag is not set, no operation is done in this step. ;3. Carry has not occured, so carry flag is not set. ; Calculate 99 + 99 (= 198) in decimal. CLRC ; ***-*-** MOV A, #$99 ; ***-*-*c ADC A, #$99 ; n**-*-zc A: 99 First, add two numbers in hexadecimal. DAA A ; nv*-H-zC A: 32 Then, execute DAA instruction. *** ; Nv*-H-zC A: 98 100's place is stored in carry flag. DAA instruction result is 198 in decimal. ;DAA instruction runs following operations in this case. ;1. Since half-carry flag is set, adds 0x6 to accumulator. 0x32 + 6 = 0x38 ;2. Since carry flag is set, adds 0x60 to accumulator. 0x38 + 0x60 = 0x98 ;3. Since carry flag was set befor do DAA, carry flag is still set.