Instead of using the built in routines to output characters to the screen, this version of the Hello World program shows how you can write characters directly to screen memory.
The Commodore 64 has two seperate screen RAM locations that affect what is displayed. One memory area starts at hex $0400 (decimal 1024) which is used to store the character to be displayed. The other area is the color RAM, which determines what color of the the corresponding character in screen RAM is displayed in. Color RAM starts at hex $D800 (decimal 55296).
For example if you type the following BASIC pokes in you will see a green letter A.
POKE 1024,1: POKE 55296,5
if you add one to 1024 the next character will be placed in the screen position to the right of the A and the corresponding color RAM location will be 55297.
Note the variation on clearing the screen in this version, which uses the routin at $e544 to clear the screen rather than the alternative which could have been used.
The BASIC equivalent to the screen clearing routine call is
Which in assembly is just
Here is the source for the full program to store a text string directly in screen RAM.
; comment out the firtst line if your assembler doens’t like it
; filename: hello2.asm
; Assmbly Language Hello World in color using direct writes to screen RAM
; for the Commodoare 64
; assemble with acme assembler or modify to for your particular assember
; acme hello.asm
; to run in C64 BASIC and
; load the compiled file:
*=$8000 ; start address 32768
scrnmem = $0400 ; start of screen memory
colormem = $d800 ; start of color memory
clrscrn = $e544 ; clear screen routine
clearscrn ; clear the entire screen
ldx #$00 ; char ptr
ldy #$00 ; use Y to store current color
loop ; output text string (in this case “HELLO WORLD”)
lda hello,x ; load ptr to next char
cmp #$0 ; check if byte is 0 to terminate string
and #$3f ; correction because for poke A is 1 and not 65.
sta scrnmem,x ; store character directly in screen memory
; change the color for each char (just for fun)
iny ; next color
cpy #$06 ; skip the standard background color
; otherwise we wont see the character
sta colormem,x ; colorize character
inx ; add one to char ptr
continue ; keep going until we have processed the entire string
bvc loop ; branch always – two opcode relocatable version of jmp
done ; return to BASIC
; null terninated string
hello !text “HELLO WORLD”,0
; hello .byte “HELLO WORLD”,0 ; for some assemblers use this instead