Branch table

A branch table (also branch table or jump bar called, english jump table ) is a software design to be able to call a certain set of functions ( of an operating system or from a function library) comfortable and compatibility safely. For this, the calls are sequentially arranged ( or sometimes just the bare function address) of a constant length such as in a table in memory. They typically consist of simple jump instructions to the location in ROM or within the function library where the actual code is at. In this way multiple purposes to be fulfilled simultaneously:

  • Thereby achieved compatibility between successive versions of the software: Although changing the actual code of one or more functions and the address location of the Funktionseinsprünge changes by only changing the address in the jump instructions, the jump table, while the application software that uses this jump table, just not must be adjusted.
  • One can practically these functions over a number address ( its index within the table ), which simplifies the programming in certain areas.

Some microprocessors support such constructs by special commands that implement such indexed jumps.

Implementation

Implementation principle of a library program in 6502 assembler syntax:

Library Base:    JMP function1; jump Bar    JMP function2; Each of these jump instructions    JMP Function3; occupies exactly 3 bytes of ROM    ...    JMP Funktionn    ... Function1 :; Implementation function 1    ...    RTS; Return from function routine Function2 :; Implementation function 2    ...    RTS; Return from function routine    ... Funktionn :; Implementation function n    ...    RTS; Return from function routine Calling a function from such a library by its number:

JSR library base 3 * (Function number 1 ) With a 68k processor has a branch instruction 6 instead of 3 bytes, corresponding to must then be multiplied by 6 in the call.

In high- level language, the respective runtime library does the conversion of a function name or a number in such a jump instruction.

Here we also recognize the advantage of this method: If, in a review of the function library for example, the implementation of the function1 expanded so that it occupies more space in the ROM to move the entry points of the higher function numbers backwards. The jump bar at the very beginning does not change its structure but so that the call from the application program must not be changed.

Examples

  • The operating system was the Commodore PET 2001 and his successors up to the C64 at the end of his ROMs as a jump table for major operating system calls. For example, standing in all of these operating systems to address $ FFD2 a jump in the routine to output a single character (which was passed in the accumulator) to the screen.
  • The shared libraries ( libraries of functions ) of the AmigaOS are all at their start over as a jump table, via the default all calls to its functions.
  • Programming language element
742883
de