C64 Assembly Language Hello World in color using the Kernal CHROUT routine


This is classic “Hello World” program written for the classic computer, the Commodore 64. It is written in 6502 assembly language.
I have added a few extra features on top of the bare bones Hello World implementation. It also clears the screen at the beginning, and changes the color of each character as it goes. These extras can easily be commented out. This should make it a good starting point for more complex programs but not so complicated as to lose you straight away.

In BASIC the clear screen command would be:


In assembly this translates to

lda #$93 ; decimal 147 is the same as hex $93
jsr $ffd2 ; output char using kernal routine
!to “hello.prg”,cbm
; comment out the firtst line if your assembler doens’t like it; filename: hello.asm; Assmbly Language Hello World in color using the Kernal CHROUT routine
; 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:; LOAD”HELLO.PRG”,8,1
; SYS32768

*=$8000 ; start address 32768
chrout = $ffd2 ; CHROUT Kernal routine
txtcolor = $0286 ; determines text color

ldx #$00 ; char ptr
stx txtcolor ; also init txt color

clearscrn ; clear the entire screen
lda #$93 ; clear screen character
jsr chrout ; output char

loop ; output text string (in this case “HELLO WORLD”)
lda hello+1,x ; load ptr to next char
; +1 skip size byte
jsr chrout ; output char
inx ; add one to char ptr

; change the color for each char (just for fun)
inc txtcolor ; colorize
lda txtcolor
cmp #$06 ; skip the standard background color
; otherwise we wont see the character
beq chgcolor

continue ; keep going until we have processed the entire string
cpx hello ; check if ptr is past end. remeber the first byte in hello holds the length
bne loop

; set text color to default and put things back to normal
lda #$0e
sta txtcolor

done ; return to BASIC

; messge string, first byte is the length, then actual text string

hello !text 11,”HELLO WORLD”
; hello .byte 11,”HELLO WORLD” ; for some assemblers use this instead

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s