I thought I’d share some of the cool features I’ve discovered over the years using LWASM that I don’t think are widely known or maybe I just live under a rock. 🙂
One of the best things are the need for less labels when writing your code. You can use the less than (<) and greater than (>) as labels that direct the code to the exclamation mark (!) in your code. For example:
Cool program #1 with labels:
LDX #$1000 LOOP1: INC ,X+ CMPX #$2000 BNE LOOP1 LDD ,Y BNE Done LDD #$BBBB Done: RTS
Cool program #1 with <, > and ! – Look ma, no labels:
LDX #$1000 ! INC ,X+ CMPX #$2000 BNE < LDD ,Y BNE > LDD #$BBBB ! RTS
Another cool label shortcut/feature is the use of @ at the end of your labels. You can re-use labels in the same source code as long as you leave a blank line between code sections and use an @ at the end. I haven’t used this too much myself but I have seen it used in a few 6809 source code files I’ve come across. It works like this
Cool program #2 with all different labels:
LDX #$1000 Loop1 INC ,X+ CMPX #$2000 BNE Loop1 CMPD #$AAAA BNE Skip1 LDD #$BBBB Skip1: BRA NextCode RTS NextCode: LDX #$5000 Loop2 INC ,X+ CMPX #$6000 BNE Loop2 RTS
If you leave a blank line after the RTS and put @ at the end of your label names you can reuse the same labels in the next section (see the 1@):
LDX #$1000 1@ INC ,X+ CMPX #$2000 BNE 1@ CMPD #$AAAA BNE 2@ LDD #$BBBB 2@ BRA NextCode RTS NextCode: LDX #$5000 1@ INC ,X+ CMPX #$6000 BNE 1@ RTS
Another cool thing LWASM can do is tell you the CPU cycle counts of your code. You can insert the following anywhere in your code that you’d like to count the cycles. Leave a few spaces on a line then type
opt c * enable cycle counts opt cd * enable detailed cycle counts breaking down addressing modes opt ct * show a running subtotal of cycles opt cc * clear the running subtotal
As the comments show the c shows the cycle counts, the ct tells the assembler to add the counts and the cc clears the current count. You can use any of these individually or together as I have.
opt c,ct,cc * show cycle count, add the counts, clear the current count
When you look at the output listing LWASM writes when it assembles your program you will see the cycles
Mem Code Cycles Assembly Code (Mnemonics) 4000 8E2000  LDX #$2000 4003 A684 [4+0] LDA ,X 4005 A61F [4+1] LDA -1,X 4009 A610 [4+1] LDA -16,X 400B A688EF [4+1] LDA -17,X 400E A68880 [4+1] LDA -128,X 4011 A689FF7F [4+4] LDA -129,X 4015 A601 [4+1] LDA 1,X 4017 A60F [4+1] LDA 15,X 4019 A68810 [4+1] LDA 16,X 401C A6887F [4+1] LDA 127,X 401F A6890080 [4+4] LDA 128,X
Another cool feature is Conditional Assembly. Conditional assembly basically uses IF, ELSE and END in your code and depending on the setting that you define then LWASM will assemble the code one way or another. There are many different conditions show in the LWASM documentation here. Just remember to use some spaces on the lines that you have your IF, ELSE, END or whatever other DEFINE you are using.
One last thing I sometimes use are Pragmas. You use them again with some spaces on the line then the word pragma a few spaces then the pragma itself. For example if I don’t want to see all the output in the assembly listing I use these pragmas:
pragma nolist * The code below will not be shown in the listing INCLUDE ./includes/CoCo3_Start.asm INCLUDE ./includes/Def_CoCo3_Memory_Description_and_Defines.asm pragma list * The code below will be shown in the listing
In the example above, everything still gets assembled as normal but the output of sections will be hidden in the listing. Useful if you have tons of code you don’t need to look through. Here’s the list of pragmas available.
There’s much more the LWASM program can do like macros and more. Of course the documentation is available here.