Table Branching in assembly
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
·
············· 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
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
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.
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