Definition:
An indentifier or indicator of the location of data; for example an address, an algorithm for generating an address ,a code for generating an address or a destination or source designator.[1] : A useful suggestion or hint.[2]
INTRODUCTION
In this introduction to Z80 programming we focus on small, efficient routines, that provide maximum power in minimum size.
Such programs are small enough to be understood by reading a short functional desciption and by reading the annotated source code.
A library of short programs and subroutines is used to build complex programs with a modular structure.
This approach has benefit for robotic controllers,and small personal computers because of highly concentrated code coupled with modular structure.
A short review of the Z80 and the tools to write Z80 MC programs is required to establish a common terminology.
Z80 M/L
The most popular CPU chip in the world is …. you guessed it: the Z80!
It is a cheap, easy to use processor with a powerful instruction set for which alot of software has been written. It has found it’s way into numerous products , especially in personal computer and controller applications.
It is software upwardcompatible with older 8080 CPU but has much enhanced registers including a alternate set of main registers and new index registers.
The Z80 can execute 158 (not including the unofficial ones) different types of instructions.
In order to write Z80 software, it is essential to obtain a copy of the Z80 Data Book which contains a complete description and detailed references for the programmer.
What makes it tick? …. A simple description is the analogy of a human being reading a book of instructions with eyes to read and pencil and paper to write and a finger pointing to the first instruction on the top left corner of page 1. The book of instructions is the ROM , the pencil and notebook is the RAM and the finger is the program counter pointing to the first instruction after reset. The brain interprets the instruction, advances the finger to read the next part of the instruction, then tells the hand to turn several pages to point to a new instruction. VOILA, we have just executed a JP NN istruction with the finger pointing to new location NN. For human beings this is a slow boring task but for the CPU chip and memory it comes natural and FAST!
I would like to introduce the fundamental levels of computer operation and show how layer by layer the concept of the computer changes until we reach AI and beyond .
Assuming a Z80 personal computer (ie TS1000) and the Z80 Data Book, let’s look a bit closer at how we can deal more efficiently with CPU instructions, by using some of the powerful tools of the programming trade.
BINARY CODE
To begin, the most primitive representation of any program are the bytes in RAM or ROM which tell the CPU what to do. These are the instruction codes and data which mean everything to the CPU but very little to all but the most dedicated M/L enthusiast.
These bytes are the product of a multilevel programming environment and, other than the space they occupy, are of little interest to the programmer.
HEX CODE
The next level up , still quite primitive, is the world of M/L instructions and HEX codes asssembled by hand. All that is needed is a Z80 Data Handbook and some paper and you can, in theory, write a program which is then translated by hand into HEX or Decimal numbers which in turn are poked into memory.
With a M/L monitor HEX data can be directly entered into memory and utilities such as Block Move , HEX Dump and sometimes Disassembler are provided to view and manipulate data. It still requires hand assembly and although I have written a number of small programs (including a 100 byte Game of Life) with such tools but don’t recommend it It does however build an appreciation of the relations between High Level Language programming and the code that the CPU actually uses. Compact coding habits are acquired of necesity at this level.
ASSEMBLER
The first practical working level is the Assembler programming environment.
Symbolic names, used to replace physical values of data and program modules, allow the program to be written from the “Top Down”.
The programmer has more conceptual freedom when he can write programs without worrying about the details.