;Adds two integers together (int_c = int_a + int_b).
;An integer is a two byte number.
;int_aH: the address of the high byte of the integer. The low byte is assumed
; to be at the next address (int_aH+1) so that the integer is int_aH:int_aL.
;int_bH: the address of the high byte of the integer. The low byte is assumed
; to be at the next address (int_bH+1) so that the integer is int_bH:int_bL.
;int_cH: the address of the high byte of the integer. The low byte is assumed
; to be at the next address (int_cH+1) so that the integer is int_cH:int_cL.
; int_cH can be equal to int_aH or int_bH
;Affects WREG and STATUS
;------------------------------------------------------------------------------
INT_ADD macro int_aH, int_bH, int_cH
local int_aL, int_bL, int_cL
int_aL = int_aH+1
int_bL = int_bH+1
inc_cL = int_cH+1
if int_aH == int_cH ;Special case int_a = int_a + int_b
movf int_bL, w
addwf int_aL, f
movf int_bH, w
btfsc STATUS, C
addlw 0x01
addwf int_aH, f
else
if int_bH == int_cH ;Special case int_b = int_a + int_b
movf int_aL, w
addwf int_bL, f
movf int_aH, w
btfsc STATUS, C
addlw 0x01
addwf int_bH, f
else
movf int_aL, w
addwf int_bL, w
movwf int_cL
movf int_aH, w
btfsc STATUS, C
addlw 0x01
addwf int_bH, w
movwf int_cH
endif
endif
endm
;Subtracts two integers (int_c = int_a - int_b).
;An integer is a two byte number.
;int_aH: the address of the high byte of the integer. The low byte is assumed
; to be at the next address (int_aH+1) so that the integer is int_aH:int_aL.
;int_bH: the address of the high byte of the integer. The low byte is assumed
; to be at the next address (int_bH+1) so that the integer is int_bH:int_bL.
;int_cH: the address of the high byte of the integer. The low byte is assumed
; to be at the next address (int_cH+1) so that the integer is int_cH:int_cL.
; int_cH can be equal to int_aH or int_bH
;Affects WREG and STATUS
;------------------------------------------------------------------------------
INT_SUB macro int_aH, int_bH, int_cH
local int_aL, int_bL, int_cL
int_aL = int_aH+1
int_bL = int_bH+1
inc_cL = int_cH+1
if int_aH == int_cH ;Special case int_a = int_a - int_b
movf int_bL, w
subwf int_aL, f
movf int_bH, w
btfss STATUS, C
addlw 0x01
subwf int_aH, f
else
movf int_bL, w
subwf int_aL, w
movwf int_cL
movf int_bH, w
btfss STATUS, C
addlw 0x01
subwf int_aH, w
movwf int_cH
endif
endm