|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <!-- This file documents the GNU Assembler "as".
-
- Copyright (C) 1991-2020 Free Software Foundation, Inc.
-
- Permission is granted to copy, distribute and/or modify this document
- under the terms of the GNU Free Documentation License, Version 1.3
- or any later version published by the Free Software Foundation;
- with no Invariant Sections, with no Front-Cover Texts, and with no
- Back-Cover Texts. A copy of the license is included in the
- section entitled "GNU Free Documentation License".
- -->
- <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>i386-Memory (Using as)</title>
-
- <meta name="description" content="i386-Memory (Using as)">
- <meta name="keywords" content="i386-Memory (Using as)">
- <meta name="resource-type" content="document">
- <meta name="distribution" content="global">
- <meta name="Generator" content="makeinfo">
- <link href="index.html#Top" rel="start" title="Top">
- <link href="AS-Index.html#AS-Index" rel="index" title="AS Index">
- <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
- <link href="i386_002dDependent.html#i386_002dDependent" rel="up" title="i386-Dependent">
- <link href="i386_002dJumps.html#i386_002dJumps" rel="next" title="i386-Jumps">
- <link href="i386_002dPrefixes.html#i386_002dPrefixes" rel="prev" title="i386-Prefixes">
- <style type="text/css">
- <!--
- a.summary-letter {text-decoration: none}
- blockquote.indentedblock {margin-right: 0em}
- blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
- blockquote.smallquotation {font-size: smaller}
- div.display {margin-left: 3.2em}
- div.example {margin-left: 3.2em}
- div.lisp {margin-left: 3.2em}
- div.smalldisplay {margin-left: 3.2em}
- div.smallexample {margin-left: 3.2em}
- div.smalllisp {margin-left: 3.2em}
- kbd {font-style: oblique}
- pre.display {font-family: inherit}
- pre.format {font-family: inherit}
- pre.menu-comment {font-family: serif}
- pre.menu-preformatted {font-family: serif}
- pre.smalldisplay {font-family: inherit; font-size: smaller}
- pre.smallexample {font-size: smaller}
- pre.smallformat {font-family: inherit; font-size: smaller}
- pre.smalllisp {font-size: smaller}
- span.nolinebreak {white-space: nowrap}
- span.roman {font-family: initial; font-weight: normal}
- span.sansserif {font-family: sans-serif; font-weight: normal}
- ul.no-bullet {list-style: none}
- -->
- </style>
-
-
- </head>
-
- <body lang="en">
- <a name="i386_002dMemory"></a>
- <div class="header">
- <p>
- Next: <a href="i386_002dJumps.html#i386_002dJumps" accesskey="n" rel="next">i386-Jumps</a>, Previous: <a href="i386_002dPrefixes.html#i386_002dPrefixes" accesskey="p" rel="prev">i386-Prefixes</a>, Up: <a href="i386_002dDependent.html#i386_002dDependent" accesskey="u" rel="up">i386-Dependent</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
- </div>
- <hr>
- <a name="Memory-References"></a>
- <h4 class="subsection">9.16.7 Memory References</h4>
-
- <a name="index-i386-memory-references"></a>
- <a name="index-memory-references_002c-i386"></a>
- <a name="index-x86_002d64-memory-references"></a>
- <a name="index-memory-references_002c-x86_002d64"></a>
- <p>An Intel syntax indirect memory reference of the form
- </p>
- <div class="smallexample">
- <pre class="smallexample"><var>section</var>:[<var>base</var> + <var>index</var>*<var>scale</var> + <var>disp</var>]
- </pre></div>
-
- <p>is translated into the AT&T syntax
- </p>
- <div class="smallexample">
- <pre class="smallexample"><var>section</var>:<var>disp</var>(<var>base</var>, <var>index</var>, <var>scale</var>)
- </pre></div>
-
- <p>where <var>base</var> and <var>index</var> are the optional 32-bit base and
- index registers, <var>disp</var> is the optional displacement, and
- <var>scale</var>, taking the values 1, 2, 4, and 8, multiplies <var>index</var>
- to calculate the address of the operand. If no <var>scale</var> is
- specified, <var>scale</var> is taken to be 1. <var>section</var> specifies the
- optional section register for the memory operand, and may override the
- default section register (see a 80386 manual for section register
- defaults). Note that section overrides in AT&T syntax <em>must</em>
- be preceded by a ‘<samp>%</samp>’. If you specify a section override which
- coincides with the default section register, <code>as</code> does <em>not</em>
- output any section register override prefixes to assemble the given
- instruction. Thus, section overrides can be specified to emphasize which
- section register is used for a given memory operand.
- </p>
- <p>Here are some examples of Intel and AT&T style memory references:
- </p>
- <dl compact="compact">
- <dt>AT&T: ‘<samp>-4(%ebp)</samp>’, Intel: ‘<samp>[ebp - 4]</samp>’</dt>
- <dd><p><var>base</var> is ‘<samp>%ebp</samp>’; <var>disp</var> is ‘<samp>-4</samp>’. <var>section</var> is
- missing, and the default section is used (‘<samp>%ss</samp>’ for addressing with
- ‘<samp>%ebp</samp>’ as the base register). <var>index</var>, <var>scale</var> are both missing.
- </p>
- </dd>
- <dt>AT&T: ‘<samp>foo(,%eax,4)</samp>’, Intel: ‘<samp>[foo + eax*4]</samp>’</dt>
- <dd><p><var>index</var> is ‘<samp>%eax</samp>’ (scaled by a <var>scale</var> 4); <var>disp</var> is
- ‘<samp>foo</samp>’. All other fields are missing. The section register here
- defaults to ‘<samp>%ds</samp>’.
- </p>
- </dd>
- <dt>AT&T: ‘<samp>foo(,1)</samp>’; Intel ‘<samp>[foo]</samp>’</dt>
- <dd><p>This uses the value pointed to by ‘<samp>foo</samp>’ as a memory operand.
- Note that <var>base</var> and <var>index</var> are both missing, but there is only
- <em>one</em> ‘<samp>,</samp>’. This is a syntactic exception.
- </p>
- </dd>
- <dt>AT&T: ‘<samp>%gs:foo</samp>’; Intel ‘<samp>gs:foo</samp>’</dt>
- <dd><p>This selects the contents of the variable ‘<samp>foo</samp>’ with section
- register <var>section</var> being ‘<samp>%gs</samp>’.
- </p></dd>
- </dl>
-
- <p>Absolute (as opposed to PC relative) call and jump operands must be
- prefixed with ‘<samp>*</samp>’. If no ‘<samp>*</samp>’ is specified, <code>as</code>
- always chooses PC relative addressing for jump/call labels.
- </p>
- <p>Any instruction that has a memory operand, but no register operand,
- <em>must</em> specify its size (byte, word, long, or quadruple) with an
- instruction mnemonic suffix (‘<samp>b</samp>’, ‘<samp>w</samp>’, ‘<samp>l</samp>’ or ‘<samp>q</samp>’,
- respectively).
- </p>
- <p>The x86-64 architecture adds an RIP (instruction pointer relative)
- addressing. This addressing mode is specified by using ‘<samp>rip</samp>’ as a
- base register. Only constant offsets are valid. For example:
- </p>
- <dl compact="compact">
- <dt>AT&T: ‘<samp>1234(%rip)</samp>’, Intel: ‘<samp>[rip + 1234]</samp>’</dt>
- <dd><p>Points to the address 1234 bytes past the end of the current
- instruction.
- </p>
- </dd>
- <dt>AT&T: ‘<samp>symbol(%rip)</samp>’, Intel: ‘<samp>[rip + symbol]</samp>’</dt>
- <dd><p>Points to the <code>symbol</code> in RIP relative way, this is shorter than
- the default absolute addressing.
- </p></dd>
- </dl>
-
- <p>Other addressing modes remain unchanged in x86-64 architecture, except
- registers used are 64-bit instead of 32-bit.
- </p>
- <hr>
- <div class="header">
- <p>
- Next: <a href="i386_002dJumps.html#i386_002dJumps" accesskey="n" rel="next">i386-Jumps</a>, Previous: <a href="i386_002dPrefixes.html#i386_002dPrefixes" accesskey="p" rel="prev">i386-Prefixes</a>, Up: <a href="i386_002dDependent.html#i386_002dDependent" accesskey="u" rel="up">i386-Dependent</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
- </div>
-
-
-
- </body>
- </html>
|