Taken from this repository
/// @notice Generate number
function asmbl() public view returns (uint8 b) {
assembly {
let c := add(27, 16)
mstore(0x80, c)
{ let d := add(sload(c), 255) b := d }
b := add(b, c) }
}
My understanding is:
- let c := add(27, 16). c stores now the value 42
- mstore(0x80, c). c was stored in memoryon address 0x80. Probably an useles statement without an effect. Because the memory is not used afterwards.
- let d := add(sload(c), 255).
sload(c). loads the length of c??? Not sure about this, but I read somewhere that sloading the varible without an offset returns the length of it. But if true, the sload(c) value is probably 256, because int256
add(sload(c), 255) is the same as add(256, 255) = 511. d = 511
- b := d. this is simple. value of d is assigned to b.
- b := add(b, c). b is 511 + 42 = 553
- 553 is returned by the function
Is this correct?