2.2.58. FPRINTF

The FPRINTF command displays formatted text to a specified file or window.

Syntax

FPRINTF windowid, "format_string" [,argument]...

where:

windowid

Specifies a window or file number (in the range 50–1024).

format_string

Specifies the format to be applied to argument.

argument

The value or values to be written.

Description

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

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

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 Output pane. Whenever a conversion specification is encountered, the next argument is converted according to the specification, and the result is copied to the Output pane.

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

  • FPRINTF runs synchronously

  • windowid must be one of the predefined values or have been previously assigned by an FOPEN or VOPEN 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.

Example

The following examples show how to use FPRINTF:

fprintf 50,"Syntax error\n"

Write the string Syntax error to the window or file.

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

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

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

Print the following to the window or file:

Value=<invalid value>

See also

The following commands provide similar or related functionality:

Copyright © 2003, 2004 ARM Limited. All rights reserved.ARM DUI 0235B
Non-Confidential