Working with storage slots
Similar to memory variables, Solidity also provides opcodes for working with state variables. The state variables' related opcodes are sload
and sstore
. Again, similar to memory functions, sload
reads the value stored in the storage slot and returns the value. It accepts the storage slot location as its only argument. sstore
updates the value at a given storage slot. It accepts the storage slot as its first argument and the value to be stored as its second argument. The storage slot is created if it already does not exist. The usage of both sload
and sstore
is shown using a smart contract in the following code block:
// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; contract StorageAssembly { uint256 StateVariable; function AssemblyUsage() public returns (uint256 newstatevariable, uint256 newderivedvariable) { ...