Literals/String: Difference between revisions

m
no edit summary
No edit summary
mNo edit summary
Line 41:
db $48,$65,$6c,$6c,$6f,$20,$57,$6f,$72,$6c,$64</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:
<lang 6502asm>db "Hello World",13,10,0</lang>
 
Creating your own printing routine is a bit out of the scope of this task but here's a simple demonstration that supports the \n and null termination:
<lang 6502asm>PrintString:
lda (StringPtr),y
beq Terminated
cmp #'\' ; a single ascii character is specified in single quotes.
beq HandleSpecialChars
jsr PrintChar ;unimplemented print routine
iny ;next character
jmp PrintString ;back to top
Terminated:
rts ;exit
HandleSpecialChars:
iny ;next char
lda (StringPtr),y
cmp #'n'
beq NextLine ;unimplemented new line routine, it ends in "JMP DoneSpecialChar"
DoneSpecialChar
iny
jmp PrintString ;jump back to top. Notice that neither the backslash nor the character after it were actually printed.
 
=={{header|Ada}}==
 
1,489

edits