The following opcodes 0x40 is "offset in the memory in bytes"
My question is why evm uses 0x80 as a "32-byte value to write in the memory."
PUSH1 0x80
PUSH1 0x40
MSTORE
Sincerely
The free memory pointer (stored at 0x40) starts at 0x80 simply because there are 4 32 byte slots at the start of memory that are reserved. From the Solidity docs on the memory layout:
If the free memory pointer started any earlier than 0x80, it would interfere with these reserved slots (including the free memory pointer itself)
First of all what exactly is a free memory pointer ?
Free memory pointer points to a place where we can store whatever we want in memory right now meaning; we can store something right there in that location without worrying if that place is used by something else.
Now where is the place in memory reserved to the store this free location where anything can be stored ? aka free memory pointer
From the docs:
0x7f is 127
0x80 is 128
From the solidity docs: 0x40 - 0x5f (32 bytes): currently allocated memory size (aka. free memory pointer)
So as we can see that 0x40 is the place to store our free memory location which is 0x80. And 0x40 becomes our free memory pointer.
Again, remember that 0x40 is not the free memory location where we can store anything we want, it points to a place where we can store anything we want. Aka free memory pointer.
Here's a more in-depth explanation of this: https://pvnotpv.github.io/posts/runtimeinitcode/
Free memory start location is 0x40,
0x80 value indicates this location.
0x80=128 decimals is equal to 64 bytes
64 bytes is equal to 0x40
0x80 is decimal value but it indicates 0x40 location