Under certain circumstances, a jump table provides a very efficient way of implementing a C language switch
statement block. We can define a jump table as a list of unconditional branch instructions—each referencing a different procedure or subroutine. We branch to one of the subroutines by loading the program counter with the address of the unconditional branch that is stored in the jump table. The effective addresses of items in the jump table are formed using a base + offset addressing mode. Base + offset addressing is commonly used to access data items stored in arrays, and a jump table is effectively just an array of address items.
To illustrate a jump table, we'll develop a recipe called asmJumpTable_c4v0
. Assume that we have a function named jumpT ()
that accepts a val
integer input argument. The function calls either proc1 ()
, proc2 ()
, or proc3 (),
depending on the value of the input argument:
void jumpT ( int val ) { switch (val) { case...