Machine code from zero

A course for the Dragon 32 · Chapters 0 to 15

Chapter 0

What is a computer? A street of houses

On the Dragon, as on every computer, we count from zero. So we start here too.
About 10 minutes · no code at all

★Where we are going

By the end of the course you will write this game yourself: a yellow apple falls, and you catch it in a blue basket. You will write it in the language the fast games of 1982 were written in: machine code.

Hello. I’ll be with you all through the course. Sounds hard? Don’t worry. We’ll go slowly: in every step one idea, a picture, and something to press. If you understand how to write a number in a house, you’ve already come most of the way.

1Memory is a street

Inside the computer there is a very long street of little houses. Every house has a house number, like on a real street.

On every house hangs a small wipeable board, and on it is written one number. Only one, never two. The number is always between 0 and 255.

Figure 1: The street of houses. On the sign: the house number. On the board: the number that lives in the house.

The Dragon has 65,536 houses like these. The game, the letters on the screen, the sounds: it is all numbers on these boards.

Every sign shows the number in two ways: 1024, and below it, small, $0400. It is the same number, in the computer’s way of writing. For now you can ignore the small line. We’ll learn it in Chapter 3.

2Writing: wipe, then write

When you write a number in a house, the board is wiped first. The old number disappears, and the new one is written in its place.

Figure 2: It was 5. Wipe. Write 7. Now the board holds only 7.

3Reading: take a photo, and the original stays

When the computer reads a number from a house, it doesn’t take the board. It takes a photo of it. The copy goes onto a note in its hand, and the number stays in the house exactly as it was.

Figure 3: Reading takes a photo. House 1025 still holds 65, and the note holds 65 too.

4Try it yourself on the street

Click a house to choose it. Then write a number in it, or take a photo of it onto the note.

    Did you try to write 300? The board won’t have it. The biggest number that fits is 255. That isn’t our rule, it is how the Dragon itself works. Why 255 of all numbers? We’ll find out in Chapter 4.

    What happens on the real Dragon with 300? In BASIC the command POKE 1024,300 answers ?FC ERROR. In DREAM the line LDA #300 doesn’t complain, but keeps only what fits: 44 (because 300 minus 256). ✓ Both checked on our Dragon machine

    ?Puzzles

    Puzzle 1 · Follow along

    At the start, house 1030 holds 4. Now we do, in this order:

    1. Write 8 in house 1030.
    2. Take a photo of house 1030 onto the note.
    3. Write 2 in house 1030.
    4. Write what is on the note in house 1031.
    House 1030 holds: and house 1031 holds:
    Puzzle 2 · Copy without typing

    Copy the number from house 1029 to house 1033, without typing it. You may only use “Photo to the note” and “Write from the note”.

    What we learnt: memory is a street of numbered houses, and every house has a board with one number between 0 and 255.
    Writing wipes the old and writes the new. Reading takes a photo, and the original stays.

    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).