Shop OBEX P1 Docs P2 Docs Learn Events
Table Branching in assembly — Parallax Forums

Table Branching in assembly

tekochiptekochip Posts: 56
edited 2007-04-28 11:30 in Propeller 1
I would like to have my code branch based upon a value passed to it, but I haven't found a way for the assembler to resolve the addresses.· Something like this:


············· add······ jumpPtr, par
············· movd····· :dest, JumpPtr
············· nop
:dest······ jmp······ jumpPtr



StringBuildUp
············ nop
·············nop


StringFill
············ nop
············ nop


JumpTable
············· long····· StringBuildUp
············· long····· StringFill
jumpPtr
············ long······ JumpTable
·

Comments

  • tekochiptekochip Posts: 56
    edited 2007-04-27 20:51
    Got it, I needed one more level of indirection:

    add jumpPtr, par 'Grab the offset
    movs :dest, jumpPtr 'Pointing at
    nop
    :dest
    movs :dest1, jumpPtr 'now what I'm pointing at
    nop
    :dest1 jmp jumpPtr
  • KaioKaio Posts: 253
    edited 2007-04-27 21:10
    Chip,

    you could have a look at file AsmDebug.spin of POD, where I pass the command to jump to the related subroutine. I have used a jump table for this while it is the easiest way and you can save memory which is otherwise used to get the address from table.
  • KaioKaio Posts: 253
    edited 2007-04-27 22:12
    I have separated the code which I was using in POD.
                            rdbyte  Command,par             'get command value in range 0 - 3
                            add     Command,#cmdJumpTable
                            movs    :jmpCmd,Command
                            nop
    :jmpCmd                 jmp     #0-0                    
    cmdJumpTable            jmp     #subroutine0
                            jmp     #subroutine1
                            jmp     #subroutine2
                            jmp     #subroutine3
    '-----------------------
    subroutine0             nop
    '-----------------------
    subroutine1             nop
    '-----------------------
    subroutine2             nop
    '-----------------------
    subroutine3             nop
    
    Command                 res     1
    
    
    
  • tekochiptekochip Posts: 56
    edited 2007-04-28 02:15
    Much cleaner, thanks.
  • Gary PrestonGary Preston Posts: 6
    edited 2007-04-28 11:30
    Have a look at the parallax graphics driver code, it has a jumptable setup using bytes to minimise the space used. It reads a command from PAR then jumps to the address held in the jmp table.
Sign In or Register to comment.