-
Notifications
You must be signed in to change notification settings - Fork 1
/
macros.inc
130 lines (101 loc) · 4.06 KB
/
macros.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
; SPDX-License-Identifier: GPL-3.0-or-later
;**************************************************************************
; *
; 16 and 32 bit arithmetic macros *
; *
;**************************************************************************
CQUAD MACRO value
retlw value>>24 ; high byte
retlw (value>>16)&0xFF; middle-high byte
retlw (value>>8)&0xFF ; middle-low byte
retlw value&0xFF ; low byte
ENDM
;--------------------------------------------------------------------------
; MACRO to perform 32-bit subtraction - subtracts the four bytes at src
; from the four bytes at dst (most significant bytes first), returns the
; result in dst with src unchanged and the no carry flag set if underflow
;--------------------------------------------------------------------------
SUBx32 MACRO src, dst ;dst := dst - src
bsf STATUS, C
movf src+3, w
btfss STATUS, C
incfsz src+3, w
subwf dst+3, f
movf src+2, w
btfss STATUS, C
incfsz src+2, w
subwf dst+2, f
movf src+1, w
btfss STATUS, C
incfsz src+1, w
subwf dst+1, f
movf src+0, w
btfss STATUS, C
incfsz src+0, w
subwf dst+0, f
ENDM
;--------------------------------------------------------------------------
; MACRO to perform 16-bit subtraction - subtracts the two bytes at src
; from the two bytes at dst (most significant bytes first), returns the
; result in dst with src unchanged and the no carry flag set if underflow
;--------------------------------------------------------------------------
SUBx16 MACRO src, dst ;dst := dst - src
bsf STATUS, C
movf src+1, w
btfss STATUS, C
incfsz src+1, w
subwf dst+1, f
movf src+0, w
btfss STATUS, C
incfsz src+0, w
subwf dst+0, f
ENDM
;--------------------------------------------------------------------------
; MACRO to perform 32-bit addition - adds the four bytes at src
; to the four bytes at dst (most significant bytes first), returns the
; result in dst with src unchanged and the no carry flag set if underflow
;--------------------------------------------------------------------------
ADDx32 MACRO src, dst ;dst := dst + src
bcf STATUS, C
movf src+3, w
btfsc STATUS, C
incfsz src+3, w
addwf dst+3, f
movf src+2, w
btfsc STATUS, C
incfsz src+2, w
addwf dst+2, f
movf src+1, w
btfsc STATUS, C
incfsz src+1, w
addwf dst+1, f
movf src+0, w
btfsc STATUS, C
incfsz src+0, w
addwf dst+0, f
ENDM
;--------------------------------------------------------------------------
; MACROs to move a 16bit and 32bit literal into the two/four bytes at dst
; (most significant bytes first), returns the result in dst
;--------------------------------------------------------------------------
MOVLx32 MACRO lit, dst ;dst := lit
movlw (lit >> 24) & 0xff
movwf dst
movlw (lit >> 16) & 0xff
movwf dst+1
movlw (lit >> 8) & 0xff
movwf dst+2
movlw lit & 0xff
movwf dst+3
ENDM
MOVLx16 MACRO lit, dst ;dst := lit
movlw (lit >> 8) & 0xff
movwf dst
movlw lit & 0ffh
movwf dst+1
ENDM
;**************************************************************************
; *
; Macros end *
; *
;**************************************************************************