ASSEMBLY / CHAPTER 03
Addresses and sized memory operands
MasterSeparate address calculation from reading a valid memory object.
By the end of this chapter
- Interpret base-plus-index addressing
- Distinguish lea from a memory load
- Match element size and address scale
The idea
Enter with register widths and array layout understood. Square brackets indicate a memory operand in NASM-style Intel syntax. A load such as mov eax, [rdi] reads four bytes at the address in RDI. The address must refer to valid readable memory; assembly provides no automatic array bounds check. Always state the memory layout and valid extent before tracing accesses.
An effective address can combine a base, an index multiplied by one, two, four, or eight, and a displacement. This matches common element sizes but does not validate the index. lea computes that address expression without reading the addressed memory. Use it for pointer arithmetic when you need an address, and use mov with a memory source when you need the stored value.
; RDI points to three readable dwords: 10, 20, 30
mov ecx, 1
lea rdx, [rdi+rcx*4]
mov eax, [rdx]Final EAX = 20; RDX = RDI + 4; no console output.
The scale of four advances by one dword. LEA calculates the second element’s address; MOV reads its stored integer.
Try it yourself
For a four-element qword array, form the address of element index two without reading it.
Use your own editor for this exercise. Runnable challenges on CodeQuest are available for JavaScript, Python, and SQL.
CHECK YOUR UNDERSTANDING