_value
state variable from storagepragma solidity ^0.8.7;
contract Box {
uint256 private _value;
event NewValue(uint256 newValue);
function store(uint256 newValue) public {
_value = newValue;
emit NewValue(newValue);
}
function retrieve() public view returns (uint256) {
return _value;
}
}
Compiled from Solidity to Bytecode.
//bytecode exampl
**608060405234801561**001....36f6c63430008070033
These tiny instructions are called opcodes.
it is nothing but a list of tiny, 1 byte(the number represented in hex decimal so 2hex = 1byte), instructions appended together.
EVM understands/interprets these opcodes during the execution of any operation in the contract.
60 (1 byte), which is code for opcode PUSH1
これはよく0x60とかで表されるけど0x > hexを表すからこうなる!
These opcodes comprise of "EVM dialect".
Solidity < Yul (assembly) < bytecode (opcodes)
function retrieve() public view returns (uint256) {
return _value;
}
assembly {
let v := sload(0) // **read** from slot #0
mstore(0x80, v)
// store v at position 0x80 in memory
// **move call-stack to memory**
return(0x80, **32**) // v is **32** bytes (uint256)
// return({memory position},{size})
// returnがmemory領域しか返却できないのでmstoreが重要
}