Literals/String: Difference between revisions

m
Line 40:
<lang 6502asm>db "Hello World"
db $48,$65,$6c,$6c,$6f,$20,$57,$6f,$72,$6c,$64</lang>
 
When using a single-character literal as an operand for an instruction, it MUST have a # in front, or else the CPU will treat it as a pointer being dereferenced rather than a numeric constant. (We've all made this mistake at least once without realizing it.)
<lang 6502asm>LDA #'A' ;load ascii code of "A" into the accumulator.
LDA 'A' ;load the byte stored at memory address 0x41 into the accumulator.</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:
1,489

edits