【问题标题】:assembly logical shift left solidity don't work装配逻辑左移坚固性不起作用
【发布时间】:2018-08-20 10:47:42
【问题描述】:
function shift(int val) returns(int) {
    int res;
    assembly {
        let m := mload(0x40)
        mstore(m, shl(2, val))
        mstore(0x40, add(m, 0x20))
        res := mload(m)
    }

    return res;
}

文档 shl(x, y) //将y逻辑左移x位

结果始终为 0; 在 testrPC 中它根本不起作用。

Geth 版本:1.8.10-stable 操作系统:ubuntu 16.04 Go 版本:1.9.2

【问题讨论】:

    标签: solidity


    【解决方案1】:

    我在编译您的代码时收到此警告:

    browser/Untitled3.sol:8:23: Warning: The "shl" instruction is only available for
    Constantinople-compatible VMs. You are currently compiling for "byzantium", where it will
    be interpreted as an invalid instruction.
    
                mstore(m, shl(2, val))
                          ^---------^
    

    似乎计划在君士坦丁堡分叉中添加此指令,但尚未发生:https://github.com/ethereum/EIPs/issues/145。目前,不存在这样的操作码。

    【讨论】:

      猜你喜欢
      • 2019-12-11
      • 2020-07-22
      • 2018-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-23
      • 1970-01-01
      相关资源
      最近更新 更多