DYSTOPIANPIXEL

Assemble the source

Assemble successfully, choose the starting address and practise recognising an assembly error.

Next Asset Lab concept artwork showing sprite patterns, palette colours and animation frames
Next Asset Lab concept artwork · Begin with Odin Dev.2k and the foundations of Z80 assembly.
TUTORIAL 1 / PART 10

Assemble the source

What 'assemble' means

The Z80 cannot execute the text 'ld a,$42'. It can only execute numerical instruction codes. An assembler translates human-readable assembly source into machine-code bytes.

In Odin, enter:

A

A successful assembly on this machine finishes with ASSEMBLED OK in green.

From source text to executable bytes

It is worth seeing the whole transformation again now that we have real source code:

  1. source code
  2. ld a,$42
  3. Odin parses the mnemonic and operands
  4. Odin chooses the correct Z80 encoding
  5. machine code
  6. 3E 42
  7. bytes are placed in RAM
  8. the Z80 fetches and executes them

The assembler is therefore a translator and organiser. It is not the CPU, and it does not execute the instructions itself.

Inspect the label with T

Enter:

T

Odin reports:

$6000: start

This means that Odin resolved the label start to address $6000. The label itself is for us and for the assembler. The Z80 ultimately works with the numerical address.

A first deliberate assembly error

Real assembly work includes errors. It is better to meet one intentionally now than to treat the first unexpected error message as a disaster.

Return to the editor and temporarily replace the RET line with a word that is not a Z80 instruction, for example:

start:
    ld a,$42
    ld hl,$6000
    not_an_instruction

Return to the Monitor and enter A. Odin should reject the source rather than produce a successful assembly. The exact wording and presentation of the diagnostic may depend on the build, so read what your copy of Dev.2k reports rather than expecting a particular sentence.

Now return to the editor, restore RET, return to the Monitor and assemble again. Confirm that ASSEMBLED OK returns.

Common causes of early assembly errors

  • A mistyped instruction mnemonic.
  • A missing or mistyped register name.
  • Malformed numeric syntax.
  • A label typed differently in two places.
  • Editing the wrong source document.
  • Trying to run before the source has assembled successfully.

Do not try to memorise opcode bytes

Likewise, you do not need to memorise every common register use from the earlier table. Use it as a reference; repetition will make the common patterns familiar.