Text Strings

MPASM Assembler

Text Strings

A "string" is a sequence of any valid ASCII character (of the decimal range of 0 to 127) enclosed by double quotes.

Strings may be of any length that will fit within a 255 column source line. If a matching quote mark is found, the string ends. If none is found before the end of the line, the string will end at the end of the line. While there is no direct provision for continuation onto a second line, it is generally no problem to use a second DW directive for the next line.

The DW directive will store the entire string into successive words. If a string has an odd number of characters (bytes), the DW and DATA directives will pad the end of the string with one byte of zero (00).

If a string is used as a literal operand, it must be exactly one character long, or an error will occur.

Code Examples

See the examples below for the object code generated by different statements involving strings.

7465 7374 696E dw "testing output string one\n"

6720 6F75 7470

7574 2073 7472

696E 6720 6F6E

650A

#define str "testing output string two"

B061 movlw "a"

7465 7374 696E data "testing first output string"

6720 6669 7273

7420 6F75 7470

7574 2073 7472

696E 6700

Escape Characters

The assembler accepts the ANSI `C' escape sequences to represent certain special control characters:

Table: ANSI `C' Escape Sequences
Escape
Character
Description
Hex
Value
\a
Bell (alert) character
07
\b
Backspace character
08
\f
Form feed character
0C
\n
New line character
0A
\r
Carriage return character
0D
\t
Horizontal tab character
09
\v
Vertical tab character
0B
\\
Backslash
5C
\?
Question mark character
3F
\'
Single quote (apostrophe)
27
\"
Double quote character
22
\0OO
Octal number (zero, Octal digit, Octal digit)
 
\xHH
Hexadecimal number
 


Microchip Technology Inc.
Microchip's Web Site
Voice: (480) 792-7200
Fax: (480) 899-9210
Microchip's E-mail Address
PreviousNext