jakeselectronics
Member
Hey everyone.
I've just been looking through microchips PIC Assembly templates and have a question regarding the code the use for context saving.
Why are there 2 swapf instructions together?
Isn't the objective to load the W register to its pre-isr state?
So wouldn't a simple MOVF W_TEMP,W do the same job?
Why are the swapf instructions used?
I've just been looking through microchips PIC Assembly templates and have a question regarding the code the use for context saving.
Code:
ORG 0x000 ; Processor reset vector go to beginning of program
GOTO SETUP ;
ORG 0x004 ; Interrupt vector location. When an Interupt occurs, the program jumps here
MOVWF W_TEMP ; Save current W register contents
MOVF STATUS,W ; Move STATUS register into W register
MOVWF STATUS_TEMP ; Save contents of STATUS register in temporary register
; Interrupt Service Routine goes here
MOVF STATUS_TEMP,W ; Retrieve saved status of STATUS register
MOVWF STATUS ; Restore pre-ISR STATUS register contents
SWAPF W_TEMP,F ;
SWAPF W_TEMP,W ; Restore pre-ISR W register contents
RETFIE
Why are there 2 swapf instructions together?
Isn't the objective to load the W register to its pre-isr state?
So wouldn't a simple MOVF W_TEMP,W do the same job?
Why are the swapf instructions used?