组装逻辑移位左坚固不起作用


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稳定版 操作系统: ubuntu 16.04 Go 版本:1.9.2

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

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。目前,不存在这样的操作码。

最新更新