Eric Johnson wrote: > > When saving status during interrupts on the 16c74, > Microchip recommends the following: > movwf W_Temp ;Copy W to TEMP register, could be bank one or zero Note that W_Temp MUST be defined so that it appears in the same location independent of the RP0 (RP1, ...) bits. For example W_Temp equ h'20' AND W_Temp equ h'A0'. > swapf STATUS, w ;Swap status to be saved into W > bcf STATUS, RP0 ;Change to bank zero, regardless of current bank > movwf STATUS_TEMP ;Save status to bank zero STATUS_TEMP register > :(ISR) > swapf STATUS_TEMP, w ;Swap STATUS_TEMP register into W > ;(sets bank to original state) > movwf STATUS ;Move W into STATUS register > swapf W_TEMP, f ;Swap W_TEMP > swapf W_TEMP, w ;Swap W_TEMP into W > > Why not: > swapf W_Temp ;save w with nibbles reversed, could be either bank This is not the proper syntax for swapf. The assembler will convert the above instruction to swapf W_Temp,F ie. swap the nibbles in file W_Temp and put the result into file F (W_Temp). The syntax is: swapf f,d where f=a file(RAM) location and d=destination (W or F) Note that in the Harvard architecture there are no instructions that move data from one file (RAM) location to another file (RAM) location. Data always moves to/from the W register. This is because there are not enough bits in a single command word to contain 2 file (RAM) addresses. Von Neumann machines use a variable number of bytes/instruction to handle this. > swapf STATUS, w ;get status and reverse the nibbles > bcf STATUS, RP0 ;set bank 0 > movwf STATUS_TEMP ;save old status with nibbles reversed > :(ISR) ;interrupt service routine > swapf STATUS_TEMP, w ;get old status > movwf STATUS ;restore old status (and bank register) > swapf W_TEMP, w ;get back w with correct nibble order > > By pre-swapping w, it looks like I can save a step. > > I also like to: > movf FSR, w ;get indirect file select register > movwf Temp_Fsr, f ;save indirect files select register > :(ISR) ;interrupt routine > movf Temp_Fsr, w ;get saved indirect file select register > movwf FSR, f ;restore indirect files select register > clrwdt ;clear watchdog timer Required if you are using FSR. DO after STATUS & W are saved. Thanks for asking, I think I now understand this better myself, Brooke PS I wonder if Harvard architecture machines would be easier to understand if the instructions that worked with RAM were different from instructions that worked with the program space in some way that made it clear which space was being used?