Hi, Looks like just another useful code snipped - not used more then 2 K PIC4s till now. but... Dmitry Kiryashov wrote: > > Hello. Probably you ask about the following construction... > > WBR Dmitry. > > movlw 0 ;for instance zero > call subroutine_switcher ;function is called > movlw 1 > call subroutine_switcher > ;... > ; continue here > ;... > Dmitry, can you please give me an hint what Idea is behind the following shortcut-math ? I recognize it will calculate the address for setting the appropriate PC for the subroutine, but how does it work ?? ( I never used xor for doing a something like an n * 4 before ). > switcher_to_subroutines: > movwf pclath > xorlw high ($+4) > xorwf pclath,f > xorlw high ($+2) > addwf pcl,f > > ;function_0 is here > > movlw high function_0 ;probably isn't required > movwf pclath ;in 2K PICs > movlw low function_0 > movwf pcl > > ;function_1 is here > > movlw high function_1 > movwf pclath > movlw low function_1 > movwf pcl > > ;etc... > > function_0: > ;... > ; function_0 program body > ;... > return