Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
X86 assembly language
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Syntax== x86 assembly language has two primary [[Syntax of programming languages|syntax]] branches: ''[[Intel]] syntax'' and ''[[AT&T Corporation|AT&T]] syntax''.<ref name="GASvsNASM">{{cite web|url=http://www.ibm.com/developerworks/linux/library/l-gas-nasm/index.html |title=Linux assemblers: A comparison of GAS and NASM |date=2007-10-17 |access-date=2008-07-02 |first=Ram |last=Narayam |website=[[IBM]] |url-status=dead |archive-url=https://web.archive.org/web/20131003180256/http://www.ibm.com/developerworks/linux/library/l-gas-nasm/index.html |archive-date=October 3, 2013 }}</ref> Intel syntax is dominant in the [[DOS]] and [[Microsoft Windows|Windows]] environments, while AT&T syntax is dominant in [[Unix-like]] systems, as Unix was originally developed at [[AT&T Bell Labs]].<ref>{{cite web|title=The Creation of Unix |url=http://www.bell-labs.com/history/unix/ |url-status=dead |archive-url=https://web.archive.org/web/20140402192351/http://www.bell-labs.com/history/unix/ |archive-date=April 2, 2014 }}</ref> Below is a summary of the main differences between ''Intel syntax'' and ''AT&T syntax'': {| class="wikitable" ! ! AT&T ! Intel |- ! scope="row" | Parameter order | style="vertical-align:top;" | <syntaxhighlight lang="asm">movl $5, %eax</syntaxhighlight> Source before the destination. | style="vertical-align:top;" | <syntaxhighlight lang="nasm">mov eax, 5</syntaxhighlight> Destination before source. |- ! scope="row" | Parameter size | style="vertical-align:top;" | <syntaxhighlight lang="asm">addl $0x24, %esp movslq %ecx, %rax paddd %xmm1, %xmm2</syntaxhighlight> Mnemonics are suffixed with a letter indicating the size of the operands: ''q'' for qword (64 bits), ''l'' for long (dword, 32 bits), ''w'' for word (16 bits), and ''b'' for byte (8 bits).<ref name="GASvsNASM"/> <syntaxhighlight lang="asm"></syntaxhighlight> | style="vertical-align:top;" | <syntaxhighlight lang="nasm">add esp, 24h movsxd rax, ecx paddd xmm2, xmm1</syntaxhighlight> Derived from the name of the register that is used (e.g. ''rax, eax, ax, al'' imply ''q, l, w, b'', respectively). Width-based names may still appear in instructions when they define a different operation. * MOVSXD refers to sign extension with dword input, unlike MOVSX. * SIMD registers have width-named instructions that determine how to split up the register. AT&T tends to keep the names unchanged, so PADDD is not renamed to "paddl". |- ! scope="row" | [[Sigil (computer programming)|Sigils]] | style="vertical-align:top;" | [[Constant (programming)|Immediate values]] prefixed with a "$", registers prefixed with a "%".<ref name="GASvsNASM"/> | style="vertical-align:top;" | The assembler automatically detects the type of symbols; i.e., whether they are registers, constants or something else. |- ! scope="row" | Effective [[Memory address|addresses]] | style="vertical-align:top;" | <syntaxhighlight lang="asm">movl offset(%ebx, %ecx, 4), %eax</syntaxhighlight> General syntax of <code>''displacement''(''base'', ''index'', ''scale'')</code>. | style="vertical-align:top;" | <syntaxhighlight lang="nasm">mov eax, [ebx + ecx*4 + offset]</syntaxhighlight> Arithmetic expressions in square brackets; additionally, size keywords like ''byte'', ''word'', or ''dword'' have to be used if the size cannot be determined from the operands.<ref name="GASvsNASM"/> |} Many x86 assemblers use ''Intel syntax'', including [[FASM]], [[MASM]], [[Netwide Assembler|NASM]], [[TASM]], and [[YASM]]. The [[GNU Assembler]], which originally used ''AT&T syntax'', has supported both syntaxes since version 2.10 via the ''<code>.intel_syntax</code>'' directive.<ref name="GASvsNASM"/><ref name="WhichAsm">{{cite web|url=http://webster.cs.ucr.edu/AsmTools/WhichAsm.html|title=Which Assembler is the Best?|access-date=2008-05-18| first = Randall | last = Hyde }}</ref><ref>{{cite web|title = GNU Assembler News, v2.1 supports Intel syntax|url = http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/NEWS?rev=1.93&content-type=text/x-cvsweb-markup&cvsroot=src|date=2008-04-04|access-date=2008-07-02}}</ref> A quirk in the AT&T syntax for x86 is that [[x87]] floating-point operands are reversed, an inherited bug from the original AT&T assembler.<ref>{{cite web |title=i386-Bugs (Using as) |url=https://sourceware.org/binutils/docs/as/i386_002dBugs.html |website=Binutils documentation |access-date=15 January 2020}}</ref> The AT&T syntax is nearly universal across other architectures (retaining the same operand order for the {{code|mov}} instruction); it was originally designed for PDP-11 assembly and was inherited onto [[Unix-like]] systems. In contrast, the Intel syntax is specific to the [[x86 architecture]] and is the one used in the x86 platform's official documentation. The [[Intel 8080]], which predates the x86 architecture, also uses the "destination-first" order for {{code|mov}} instruction.<ref>{{cite web |title=Intel 8080 Assembly Language Programming Manual |url=https://altairclone.com/downloads/manuals/8080%20Programmers%20Manual.pdf |access-date=12 May 2023}}</ref> === Reserved words === In most x86 assembly languages, the [[reserved word]]s consist of two parts: mnemonics that translate to opcodes, and directives (or "pseudo-ops") that access features in the assembler program beyond the simple translation of opcodes. For a list of the former part, see [[x86 instruction listings]]. The latter part is highly assembler-dependent, with no such thing as a standard among Intel-syntax assemblers.<ref>{{cite web |title=NASM - The Netwide Assembler |url=https://www.nasm.us/xdoc/2.13/html/nasmdoc6.html |website=www.nasm.us}}</ref> AT&T-syntax assemblers share a common way of naming directives (all directives starts with a dot, like <code>.ascii</code>),<ref>{{cite web |title=Statements (Using as) |url=https://sourceware.org/binutils/docs/as/Statements.html |website=sourceware.org}}</ref> and a number of basic directives such as <code>.ascii</code> and <code>.string</code> are broadly supported.<ref>{{cite web |title=Pseudo Ops (Using as) :: Assembler Directives |url=https://sourceware.org/binutils/docs/as/Pseudo-Ops.html |website=sourceware.org}}</ref><ref>{{cite web |title=Assembler Directives - x86 Assembly Language Reference Manual |url=https://docs.oracle.com/cd/E37838_01/html/E61064/eoiyg.html |website=docs.oracle.com}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)