Slide 5.7: Multiple initializers
Slide 5.9: Defining WORD and SWORD data
Home

Defining Strings


To create a string data definition, enclose a sequence of characters in quotation marks. A string is ended with a null byte, a byte containing the value 0.
  preface  BYTE  "Hello", 0
Each character uses a byte of storage. The above code is equal to:
  preface  BYTE  'H', 'e', 'l', 'l', 'o', 0
A string can be spread across multiple lines, for example:
  preface  BYTE  "Assembly language for Intel computers", 0Dh, 0Ah
           BYTE  "A book for IA-32 processor architecture.", 0
The hexadecimal bytes 0Dh and 0Ah (carriage-return line-feed) advance the cursor to the beginning of the next line of standard output. The continuation character (\) may be used to concatenate two lines into a single program statement. For example, the following two statements are the same:
  preface  BYTE  "Assembly language for Intel computers", 0
  preface \
  BYTE  "Assembly language for Intel computers", 0
 Replacing a Character  Printing Part of a String  4 + 6
 .data
 s BYTE "This is ? test.", 0 
 .code

 

 mov   edx, OFFSET s
 call  WriteString
 
 .data
 s BYTE "This is ? test.", 0
 .code

 

 call  WriteString
 

 .data
 s BYTE "123456789", 0
 .code
 mov   eax, 0
 
 mov   al, [esi+3]
 sub   al, '0'
 add   al, [esi+5]
 sub   al, '0'
 call  WriteInt
 

 Output  Output  Output
  This is a test.     test.     10