SourcePoint Intel Help

Table of Contents

printf

Write formatted output to the Command window.

Syntax

printf("format" [, expr] [...])

Where:

"format"

is a list of conversion specifications that corresponds to the like-ordered items in the list of expressions. Quotation marks are required.

expr

is an expression that is evaluated and displayed.

Discussion:

Use the printf function to write formatted output to the Command window. The printf command is similar to the C-language printf routine.

The format string is comprised of a series of conversion specifications of the form:

"% [flags] [width] [.precision] [data-length] conversion-operator"

These fields are defined as follows:

Flags

The flags element can be one of the following:

Flag

Description

- (minus)

causes the output to left-justify.

+ (plus)

causes signed numeric output to always display a sign.

0 (zero)

causes the field to zero fill.

(space)

causes the field to space fill (default)

Width

Use the digits 0 through 9 to define the minimum width of a field. Use an asterisk (*) to assign this value from an expression.

Precision

Use the digits 0 through 9 to define the decimal precision of a field.

Data-length

The following list gives the data size operators and their descriptions. ย If not specified the length is determined from the expression itself.

Operator

Description

h

typecasts the corresponding argument to a 16-bit value.

l, L

typecasts the corresponding argument to a 32-bit value.

I64

typecasts the corresponding argument to a 64-bit value (SourcePoint extension).

I128

typecasts the corresponding argument to a 128-bit value (SourcePoint extension).

Conversion-operator

The following list gives the conversion operators and their descriptions.

Operator

Description

d, i

displays corresponding argument in signed decimal

u

displays corresponding argument in unsigned decimal

o

displays corresponding argument in octal

x, X

displays corresponding argument in hexadecimal

e, E, f, g, G

displays corresponding argument as floating-point

c

displays corresponding argument as a character

s

displays corresponding argument as a null-terminated string

b, B

displays corresponding argument as a boolean (SourcePoint extension).

y, Y

displays corresponding argument in binary (SourcePoint extension).

D

displays corresponding argument in the current default number base (SourcePoint extension).

p

displays corresponding argument as a pointer (SourcePoint extension).

Escape Characters

The printf function accepts the following escape characters. The leading backslash is required.

Escape Character

Description

\b

backspace

\f

form-feed

\n

new line (flushes output to the Command line)

\r

carriage return

\t

tab

\\

backslash

\โ€

double quote

\nnn

a three-digit octal number that represents the ASCII value of the character. This value enables characters that are not directly available from the keyboard to be inserted into a character string.

\xnn

a two-digit hexadecimal number that represents the ASCII value of the character. This value enables characters that are not directly available from the keyboard to be inserted into a character string. The x indicates that a hexadecimal number follows

Example 1

To print a simple message to the screen (the \n character is required to flush output to the Command line):

Command input:

printf("This is my message.\n")

Result:

This is my message.

Example 2

To use character strings to print a date:

Command input:

define nstring date = "Saturday"
define ord1 day = 3
printf("Today is %s, the %drd of July.\n", date, day)

Result:

Today is Saturday, the 3rd of July.

Example 3

To print a message with an audible beep (007 octal is the ASCII code for beep):

Command input:

printf("\007ATTENTION: Emulation has stopped \n")

Result:

ATTENTION: Emulation has stopped

Related Topics: