汇编逻辑左移 solidity 不起作用
assembly logical shift left solidity don't work
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-稳定
OS: ubuntu 16.04
去版本: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。目前,不存在这样的操作码。
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-稳定 OS: ubuntu 16.04 去版本: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。目前,不存在这样的操作码。