diff options
author | chriseth <chris@ethereum.org> | 2017-08-11 17:02:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-11 17:02:09 +0800 |
commit | bd639b9c6b627c26bea21cbf4e54fd5c0604be75 (patch) | |
tree | 1724cb49e187127cdb70cb39d3bbde53ba73f8f9 | |
parent | c84de7fa63d34dde03aa97c6ff1101c56202c880 (diff) | |
parent | 9358001ba4074d94d9daa566d225e1f8b2305009 (diff) | |
download | dexon-solidity-bd639b9c6b627c26bea21cbf4e54fd5c0604be75.tar.gz dexon-solidity-bd639b9c6b627c26bea21cbf4e54fd5c0604be75.tar.zst dexon-solidity-bd639b9c6b627c26bea21cbf4e54fd5c0604be75.zip |
Merge pull request #2653 from ethereum/docs-asm
Add pure assembly example for summing
-rw-r--r-- | docs/assembly.rst | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/docs/assembly.rst b/docs/assembly.rst index 2f5b8812..bdb708a9 100644 --- a/docs/assembly.rst +++ b/docs/assembly.rst @@ -96,6 +96,31 @@ you really know what you are doing. } } } + + // Same as above, but accomplish the entire code within inline assembly. + function sumPureAsm(uint[] _data) returns (uint o_sum) { + assembly { + // Load the length (first 32 bytes) + let len := mload(_data) + + // Skip over the length field. + // + // Keep temporary variable so it can be incremented in place. + // + // NOTE: incrementing _data would result in an unusable + // _data variable after this assembly block + let data := add(_data, 0x20) + + // Iterate until the bound is not met. + for + { let end := add(data, len) } + lt(data, end) + { data := add(data, 0x20) } + { + o_sum := add(o_sum, mload(data)) + } + } + } } |