LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

How do you recognize array access in assembly?

Look for scaled-index addressing base(,%index,scale), where the scale (1/2/4/8) equals the element size in bytes.

Scaled-index addressing (%rdi,%rsi,4): address = base + index*scale, where scale (1/2/4/8) equals the element size, and a single memory read yields Ai.

* Scaled-index addressing base(,index,scale): the scale (1/2/4/8) equals the element size in bytes. One memory access = contiguous array element MEM[&A[0] + i*scale]. *

# eax = A[i] (int array, 4 bytes per element)
movl (%rdi,%rsi,4), %eax

# rax = A[i] (long/pointer array, 8 bytes per element)
movq (%rdi,%rsi,8), %rax

Common scales and what they mean:

Scale Element size Type
1 1 byte char, byte
2 2 bytes short
4 4 bytes int, float
8 8 bytes long, double, pointer

Multidimensional array A[i][j] with M columns:

# index = i*M + j, then scale by element size
imul $M, %rdi, %rax
add  %rsi, %rax
movl (%rcx,%rax,4), %eax

vs pointer array (array of pointers to rows):

# First dereference: get row pointer
mov  (%rdi,%rsi,8), %rax
# Second dereference: get element
mov  (%rax,%rdx,4), %eax

Two memory accesses = multilevel (pointer array). One = contiguous 2D array.

Go deeper:

From Quiz: REVE1 / Assembly Patterns & GDB | Updated: Jul 14, 2026