DYSTOPIANPIXEL

Inspect machine code

Connect the source instructions to the actual bytes produced by Odin.

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 11

Inspect the actual machine code

Use M to look at memory

Enter:

M $6000

The beginning of memory contains:

3E 42 21 00 60 C9

These are the actual bytes that the Z80 will execute.

Assembly sourceMachine-code bytes
LD A,$423E 42
LD HL,$600021 00 60
RETC9

Opcode and operand

An instruction often consists of an opcode plus one or more operand bytes. The opcode identifies the operation. The operand supplies the value or address involved.

For example:

Byte in 3E 42Purpose
$3EOpcode for LD A,n
$42Immediate operand

You do not need to memorise opcode numbers. Odin exists so that we can write readable mnemonics instead.

Z80 instructions are not all the same length

A Z80 instruction can occupy a different number of bytes depending on the instruction and its operands. This is called variable-length instruction encoding.

InstructionBytes in our example
LD A,$422 bytes: 3E 42
LD HL,$60003 bytes: 21 00 60
RET1 byte: C9

This is why our first instruction begins at $6000, the second begins at $6002, and RET begins at $6005. The CPU advances through however many bytes belong to each instruction.

You do not need to memorise instruction lengths. Odin assembles the code for us. Understanding that lengths vary simply helps memory dumps and addresses make sense.