Jump Table

  The program requires one of several alternative behaviors. The alternatives have been numbered and the current choice is known and represented by a small integer. The CDC-6000 has an indexed jump but no indirect jump instruction. Therefore:
Build a table of jumps to handlers with one jump instruction for each alternative. Jump to the correct jump by indexing the initial jump with the known small integer. Include jumps to an error handler for unexpected (but possible) codes.
  Use the instruction sequence: 
       JP    Bi+TABLE 
TABLE  EQ    CHOICE.0
+      EQ    CHOICE.1
+      EQ    CHOICE.2
       ...
where Bi conains the number of the desired  choice and CHOICE.n are the various handlers. EQ is a slightly faster jump instruction than the non-indexed JP. The plus signs (+) insure that every jump begins in a new word. 

Machines with an indexed indirect jump instruction can use a variation of this pattern where the table contains only the address of the handlers.

Contrast with Skip Chain which doesn't require the choice be encoded as a number.

 

PDP-8 Simulator
© 1975, 1998, Ward Cunningham
all rights reserved