-
Notifications
You must be signed in to change notification settings - Fork 1
/
standard 2.mac
84 lines (68 loc) · 2.85 KB
/
standard 2.mac
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
;--------------------------------------------------------------------------------------------------
; MKSystems / Curt Irvin
;
; Project: Macros for all PIC projects
; Date: 4/21/01
; Authors: Mike Schoonover, Curt Irvin
; Revision: 1.0
;
; Overview:
;
; These macros are useful for most PIC software projects.
;
;
;--------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------
; PUSH_MACRO
;
; Stores W, STATUS, PCLATH, and FSR registers in W_TEMP, STATUS_TEMP, PCLATH_TEMP, and FSR_TEMP
; registers.
;
; NOTES:
;
; W_TEMP, STATUS_TEMP, PCLATH_TEMP and FSR_TEMP registers must be defined by the main program file
; in the register area common to all four data memory banks (0x70 to 0x7f for the PIC16F876).
;
; This macro should only be used for PICs with common register areas in all 4 memory banks. See
; MicroChip reference manuals for creating a macro for other PICs.
;
PUSH_MACRO MACRO
movwf W_TEMP ; copy W to a temporary register
; regardless of current bank
swapf STATUS,W ; swap STATUS nibbles and place into W register
; (swap is used because it does not affect any status
; bits - problematic when trying to save the status
; register itself - must be swapped again to restore)
movwf STATUS_TEMP ; save STATUS to a temporary register
movf PCLATH,W ; store PCLATH
movwf PCLATH_TEMP
movf FSR0L,W ; store FSR
movwf FSR0L_TEMP
movf FSR0H,W
movwf FSR0H_TEMP
ENDM ; end this macro
;end of PUSH_MACRO
;--------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------
; POP_MACRO
;
; Restores W, STATUS, PCLATH, and FSR registers from W_TEMP, STATUS_TEMP, PCLATH_TEMP and FSR_TEMP
; registers.
;
; See PUSH_MACRO for more information.
;
POP_MACRO MACRO
movf FSR0L_TEMP,W ; restore FSR
movwf FSR0L
movf FSR0H_TEMP,W
movwf FSR0H
movf PCLATH_TEMP,W ; restore PCLATH
movwf PCLATH
swapf STATUS_TEMP,W ; swap original STATUS register value into W
movwf STATUS ; restore the STATUS register
swapf W_TEMP,F ; swap W_Temp nibbles (temporarily)
swapf W_TEMP,W ; swap again and move to W to restore original
; (use swap to avoid affecting STATUS bits)
ENDM ; end this macro
;end of POP_MACRO
;--------------------------------------------------------------------------------------------------