Many people have e-mailed me telling me that they are unclear with registers. Chances are if you are new to programming, or computers in general, you probably aren't clear on the concept of registers either. In that case, I have dedicated the next few tutorials to registers, their uses, and their specific functions.
You have probably learned from past experiences, that most data is stored in the user-memory (RAM) of the calculator. This is true, but lets say you wanted to manipilate (add/subtract/multiply/divide/etc.) a number you stored in user-memory. It's possible, but it is hard and access to the user-memory is rather slow. So the computer people decided to create fast-access areas of memory in the CPU itself just for storing data and variables in. They called these areas of memory "Registers".
There are many kinds of registers for the Z80. No, you can't pick the one you like the most at the moment and you that one, well, sometimes you can. The names of the individual registers are - a, b, c, d, e, h, l. Each register (the one lettered ones) are themselves 8-bit. This means you can store 1 byte of information in them. For example, you can store decimal numbers 0-255 in them. The "a" register is special. It is also called the accumulator. When you use the cp command, it checks this register. The "a" register will be used in many commands.
You have also probably seen af, hl, de, bc used instead of a, b, c, d, e, h, I. These are also registers. If you wanted to hold numbers greater than 255 (Decimal numbers 0-65536) , you would use these registers because they are 16-bit registers. They can store 2 bytes of data.
Here's a brief description of the registers:
A,B,C,D,E 8-bit registers AF 16-bit register containing A and flags BC 16-bit register containing B and C DE 16-bit register containing D and E HL 16-bit register used for addressing F 8-bit Flag register I 8-bit Interrupt Page address register IX,IY 16-bit index registers PC 16-bit Program Counter register R 8-bit Memory Refresh register SP 16-bit Stack Pointer register
Let's say you wanted to load the value 4 into the "a" register, the syntax would be:ld a,14 The ld, command stands for load. So you are loading the value 4 into the "a" register. The same syntax goes for loading values into any other register.
Now lets say you wanted to load 0235 into the register "hl". You would think this - ld hl,0235. That's right, sort of. "0235" could be a decimal, hex, or binary(maybe not) value. When assembling programs, TASM needs to know what kind of value it is. So you need to include an h for hexadecimal value, d for decimal, or b for binary after the value. So let's say the value "0235" was hexadecimal, the syntax would be:ld hl,0235h
Notice the h at the end. Or, instead of putting letters behind the value, you can out symbols in front of them to tell TASM what kind of values they are. You can put a % for binary values, and a $ for hexadecimal. So to use symbols, it would look like this for hexadecimal:ld hl,$0235
This is what it would look like for binary:ld hl,%0100101
Notice tht you leave out the letter when using symbols. When using decimal (Integers, whole numbers) no symbol or letter is needed before or after the value. This is because TASM will assume if no format is specified, that the value is a decimal value.Tutorial 18