Your place is saved automatically on this browser.
Overview
This tutorial is the starting point for building Next Asset Lab in Z80/Z80N assembly on the ZX Spectrum Next. We begin by checking the exact Odin environment running on the real machine, then build the essential foundations needed to understand what the assembler, CPU and debugger are showing us. No previous assembly-language knowledge is assumed.
By the end of the tutorial, you will have created, saved, assembled, inspected, run, exported and re-imported a small Odin program. Along the way you will learn what bits, nibbles, bytes and 16-bit values are; why hexadecimal is so widely used in assembly language; how memory addresses, registers, pointers, the accumulator and flags fit together; and how readable assembly source becomes the machine-code bytes that the Z80 actually executes. The examples are deliberately small so that every result can be understood and checked before the project moves on to more advanced Z80 and ZX Spectrum Next topics.
Learning objectives
- Recognise the difference between the NextZXOS command prompt, the Odin Monitor and the Odin Editor.
- Identify the exact Odin build being used and the commands that are really available.
- Understand decimal, binary and hexadecimal notation and why hexadecimal is so common in assembly language.
- Understand bits, nibbles, bytes and 16-bit values.
- Understand the idea of memory, addresses and machine-code bytes.
- Understand what CPU registers are and why the Z80 has both 8-bit registers and 16-bit register pairs.
- Understand what the accumulator is and why the A register is special.
- Understand what flags are, what the F register contains and why some instructions change flags while others do not.
- Create, edit, save, assemble, inspect, run, export and re-import a tiny Odin program.
- Connect the source code you type to the actual bytes that the Z80 executes.
What we are building
This first tutorial does not attempt to build a screen, sprite editor, project loader or NEX executable. That would be too much too soon. Instead, we are building the development foundation on which the real Next Asset Lab will depend.
By the end of the chapter, you will have a real Odin source file, a portable text export of that source, and a very small program that you have assembled and inspected on the ZX Spectrum Next itself. More importantly, you will understand what the numbers and displays in Odin are telling you.
The code is deliberately tiny because the learning target is not the number of instructions typed. The learning target is the connection between source code, CPU registers, memory addresses, machine-code bytes and the debugging information Odin shows.
What this first tutorial deliberately does not teach
This is only Tutorial 1. It is intentionally foundational. We will not try to squeeze the whole Z80, the whole ZX Spectrum Next, or the whole Next Asset Lab architecture into one chapter.
Topics such as signed two's-complement arithmetic, detailed stack manipulation, addressing modes, alternate registers, interrupts, cycle timing, calling conventions, Z80N extensions, NextRegs, MMU paging, Layer 2, Tilemap, sprites, palettes, NextZXOS file APIs and NEX packaging belong in later tutorials.
A topic may be mentioned briefly when it helps explain something we can already see — for example, RET uses the stack — but we will not teach the full subject until the reader has the foundations needed to understand it properly.
Required prior knowledge
None beyond basic computer use. You do not need to know assembly language, binary or hexadecimal before starting this chapter. If you have used BASIC, C, Python or another language, some ideas will feel familiar, but the chapter does not assume that experience.
How to use this tutorial
Work through the chapter on the real ZX Spectrum Next rather than reading it as theory only. Type the short examples yourself, stop when a result is different, and use Odin's own inspection facilities to confirm what happened.
Do not worry about memorising hexadecimal tables, opcodes or every register use on the first pass. The important first skill is being able to recognise what kind of thing you are looking at and know where to look when you forget.
A good learning rhythm
This rhythm is intentionally slower than copying a long finished listing, but it builds the understanding needed to debug a real application later.
Explore the sections
Your Odin environment
Recognise the three command environments, check Dev.2k and establish a reliable editing and saving routine.
Read section NEXT ASSET LAB / PART 02What the CPU does
Follow the fetch, decode and execute cycle, and distinguish the assembler from the processor.
Read section NEXT ASSET LAB / PART 03Number systems
Learn why decimal, binary and hexadecimal appear together, with small conversions you can check.
Read section NEXT ASSET LAB / PART 04Bits, bytes and words
Understand nibbles, eight-bit values, sixteen-bit values and their high and low parts.
Read section NEXT ASSET LAB / PART 05Memory and addresses
Tell an address from its contents and see how the processor finds bytes in memory.
Read section NEXT ASSET LAB / PART 06CPU registers
Meet the Z80 registers, register pairs, pointers and the programme counter.
Read section NEXT ASSET LAB / PART 07The accumulator
Understand the A register and how it holds values for simple calculations.
Read section NEXT ASSET LAB / PART 08Understanding flags
Read the individual flags in F and check your foundations before typing the first source file.
Read section NEXT ASSET LAB / PART 09Your first source file
Create, edit and save a tiny Odin programme, with each label and instruction explained.
Read section NEXT ASSET LAB / PART 10Assemble the source
Assemble successfully, choose the starting address and practise recognising an assembly error.
Read section NEXT ASSET LAB / PART 11Inspect machine code
Connect the source instructions to the actual bytes produced by Odin.
Read section NEXT ASSET LAB / PART 12Little-endian byte order
See why a sixteen-bit value is stored with its low byte first.
Read section NEXT ASSET LAB / PART 13Run and inspect
Run the programme and explain the register, memory and flags displays.
Read section NEXT ASSET LAB / PART 14Export and import
Save native Odin source, export ordinary text and import it again without confusing the formats.
Read section NEXT ASSET LAB / PART 15Arithmetic and flags
Use two small additions to see how arithmetic changes A and the flags.
Read section NEXT ASSET LAB / PART 16Exercises and next steps
Work through exercises, answers and troubleshooting, then check that you are ready to continue.
Read section