<divclass="link title"><ahref="/v5/">Documentation</a></div><divclass="base show link depth-1"><ahref="/v5/getting-started/">Getting Started</a></div><divclass="base show link depth-1"><ahref="/v5/concepts/">Ethereum Basics</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/events/">Events</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/gas/">Gas</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/security/">Security</a></div><divclass="base ancestor show link depth-1"><ahref="/v5/api/">Application Programming Interface</a></div><divclass="show link depth-2"><ahref="/v5/api/contract/">Contract Interaction</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/contract/">Contract</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/contract-factory/">ContractFactory</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/example/">Example: ERC-20 Contract</a></div><divclass="show link depth-2"><ahref="/v5/api/signer/">Signers</a></div><divclass="show link depth-2"><ahref="/v5/api/providers/">Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/provider/">Provider</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/api-providers/">API Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/other/">Other Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/types/">Types</a></div><divclass="show link depth-2"><ahref="/v5/api/utils/">Utilities</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/abi/">Application Binary Interface</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/interface/">Interface</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/fragments/">Fragments</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/address/">Addresses</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/bignumber/">BigNumber</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/bytes/">Byte Manipulation</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/constants/">Constants</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/display-logic/">Display Logic and Input</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/encoding/">Encoding Utilities</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/fixednumber/">FixedNumber</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/hashing/">Hashing Algorithms</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/hdnode/">HD Wallet</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/logger/">Logging</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/properties/">Property Utilities</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/signing-key/">Signing Key</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/strings/">Strings</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/transactions/">Transactions</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/web/">Web Utilities</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/wordlists/">Wordlists</a></div><divclass="ancestor show link depth-2"><ahref="/v5/api/other/">Other Libraries</a></div><divclass="ancestor show link depth-3"><ahref="/v5/api/other/assembly/">Assembly</a></div><divclass="myself ancestor ancestor show link depth-4"><ahref="/v5/api/other/assembly/dialect/">Ethers ASM Dialect</a></div><divclass="show link depth-4"><ahref="/v5/api/other/assembly/api/">Utilities</a></div><divclass="show link depth-4"><ahref="/v5/api/other/assembly/ast/">Abstract Syntax Tree</a></div><divclass="show link depth-3"><ahref="/v5/api/other/hardware/">Hardware Wallets</a></div><divclass="show link depth-2"><ahref="/v5/api/experimental/">Experimental</a></div><divclass="base show link depth-1"><ahref="/v5/cli/">Command Line Interfaces</a></div><divc
<aname="asm-dialect"></a><aname="asm-dialect"></a><h1class="show-anchors"><div>Ethers ASM Dialect<divclass="anchors"><aclass="self"href="/v5/api/other/assembly/dialect/#asm-dialect"></a></div></div></h1><p>This provides a quick, high-level overcview of the <b>Ethers ASM Dialect</b> for EVM, which is defined by the <ahref="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/asm/grammar.jison">Ethers ASM Dialect Grammar</a></p>
<p>Once a program is compiled by a higher level langauge into ASM (assembly), or hand-coded directly in ASM, it needs to be assembled into bytecode.</p>
<p>The assembly process performs a very small set of operations and is intentionally simple and closely related to the underlying EVM bytecode.</p>
<p>Operations include embedding programs within programs (for example the deployment bootstrap has the runtime embedded in it) and computing the necessary offsets for jump operations.</p>
<p>The <ahref="/v5/cli/asm/">Command-Line Assembler</a> can be used to assemble an <i>Ethers ASM Dialect</i> file or to disassemble bytecode into its human-readable (ish) opcodes and literals.</p>
<aname="asm-dialect-opcode"></a><aname="asm-dialect--asm-dialect-opcode"></a><h2class="show-anchors"><div>Opcodes<divclass="anchors"><aclass="self"href="/v5/api/other/assembly/dialect/#asm-dialect-opcode"></a></div></div></h2><p>An <b>Opcode</b> may be provided in either a <i>functional</i> or <i>instructional</i> syntax. For Opcodes that require parameters, the <i>functional</i> syntax is recommended and the <i>instructional</i> syntax will raise a warning.</p>
<p>@TODO: Examples</p>
<aname="asm-dialect-label"></a><aname="asm-dialect--asm-dialect-label"></a><h2class="show-anchors"><div>Labels<divclass="anchors"><aclass="self"href="/v5/api/other/assembly/dialect/#asm-dialect-label"></a></div></div></h2><p>A <b>Label</b> is a position in the program which can be jumped to. A <codeclass="inline">JUMPDEST</code> is automatically added to this point in the assembled output.</p>
<p>@TODO: Exmaples</p>
<aname="asm-dialect-literal"></a><aname="asm-dialect--asm-dialect-literal"></a><h2class="show-anchors"><div>Literals<divclass="anchors"><aclass="self"href="/v5/api/other/assembly/dialect/#asm-dialect-literal"></a></div></div></h2><p>A <b>Literal</b> puts data on the stack when executed using a <codeclass="inline">PUSH</code> operation.</p>
<p>A <b>Literal</b> can be provided using a <ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a> or a decimal byte value.</p>
<p>@TODO: exmples</p>
<aname="asm-dialect-comment"></a><aname="asm-dialect--asm-dialect-comment"></a><h2class="show-anchors"><div>Comments<divclass="anchors"><aclass="self"href="/v5/api/other/assembly/dialect/#asm-dialect-comment"></a></div></div></h2><p>To enter a comment in the <b>Ethers ASM Dialect</b>, any text following a semi-colon (i.e. <codeclass="inline">;</code>) is ignored by the assembler.</p>
<aname="asm-dialect-scope"></a><aname="asm-dialect--asm-dialect-scope"></a><h2class="show-anchors"><div>Scopes<divclass="anchors"><aclass="self"href="/v5/api/other/assembly/dialect/#asm-dialect-scope"></a></div></div></h2><p>A common case in Ethereum is to have one program embedded in another.</p>
<p>The most common use of this is embedding a Contract <b>runtime bytecode</b> within a <b>deployment bytecode</b>, which can be used as <b>init code</b>.</p>
<p>When deploying a program to Ethereum, an <b>init transaction</b> is used. An <i>init transaction</i> has a null <codeclass="inline">to</code> address and contains bytecode in the <codeclass="inline">data</code>. This <codeclass="inline">data</code> bytecode is a program, that when executed returns some other bytecode as a result, this restul is the bytecode to be installed.</p>
<p>Therefore it is important that embedded code uses jumps relative to itself, not the entire program it is embedded in, which also means that a jump can <b>only</b> target its own scope, no parent or child scopes. This is enforced by the assembler.</p>
<p>A scope may access the offset of any child <ahref="/v5/api/other/assembly/dialect/#asm-dialect-datasegment">Data Segment</a> or child <ahref="/v5/api/other/assembly/dialect/#asm-dialect-scope">Scopes</a> (with respect to itself) and may access the length of any <ahref="/v5/api/other/assembly/dialect/#asm-dialect-datasegment">Data Segment</a> or <ahref="/v5/api/other/assembly/dialect/#asm-dialect-scope">Scopes</a> anywhere in the program.</p>
<p>Every program in the <b>Ethers ASM Dialect</b> has a top-leve scope named <codeclass="inline">_</code>.</p>
<aname="asm-dialect-datasegment"></a><aname="asm-dialect--asm-dialect-datasegment"></a><h2class="show-anchors"><div>Data Segment<divclass="anchors"><aclass="self"href="/v5/api/other/assembly/dialect/#asm-dialect-datasegment"></a></div></div></h2><p>A <b>Data Segment</b> allows arbitrary data to be embedded into a program, which can be useful for lookup tables or deploy-time constants.</p>
<p>An emtpty <b>Data Segment</b> can also be used when a labelled location is required, but without the <codeclass="inline">JUMPDEST</code> which a <ahref="/v5/api/other/assembly/dialect/#asm-dialect-label">Labels</a> adds.</p>
<p>@TODO: Example</p>
<aname="asm-dialect-links"></a><aname="asm-dialect--asm-dialect-links"></a><h2class="show-anchors"><div>Links<divclass="anchors"><aclass="self"href="/v5/api/other/assembly/dialect/#asm-dialect-links"></a></div></div></h2><p>A <b>Link</b> allows access to a <ahref="/v5/api/other/assembly/dialect/#asm-dialect-scope">Scopes</a>, <ahref="/v5/api/other/assembly/dialect/#asm-dialect-datasegment">Data Segment</a> or <ahref="/v5/api/other/assembly/dialect/#asm-dialect-label">Labels</a>.</p>
<p>To access the byte offset of a labelled item, use <codeclass="inline">$foobar</code>.</p>
<p>For a <ahref="/v5/api/other/assembly/dialect/#asm-dialect-label">Labels</a>, the target must be directly reachable within this scope. For a <ahref="/v5/api/other/assembly/dialect/#asm-dialect-datasegment">Data Segment</a> or a <ahref="/v5/api/other/assembly/dialect/#asm-dialect-scope">Scopes</a>, it can be inside the same scope or any child scope.</p>
<p>For a <ahref="/v5/api/other/assembly/dialect/#asm-dialect-datasegment">Data Segment</a> or a <ahref="/v5/api/other/assembly/dialect/#asm-dialect-label">Labels</a>, there is an additional type of <b>Link</b>, which provides the length of the data or bytecode respectively. A <b>Length Link</b> is accessed by <codeclass="inline">#foobar</code> and is pushed on the stack as a literal.</p>
<aname="asm-dialect-scripting"></a><aname="asm-dialect--asm-dialect-scripting"></a><h2class="show-anchors"><div>Evaluation and Excution<divclass="anchors"><aclass="self"href="/v5/api/other/assembly/dialect/#asm-dialect-scripting"></a></div></div></h2>
<divclass="copyright">The content of this site is licensed under the <ahref="https://choosealicense.com/licenses/cc-by-4.0/">Creative Commons License</a>. Generated on June 10, 2020, 12:47am.</div>