5.1 Functional summary.
Z8 instructions can be divided functionally into the following eight groups:
Load instructions.
| Mnemonic | Operands | Action |
|---|---|---|
| CLR | dst | dst := 0 |
| LD | dst, src | dst := src |
| LDC | dst, src | dst := src (src in code memory) |
| LDE | dst, src | dst := src (src in external memory) |
| POP | dst | dst := [SP] INC (SP) |
| PUSH | src | DEC (SP) [SP] := src |
Arithmetic instructions.
| Mnemonic | Operands | Action |
|---|---|---|
| ADC | dst, src | dst := dst + src + Carry |
| ADD | dst, src | dst := dst + src |
| CP | dst, src | IF dst>src THEN Carry := TRUE ELSE Carry := FALSE |
| DA | dst | Decimal adjust |
| DEC | dst | dst8 := dst8 - 1 |
| DECW | dst | dst16 := dst16 - 1 |
| INC | dst | dst8 := dst8 + 1 |
| INCW | dst | dst16 := dst16 + 1 |
| SBC | dst, src | dst := dst - src - Carry |
| SUB | dst, src | dst := dst - src |
Logical instructions.
| Mnemonic | Operands | Action |
|---|---|---|
| AND | dst, src | dst := dst AND src |
| COM | dst | dst := NOT dst |
| OR | dst, src | dst := dst OR src |
| XOR | dst, src | dst := dst XOR src |
Program control instructions.
| Mnemonic | Operands | Action |
|---|---|---|
| CALL | dst | PUSH PC JUMP dst |
| DJNZ | r, dst | DEC (r) IF r # 0 THEN JUMP dst |
| IRET | POP FLAGS POP PC |
|
| JP | cc, dst | IF cc = TRUE THEN JUMP dst |
| JR | cc, dst | IF cc = TRUE THEN JMP (PC + dst) |
| RET | POP PC |
Bit manipulation instructions.
| Mnemonic | Operands | Action |
|---|---|---|
| TCM | dst, src | Test complement under mask |
| TM | dst, src | Test under mask |
| AND | dst, src | Bit clear |
| OR | dst, src | Bit set |
| XOR | dst, src | Bit complement |
Block transfer instructions.
| Mnemonic | Operands | Action |
|---|---|---|
| LDCI | dst, src | dst := [src] from program memory INC (src) |
| LDEI | dst, src | dst := [src] from external memory INC (src) |
Rotate and shift instructions.
| Mnemonic | Operands | Action |
|---|---|---|
| RL | dst | Rotate left |
| RLC | dst | Rotate left through carry |
| RR | dst | Rotate right |
| RRC | dst | Rotate right through carry |
| SRA | dst | Shift right arithmetic |
| SWAP | dst | Swap high and low nibble |
CPU control instructions.
| Mnemonic | Operands | Action |
|---|---|---|
| CCF | Carry := NOT Carry | |
| DI | Disable interrupts | |
| EI | Enable interrupts | |
| NOP | Do nothing | |
| RCF | Carry := 0 | |
| SCF | Carry := 1 | |
| SRP | src | RP := src |
5.2 Processor flags.
The FLAGS register (R252) informs the user about the current status of the Z8. The flags and their bit positions in the FLAGS register are shown in figure 5.1:
R252 FLAGS register
| D0 | User flag 1 | F1 | |
| D1 | User flag 2 | F2 | |
| D2 | Half carry | H | |
| D3 | Decimal adjust | D | |
| D4 | Overflow | V | |
| D5 | Sign | S | |
| D6 | Zero | Z | |
| D7 | Carry | C |
The Z8 flag register contains six bits of status information which are set or cleared by CPU operations. Four
of these (C, V, Z and S) can be tested for use with conditional JUMP instructions. Two flags (H and D) cannot
be tested and are used for BCD arithmetic.
The two remaining bits in the FLAGS register (F1 and F2) are available to the user but they must be set or
cleared by instruction and are not usable for conditional jumps.
As with bits in the other control registers, FLAGS register bits can be set or cleared by software. However,
this is only possible when instructions are used that do not influence the FLAGS register as an outcome of
their own execution.
5.2.1 CARRY flag (C).
The CARRY flag is set to '1' whenever the result of an arithmetic operation generates a carry out of or borrow
into the high order bit 7; otherwise the CARRY flag is reset to '0'.
Following rotate and shift instructions, the CARRY flag contains the last value shifted out of the specified
register.
An instruction can set, reset or complement the CARRY flag. IRET changes the value of the CARRY flag when the
saved FLAGS register is restored.
5.2.2 ZERO flag (Z).
For arithmetic and logical operations, the ZERO flag is set to '1' if the result of that operation is ZERO.
Otherwise the ZERO flag is set to '0'.
If the result of testing bits in a register is zero, the ZERO flag is set to '1'; otherwise the flag is
cleared.
If the result of a rotate or shift instruction is zero, the ZERO flag is set to '1'; otherwise the flag is set
to '0'.
IRET changes the value of the CARRY flag when the saved FLAGS register is restored.
5.2.3 SIGN flag (S).
The SIGN flag stores the value of the most significant bit of a result following arithmetic, logical, rotate
or shift operations.
When performing arithmetic operations on signed numbers, binary 2's complement notation is used to represent
and process information. A positive number is identified by a '0' in the most significant bit position, and
therefore the SIGN flag is also ZERO.
A negative number is identified by a '1' in the most significant bit position and therefore the SIGN flag is
also ONE.
IRET changes the value of the CARRY flag when the saved FLAGS register is restored.
5.2.4 Overflow flag (V).
For signed arithmetic, rotate and shift operations, the OVERFLOW flag is set to '1' when te result is greater
than the maximum possible positive number (i.e. >127) or smaller than the maximum possible negative number
(i.e. <-128) that can be represented in two's complement form. The flag is reset to ZERO if no overflow
occurs.
Following logical operations, the OVERFLOW flag is set to '0'.
IRET changes the value of the CARRY flag when the saved FLAGS register is restored.
5.2.5 Decimal adjust (D).
The DECIMAL ADJUST flag is used by for BCD arithmetic. Since the algorithm for correcting BCD operations is
different for addition and subtraction, this flag specifies what type of instruction was last executed so that
the subsequent DA (Decimal adjust) operation can function properly. Normally, the DECIMAL ADJUST flag cannot
be used as a test condition.
After a subtraction, the DECIMAL ADJUST flag is set to '1' and following an addition it is cleared to '0'.
IRET changes the value of the CARRY flag when the saved FLAGS register is restored.
5.2.6 Half carry flag (H).
The HALF CARRY flag is set to '1' whenever an addition generates a carry out of bit 3 (BCD overflow), or a
subtraction generates a borrow into bit 3. The HALF CARRY flag is used by the Decimal adjust (DA) instruction
to convert the binary result of a previous addition or subtraction into the correct BCD result. As in the case
of the DECIMAL ADJUST flag, the user does not normally access this flag.
IRET changes the value of the CARRY flag when the saved FLAGS register is restored.
5.3 Condition codes.
Flags C, Z, S and V control the operation of the conditional jump instructions. Sixteen frequently useful functions of the flag settings are encoded in a 4 bit field called the CONDITION CODE (cc), which forms bits 4-7 of the conditional instructions. Section 5.4.2 lists the conditional codes and the flags settings they represent.
5.4 Notation and binary encoding.
In the detailed instruction descriptions that make up the rest of this chapter, operands and status flags are
represented by a notational shorthand. Operands (condition codes and address modes) and their notations are as
follows:
| Notation | Address mode | Actual operand/range |
|---|---|---|
| cc | Condition code | See condition code list below |
| r | Working register only | Rn : where n = [0..15] |
| R | Register Rn or working register Rw | n = [0..127] or [240..255] w = [0..15] |
| RR | Register pair RRn or working register pair RRw |
n = even number in range [0..126] w = even number in range [0..14] |
| Ir | Indirect working register only | @ Rn where n = [0..15] |
| IR | Indirect 'register' or 'working register' |
@ reg where reg = [0..127] or [240..255] @ Rn where n = [0..15] |
| Irr | Indirect 'working register pair' only | @RRp with p = [0..14] even only |
| IRR | Indirect 'register pair' RRn or 'working register pair' RRw |
n = [0..126] and [240..254] even only w = [0..14] even only |
| X | Indexed | reg (Rn): reg = [0..127] or [240..255] and n = [0..15] |
| DA | Direct address | address = [0..65535] |
| RA | Relative address | address = [-128..+127] relative to current PC |
| IM | Immediate data | data = [0..255] |
Additional symbols are:
| Meaning | |
| [a..b] | a range between a and b including the values 'a' and 'b' |
| dst | destination operand |
| src | source operand |
| @ | indirect address prefix |
| SP | Stack pointer |
| PC | Program counter |
| FLAGS | FLAGS register (R252) |
| RP | Register pointer (R253) |
| IMR | Interrupt mask register (R251) |
| # | Immediate operand prefix |
| % | Hexadecimal number prefix |
| 0x | Hexadecimal number prefix |
| OPC | Opcode |
| ASM | Assembly language |
| OBJ | Object code |
Assignment of a value is indicated by the symbol ':='. For example:
dst := dst + srcindicates that the source data is added to the destination data and the result is stored in the destination location. The notation 'addr (n)' is used to refer to bit 'n' of a given location. For example:
dst (7)refers to bit 7 of the destination operand.
5.4.1. Assembly langage syntax.
For proper instruction execution, Z8 PLZ/ASM assembly language syntax requires that "dst, src" be specified,
in that order. The following instruction descriptions show the format of the object code produced by the
assembler. This binary format should be followed by users who prefer manual program coding or who intend to
implement their own assembler.
Example: If the contents of register 0x43 and 0x08 are added and the result stored in 0x43 the assembly syntax
and resulting object code are:
| ASM: | ADD | 0x43, | 0x08 | (ADD dst, src) |
| OBJ: | 04 | 08 | 43 | (OPC src, dst) |
In general, whenever an instruction format requires an 8 bit register address, that address can specify any register location in the range [0..127], [240..255] or a working register [R0..R15]. If, in the above example, register 0x08 is a working register, the assembly syntax and resulting object code will be:
| ASM: | ADD | 0x43, | R8 | (ADD dst, src) |
| OBJ: | 04 | E8 | 43 | (OPC src, dst) |
For a more complete description of assembler syntax refer to the Z8 PLZ/ASM assembly language manual (publication nr 03-3023-03) and ZSCAN 8 User's tutorial (publication nr 03-8200-01).
5.4.3 Condition codes and flag settings.
The condition codes and flag settings are summarized in the following tables. Notation for the flags and how they are affected are as follows:
C Carry flag 0 cleared to ZERO
Z Zero flag 1 set to ONE
S Sign flag * set or cleared according
to operation
V Overflow flag
D Decimal adjust flag - not affected
H Half-carry flag X undefined
| Binary | Mnemonic | Meaning | Flag settings |
| 0000 | F | Always FALSE | - |
| 1000 | Always TRUE | - | |
| 0111 | C | Carry | C = 1 |
| 1111 | NC | No carry | C = 0 |
| 0110 | Z | Zero | Z = 1 |
| 1110 | NZ | Not zero | Z = 0 |
| 1101 | PL | Plus | S = 0 |
| 0101 | MI | Minus | S = 1 |
| 0100 | OV | Overflow | V = 1 |
| 1100 | NOV | No overflow | V = 0 |
| 0110 | EQ | Equal | Z = 1 |
| 1110 | NE | Not equal | Z = 0 |
| 1001 | GE | Greater than or equal | (S XOR V) = 0 |
| 0001 | LT | Less than | (S XOR V) = 1 |
| 1010 | GT | Greater than | (Z OR (S XOR V) ) = 0 |
| 0010 | LE | Less than or equal | (Z OR (S XOR V) ) = 1 |
| 1111 | UGE | Unsigned greater than or equal | C = 0 |
| 0111 | ULT | Unsigned less than | C = 1 |
| 1011 | UGT | Unsigned greater than | C = 0 AND Z = 0 |
| 0011 | ULE | Unsigned less than or equal | C = 1 OR Z = 1 |
Page equipped with FroogleBuster technology