I wanted to start out with something simple when beginning to look at Assembly. The traditional Hello World output seemed like the best choice for this. I’ve taken an example from the excellent ‘The Anatomy of The Commodore 64‘ and Old Skool Coder‘s Youtube channel for this one.
Starting the Code Block
The first thing we have to do is to emulate assembling the program and run it from BASIC. As if it was a program that we had bought on a tape. If you are using the CBM Assembler there is an easy way to do this.
First Tell the Assembly where to start from in memory .

Then go to Tools -> Generate Sys Call and then press OK. It should have picked up the start of your memory address from your previously typed code.

So now you should see something like this –

On the Commodore 64, BASIC memory starts at 2040 (0x800) so we place some code in here which theC64 will interpret as a BASIC program.
If you are running Kick Assembler you can replace these lines of code with:

This is a macro which then points to the beginning routine of your program.
Changing the Color of your screen and Border
Let’s look at the next section of code. This changes the color of our screen background to black and sets our Text color to white.

We begin by loading the color black into the accumulator – lda #$00.
We next store this value in the border color address – which is $d020
We also store this value in the background color address – which is $d021
Next we load the color white into the accumulator – lda #$01
We store this value in the cursor color address – which is $0286.
Right now you may be asking me how I know these addresses? Is this magic? Well no, it’s because I have a handy memory reference which you can find here.
Now we want to clear the screen of all text so that we can display our message clearly.

We do this by calling the screen function to clear the screen – which is $e544. Again this is not magic, you can find a good list of screen functions here.
We haven’t coded the sub routine that will draw our text yet but it will be called draw_text. This is where we jump to that subroutine – jsr
Drawing the Text to the Screen

With this code we complete our project. We create the label .msg and place a C style string in it.
We draw the text by placing the color white in the x registry – ldx #$00
Next we enter a loop and draw each character, loading the message into the accumulator – lda msg,x.
We place 2 lines below the word – sta $05e0,x
Increment the value in the x registry – inx
Check is all 40 cols of the line are processed – cpx #$28
If they are not then continue to go back to the draw loop until the sentence is done – bne draw_loop.
When run we should see :

Entire Listing:

Hey OldSkoolCoder here, what a great example of getting started, thank you for my shout out too.
LikeLike
Thanks mate – glad you liked it!
LikeLike