aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-07-26 22:01:17 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-08-11 00:30:57 +0800
commita323486a9bf40d60eb1a7914aaf38bb412c74ea0 (patch)
tree5df510e099ced84733b6f0a99dd140944450220a /docs
parentabe6eb983073d5a8e6d5ac469e4c437ea421c79d (diff)
downloaddexon-solidity-a323486a9bf40d60eb1a7914aaf38bb412c74ea0.tar
dexon-solidity-a323486a9bf40d60eb1a7914aaf38bb412c74ea0.tar.gz
dexon-solidity-a323486a9bf40d60eb1a7914aaf38bb412c74ea0.tar.bz2
dexon-solidity-a323486a9bf40d60eb1a7914aaf38bb412c74ea0.tar.lz
dexon-solidity-a323486a9bf40d60eb1a7914aaf38bb412c74ea0.tar.xz
dexon-solidity-a323486a9bf40d60eb1a7914aaf38bb412c74ea0.tar.zst
dexon-solidity-a323486a9bf40d60eb1a7914aaf38bb412c74ea0.zip
Add pure assembly example for summing
Diffstat (limited to 'docs')
-rw-r--r--docs/assembly.rst23
1 files changed, 23 insertions, 0 deletions
diff --git a/docs/assembly.rst b/docs/assembly.rst
index 2f5b8812..5288089f 100644
--- a/docs/assembly.rst
+++ b/docs/assembly.rst
@@ -96,6 +96,29 @@ 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.
+ _data := add(_data, 0x20)
+
+ // Set up a bound.
+ let end := add(_data, len)
+
+ // Iterate until the bound is not met.
+ for {} lt(_data, end) {} {
+ o_sum := add(o_sum, mload(_data))
+ _data := add(_data, 0x20)
+ }
+
+ // NOTE: after this point it is not safe to use _data in Solidity code
+ // because its offsets are in an invalid position
+ }
+ }
}