Working with memory slots
Solidity provides opcodes for working with memory variables in assembly code. We already know that there are three types of variables – storage
, memory
, and calldata
. Assembly language can work with all three.
Assembly provides the mload
and mstore
opcodes for loading or storing values in memory variables. The mload
opcode helps to load or read the memory location and the returning data stored therein. The mstore
opcode helps to store data in memory. The usage of both mload
and mstore
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 MemoryAssembly { function AssemblyUsage() public pure returns (uint256) { assembly { let addresult := add(100,200) &...