Please read this page from the main YASEP interface
version 2011-09-19

SUB : SUBstract two operands

Substraction is identical to ADD, but the first operand is negated (like A-B=A+(-B)).

Short forms : The second operand (snd) is substracted from the first operand (si4, either a register or a sign-extended 4-bit value) and the result is written into the second operand (snd).

Long immediate version : The source register (snd) is substracted from immediate field (Imm16, sign-extended with YASEP32) and the result is written to the destination register (si4).

; D4 = 123h
; R1 = 1h
SUB R1 D4   ; D4= D4+(-R1) = 123h+FFFFFFFEh = 122h
SUB 4 R1 D4 ; D4= 4h+(-R1) =   4h+FFFFFFFEh =   3h

Note that substraction by an immediate value is possible by ADD-ing a negative immediate value.

; R1 = 5678h
ADD -4 R1 D4 ; D4= 5678h+(-4) = 5674h

NEGation of a register is possible with an alias that substracts this register from immediate 0.

The result is truncated to the 16 (YASEP16) or 32 (YASEP32) lower bits. The borrow bit is the same as the carry bit, accessed with the CARRY condition.
Due to architectural optimisations, the borrow bit is negated : it is set when the substraction did not borrow.

; R1 = 4h
SUB 3 R1 ; R1 = 3 - 4 = -1 ==> borrow=0
SUB 4 R1 ; R1 = 4 - 4 = 0  ==> borrow=1
SUB 5 R1 ; R1 = 5 - 4 = 1  ==> borrow=1