Example - Generate destination address depending on source address

; The macro I2C_TASK_YIELD is used to embed a co-operative task switch
; in an assembler program. The following two examples show how this is
; done with and without taking advantage of the callers address as part
; of the destination address.

I2C_TASK_YIELD  .macro

        movlw   ($+4) & 0xff
        movwf   i2c_pc+0
        movlw   (($+2) >> 8) & 0xff
        goto    resume2_isr

        .endm

;;;
;;; the above macro could be re-written as:
;;;

I2C_TASK_YIELD  .macro

resume2_isr_ind .set    LABEL(STR(resume2_isr)+"_"+STR(($+2) >> 8))

        movlw   ($+2) & 0xff
        goto    resume2_isr_ind

        .endm


;----------------------

; dispatch the co-routine at the point at which it was suspended
        movfw   i2c_pc+1
        movwf   PCLATH
        movfw   i2c_pc+0
        movwf   PCL

; this is where the co-routine comes back when it suspends itself
; using the I2C_TASK_YIELD macro

resume2_isr_0
        movwf   i2c_pc+0
        movlw   0
        goto    resume2_isr

resume2_isr_1
        movwf   i2c_pc+0
        movlw   1
        goto    resume2_isr

resume2_isr_2
        movwf   i2c_pc+0
        movlw   2
        goto    resume2_isr

resume2_isr_3
        movwf   i2c_pc+0
        movlw   3
        goto    resume2_isr


resume2_isr
        movwf   i2c_pc+1