
Naviagtion
Home
|
Z8 Cross Overlay Overview
Introduction
Don't be fooled by its name thinking the Z8 is a little brother of the Z80 family!
To my humble opinion quite the opposite is true!
There are too many benefits to the Z8 to be mentioned here. The most important ones are mentioned above. Comparing the Z8 with the ever so popular Intel 8051 makes you wonder why Intel won the race! The 8051 doesn't even come close! Why is the absence of a dedicated Accumulator so efficient? Because it reduces the need to move data in and out of the Accumulator to be able to perform an operation on the data. Let me give you an example: First we take a look at how an 8051 shifts a 16-bit number 1 bit to the left.
CLR C
MOV A,R3
RLC A
MOV R3,A
MOV A,R2
RLC A
MOV R2,A
And now the way the Z8 would do the same thing.
RCF
RLC R3
RLC R2
Does this require any explanation?!
The 8051 needs 7 instructions, where the Z8 is satisfied with only 3!
If you don't count the clearing of the carry flag, it is a 3:1 ratio, simply because the Z8 doesn't have to move the data in and out of the Accumulator.
CLR C
MOV A,R3 Shift once
RLC A
MOV R3,A
MOV A,R2
RLC A
MOV R2,A
MOV A,R3 Shift again
RLC A
MOV R3,A
MOV A,R2
RLC A
MOV R2,A
MOV A,R3 And again
RLC A
MOV R3,A
MOV A,R2
RLC A
MOV R2,A
And now the Z8 code.
RCF
RLC R3 Shift once
RLC R2
RLC R3 Shift again
RLC R2
RLC R3 And again
RLC R2
I'm sorry, maybe I've got a bit carried away by the beauty of this processor. Does it show that I'm a little biased? Programming ModelThe programming model below shows the unusual structure of the Z8 processor. I only include a little summary about the features of the Z8'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.
The first thing we should notice is the absence of a dedicated Accumulator because every location of the internal RAM may be used as Accumulator. The internal memory is divided into 16 banks of 16 registers each. All the internal RAM memory in the center column can be accessed directly, except bank $Ex.
One of the 16 banks can be selected as the working register bank, which enables short addressing of its 16 individual registers.
This is shown in the left column, where register bank $4x is selected.
Only working registers can be used as indirect/indexed addressing pointers, pointing to internal or external memory.
Two adjacent working registers can be concatenated to form a 16-bit pointer register.
The most significant byte of the target address is always located in the even numbered working register, while the least significant byte is located in the next odd numbered working register.
Not all register banks are always available on all Z8 devices. And some devices may even have more memory, which will be bank switched to maintain addressing compatibility. Please refer to the proper manual to see what memory is available.
There are three special banks.
The lowest 4 bytes of bank $0x are assigned to the 4 standard I/O ports of the Z8 and therefore not to real RAM.
This doesn't mean however that they can't be used as Accumulator!
Serial Input Output register
This register is used to pass data to and from the serial port.
Reading this register reads the data that was serially clocked in.
Writing to it sets the data to be shifted out of the serial port.
Timer control registers TMR ($F1), T1 ($F2), PRE1 ($F3), T0 ($F4) and PRE0 ($F5) These registers are used to control the 2 basic timers on the Z8. A description of the timers is beyond the scope of this brief description though. Please refer to the user manual for all the details. Port configuration registers P2M ($F6), P3M ($F7) and P01M ($F8)
These three registers are used to select the input/output configuration of the 4 basic I/O ports on a Z8 controller.
The bits on port 2 and 3 can be individually set to be an input or an output, dictated by the P2M and P3M registers.
Interrupt control registers IPR ($F9), IRQ ($FA) and IMR ($FB) The Z8 has a powerful interrupt system. Interrupts can be serviced automatically via the interrupt vectors, or can be polled.
The Interrupt Mask Register (IMR) determines which interrupts are enabled.
A vectored interrupt service routine is only possible when its associated mask bit is set.
Describing all interrupt capabilities of the Z8 is beyond the scope of this brief description, so please refer to the appropriate manuals for details. The FLAGS register (Address $FC) The FLAGS register contains 8 system flags:
Register set Pointer RP (Address $FD)
The 4 most significant bits determine which register bank is to be used.
After a hardware reset the RP register is cleared, effectively activating working register set $0x.
Working registers are addressed with only 4 bits, whereas all other internal memory is addressed using 8 bits. This makes the working registers faster. Apart from being faster the working registers have other privileges. They can be joined together to form 16-bit registers and they can be used as pointers.
The SB-Assembler can translate label names automatically to working registers.
To be able to do this the SB-Assembler needs to know what the currently expected working register bank is.
This is done with the .RP directive, which is added by the Z8 Cross overlay.
Stack pointer SPL and SPH (Addresses $FF and $FE)
The stack on a Z8 can be located in internal or in external RAM memory.
In case the stack is located in external RAM both stack pointer registers are concatenated to form a 16-bit pointer.
When the stack is located in internal RAM memory only SPL is used as stack pointer.
This frees the SPH register, which can then be used like any other internal RAM memory byte.
During a Push operation the stack pointer is decremented first and then the data is stored at the address pointed to by the stack pointer.
This means that the stack pointer always points to the last byte pushed on the stack.
A Pull operation loads the data first, then increments the stack pointer.
CALL instructions store the address of the next instruction to be executed after a return on the stack, pushing its LSB first. Interrupts also push the Flags register on the stack, after pushing the return address. 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.
There is one odd thing to mention about the Z8.
When the device comes out of reset it will start execution of the program from address $000C, instead of $0000, which you might have expected.
TimingIn Version 3 of the SB-Assembler you can display the instruction times of each instruction by turning on the list option TON. The shown values are the number of clock cycles each instruction takes. Reserved Words
The SB-Assembler Z8 cross overlay has some reserved words.
Reserved words are all register names and condition codes.
You better avoid these reserved words when you assign your own labels.
E.g. don't call your labels R0 or RR12.
Here's the list of all reserved words:
R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15,
Special FeaturesRegister addressing Internal memory of the Z8 consists of 16 banks of 16 registers each. These registers are simply a small portion of internal memory that can be addressed with only 4 bits, instead of 8. Many instructions which use registers are only 1 byte long, resulting in compact code and fast execution time.
Selecting one of the 16 banks is done by writing the desired register bank number into the RP register (upper 4 bits).
Registers are called R0 to R15 by default.
The SB-Assembler allows you to give your registers more meaningful names by assigning labels to the appropriate RAM addresses.
The SB-Assembler will automatically use register addressing whenever a label is used where register addressing is available.
The assembler will use register or register pair mode whenever the addressing mode is available and the effective address is within the currently selected register bank.
The address must be resolved completely to know for sure that it will be a register addressable memory location, therefore the expression may not contain any forward referenced labels.
The worst case is expected when a forward referenced label is used, which means that the assembler will use an 8-bit address for internal memory.
There is one situation where the assembler is unable to translate the address to a register (pair). Both instructions LDCI and LDCE need two parameters, an indirect register and an indirect register pair. The problem is though that the two operands can be reversed depending on which one is the source or destination. The example below explains the problem:
LDCI @R1,@RR2 It is perfectly clear who is who
LDCI @RR2,@R1 This is clear too
LDCI @POINTER,@RR2 Even this is clear
LDCI @RR2,@POINTER No problem with this either
LDCI @PNTR1,@PNTR2 But who is who here?
Only with these two rarely used instructions you may not use a label name (or expression) to refer to the first operand if it must be a register pair.
So if the first operand isn't an explicit register pair, e.g. RR2, then the assembler will assume that 1st operand is a register and the 2nd operand is a register pair.
CMOS instructions
Some Z8 versions have a few extra instructions to limit power consumption during inactive times.
These instructions are HALT, STOP and WDT.
The SB-Assembler Z8 cross knows these instructions too.
But you shouldn't use these instructions unless you are absolutely certain that the processor you're programming really understands them.
Differences between Version 2 and Version 3 Version 3 of the Z8 cross has a few additional differences with Version 2.
Overlay InitializationThree things are set while initializing the Z8 overlay every time it is loaded by the .CR directive.
.RP Register bank PointerSyntax: .RP expression Function: The .RP directive is used to tell the SB-Assembler what the currently selected register bank is. Knowing this enables the SB-Assembler to select between register or direct addressing mode automatically. The SB-Assembler will use register addressing mode whenever the address and the instruction both allow it. Explanation:
One of the features of the Z8 SB-Assembler is the ability to select the most economical addressing mode for internal RAM.
You can assign any name to an internal RAM location and the SB-Assembler will use register addressing mode whenever it can.
In order to do this the SB-Assembler must know which one of the 16 possible register banks is selected at the moment.
You can use the .RP directive to tell the SB-Assembler what register bank is selected.
The expression must evaluate to a value from $00 to $F0, in increments of $10 and may not contain forward referenced labels.
Other values will result in a "Range error".
Please note that you can use a complete expression to indicate a direct address, even if it is translated into a register automatically.
But it is not possible to use a register name in any expression.
The Z8 assembler does not allow you to force register or direct addressing modes with < and > symbols. But you can always use normal register names to force register addressing mode, e.g. R3 or RR8. Examples: 0014- LABEL .EQ $14 Just a location 0000- 0000- .RP $00 Assume register bank $00 0000-31 00 SRP #$00 Select bank $00 on Z8 0002-2C 12 LD R2,#$12 Load R2 with $12 0004-2C 12 LD $02,#$12 Does the same 0006-E6 14 12 LD $14,#$12 Load RAM address $14 with $12 0009- 0009- .RP $10 Now assume register bank $10 0009-31 10 SRP #$10 Select bank $10 on Z8 000B-2C 12 LD R2,#$12 Load R2 with $12 000D-E6 02 12 LD $02,#$12 This is not a register anymore! 0010-4C 12 LD $14,#$12 Load register R4 with $12 0012-4C 12 LD LABEL,#$12 Works also with expressions 0014-E6 04 12 LD FORWARD,#$12 But not with forward referenced! 0014- 0014- FORWARD .EQ $14 Please note that the assembler would still generate the same code when the SRP $10 instruction at address $0009 was omitted. But in real life R4 would point to RAM address $04 in the instruction at address $0010 and not the intended address $14!
Differences With Other AssemblersThere are some differences between the SB-Assembler and other assemblers for the Z8 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.
|