SUB, SUBB

 

SUB        fr,#literal        Subtract literal from fr


Words:        2        Cycles:        2                Affects:        C, DC, Z

 

Operation:        Literal is subtracted from fr via W. C will be cleared to 0 if an underflow occurred, otherwise C will be set to 1. DC will be cleared or set, depending on whether or not an underflow occurred in the least-significant nibble. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0.

 

Coding:        MOVLW                literal

       SUBWF                fr,1

 

 

SUB        fr1,fr2        Subtract fr2 from fr


Words:        2        Cycles:        2                Affects:        C, DC, Z

 

Operation:        Fr2 is subtracted from fr1 via W. C will be cleared to 0 if an underflow occurred, otherwise C will be set to 1. DC will be cleared or set, depending on whether or not an underflow occurred in the least-significant nibble. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0.

 

Coding:        MOVF                fr2,0

       SUBWF                fr1,1

 

 

 

SUB        fr,W                Subtract W from fr


Words:        1        Cycles:        1                Affects:        C, DC, Z

 

Operation:        W is subtracted from fr. C will be cleared to 0 if an underflow occurred, otherwise C will be set to 1. DC will be cleared or set, depending on whether or not an underflow occurred in the least-significant nibble. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0.

 

Coding:        SUBWF                fr,1

 

 

SUBB        fr,bit                Subtract bit from fr


Words:        2        Cycles:        2                Affects:        Z

 

Operation:        If bit reads 0, fr is decremented. If fr was decremented, Z will be set to 1 if the result was 0, else Z will be cleared to 0. This instruction is useful for subtracting the carry from the upper byte of a double-byte value after the lower byte has been subtracted.

 

Coding:        BTFSS        3,0

       DECF                fr,1

 

Note:        The TechTools assemblers define a bit as port.bitposition, as in the following examples:

 

       RA.3 = bit 3 of port A        PortB.0 = bit 0 of port B