Suppose you want to output the string "I love you!". It might be tedious to put in memory the ASCII code for each character in this sentence.
MESSAGE .FILL x0049 ; ASCII code for IIs there an easy way to store those characters in memory so that we do not have to type them in one by one using the .FILL pseudo-op? The answer is yes.
.FILL x0020 ; ASCII code for space
.FILL x006c ; ASCII code for l
.FILL x006f ; ASCII code for o
.FILL x0076 ; ASCII code for v
.FILL x0065 ; ASCII code for e
.FILL x0020 ; ASCII code for space
.FILL x0079 ; ASCII code for y
.FILL x006f ; ASCII code for o
.FILL x0075 ; ASCII code for u
.FILL x0021 ; ASCII code for !
.FILL x0000 ; ASCII code for nul signifies the end of string and also acts as a sentinel
.STRINGZ pseudo-op which is explained in detail on pages 144-145 of the textbook exactly does what we want. Let's see how it works:
When the assembler assembles the above code fragment, it generates the following machine code. Notice what the assembler does with the .STRINGZ pseudo-op. It initializes the memory locations x3001 through x300b with the ASCII codes corresponding to the characters in the string "I love you!"..ORIG x3000 TRAP x25 MESSAGE .STRINGZ "I love you!" .END
x3000: xF025 ; HALTNote that the assembler automatically inserts the ASCII code for nul at the location following the string. This is very convenient for programmers, because we can easily identify the end of the string.
x3001: x0049 ; ASCII code for I
x3002: x0020 ; ASCII code for space
x3003: x006c ; ASCII code for l
x3004: x006f ; ASCII code for o
x3005: x0076 ; ASCII code for v
x3006: x0065 ; ASCII code for e
x3007: x0020 ; ASCII code for space
x3008: x0079 ; ASCII code for y
x3009: x006f ; ASCII code for o
x300a: x0075 ; ASCII code for u
x300b: x0021 ; ASCII code for !
x300c: x0000 ; ASCII code for nul signifies the end of string and also acts as a sentinel