9.5 String definition directives

Allocates one or more bytes of memory in the current section, and defines the initial contents of the memory from a string literal.

Syntax

.ascii "string"
.asciz "string"
.string "string"

Description

.ascii

The .ascii directive does not append a null byte to the end of the string.

.asciz

The .asciz directive appends a null byte to the end of the string.

The .string directive is an alias for .asciz.

string

The following escape characters are accepted in the string literal:

Table 9-12 Escape characters for the string definition directives

Escape character Meaning
\b Backspace
\f Form feed
\n Newline
\r Carriage return
\t Horizontal tab
\" Quote (")
\\ Backslash (\)
\Octal_Escape_Code Three digit octal escape code for each ASCII character

Examples

Using a null-terminated string in a constant pool:

      .text
    hello:
      adr r0, str_hello
      b printf
    str_hello:
      .asciz "Hello, world!\n"

Generating pascal-style strings (which are prefixed by a length byte, and have no null terminator), using a macro to avoid repeated code (see also macros and temporary numeric labels).

      .macro pascal_string, str
      .byte 2f - 1f
    1:
      .ascii "\str"
    2:
      .endm

      .data
    hello:
      pascal_string "Hello"
    goodbye:
      pascal_string "Goodbye"
Non-ConfidentialPDF file icon PDF versionDUI0774J
Copyright © 2014–2017, 2019 Arm Limited or its affiliates. All rights reserved.