This is the ASCII CR / LF (carriage / line return) sequence used to jump to the beginning of the next line.
History lesson:. On older teletype machines, carriage return did just that, he returned the carriage (printhead) to the beginning of the current line, while the feed line moved the paper so that printing would occur on the next line.
And your two samples should not give the same result. If your cursor is not at the beginning of the line when outputting a line without CR/LF , Hello world will appear in the middle of the line somewhere and, even if you start at the beginning of the line, the version with CR/LF should first move the cursor one line.
Zero at the end is just a terminator for the string. Some early systems used other characters, such as $ in the original BIOS:
str db "Hello, world$"
which makes it painful to display the $ sign on the console :-)
A terminator exists because your line output will almost certainly be written as a symbol output, such as pseudo-asm code:
; func: out_str ; input: r1 = address of nul-terminated string ; uses: out_chr ; reguse: r1, r2 (all restored on exit) ; notes: none out_str push r1 ; save registers push r2 push r1 ; get address to r2 (need r1 for out_chr) pop r2 loop: ld r1, (r2) ; get char, finish if nul cmp r2, 0 jeq done call out_chr ; output char, advance to next, loop back incr r2 jmp loop done: pop r2 ; restore registers and return pop r1 ret ; func: out_chr ; input: r1 = character to output ; uses: nothing ; reguse: none ; notes: correctly handles control characters out_chr ; insert function here to output r1 to screen
source share