What’s a Branch Table?

Print anything with Printful



Branch tables efficiently transfer program control by implementing a switch statement or sending a branch of instructions. They are memory-efficient and still used in assembly programming for embedded systems and operating system development. Compiler programming languages generate their own branch tables using compiler optimization lookup keys.

A branch table is a method of efficiently transferring program control from one part of a program to another, or to a second program that has been dynamically loaded, by sending a branch of instructions or by implementing a switch statement. This method, sometimes called a jump table, relies on a set of circumstances or conditions to jump to implement a procedure based on a switch statement from a C+ compiler. Some of the major benefits of branch tables are compact code structure and reducing the need to test return codes individually when determining program flow.

In the 1980s, branching tables were used extensively in assembly language programming. They are still used in assembly programming for embedded systems and operating system development. Since the 1990s, compiler programming languages ​​have also made use of how branch tables work.

Branch tables consist of a list of unconditional statements that, given inputs, branch to other destinations. Most computer hardware is capable of executing these instructions efficiently. Sometimes, the offset, essentially the distance from the destination, can be added to a program counter register which can then point to jump instruction sets or jump between jump instruction sets. All that is required to implement a branch table is validation of the input code, transforming the data into an offset and multiplying the data by a given statement length.

Embedded programming uses branch tables as they are more memory efficient than using machine code or pointers in arrays. Embedded control systems need this memory savings, and while it may cost a small amount of performance when accessing the branch table, any virtual method function call would cost the same amount of performance for stable operation. Limited CPU access and memory savings in embedded systems require a branching table for static function sets.

Compiler programming languages ​​generate their own branch tables when needed using compiler optimization lookup keys. Some programmers choose to manually assist the compiler with generating the contextual branch table by providing the compiler with two-step conditional parameters from which to look up keys. In the early years of compiling programs, the derivation table implementation was the “GoTo” commands in the Fortran compiler languages. Branch tables are still used to implement changes in program flow in compiler languages ​​or to be a starting point for repeating instruction sequences.




Protect your devices with Threat Protection by NordVPN


Skip to content