Smart Branches (version 2)

Macross is a macro cross assembler for the 6502. It’s a higher level assembly language in that there you can write code like this:

    inc bleh
    if (equal) {
        inc bleh+1
    }
    do {
        lsr
    } while (!carry)

and it will generate the appropriate branches and labels. I intend to add similar high level constructs to my 816 assembler. They won’t be useful for generated lcc code, but they will be useful for hand-written assembly (which includes parts of libc and the subroutine library).

The first step is a new branch syntax as an alternative to the smart branches. Behold:

    branch condition, target

    branch cc, here
    branch signed lt, there
    branch unsigned ge, another

Condition may also be a boolean (number) for always or never.

    branch true, label
    branch false, label  ; will be optimized out!

Debugging

“Everyone knows that debugging is twice as hard as writing a program in the first place. So if you’re as clever as you can be when you write it, how will you ever debug it?” – Brian Kernighan.

That applies, even more so, to debugging an optimizer. The optimizer is smart enough now that half the “bugs” I’ve found recently weren’t bugs at all – the optimizer code was just smarter than I expected.