Using HESmon64 to program Hello World in 6502 assembly#

A while back, I showed how to build a “Hello World” program in 8088-assembly on a P2000C. Here, I would like to show how we can achieve the same thing for the C64. In contrast to the P2000C with its 8088 CoPower expansion board, the C64 hosts a 6502 processor and as such, we have to write the Hello World in 6502-assembly. Similar as to how we programmed on the P2000C, here, we will also be using a so-called monitor program.

Monitor programs#

A monitor program, often simply called a “monitor,” is a software tool used in computing for low-level examination and manipulation of a computer’s memory and processor registers. It provides a command-line interface that allows users to interact directly with the machine’s hardware, typically bypassing the operating system.

With a monitor program, users can view, modify, and execute machine code, inspect memory contents, set breakpoints, and trace program execution. This makes monitor programs invaluable for tasks such as debugging, reverse engineering, and learning about the inner workings of a computer’s architecture. They are especially common in early home computers, like the Commodore 64, where developers and enthusiasts used them to develop and troubleshoot software at a fundamental level.

In the previous blogpost, we used DEBUG.EXE, which is an example of a monitor program. In this blog post, we will be looking into HESmon64, a cartridge-based monitor program written for the C64.

HESmon64#

HESmon64 is a popular machine language monitor program developed for the Commodore 64 by HesWare, a software company known for producing various utilities and games in the 1980s. Released in 1983, HESmon64 quickly became a favorite among hobbyists and developers for its powerful yet user-friendly features. HESmon64’s popularity helped establish HesWare as a significant player in the early days of personal computing, and the program remains a nostalgic favorite among retro computing enthusiasts today.

Note

  • HESMon64 can be found on the MegaCart. It is the 8th program on the list, under the generic name “C64 Monitor”.

  • If you do not own a C64 or not have a cartridge containing HESMon64, you can use the VICE emulator. The cartridge .crt can be found via this link.

When booting from the cartridge, one is greeted with the screen as shown below.

../_images/hesmon64.png

HESmon64 screen upon loading the monitor program from the cartridge.#

Writing Hello World#

To start programming the “Hello World” program, we first enter A 1200 LDX #00, which starts the inline-assembler at position $1200 in memory and assembles the instruction LDX #00 at that location.

Note

In HESMon64, you do not have to explicitly type ‘$’ to indicate hexadecimal notation. The assembler assumes that all numbers are written in hexadecimal format.

../_images/c64-assembly-helloworld-02.png

By writing A1200 LDX #00, we start the inline-assembler and write the first instruction to memory#

At this point, you can continue adding instructions which will be sequently assembled into memory.

../_images/c64-assembly-helloworld-03.png

The inline-assembler automatically jumps to the next available memory location, corresponding to $1202.#

Copy the instructions as shown below into the inline assembler. Note that you do not have to copy the addresses, only the instructions. For convenience, the instructions are shown in the listing below.

LDX #00
LDA 1210,X
BEQ 120E
JSR FFD2
INX
JMP 1202
BRK
NOP

Before we continue, let me briefly explain this code. First, we set the x-register to zero. This register will be used as a counter. Next, we load the value at memory location $1210 into the accumulator, using the value of the x-register as an offset. When a value of $00 is being read, we jump to location $120E where a BRK instruction is written. If not, we jump to the subroutine located at $FFD2 which is KERNAL routine that writes the value of the accumulator to the screen. Next, the x-register is incremented and we loop back to address $1202 which essentially loads the next value into the accumulator. After the BRK instruction there is also a NOP instruction, which basically does nothing. This instruction will actually not be invoked due to the preceding BRK and is only there to provide some padding.

After entering the last instruction, i.e. the NOP instruction, we hit ENTER another time to exit the inline-assembler mode. So far, we have only entered the intructions, but not yet the data on which the instructions will act. As a final step, we will thus write the string “Hello World!” in ASCII encoding. To do this, we first type M 1210 1220 to show the contents of memory between $1210-1220. Next, we can move the cursor and change the values in memory. To insert the string, copy the values shown in the listing below. It should look similar to the image shown below the code listing.

:1210 48 45 4C 4C 4F 20 57 4F
:1218 52 4C 44 21 00
../_images/c64-assembly-helloworld-04.png

The assembly instructions as well as the contents in memory.#

Finally, we can execute the small program. Move the cursor below the line starting with :1220 and type G 1200. This will inform the monitor to start code execution at position $1200. As can be seen from the image below, this will print the text “Hello World!” on the screen.

../_images/c64-assembly-helloworld-05.png

Running Hello World in 6502 assembly using the HESMon64 monitor.#

And that’s it. We have written a small Hello World program in 6502 assembly!

Further reading#