DYSTOPIANPIXEL

Run and inspect

Run the programme and explain the register, memory and flags displays.

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 13

Run the program and read Odin's inspection screen

Before running experimental machine code

Assembly success tells us that the source is syntactically valid; it does not prove that the program is logically safe. A perfectly valid machine-code program can still jump to the wrong place, overwrite memory or fail to return.

For early experiments, keep the program tiny, save the source first, and run only code whose instructions we have just discussed. If an experiment ever leaves the machine unresponsive, a reset or reboot may be necessary; saved source can then be loaded again.

Run with R

Enter:

R

On Odin Dev.2k, R executes the assembled program and then shows an inspection screen containing CPU registers, flags and memory rows.

What we deliberately changed

Our program deliberately loaded A with $42 and HL with $6000. Odin therefore showed values consistent with:

AF = 42A0
HL = 6000

AF is displayed as a 16-bit pair. The first byte is A, so 42 tells us that our LD A,$42 instruction worked. The second byte is F. At this point we had not deliberately recalculated the flags, so $A0 was inherited state rather than a result we intended to study.

What PC was doing while this tiny program ran

Using the bytes we already inspected, we can sketch the instruction flow. This is a conceptual view; Odin and the CPU handle the details automatically.

$6000: 3E 42       LD A,$42       ; 2 bytes
$6002: 21 00 60    LD HL,$6000    ; 3 bytes
$6005: C9          RET            ; 1 byte

The CPU begins at the first instruction, consumes the bytes belonging to it, and moves to the next instruction address. RET then changes the normal sequence by restoring the saved return address.

Why the HL memory row was so useful

Because HL contained $6000, Odin's HL-based memory row pointed directly at our own program. It showed:

3E 42 21 00 60 C9

This connects three different views of the same program: the source we typed, the address Odin assigned, and the machine-code bytes stored in memory.

Expected results for the first successful program

If you entered the same source on Odin Dev.2k, these are useful comparison points. Unrelated register values may differ because our code does not deliberately set them.

CheckExpected result
T symbol tablestart resolves to $6000
M $6000Begins 3E 42 21 00 60 C9
A after R$42
HL after R$6000
HL memory rowBegins 3E 42 21 00 60 C9
F in the LD-only testDo not treat the inherited value as a deliberate arithmetic result

If an important result differs, stop and compare the source line by line rather than pressing on.