2.3.96. PRINTF

Displays formatted text on the screen.

Syntax

PRINTF "format_string" [,argument]...

where:

format_string

Is a format specification conforming to C/C++ rules with extensions. It might be a text message, or it can describe how one or more arguments are to be presented. See Format string syntax for details.

Note

Only the first 256 characters of the string are displayed, even after formatting is applied.

argument

Is a list of values that you want displayed in the way described by the specified format.

Description

The PRINTF command uses a special format string to write text and numbers to the screen. If you are using the GUI, then they are displayed in the Output view. It works in a similar way to the ANSI C standard library function printf(), with a number of extensions to better support the debugger environment.

Format string syntax

The message in format_string is a string. If there are no % characters in the string, the message is written out and any arguments are ignored. The % symbol is used to indicate the start of an argument conversion specification.

The syntax of the specification is:

%[flag][fieldwidth][precision][lenmod]convspec

where:

flag

An optional conversion modification flag -. If specified, the result is left-justified within the field width. If not specified, the result is right-justified.

fieldwidth

An optional minimum field width specified in decimal.

precision

An optional precision specified in decimal, with a preceding . (period character) to identify it.

lenmod

An optional argument length specifier:

h

a 16-bit value

l

a 32-bit value

ll

a 64-bit value

convspec

The possible conversion specifier characters are:

%

A literal % character.

m

The mnemonic for the processor instruction in memory pointed to by the argument. The expansion includes a newline character. The information that is printed includes:

  • the memory address in hexadecimal

  • the memory contents in hexadecimal

  • the instruction mnemonic and arguments

  • an ASCII representation of the memory contents, if printable.

H

A line from the current source file, where the argument is the line number.

h

A line from the current source file, where the argument is a target memory address.

d, i, or u

An integer argument printed in decimal. d and i are equivalent, and indicate a signed integer. u is used for unsigned integers.

x or X

An integer argument printed in unsigned hexadecimal. x indicates that the letters a to f are used for the extra digits, and X indicates that the letters A to F are used.

c

A single character argument.

s

A string argument. The string itself can be stored on the host or on the target.

p

A pointer argument. The value of the pointer is printed in hexadecimal.

e, E, f, g, or G

A floating point argument, printed in scientific notation, fixed point notation, or the shorter of the two. The capital letter forms use a capital E in scientific notation rather than an e.

Rules

The following rules apply to the use of the PRINTF command:

  • if there are too many arguments, some of them are not printed

  • if there are too few arguments (that is, there are more conversion specifiers in the format string than there are arguments after the format string), the string <invalid value> is output instead

  • if the argument type does not correspond to its conversion field specification, arguments are converted incorrectly.

Examples

The following examples show how to use PRINTF:

printf "Found %d errors\n", ecount

Print out a message, substituting the value of ecount. So, if ecount had the value 5, the message is:

Found 5 errors
printf "Completion %\n", runs

Print out a message that includes a single percent symbol. The argument runs is ignored, so the message is:

Completion %
printf "%h\n", #82

Print out a source file line 82. For example:

REG   char            Ch_Index;
printf "Var is %hd.\n", short_var

Print out the variable short short_var. For example:

Var is 22.
printf "Instruction1 %m\nInstruction2 %m", 0x100, 0x104

Print out the disassembly of the contents of location 0x100, two newlines and the contents of location 0x104. For example, it might print:

Instruction1 000000100 20011410  ANDCS    r1,r1,r0,LSL r4

Instruction2 000000104 20011412  ANDCS    r1,r1,r2,LSL r4
printf "Average execution time %f secs\n", totaltime / (double)20

Print out a message, substituting the value of the expression. So, if totaltime had the value 523.3, the message is:

Average execution time 26.165 secs

See also

Copyright © 2002-2011 ARM. All rights reserved.ARM DUI 0175N
Non-ConfidentialID052111