We've just updated MediaWiki and its underlying software. If anything doesn't look or work quite right, please mention it to us. --RanAS
SUB (Super FX): Difference between revisions
From SnesLab
(added basic info) |
(made flags affected more prominent) |
||
(32 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{| class="wikitable" style="float:right;clear:right;width:50%" | |||
{| class="wikitable" style="float:right;clear:right;width: | |||
!colspan="8"|Basic Info | !colspan="8"|Basic Info | ||
|+ | |+ | ||
|'''Addressing Mode''' | |||
|'''Opcode''' | |'''Opcode''' | ||
|'''Length''' | |'''Length''' | ||
Line 10: | Line 9: | ||
|'''Cache Speed''' | |'''Cache Speed''' | ||
|+ | |+ | ||
|[[Implied]] (type 1) | |||
|6n | |6n | ||
|1 byte | |1 byte | ||
Line 15: | Line 15: | ||
|3 cycles | |3 cycles | ||
|1 cycle | |1 cycle | ||
|+ | |||
|[[Immediate]] | |||
|3E6n | |||
|2 bytes | |||
|6 cycles | |||
|6 cycles | |||
|2 cycle | |||
|} | |} | ||
{| class="wikitable" style="float:right;clear:right;width:30%" | {| class="wikitable" style="float:right;clear:right;width:30%" | ||
!colspan="9"|Flags | !colspan="9"|Flags Affected | ||
|+ | |+ | ||
|B | |[[B Flag|B]] | ||
|ALT1 | |[[ALT1]] | ||
|ALT2 | |[[ALT2]] | ||
|[[O/V]] | |||
|[[Sign Flag|S]] | |||
|[[CY]] | |||
|[[Zero Flag|Z]] | |||
|+ | |||
|0 | |||
|0 | |||
|0 | |||
|O/V | |O/V | ||
|S | |S | ||
|CY | |CY | ||
|Z | |Z | ||
|} | |} | ||
'''SUB''' is a [[Super FX]] instruction that performs a subtraction between the [[source register]] and an operand. The difference is stored in the [[destination register]]. The subtrahend may be any register from R<sub>0</sub> to R<sub>15</sub> or any immediate value from 0 to 15. The source register is the minuend. | |||
The [[ALT0]] state is restored. | |||
The source and destination registers should be specified in advance using [[WITH]], [[FROM]], or [[TO]]. Otherwise, R<sub>0</sub> serves as the default. | |||
If an unsigned borrow occurred, [[CY]] is set, otherwise it is cleared. | |||
==== Syntax ==== | |||
<pre> | |||
SUB Rn | |||
SUB #n | |||
</pre> | |||
==== Example 1 ==== | |||
Let: | |||
S<sub>reg</sub> : R<sub>5</sub> | |||
D<sub>reg</sub> : R<sub>4</sub> | |||
R<sub>5</sub> = 735ah | |||
R<sub>8</sub> = 426bh | |||
After executing SUB R<sub>8</sub>: | |||
R<sub>4</sub> = 30efh | |||
==== Example 2 ==== | |||
Let: | |||
S<sub>reg</sub> : R<sub>0</sub> | |||
D<sub>reg</sub> : R<sub>0</sub> | |||
R<sub>0</sub> = 329bh | |||
After executing SUB #10: | |||
R<sub>0</sub> = 3291h | |||
=== See Also === | |||
* [[ADD]] | |||
* [[ADC (Super FX)]] | |||
* [[ADC]] | |||
* [[CMP (Super FX)]] | |||
* [[SBC (Super FX)]] | |||
* [[ALT2]] | |||
=== External Links === | |||
* Official Nintendo documentation on SUB: 9.86 on [https://archive.org/details/SNESDevManual/book2/page/n274 page 2-9-118 of Book II] | |||
* SUB with immediate addressing: 9.87 on [https://archive.org/details/SNESDevManual/book2/page/n275 page 2-9-119 of Book II] | |||
[[Category:ASM]] | [[Category:ASM]] | ||
[[Category:Super FX]] | [[Category:Super FX]] | ||
[[Category:Arithmetic Operation Instructions]] | |||
[[Category:One-byte Instructions]] | |||
[[Category:Expects Sreg/Dreg Prearranged]] |
Latest revision as of 19:14, 30 July 2024
Basic Info | |||||||
---|---|---|---|---|---|---|---|
Addressing Mode | Opcode | Length | ROM Speed | RAM Speed | Cache Speed | ||
Implied (type 1) | 6n | 1 byte | 3 cycles | 3 cycles | 1 cycle | ||
Immediate | 3E6n | 2 bytes | 6 cycles | 6 cycles | 2 cycle |
Flags Affected | ||||||||
---|---|---|---|---|---|---|---|---|
B | ALT1 | ALT2 | O/V | S | CY | Z | ||
0 | 0 | 0 | O/V | S | CY | Z |
SUB is a Super FX instruction that performs a subtraction between the source register and an operand. The difference is stored in the destination register. The subtrahend may be any register from R0 to R15 or any immediate value from 0 to 15. The source register is the minuend.
The ALT0 state is restored.
The source and destination registers should be specified in advance using WITH, FROM, or TO. Otherwise, R0 serves as the default.
If an unsigned borrow occurred, CY is set, otherwise it is cleared.
Syntax
SUB Rn SUB #n
Example 1
Let:
Sreg : R5 Dreg : R4 R5 = 735ah R8 = 426bh
After executing SUB R8:
R4 = 30efh
Example 2
Let:
Sreg : R0 Dreg : R0 R0 = 329bh
After executing SUB #10:
R0 = 3291h
See Also
External Links
- Official Nintendo documentation on SUB: 9.86 on page 2-9-118 of Book II
- SUB with immediate addressing: 9.87 on page 2-9-119 of Book II