uint8, uint128, uint256


The storage of uint8, uint128, uint256 in memory are very simple, they are written directly at our chosen memory location and are returned the same.

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;

contract Yul {
    function uint8InMemory(uint8 value) public pure returns (bytes32) {
        assembly {
            mstore(0x80, value)
            return(0x80, 0x20)
        }
    }

    function uint128InMemory(uint128 value) public pure returns (bytes32) {
        assembly {
            mstore(0x80, value)
            return(0x80, 0x20)
        }
    }

    function uint256InMemory(uint256 value) public pure returns (bytes32) {
        assembly {
            mstore(0x80, value)
            return(0x80, 0x20)
        }
    }
}