We've just updated MediaWiki and its underlying software. If anything doesn't look or work quite right, please mention it to us. --RanAS

DAS (SPC700): Difference between revisions

From SnesLab
Jump to: navigation, search
(added syntax)
(clarify first sentence)
 
(14 intermediate revisions by the same user not shown)
Line 25: Line 25:
|[[Carry Flag|C]]
|[[Carry Flag|C]]
|+
|+
|
|N
|.
|.
|.
|.
Line 31: Line 31:
|.
|.
|.
|.
|
|Z
|
|C
|}
|}


'''DAS''' (Decimal Adjust for Subtraction) is an [[SPC700]] instruction that performs the following:
'''DAS''' (Decimal Adjust for Subtraction) is an [[SPC700]] instruction that [[BCD]]-corrects a difference:
# If either the [[carry flag]] is clear or the accumulator exceeds 0x99, subtract 0x60 from the accumulator and clear the carry flag.
# If either the [[carry flag]] is clear or the accumulator exceeds 0x99, subtract 0x60 from the accumulator and clear the carry flag.  This corrects the tens column (but perhaps not completely).
# Then, if either the [[half-carry flag]] is clear or the low nibble of the accumulator exceeds 0x09, subtract 0x06 from the accumulator.
# Then, if either the [[half-carry flag]] is clear or the low nibble of the accumulator exceeds 0x09, subtract 0x06 from the accumulator.  This corrects the ones column and possibly decrements the tens column by one.  Subtracting six effectively maps $F to 9, $E to 8, etc.  These hex digits $A to $F can appear in the difference when a borrow occurs.
 
Before DAS, the value in the accumulator is assumed to be encoded in binary/hexadecimal (with any value in the range $00 to $FF) because that is what the [[SBC (SPC700)|SBC]] command can output.  But the inputs to SBC are supposed to be in BCD.  After DAS, the value in the accumulator will be encoded in BCD once again where both nybbles are in the range 0-9.  The SPC700 has no [[decimal mode]], so that is why this command is important when working with decimal data.


==== Syntax ====
==== Syntax ====
<pre>
<pre>
DAS
DAS
DAS A
</pre>
</pre>


=== See Also ===
=== See Also ===
* [[DAA]]
* [[DAA]]
* [[BCD]]
* [[SED]]
* [[CLD]]


=== External Links ===
=== External Links ===
Line 52: Line 56:
* [https://archive.org/details/SNESDevManual/book1/page/n180 page 3-8-2 of Book I], lbid
* [https://archive.org/details/SNESDevManual/book1/page/n180 page 3-8-2 of Book I], lbid
* ares source code, SPC700::instructionDecimalAdjustSub
* ares source code, SPC700::instructionDecimalAdjustSub
* anomie: https://github.com/yupferris/TasmShiz/blob/8fabc9764c33a7ae2520a76d80ed7220bb939f12/spc700.txt#L410


[[Category:ASM]]
[[Category:ASM]]
[[Category:SPC700]]
[[Category:SPC700]]
[[Category:Decimal Compensation Commands]]
[[Category:Decimal Compensation Commands]]

Latest revision as of 08:19, 23 September 2024

Basic Info
Addressing Mode Opcode Length Speed
Accumulator BE 1 byte 3 cycles
Flags Affected
N V P B H I Z C
N . . . . . Z C

DAS (Decimal Adjust for Subtraction) is an SPC700 instruction that BCD-corrects a difference:

  1. If either the carry flag is clear or the accumulator exceeds 0x99, subtract 0x60 from the accumulator and clear the carry flag. This corrects the tens column (but perhaps not completely).
  2. Then, if either the half-carry flag is clear or the low nibble of the accumulator exceeds 0x09, subtract 0x06 from the accumulator. This corrects the ones column and possibly decrements the tens column by one. Subtracting six effectively maps $F to 9, $E to 8, etc. These hex digits $A to $F can appear in the difference when a borrow occurs.

Before DAS, the value in the accumulator is assumed to be encoded in binary/hexadecimal (with any value in the range $00 to $FF) because that is what the SBC command can output. But the inputs to SBC are supposed to be in BCD. After DAS, the value in the accumulator will be encoded in BCD once again where both nybbles are in the range 0-9. The SPC700 has no decimal mode, so that is why this command is important when working with decimal data.

Syntax

DAS
DAS A

See Also

External Links