Aslak3 wrote:
What about literal jump tables? I've seen this used as well:
Code:
routine1: jmp myroutine1
routine2: jmp myroutine2
User code then does:
Code:
jsr routine1
....
This mechanism is nice because you can jsr to a label (the address of which does not change) which takes you to a build-specific routine address. Less CPU overhead then a table of vectors, but of course you have the extra byte per routine for the jmp opcode.
Yea, but, frankly, this is fundamentally different.
I'd consider this more of a vectored JSR than a jump table. This is typically seen in things like operating systems and what not where they defined public, known entry points, but at those spots are just JMPs to the real code. This allows the underlying code to change and move while the published entry points remain stable for 3rd party code.
The Jump Table, as mentioned here, and portrayed above, tends to be more similar to the the BASIC ON GOTO statement.
Code:
10 PRINT "1. Create Thing"
20 PRINT "2. Edit Thing"
30 PRINT "3. Delete Thing"
40 PRINT "4. Quit"
50 INPUT "Enter command #", I
60 ON I GOTO 100, 200, 300, 400
100 REM Do create
...
200 REM Do edit
...
300 REM Do delete
...
400 REM Do quit
The '816 addressing modes make Jump Tables much easier and idiomatic in the '816 than the '02.