Quiz Entry - updated: 2026.07.14
How does the indirect jump instruction jmp *.L4(,%rdi,8) work for a switch?
The * makes it indirect: the CPU computes the table-slot address .L4 + %rdi*8, reads the 8-byte target stored there, and jumps to that target.
* Indirect jump: compute the address, read the target stored there, then jump. *
A normal jmp .L2 jumps to a label whose address is fixed at assemble time. An indirect jump (jmp *…) jumps to an address it reads from memory at runtime — perfect when the destination depends on a variable.
jmp *.L4(,%rdi,8)
Breaking down the memory operand .L4(,%rdi,8):
.L4— base address of the jump table%rdi— the switch valuex(the index)8— scale factor: each entry is an 8-byte (64-bit) address on x86_64- Effective address =
.L4 + %rdi*8
| Syntax | Meaning | |
|---|---|---|
| Direct | jmp .L2 |
Jump to the address .L2 |
| Indirect | jmp *.L4(,%rdi,8) |
Jump to the address stored at .L4 + %rdi*8 |
The crucial *: without it, you'd jump into the table data itself. With it, you jump to the address the table contains. This is also how function-pointer calls (call *%rax) and vtables work.
Go deeper:
Branch table / jump table (Wikipedia) — jump tables and the indirect jump that reads them.
Addressing mode (Wikipedia) — the base+index*scale addressing mode being computed.