diff options
author | chriseth <chris@ethereum.org> | 2017-04-26 17:58:36 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-04-26 17:58:36 +0800 |
commit | a46a059e3a4b860c51821cabcfd8316b021f4245 (patch) | |
tree | 26438b4d0f67bd15780aef1c23cf1526edfef5f8 | |
parent | e64a03d86ba37b379b5cbaf797800135914599a7 (diff) | |
download | dexon-solidity-a46a059e3a4b860c51821cabcfd8316b021f4245.tar.gz dexon-solidity-a46a059e3a4b860c51821cabcfd8316b021f4245.tar.zst dexon-solidity-a46a059e3a4b860c51821cabcfd8316b021f4245.zip |
Document storage variable access.
-rw-r--r-- | docs/assembly.rst | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/docs/assembly.rst b/docs/assembly.rst index 30f7fc01..eb1bf276 100644 --- a/docs/assembly.rst +++ b/docs/assembly.rst @@ -323,9 +323,12 @@ Access to External Variables and Functions ------------------------------------------ Solidity variables and other identifiers can be accessed by simply using their name. -For storage and memory variables, this will push the address and not the value onto the -stack. Also note that non-struct and non-array storage variable addresses occupy two slots -on the stack: One for the address and one for the byte offset inside the storage slot. +For memory variables, this will push the address and not the value onto the +stack. Storage variables are different: Values in storage might not occupy a +full storage slot, so their "address" is composed of a slot and a byte-offset +inside that slot. To retrieve the slot pointed to by the variable ``x``, you +used ``x_slot`` and to retrieve the byte-offset you used ``x_offset``. + In assignments (see below), we can even use local Solidity variables to assign to. Functions external to inline assembly can also be accessed: The assembly will @@ -340,17 +343,13 @@ changes during the call, and thus references to local variables will be wrong. .. code:: - pragma solidity ^0.4.0; + pragma solidity ^0.4.11; contract C { uint b; function f(uint x) returns (uint r) { assembly { - b pop // remove the offset, we know it is zero - sload - x - mul - =: r // assign to return variable r + r := mul(x, sload(b_slot)) // ignore the offset, we know it is zero } } } |