2.3.68. FPRINTF

Displays formatted text to a specified file or window.

Syntax

FPRINTF {windowid | fileid} ,"format_string" [,argument...]

where:

windowid | fileid

Identifies the window or file where the command is to send the output.

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.

argument

The value or values to be written.

Description

The command is similar to the C run-time fprintf function. You select the windowid or fileid to use from the range 50..1024. For output to a file, the file must be opened using the FOPEN command. For output to a user window, the window must be opened using the VOPEN command.

Format string syntax

The text in format_string is defines what is displayed. If there are no % characters in the string, the text is written out and any other arguments to FPRINTF 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, <convspec>, 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 the source line address (as opposed to 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.

Output is formatted beginning at the left of the format string and is copied to the screen. If you are using the GUI, then the string is copied to the Output view. Whenever a conversion specification is encountered, the next argument is converted according to the specification, and the result is copied to the screen.

Rules

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

  • FPRINTF runs synchronously

  • windowid must identify a user-defined window that you have previously opened with the VOPEN command

  • fileid must identify a file that you have previously opened in write mode, for example:

    FOPEN 100, "c:\myfiles\file.txt"

  • if there are too many arguments, some of those that do not correspond with a format specifier 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.

Example

The following examples show how to use FPRINTF:

fprintf 50,"Syntax error\n"

Writes the string Syntax error to the window or file.

fprintf 50, "Execution time: %d seconds\n", tend-tstart

Prints the result of the calculation to the window or file, in the format:

Execution time: 20 seconds
fprintf 50, "Value is %d\n"

Prints the following to the window or file:

Value=<invalid value>

See also

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