79246093

Date: 2024-12-03 02:19:32
Score: 0.5
Natty:
Report link

I have the following working code which uses BRA to jump to the required function (using its relative address). The linker option -pprogramTable=100h is used in the build to locate the jump table at 0x100.

    ; The jump table is located on the start of a page boundary 0x100   
global      programTable
psect programTable,global,class=CODE,delta=2    
programTable:
    bra     f1 
    bra     f2
    bra     f3
    bra     endOfTable
    
endOfTable: ; reset the index back to start of table
    clrf    programIndex
    return

Here's the code that uses the jump table.

runCurrentProgram:
    movf    programIndex,w
    addlw   low programTable
    movwf   tabLow      ; tabLow is a temporary variable
    movlw   high programTable
    btfsc   STATUS,STATUS_CARRY_POSITION
    addlw   1
    movwf   PCLATH
    movf    tabLow,w
    movwf   PCL
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: NomadAU