-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16bits.inc
72 lines (66 loc) · 2.64 KB
/
16bits.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
; Make T1 = T2 + T3
ADD16 MACRO T1, T2, T3
MOVF T3 + 1, w ; Process the High Byte First
ADDWF T2 + 1, w ; -> Can Also be "subwf"
MOVWF T1 + 1 ; Store the Result
MOVF T3, w ; Process the Low Byte
ADDWF T2, w ; -> Can Also be "subwf"
MOVWF T1
BTFSC STATUS, C ; If "subwf", use "btfss"
INCF T1+1 ; Increment the High Byte
ENDM ; If "subwf", use "decf"
; Make T1 = T2 - T3
SUB16 MACRO T1, T2, T3
MOVF T3 + 1, w ; Process the High Byte First
SUBWF T2 + 1, w ; -> Can Also be "subwf"
MOVWF T1 + 1 ; Store the Result
MOVF T3, w ; Process the Low Byte
SUBWF T2, w ; -> Can Also be "subwf"
MOVWF T1
BTFSS STATUS, C ; If "subwf", use "btfss"
DECF T1 + 1 ; Increment the High Byte
ENDM ; If "subwf", use "decf"
; 16 bit addition macro with carry out.
; Operation: SRC + DST => DST
ADDSELF16 MACRO SRC, DST
MOVF SRC, W ; Get Low byte
ADDWF DST, F ; Add to destination
MOVF SRC+1, W ; Get high byte
BTFSC STATUS, C ; Check for carry
INCFSZ SRC+1, W ; Add one for carry
ADDWF DST+1, F ; Add high byte into DST
ENDM
; 16 bit subtraction : DST - SRC => DST
; Carry is preserved
SUBSELF16 MACRO DST, SRC
MOVF SRC, W ; Get low byte of subtrahend
SUBWF DST, F ;
MOVF SRC+1, W
BTFSS STATUS, C
INCF SRC+1, W
SUBWF DST+1, F
ENDM
; Increment 16 bits variables : VAR = VAR + 1
INC16 MACRO VAR
INCF VAR ; increment lower byte
BTFSC STATUS, Z ; if zero flag is set
INCF VAR+1 ; skip over Upper Byte Decrement
ENDM
; Decrement 16 variables : VAR = VAR -1
DEC16 MACRO VAR
MOVF VAR, F ; Set zero flag based on low byte
BTFSC STATUS, Z ; if low byte == 0 before
DECF VAR+1 ; Decrement High byte
DECF VAR
ENDM
; 16 Bits Compare with Variable
; The following code, while clunky will set the carry flag if "First" is equal to or greater than "Second":
COMP16 MACRO FIRST, SECOND
movf SECOND+1, w ; Compare the High Byte First
subwf FIRST+1, w
btfsc STATUS, Z ; If Result of High Byte Compare
goto Skip ; is Equal to Zero, Then Check
movf SECOND, w ; the Second
subwf FIRST, w
Skip: ; Carry Flag Set if 1st >= 2nd
endm