Reverse Subtract

It is an all too common occurrence – the value in your a register needs to be subtracted. ARM provides a RSB instruction. The 65816 (which, quite frankly, needs it more than ARM does) does not. But we can still achieve the same outcome!

A - B is equivalent to A + -B which is equivalent to -B + A. Normally, negation is handled with an EOR #$ffff / INC.

    eor #$ffff
    inc
    clc
    adc ....

The INC/CLC can be combined into a SEC to save an instruction:

    eor #$ffff
    sec
    adc ....

This works for multi-word math, as well.

%t0 = %t0 - a 

    eor #$ffff
    sec
    adc %t0
    sta %t0
    lda #$ffff ; #0 ^ #$ffff 
    adc %t2
    sta %t2