In this track: Inside the EVM
advanced · 4 MIN READ

MLOAD and MSTORE

Word operations use byte-addressed temporary memory.

LET’S PICTURE IT

A worktable location marks a starting byte, then a whole word spans the next thirty-two positions.

SEE IT FOR YOURSELF
Use temporary memory in one execution frameStep 1 / 4
Use temporary memory in one execution framePointer wordmemory address 0x40value: 0x80Working areabegins at 0x80not a storage slotCompiler memory conventions differ from persistent storage layoutValue 42hex: 0x2aleft-padded in a wordMSTOREoffset 0x80bytes 0x80–0x9fA retained manual allocation must also maintain the memory pointerMLOADoffset 0x80read 32 bytesStack result42same stored wordMLOAD and SLOAD access different data locationsRETURN rangeoffset 0x80size 32 bytesOutput bytesencoded integer 42caller interprets schemaEach message-call frame has its own memory working space

This frame uses temporary byte-addressed memory. Solidity normally keeps a free memory pointer at address 0x40, initially pointing to 0x80.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Count byte addresses

Memory offsets are byte positions. MSTORE at offset 0x80 writes a thirty-two-byte word across the range 0x80 through 0x9f.

Read a full word

MLOAD retrieves thirty-two bytes beginning at the specified offset. It does not automatically select a Solidity field or apply the source variable’s declared width.

Distinguish single-byte stores

MSTORE8 writes only the low byte of its value. It is a separate instruction and should not be confused with the full-width MSTORE operation.

Include expansion effects

Touching a farther range can expand active memory and increase cost. Memory remains temporary to the current execution frame rather than persistent contract state.

Trace the idea

MSTORE(offset 0x80, value 42)
MLOAD(offset 0x80) → 42

Both operations cover 32 bytes.

Stack examples list the bottom first and the top last. These small traces omit gas and surrounding dispatch unless stated.

QUICK CHECK · NO PRESSURE

Does MSTORE use a storage slot number?

Your progress stays in this browser.
Keep exploring the original referenceethereum.org ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.