Literals/String: Difference between revisions

Content added Content deleted
Line 72: Line 72:
{{trans|6502 Assembly}}
{{trans|6502 Assembly}}
Strings are enclosed in double quotes. [[C]] places a null terminator at the end of the string for you; in 68000 Assembly you have to type it manually (unless your assembler has an <code>.ASCIZ</code> directive or equivalent, and not all do).
Strings are enclosed in double quotes. [[C]] places a null terminator at the end of the string for you; in 68000 Assembly you have to type it manually (unless your assembler has an <code>.ASCIZ</code> directive or equivalent, and not all do).
<lang 68000devpac>DC.B "Hello World"
<lang 68000devpac>DC.B "Hello World",0
EVEN</lang>
EVEN</lang>
Any typed character in double quotes is assembled as the ASCII equivalent of that character. Therefore the following two data blocks are equivalent:
Any typed character in double quotes is assembled as the ASCII equivalent of that character. Therefore the following two data blocks are equivalent:
<lang 68000devpac>DC.B "Hello World"
<lang 68000devpac>DC.B "Hello World",0
EVEN
EVEN


DC.B $48,$65,$6c,$6c,$6f,$20,$57,$6f,$72,$6c,$64
DC.B $48,$65,$6c,$6c,$6f,$20,$57,$6f,$72,$6c,$64,$00
EVEN</lang>
EVEN</lang>


The assembler typically assumes nothing with regard to special characters. A <code>\n</code> will be interpreted literally, for example. How special characters are handled depends on the printing routine of the hardware's BIOS, or one created by the programmer. If your printing routine is able to support a null terminator and ASCII control codes, the following represents "Hello World" with the new line command and null terminator:
The assembler typically assumes nothing with regard to special characters. How special characters are handled depends on the printing routine of the hardware's BIOS, or in the case of embedded hardware with no BIOS or a very limited one like the Sega Genesis, the printing routine created by the programmer. By default, there is no support for any control codes unless you add it in yourself.
<lang 68000devpac>DC.B "Hello World",13,10,0
EVEN</lang>


=={{header|Ada}}==
=={{header|Ada}}==