blob: b2646971d378f6e3af38207a8a81cc9a3e7fddaf [file] [log] [blame]
<html lang="en">
<head>
<title>Strings - Using as</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Using as">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Characters.html#Characters" title="Characters">
<link rel="next" href="Chars.html#Chars" title="Chars">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This file documents the GNU Assembler "as".
Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2000, 2001, 2002, 2006, 2007, 2008, 2009, 2010 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''.
-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
<link rel="stylesheet" type="text/css" href="../cs.css">
</head>
<body>
<div class="node">
<a name="Strings"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Chars.html#Chars">Chars</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Characters.html#Characters">Characters</a>
<hr>
</div>
<h5 class="subsubsection">3.6.1.1 Strings</h5>
<p><a name="index-string-constants-142"></a><a name="index-constants_002c-string-143"></a>A <dfn>string</dfn> is written between double-quotes. It may contain
double-quotes or null characters. The way to get special characters
into a string is to <dfn>escape</dfn> these characters: precede them with
a backslash &lsquo;<samp><span class="samp">\</span></samp>&rsquo; character. For example &lsquo;<samp><span class="samp">\\</span></samp>&rsquo; represents
one backslash: the first <code>\</code> is an escape which tells
<samp><span class="command">as</span></samp> to interpret the second character literally as a backslash
(which prevents <samp><span class="command">as</span></samp> from recognizing the second <code>\</code> as an
escape character). The complete list of escapes follows.
<p><a name="index-escape-codes_002c-character-144"></a><a name="index-character-escape-codes-145"></a>
<dl>
<!-- @item \a -->
<!-- Mnemonic for ACKnowledge; for ASCII this is octal code 007. -->
<a name="index-g_t_0040code_007b_005cb_007d-_0028backspace-character_0029-146"></a><a name="index-backspace-_0028_0040code_007b_005cb_007d_0029-147"></a><dt><kbd>\b</kbd><dd>Mnemonic for backspace; for ASCII this is octal code 010.
<!-- @item \e -->
<!-- Mnemonic for EOText; for ASCII this is octal code 004. -->
<p><a name="index-g_t_0040code_007b_005cf_007d-_0028formfeed-character_0029-148"></a><a name="index-formfeed-_0028_0040code_007b_005cf_007d_0029-149"></a><br><dt><kbd>\f</kbd><dd>Mnemonic for FormFeed; for ASCII this is octal code 014.
<p><a name="index-g_t_0040code_007b_005cn_007d-_0028newline-character_0029-150"></a><a name="index-newline-_0028_0040code_007b_005cn_007d_0029-151"></a><br><dt><kbd>\n</kbd><dd>Mnemonic for newline; for ASCII this is octal code 012.
<!-- @item \p -->
<!-- Mnemonic for prefix; for ASCII this is octal code 033, usually known as @code{escape}. -->
<p><a name="index-g_t_0040code_007b_005cr_007d-_0028carriage-return-character_0029-152"></a><a name="index-carriage-return-_0028_0040code_007b_005cr_007d_0029-153"></a><br><dt><kbd>\r</kbd><dd>Mnemonic for carriage-Return; for ASCII this is octal code 015.
<!-- @item \s -->
<!-- Mnemonic for space; for ASCII this is octal code 040. Included for compliance with -->
<!-- other assemblers. -->
<p><a name="index-g_t_0040code_007b_005ct_007d-_0028tab_0029-154"></a><a name="index-tab-_0028_0040code_007b_005ct_007d_0029-155"></a><br><dt><kbd>\t</kbd><dd>Mnemonic for horizontal Tab; for ASCII this is octal code 011.
<!-- @item \v -->
<!-- Mnemonic for Vertical tab; for ASCII this is octal code 013. -->
<!-- @item \x @var{digit} @var{digit} @var{digit} -->
<!-- A hexadecimal character code. The numeric code is 3 hexadecimal digits. -->
<p><a name="index-g_t_0040code_007b_005c_0040var_007bddd_007d_007d-_0028octal-character-code_0029-156"></a><a name="index-octal-character-code-_0028_0040code_007b_005c_0040var_007bddd_007d_007d_0029-157"></a><br><dt><kbd>\ </kbd><var>digit</var> <var>digit</var> <var>digit</var><dd>An octal character code. The numeric code is 3 octal digits.
For compatibility with other Unix systems, 8 and 9 are accepted as digits:
for example, <code>\008</code> has the value 010, and <code>\009</code> the value 011.
<p><a name="index-g_t_0040code_007b_005c_0040var_007bxd_002e_002e_002e_007d_007d-_0028hex-character-code_0029-158"></a><a name="index-hex-character-code-_0028_0040code_007b_005c_0040var_007bxd_002e_002e_002e_007d_007d_0029-159"></a><br><dt><kbd>\</kbd><code>x</code> <var>hex-digits...</var><dd>A hex character code. All trailing hex digits are combined. Either upper or
lower case <code>x</code> works.
<p><a name="index-g_t_0040code_007b_005c_005c_007d-_0028_0040samp_007b_005c_007d-character_0029-160"></a><a name="index-backslash-_0028_0040code_007b_005c_005c_007d_0029-161"></a><br><dt><kbd>\\</kbd><dd>Represents one &lsquo;<samp><span class="samp">\</span></samp>&rsquo; character.
<!-- @item \' -->
<!-- Represents one @samp{'} (accent acute) character. -->
<!-- This is needed in single character literals -->
<!-- (@xref{Characters,,Character Constants}.) to represent -->
<!-- a @samp{'}. -->
<p><a name="index-g_t_0040code_007b_005c_0022_007d-_0028doublequote-character_0029-162"></a><a name="index-doublequote-_0028_0040code_007b_005c_0022_007d_0029-163"></a><br><dt><kbd>\"</kbd><dd>Represents one &lsquo;<samp><span class="samp">"</span></samp>&rsquo; character. Needed in strings to represent
this character, because an unescaped &lsquo;<samp><span class="samp">"</span></samp>&rsquo; would end the string.
<br><dt><kbd>\ </kbd><var>anything-else</var><dd>Any other character when escaped by <kbd>\</kbd> gives a warning, but
assembles as if the &lsquo;<samp><span class="samp">\</span></samp>&rsquo; was not present. The idea is that if
you used an escape sequence you clearly didn't want the literal
interpretation of the following character. However <samp><span class="command">as</span></samp> has no
other interpretation, so <samp><span class="command">as</span></samp> knows it is giving you the wrong
code and warns you of the fact.
</dl>
<p>Which characters are escapable, and what those escapes represent,
varies widely among assemblers. The current set is what we think
the BSD 4.2 assembler recognizes, and is a subset of what most C
compilers recognize. If you are in doubt, do not use an escape
sequence.
</body></html>