DAS 命令 (Decimal Adjust for Subtruction)
減算結果を二進化十進数に変換します。

DAS オーバーロード
オペコード 構文 アドレッシングモード バイト数 命令サイクル
BE
DAS A
Accumulator
1
3


フラグ変化
n------zc

n: 変換後のアキュムレータのMSBがセットされる
z: 変換後のアキュムレータがゼロの場合にセットされる
c: 変換によって算術オーバーフローが発生した(十進演算の結果が負の数となる)場合にセットされる。DASの実行前にセットされている場合はセットされたままとなる。


解説
DAS命令は、直前に実行された減算命令の演算結果を二進化十進数に変換します。変換の対象はアキュムレータとなります。

DAS命令によって実行される処理は、次の3段階に分かれます。
・ステップ1    ハーフキャリーフラグがセットされているか、下位ニブルが0xA以上である場合は0x6を引く
・ステップ2    キャリーフラグがクリアされているか、上位ニブルが(ステップ1の実行後)0xA以上である場合は0x60を引く
・ステップ3    ビット8をキャリーフラグにセットする(算術オーバーフローしなければ、このビットは0である)

変換後のアキュムレータの値によって、ネガティブフラグが変更されますが、10進での正負の識別にはキャリーフラグを用います。

; 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.

参照