Table Branching in assembly
tekochip
Posts: 56
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.