The Fast Assembler of Yves Han

The Fast AssemblerThe Fast Assembler, developed by Yves Han, is an amazing free tool from the 80’s for the Commodore 64. The impressive tiny size of this assembler (only about 2.5KB, despite all its features), ensures that the assembler loads really fast, which also makes it an ideal development tool if you are looking for a more authentic development experience on newer devices like THEC64. Despite the convenience and popularity these days of cross-platform tools for retro-computing development (such as Kick Assembler, C64 Studio [open source] and CBM prg Studio), I think The Fast Assembler deserves more attention. So, this post includes an example program to help give it some extra exposure.

Assembler Availability

This 6502/6510 assembler program is included with at least the following COMPUTE! publications, provided in type-in and/or disk format: (listed below by revision age, from older to newer)

COMPUTE!'s Gazette – Issue 31 COMPUTE!’s Gazette, Issue 31
January 1986
(the only publication with source code, although just on disk)
COMPUTE!'s More Machine Language Games for the Commodore 64 – 1987 COMPUTE!’s More Machine Language Games for the Commodore 64
published in 1987
ISBN 0874550947
(first part of Chapter 3)
COMPUTE!'s Commodore 64 and 128 Collection, Volume 2 – 1987 COMPUTE!’s Commodore 64/128 Collection, Volume 2
copyright 1987
ISBN 0874550890
(second part of Chapter 5)
Best of COMPUTE! & Gazette for Commodore 64 & 128 – 1988 Best of COMPUTE! & Gazette for Commodore 64 & 128
January 1988
(no type-in listing, only disk and article text)

The GAZETTE DISK of the 1986 publication includes the source code (tokenized) of the entire assembler itself, if you would like to modify or study the code further. If you prefer not to type the program data in yourself, or for a plain-text version of the listing, see the downloads section at the bottom of this post. (Permission granted by Yves — thanks!) Alternatively, you might find the compiled program on that GAZETTE DISK of 1986. The binary code is essentially the same for all these publications (version 3), and that is really all you need to just use the assembler. (Sometimes there is a small difference in the last 6 bytes, but this is of no consequence, since these bytes are beyond the LAST label as found in the source code and not really part of the actual program.)

Enhanced Programming Environment

Once the assembler is loaded into memory and activated (use SYS 4408 after a reset), you are in an enhanced BASIC environment, as you can tell from the text * ASSEMBLER v3 * by Yves Han 1985, 36324 basic bytes free and ready. From here you can edit, LOAD and SAVE the source code of your actual program, which can include the usual BASIC commands, some new BASIC commands (including ORG, BYTE, WORD, INCLUDE, SEND, UNSEND), as well as 6502/6510 assembly-language instructions (such as LDA, STX, JSR, RTS, and so on). You also have new and handy immediate-mode commands like AUTO and OLD at your disposal. However, this enhanced BASIC environment of The Fast Assembler is perhaps better thought of as a metaprogramming environment where the actual byte-code is generated that will eventually be executed or saved. It is at this point where the examples from the COMPUTE! article should perhaps be studied in detail (ideally the most recent revision).

So, the BASIC program represents the source-code listing of your own assembly program where you can combine BASIC keywords with 6510-assembler instructions to write your own programs. You then compile your assembly program when you RUN the BASIC program. The Fast Assembler is a multi-pass assembler. Since multiple passed would be required to compile most non-trivial programs, the BASIC source-code would usually contain a FOR … NEXT loop to represent the various passes of the assembler. To run the assembled machine code that is typically output during the final pass, a SYS command is often used afterwards, or using a JMP/JSR instruction from your custom loader; the possibilities are endless.

More Example Code

Fast Assembler ExampleAfter reading the COMPUTE! article, the following code can be studied as an intermediate example. It shows how to define a sprite that is controlled at runtime with the joystick in port 2, while continuously changing the border color to get an effect often associated with retro-game loading screens. Pressing the RUN/STOP-key while the example is running will exit this example program.

As an exercise, instead of checking for the STOP key directly by reading the keypress register at address $CB, you can change the code to call the kernal’s built-in STOP routine (located at address $FFE1).

