Code has been added to clipboard!

Solidity Standalone Assembly Example 1

Example
{
  mstore(0x40, 0x60) // this line will store the "free memory pointer"
  // dispatch function
  switch div(calldataload(0), exp(2, 226))
  case 0xb3de649b {
    let (retData) = func(calldataload(4))
    let retVal := $memAllocate(0x20)
    mstore(retVal, retData)
    return(retVal, 0x20)
  }
  default { revert(0, 0) }
  // allocate memory
  function $memAllocate(size) -> pos {
    pos := mload(0x40)
    mstore(0x40, add(pos, size))
  }
  // function of the contract
  function func(a) -> b {
    b := 1
    for { let n := 0 } lt(n, a) { n := add(n, 1) } {
      b := mul(2, b)
    }
  }
}