
Naviagtion
Home
|
Z80 Cross Overlay Overview
IntroductionThere is no doubt about it, the Z80 is one of the most popular 8-bit microprocessors ever. It was designed by a few former Intel employees, who enhanced the design of the Intel 8080. Being backward compatible with the 8080 ensured the Z80 of a large software library right from the start.
To my opinion, but who's asking me, the Z80 is not the easiest processor to start with because of some inconsistencies in the command syntax.
This doesn't effect the usefulness of the processor though, only programming it may be a bit odd.
I also must admit that there are features in the Z80 that are hardly ever found on any other processor. Especially the interrupt capabilities are state of the art, even by today's standards! Also the Z80 family peripheral chips make the competitors byte the dust! Later quite some interesting complete micro controller systems were built around the Z80. Programming ModelThe programming model in the picture below shows the most important registers of the Z80 processor. I only include a little summary about the features of the Z80's programming model here. It is not my intention to make the original documentation obsolete, so please refer to the original documentation for further details.
All working registers are shadowed by an identical second set. These shadow registers can be used for very fast context switching during interrupts, or can simply expand the standard register set. Special instructions exist to exchange the two register sets. The Accumulator
The Accumulator is the most important register for 8 bit arithmetic operations.
Its standard name is A, which is a reserved word.
The Program Status Word The Flag register contains 6 system flags:
General Purpose Registers Six additional general purpose 8-bit registers assist the Accumulator. These registers can be concatenated to form three 16-bit register pairs. Especially the HL pair is used as a data pointer to transfer data to and from memory and it can be used for a limited number of 16-bit arithmetic functions. Index register IX and IY New to the Z80, compared to the 8080, are two identical index registers. These two register assist in indexed addressing of data and supplement the use of the HL pair. Memory refresh register R The Z80 has a refresh register which enables easy interfacing with DRAM memory. Seven bits of the R register are incremented after each instruction fetch. The eighth bit remains as set by a previous LD R,A instruction. The I register The I register provides the upper 8 address bits during interrupt vectoring, while the interrupting peripheral device supplies the lower 8 address bits. This way interrupt service routines may be located anywhere in memory. The least significant bit of the vector address is always 0, which means that all interrupt service routines should start at an even address. The Stack Pointer The stack on an Z80 can be located anywhere in RAM memory, pointed to by the stack pointer SP. Every time something is pushed on to the stack, the SP pointer is decremented, so the stack is growing down in memory.
Stack operations are always performed with register pairs.
Naturally a pop from the stack has just the opposite effect:
The Program Counter The program counter PC is normally incremented after fetching each instruction or operand byte during program execution. The only way you can change this behaviour is with the jump, call and return instructions. Also interrupts can change the program counter's value. TimingVersion 3 of the SB-Assembler can display instruction timing information when the TON list option is switched on. The indicated values are the number of T cylces each instruction takes. Reserved Words
The SB-Assembler Z80 cross overlay has a few reserved words.
Reserved words are all register names.
You better avoid these reserved words when you assign your own labels.
E.g. don't call your labels IX, or A or H.
Here's the list of all reserved words: A, F, B, C, D, E, H, L, I, R, BC, DE, HL, IX, IY, SP, NC, Z, NZ, PE, PO, P, M Special FeaturesAddressing modes In the introduction I already mentioned that the Z80 assembler doesn't always follow the same syntax rules for equivalent instructions. I used the ADD and SUB example there to show you what I meant. The SB-Assembler Z80 cross is very forgiving when it comes to these inconsistencies. In the example below you see both operand notations for the ADD and SUB instructions.
ADD A,DATA Normal notation according to Zilog
ADD DATA Has the same effect as the line above
ADD A,#DATA This is also possible
ADD #DATA And this too
SUB DATA Normal notation according to Zilog
SUB A,DATA This is accepted just the same
As you can see in the example above you may also use the immediate operand identifiers, although it is not absolutely necessary. The SB-Assembler will automatically use 8 or 16-bit values, depending on the instruction's needs. If you want another part of the 32-bit number to be loaded immediately into any of the registers or register pairs you could use the other immediate mode identifiers /, =, or \. The official indexed addressing mode using one of the new index registers is (IX+offset), where offset can be an 8-bit positive or negative number. If that number is 0 it may be omitted in the SB-Assembler. So the official notation (IX+0) can also be written as (IX). Compound instruction
Another peculiar property of the Z80, inherited from the 8080, is the lack of a Clear Carry instruction.
There is an instruction to set the carry and there is one to complement the carry, two instructions that I personally rarely use.
But an instruction to clear the carry is strangely missing.
Restart Vectors
Originally the 8 possible, 8080 compatible, restart vectors are numbered from 0 to 7 in other assemblers.
This is very inconvenient, because you can't let the restart vector point to the appropriate vector address by using their label names.
Please note that the value of the operand after an RST instruction may not be any other value than 0 to 7, $08, $10, $18, $20, $28, $30 or $38. Any other value will result in a "Range error" to be reported. Overlay InitializationTwo things are set while initializing the Z80 overlay every time it is loaded by the .CR directive.
Differences With Other AssemblersThere are some differences between the SB-Assembler and other assemblers for the Z80 processor. These differences require you to adapt existing source files before they can be assembled by the SB-Assembler. This is not too difficult though, and is the (small) price you have to pay for having a very universal cross assembler.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||