Learn EVM Opcodes VI

Solidity Programming Language
2 min readMar 13, 2023

--

Learn EVM Opcodes VI

We start this section with memory, one of the most important databases of EVM. I try to explain how MSTORE opcode is working.

MSTORE Opcode

First you should read the memory layout page.

offset: offset in the memory in bytes. (Byte position on the memory where you will start placing the value)

value: 32-byte value to write in the memory. (This is the 32-byte value you want to place. It doesn’t have to be 32 bytes, but it takes up 32 bytes)

PUSH1 0xCC

PUSH1 0

MSTORE

MSTORE Opcode

Analysis: 1 byte CC value is assigned to the far right on 32 bytes of data array. CC is now at 63–64 characters, i.e. on the 31st byte. (Remember, we start counting the byte array from 0)

PUSH1 0xCC

PUSH1 1

MSTORE

MSTORE Opcode

The result is

0000000000000000000000000000000000000000000000000000000000000000CC00000000000000000000000000000000000000000000000000000000000000

Analysis: We have placed our 32 byte value on the memory starting from the 1st byte. The CC value then falls on the first byte of the new 32 byte area. Use the following link to confirm where I have marked.

MSTORE Opcode

PUSH1 0xCC

PUSH1 32

MSTORE

MSTORE Opcode

The result is

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cc

Analysis: We have placed our 32 byte value starting from the 32nd byte on the memory. The CC value then falls on the last byte of the new 32 byte area. Use the following link to confirm where I have marked.

PUSH1 0xCC
PUSH1 64
MSTORE

MSTORE Opcode

Do you understand MSTORE ?

MSTORE Opcode

Doç. Dr. Engin YILMAZ (VeriDelisi)

--

--

Solidity Programming Language
Solidity Programming Language

Written by Solidity Programming Language

Solidity basics for beginners: Learn the fundamentals of smart contract development and build your first DApp! #Solidity #Foundry #Ethereum #Opcodes #DApps

No responses yet