DEV Community

Cover image for Ethereum-Solidity Quiz Q12: What does this sequence of opcodes do? PUSH1 0x80 / PUSH1 0x40 / MSTORE
MihaiHng
MihaiHng

Posted on

Ethereum-Solidity Quiz Q12: What does this sequence of opcodes do? PUSH1 0x80 / PUSH1 0x40 / MSTORE

This sequence of opcodes initializes the free memory pointer.

PUSH1 0x80 — Push the value 0x80 (which is 128 in decimal) onto the stack
PUSH1 0x40 — Push the value 0x40 (which is 64 in decimal) onto the stack
MSTORE — Store a value in memory

MSTORE takes two arguments from the stack: an address and a value

  • It writes the value to the memory location specified by the address
  • Stack order (top to bottom): 0x40 (address), 0x80 (value)
  • It writes 0x80 to memory location 0x40

This opcode sequence is telling us that The Free Memory pointer is at 0x40, and the first available free memory location for is 0x80.

In Solidity:
This happens at the start of contract deployment or in function initialization. It's one of the first things that happens because contracts need to know where safe memory starts before they can allocate anything.

Top comments (0)