Lesson 2: Introduction to assembly and the Z80.

Right now I am going to assume that you have have some sort of programming knowledge, and if you don't, let me be the first to say assembly is not the best place to start. Others would dissagree, but thats how I feel. Well, let me start by saying, assembly is llike no other language. In fact, it's not much of a language at all. All an assmebly file is a long list of mnemonics and some parameters that the assmebler reads and converts to binary so the processor can use it. In assembly, fractions do not exist, negative numbers do not truly exist, and varibles dont exist. All you truly have is the processor and what it supplies, and the memory.

So what does the processor give us? Well, we will be woking wioth the Z80 processor, which is the cpu inside all TI-8x calcs excpet the 89. The 89 and the 92 use a different procesor and therefore, the stuff you learn in these lessons will be no good for those calcs, because rarely is assembly interchangable between processors. So, back to the Z80. What does it do for us? Well, everything. The thing we are going to be most concerned about is registers. Registers are what we store and minipulate data in on the Z80. The Z80 offers us the following registers: A,B,C,D,E,F,H,L,I,R,IX,IY,PC,and SP. 14 in total.(Actually thats not entirly true, there are more, but I will tell you about those later.) A is the special register, called the accumulator, or acc for short. B,C,D,E,H, and L are most of the time there just to hold data. F is the flag register, you will barely ever use F as a whole register. I is the interrupt vector, which we will get to later, R is the refresh register, also called the random register. IX and IY are special, and you wont use them much. PC is the program counter, in other words, it keeps track of which instrucion you are on, and SP is the stack pointer. YOU SHOULD NEVER TOUCH PC OR SP UNLESS YOU ARE TOTALLY SURE OF WHAT YOU ARE DOING. Storing data to them wil most likely result in a crash. I, if used at the wrong time can result in a crash also. The next thing you need to know is that the Z80 is an 8 bit processor, meaning each of those registers are 1 byte in size. (Except the 2 letter ones, they are 16 bit.) So, thinking back to that range of values, you can store only intigers between 0 and 255 in the acc. and all other 8 bit registers. Now, commonly you need more than 8 bits. You can get 16 bits of storage very easily. Just put two 8 bit registers together! There are restrictions though. . Only certain registers pairs are allowed. A goes with F to make AF, B with C to make BC, D and E make DE, and H and L make HL. Now dont think that this creates 4 more registers. If you have a value stored in B and then you store something to BC, the value that was in B is lost. See, you use the 2 register themselves, not just their names. When you have these 16 bir registers, they are not called 16 bit very often. Nor are they called 2 bytes. They are called a WORD. Why? I don't know. Why is 4 bits called a nibble? Who knows. Anyways, something you may want to know; the range of values for a word is 0-65535, or $0000-$FFFF. You can find the range of values for any amoun of bits by doing (2^n)-1. A word is 16 bits, and 2^16 is 65536. Subtract 1 and you end up with 65535.

The other thing that you have is the memory. Up above, where I said variables don't exist, I was lying. They really don't, but there are ways to make it seem like there are. If you want to count registers as varibles, be my guest, but registers are so few, that to keep just one dedicated to one single thing, like a variable is, makes a program near to impossible to wirte. What you can do is throw the contents of variables into the calc's memory. Then when you need it, you dump it back to a register, change it, and trow it in the memory again. Just so you know, the only 8 bit register that can communicate with the memory is the acc. Each byte of the calculator's memory is assigned its very own number called an address. Since PC is a WORD sized reigster, there is only 64k of addressable memory. But wait! There is 32k of ram and 128k of rom!!! How do you cram all that into 64k? Here is the soultion: there is only 32k of rom available at a time. There are 8 rom pages. $0000-$3FFF are always available, $4000-$7FFF is the current page, and $8000-$FFFF is th ram. It is now time to move on to the next lesson, and learn out first instruction.

1