Quiz Entry - updated: 2026.07.10
How is array access translated to assembly addressing?
array[i] becomes scaled-indexed addressing: (base, index, element_size), computing base + index × element_size.
Array indexing in C is really just address arithmetic, and the x86 scaled-indexed mode expresses it in a single operand. The scale equals sizeof(element), which is exactly why the legal scales are 1, 2, 4, and 8.
int arr[100];
int x = arr[i];
# arr address in %rax, i in %rcx
movl (%rax,%rcx,4), %edx # %edx = arr[i], because int is 4 bytes
The address %rax + %rcx×4 is precisely &arr[i]. Change the type, change the scale:
movb (%rax,%rcx,1), %dl # char (scale 1)
movw (%rax,%rcx,2), %dx # short (scale 2)
movl (%rax,%rcx,4), %edx # int (scale 4)
movq (%rax,%rcx,8), %rdx # long (scale 8)
Reverse-engineering tip: spotting a ×2, ×4, or ×8 scale in an addressing mode immediately tells you the element size, and therefore the likely C type of the array.
Go deeper:
Addressing mode (Wikipedia) — how scaled-indexed mode maps onto array[i] with scale = sizeof(element).