12

In the Solidity documentation I see a sample assembly code:

{
  mstore(0x40, 0x60) // store the "free memory pointer"
  // function dispatcher
  switch div(calldataload(0), exp(2, 226))
  case 0xb3de648b {
    let (r) = f(calldataload(4))
    let ret := $allocate(0x20)
    mstore(ret, r)
    return(ret, 0x20)
  }
  default { revert(0, 0) }
  // memory allocator
  function $allocate(size) -> pos {
    pos := mload(0x40)
    mstore(0x40, add(pos, size))
  }
  // the contract function
  function f(x) -> y {
    y := 1
    for { let i := 0 } lt(i, x) { i := add(i, 1) } {
      y := mul(2, y)
    }
  }
}

that's generated from this Solidity code:

pragma solidity ^0.4.0;

contract C {
  function f(uint x) returns (uint y) {
    y = 1;
    for (uint i = 0; i < x; i++)
      y = 2 * y;
  }
}

How can I generate the same assembly code with solc?

I know I can use --asm option but it produces desugared code.

1 Answer 1

3
+50

According to this GitHub the following question was asked regarding the status of standalone assembly:

Is this already implemented? It shows up in the documentation but I can see no other evidence of it being implemented: http://solidity.readthedocs.io/en/develop/assembly.html?highlight=assembly#standalone-assembly

Response to this by the contributor was

No, this is still work in progress. There is a note about it in the documentation, but not too visible, I have to admit.

This is the only evidence that I have got which is related to the above issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.