Hacker News

Favorites Setup
Comment by tmoertel | original | How did Woz write the Apple 1 BASIC before building the computer?
[−]tmoertel · 2026-11-15 Sun 01:46 UTC · link
> 300: A9 21 20 FO FD 60 would write a tiny program on an Apple II Plus that printed an exclamation point, if my memory serves.

Ancient assembly hacker tip: A JSR/RTS sequence can be simplified to a JMP. To continue your example, the bytes you provided decompile as follows (assuming Apple 2 monitor ROM at $F800):

            PRINTBANG:
    A9 21      LDA #$21
    20 F0 FD   JSR COUT1
    60         RTS
So, you load the A register with #$21, which is the ASCII code for `!` in hexadecimal, and then call COUT1 which will output the character in the A register, printing the exclamation point. When COUT1 is finished, it will return to you using an RTS instruction, and then you'll return to your caller using another RTS instruction.

Since the call to COUT1 is a tail call, you can borrow its RTS instruction to return to your caller and save one instruction. So the following code is equivalent to yours but a little bit smaller and faster:

            PRINTBANG:
    A9 21      LDA #$21
    4C F0 FD   JMP COUT1
Notice that the JSR instruction has become a JMP.

Another related trick: When you have a routine that callers often want to call twice—say to print `!!` for extreme exclamations—you may be tempted to create a do-it-twice call:

              PRINTBANG2:
    20 00 03    JSR PRINTBANG
    20 00 03    JSR PRINTBANG
    60          RTS
But now we know better and code it this way:

              PRINTBANG2:
    20 00 03    JSR PRINTBANG
    4C 00 03    JMP PRINTBANG
But we can do even better! We can eliminate the jump and save three more bytes by placing our do-it-twice routine immediately before the routine it is calling:

              PRINTBANG2:
    20 03 03    JSR PRINTBANG
              PRINTBANG:
    A9 21       LDA #$21
    4C F0 FD    JMP COUT1
When PRINTBANG2 is called, it calls PRINTBANG to print an exclamation point, but when PRINTBANG returns, it returns to PRINTBANG2, which promplty falls through to PRINTBANG, calling it again and printing a second exclamation point. This time, however, when PRINTBANG returns, it will return to the original caller.

Back when every byte mattered, these tricks were useful to know.