Step Into Labs

Step Into x64 Assembly · Lesson 14 · Speed & Dispatch

Switch Statements and Jump Tables

How compilers turn a switch into one indirect jump, tables of function pointers, and reading one in real compiler output.

Part of Step Into x64 Assembly. The full lesson, its missions and the real compiler and debugger are in the course. Try a free lesson first to see how it works.

A switch with 2 cases becomes 2 compares. With 50 cases that would be 50 compares, so compilers build a jump table instead: an array of addresses, one per case, indexed by the value. One bounds check and one indirect jump, however many cases there are.

In this lesson

Missions

  1. A switch by hand
  2. Half the size: relative offsets
  3. A table of functions
  4. Read the compiler's switch