10 ;demo the fast assembler of yves han
20 progaddr=$3fc0;location of compiled bytes
30 ;define constant memory locations
35 ypos0=$d001:xpos0=$d000;sprite 0 position
40 sprenab0=$d015;sprite 0 enable/disable
45 sprcolbg=$d01f;sprite to background collision
50 borcolor=$d020;border color
55 bkgcolor=$d021;background color
60 sprcolo0=$d027;sprite 0 color
65 sprslot0=2040;sprite 0 image register
70 clocktic=$a2;clock ticks register
75 keypress=$cb;keyboard keypress register
80 joyport2=$dc00;joystick input at port 2
85 joyleft=%00100:joyright=%01000:joyfire=%10000
90 runstop=$3f;keypress of run/stop
100 for pass=1 to 3
110 codefree=peek(49)+256*peek(50)
120 ;avoid overwriting of source code
130 if codefree>progaddr then print "source overflow, reallocate ram!":end
200 ;specify address and mode of output
210 org progaddr:if pass=3 then org progaddr,1
300 sprimage:;define sprite image data
310 byte %00000001,%11111110,%00000000
311 byte %00000111,%11111111,%10000000
312 byte %00001111,%11111111,%11000000
313 byte %00011111,%11000111,%11100000
314 byte %00111110,%00000001,%11110000
315 byte %01111100,%00000000,%11111000
316 byte %01111000,%11001100,%01111000
317 byte %11111001,%11001110,%01111100
318 byte %11111001,%11001110,%00111100
319 byte %11110000,%00000000,%00111100
320 byte %11110000,%00000000,%00111100
321 byte %11110001,%11111110,%00111100
322 byte %11111001,%00000010,%01111100
323 byte %11111000,%11111100,%01111100
324 byte %01111100,%00000000,%11111000
325 byte %01111110,%00000001,%11111000
326 byte %00111111,%10000111,%11110000
327 byte %00011111,%11111111,%11100000
328 byte %00001111,%11111111,%11000000
329 byte %00000111,%11111111,%10000000
330 byte %00000001,%11111110,%00000000
400 democode:;start of machine code
410 lda #8:sta borcolor;specify border color
420 lda #9:sta bkgcolor;specify background color
440 lda #(sprimage/64):sta sprslot0;specify sprite image
450 ldx #160:stx xpos0;sprite x position
460 ldy #90:sty ypos0;sprite y position
470 lda #%00000001:sta sprenab0;sprite enable
500 gameloop:
510 inc borcolor;flashing border colors
515 ldx #13;use normal sprite color by default
516 lda sprcolbg:beq sprcolgo;check for collision
517 ldx #5;use collision sprite color when needed
518 sprcolgo:stx sprcolo0;specify sprite color
520 cpy clocktic:beq gameloop:ldy clocktic;wait for next tick
530 sty ypos0;sprite y move on ticks
540 lda #joyleft:bit joyport2:bne chkright:dec xpos0
550 chkright:lda #joyright:bit joyport2:bne chkfire:inc xpos0
560 chkfire:lda #joyfire:bit joyport2:beq quit
570 lda keypress:cmp #runstop:bne gameloop;repeat until run/stop
600 quit:lda #0:sta sprenab0;sprite disable all
610 rts
900 next pass
910 print "sys";democode
920 print "press run/stop or fire to quit"
930 sys democode;autostart the demo

More than meets the eye

The fact that the assembler is implemented as a BASIC extension also means that it is an interesting kind of macro assembler. For instance, a DEF FN construct can be used at the top level (not in an INCLUDE file) to define such a macro; this technique is shown in EXAMPLE PROGRAM 2 of COMPUTE!’s article, and the source-code of The Fast Assembler itself also uses these two macros (to extract the individual high and low bytes of a 16-bit number). Various other techniques are also possible with The Fast Assembler, such as splitting larger programs into chunks and then chaining them all together.

Give this gem a try!


Scrolling Editor for The Fast Assembler

Inspired by my blog post, Dave Van Wagner contacted me with information about a previously-unpublished version of The Fast Assembler. Dave is the developer of ScrollEdit, the scrolling BASIC editor that was published in COMPUTE!’s Gazette of January 1986 (Issue 55). Dave originally created this modified version of The Fast Assembler way back in 1987 to include scrolling functionality similar to ScrollEdit. Dave was able to locate his old extension again, I connected him with Yves, and now Dave also made his enhanced version of The Fast Assembler available on his blog (with source code). Check it out — complete with YouTube video and animated GIF!