Hello World for the Commodore 64
Place the following examlpe in a file called hello-world-c64.s and compile with the command
xlr8 --target c64-basic hello-world-c64.s cbm.lib
.section zero_page | ; Place following objects into the zero page. |
ptr .reserve 2 | ; Reserve a 2-byte variable called ptr in the zero page. |
.section code | ; Place the follwing symbols in the code section, which for this target is in the BASIC program area. |
.public start { | ; Begin the code object named start , which will be called when starting the resulting program. |
lda #<message | ; Copy the address of the object message to the variable ptr . |
sta ptr | |
lda #>message | |
sta ptr + 1 | |
ldy #0 | ; Print the 0-terminated string at message to the screen using the kernal routine CHROUT . |
loop: | |
lda (ptr),y | |
beq end | |
jsr CHROUT | |
iny | |
bne loop | |
end: | |
rts | ; Return to BASIC. |
} | ; End the code object start . |
.section data | ; Place the following symbols in the data section, which for this target is also in the BASIC program area. |
message { | ; Create the object message containing the string to print, using the default stirng encoding PETSCII. |
.data "{clear}hello world!{return}", 0 | ; The named character {clear} is the control code to clear the screen. |
} |