DAS 命令 (Decimal Adjust for Subtruction) |
オペコード | 構文 | アドレッシングモード | バイト数 | 命令サイクル | 注 |
---|---|---|---|---|---|
BE
|
DAS A
|
Accumulator
|
1
|
3
|
|
; DAA Sample ; Calculate 81 - 49 (= 32) in decimal. SETC ; ***-*-** MOV A, #$81 ; ***-*-*C SBC A, #$49 ; N**-*-zC A: 81 First, subtract two numbers in hexadecimal. DAS A ; nV*-H-zC A: 38 Then, execute DAS instruction. *** ; nV*-H-zC A: 32 ;DAS instruction runs following operations in this case. ;1. Since half-carry flag is set, subtracts 0x6 from accumulator. 0x38 - 6 = 0x32 ;2. Since high nibble is 0x7 < 0xA and carry flag is set, no operation is done in this step. ;3. Since carry flag was set befor do DAS, carry flag is still set. ; Calculate 15 - 34 (= -19) in decimal. CLRC ; ***-*-** MOV A, #$15 ; ***-*-*C SBC A, #$34 ; n**-*-zC A: 15 First, add two numbers in hexadecimal. DAS A ; Nv*-h-zc A: E1 Then, execute DAS instruction. *** ; Nv*-h-zC A: 81 DAS result looks like "81", but has set carry flag, so this means -19 in decimal. Or, this result can also be understood as 115 - 34 = 81. ;DAS instruction runs following operations in this case. ;1. Since half-carry flag is cleared and low nibble is 1 < 0xA, no operation is done in this step. ;2. Since carry flag is cleared, subtracts 0x60 from accumulator. 0xE1 - 0x60 = 0x81 ;3. Since arithmetic overflow has occured in step 2, carry flag is set.