Apple2 Assembly Hello, World
Every development example starts with the classic “Hello, world!” and this one is no different.
Here's the code in all it's glory…
WRVEC = $03D0 ; Warm Re-entry vector ;;; .include "inc/asc.inc" START: JMP MAIN .include "subs/hyde.ca65" MAIN: JSR PRINT ASC "HELLO, WORLD!" .BYT $8D,$00 JMP WRVEC .END
Assemble and link in one step using CC65's
$ cl65 -v -t apple2enh -C apple2enh-asm.cfg \ -u __EXEHDR__ --start-addr 8192 hello.a65
or doing explicit assemble and link steps:
$ ca65 -v -t apple2enh --listing hello.listing hello.a65 $ ld65 -v -C apple2enh-asm.cfg --start-addr 8192 \ apple2enh.lib -u __EXEHDR__ hello.o -o hello
A few notes about this. I'm specifying a start address of 8192 ($2000)
since that's a good location for a program under Prodos
(refer to Beneath Apple Prodos for details).
I'm also including the
__EXEHDR__ which defines an
header. In the first
cl65 includes it for me and in the second I
must be explict and include the CC65-supplied library. The header
carries, among other things, the start address and the program type
Now that we have a binary, let's get it onto a disk image using the CLI version of AppleCommander. The first step is to create an empty disk image.
$ java -jar ac.jar -pro140 disk.po hw
Now we can leverage the header from above and the built in support for it in AppleCommander.
$ java -jar ac.jar -as disk.po hello < ./hello
Had I decided not to use the CC65 library and corresponding AppleCommander support, I would place the file in the image like this:
$ java -jar ac.jar -p disk.po hello bin $2000 < ./hello
Firing up our emulator, we boot Prodos and run our binary. Behold!