Machine code from zero

A course for the Dragon 32 · Chapters 0 to 15

Chapter 5

With # or without

About 20 minutes · LDA learns to read

1Two ways to give LDA a number

With #: LDA #$41 says “here is the number”. $41 goes into the drawer.

Without #: LDA $0400 says “go to house $0400, copy what is written there, and put it in the drawer”. What goes into the drawer depends on what is in the house at that moment.

Figure 16: with a hash sign, the number is in your hand. Without a hash sign, the number is an address, and you go to the house.

2Reading takes a photo, writing rubs out

This is exactly what you did on the street in Chapter 0: “Photo to the note” and “Write from the note”. LDA $0400 takes a photo of the house, and the house doesn’t change. STA $0401 rubs out and writes.

Figure 17: copying from house to house in two lines. At the end, 65 in both houses, and in the drawer too.

3Copying on the screen

4A line is missing

We wanted to copy the red square from the top left corner to the bottom right corner.

5Two hash-sign mistakes

Mistake 1: a hash sign on a house. Someone wanted to copy the corner, and wrote LDA #$0400. With a hash sign it isn’t a house any more, it’s a number. But $0400 is too big for the drawer: it needs more than eight lamps.

What happens in DREAM? No complaint at all. The translator (assembler) keeps only what fits in eight lamps, $00, and an inverse @ appears in the corner (code 0). We copied nothing. ✓ Checked in DREAM

Mistake 2: a hash sign in STA. STA #$0400 means nothing: STA always writes to a house, and has nothing to do with “here is a number”.

Here too DREAM doesn’t complain: it translates the line into a strange code ($87) that has no defined meaning in the 6809 processor. On our Dragon machine nothing was written on the screen. On a real processor the result isn’t guaranteed, so simply don’t write it that way. ✓ Checked in DREAM

Rule of thumb: # = “here is the number”. Without # = “go to the house”. STA never has a hash sign.

?Puzzles: no hash sign

In these puzzles the first lines are already written (they draw something on the screen). You carry on after them, and in your lines you may not use #. You may only copy.

All the programs in this chapter, and the puzzle solutions too (including the locked lines), were typed into DREAM on our Dragon machine and run. There too, after BREAK X, the screen starts clean: every square holds $60. So the “empty square” in example 2 really is empty. ✓ Checked
What we learned: LDA #$41 = the number itself. LDA $0400 = what is in house $0400 right now.
Reading copies, and the house stays as it is. STA never has a hash sign. That’s how we copy without knowing what we are copying.

A hobbyist tribute project, not affiliated with or endorsed by Dragon Data. The course, drawings and text are our own. Every program in the course was checked on the site's Dragon machine (XRoar running the BASIC we wrote).