This publication is subject to replacement by a later edition. To determine whether a later edition exists, or
to request copies of publications, visit www.zilog.com
.
DO NOT USE THIS PRODUCT IN LIFE SUPPORT SYSTEMS.
LIFE SUPPORT POLICY
ZILOG'S PRODUCTS ARE NOT AUTHORIZED FOR USE AS CRITICAL COMPONENTS IN LIFE
SUPPORT DEVICES OR SYSTEMS WITHOUT THE EXPRESS PRIOR WRITTEN APPROVAL OF
THE PRESIDENT AND GENERAL COUNSEL OF ZILOG CORPORATION.
As used herein
Life support devices or systems are devices which (a) are intended for surgical implant into the body, or (b)
support or sustain life and whose failure to perform when properly used in accordance with instructions for
use provided in the labeling can be reasonably expected to result in a significant injury to the user. A critical component is any componen t in a li fe supp ort device o r syste m whose failure to p erform ca n be re asonably expected to cause the failure of the life support device or system or to affect its safety or effectiveness.
Z8, Z8 Encore!, Z8 Encore! XP, Z8 Encore! MC, eZ80, and ZNEO are trademarks or registered trademarks
of Zilog, Inc. All other product or service names are the property of their respective owners.
UM018809-0611
Revision History
Each instance in the Revision History table below reflects a change to this document from
its previous version. For more details, click the appropriate links in the table.
Revision
Date
May
2011
Aug
2010
Feb
2008
Sep
2007
Mar
2007
May
2006
LevelSectionDescriptionPage
09AllUpdated for style.All
Using the Program Counter as
a Base Address
LEA
SDIVCorrected After address in Example.152
08ADC, ADDUpdated Syntax and Opcodes table.68, 71
07Flags Register (FLAGS)Updated User Flag description.9
Loading an Effective AddressUpdated example.33
System ExceptionsUpdated first paragraph.49
Stack OverflowUpdated second step for Stack Overflow
06Instruction Set ReferenceUpdated Examples for DEC Instruction.65
05Loading an Effective AddressChange in instruction.33
Flags Register (FLAGS), Vectored Interrupts, Instruction Set
Reference
04MultipleUpdated ZNEO trademark issues. Applied
Features, Control Registers,
Address Space, I/O Memory,
Direct Memory Addressing
CPU Control Register
(CPUCTL)
Memory Map, Jump Addressing
Internal Nonvolatile Memory,
Internal RAM
Direct Memory Addressing16-bit address range is in highest and low-
®
ZNEO
Added note.34
Added addressing mode offset description.
protection.
Updated with CIRQE bit.9, 41, 65
current publications template.
Clarified size of address space.1, 8, 15,
and 0001 001+ to correct listing order.
(Opcode-to-instruction relationship is not
changed); corrected sequence of unimplemented opcodes and removed duplicate
row.
This user manual describes the CPU architecture and instruction set common to all Zilog
devices that incorporate the ZNEO
internal peripherals and memory, and I/O registers for each device, refer to the device-specific Product Specification.
About This Manual
Zilog® recommends you to read and understand everything in this manual before setting
up and using the product. We have designed this manual to be used either as an instructional manual or a reference guide to important data.
Intended Audience
This document is written for Zilog customers with experience in writing microprocessor,
assembly code, and compilers. Some introductory material is included to help new customers who are less familiar with this device.
Manual Organization
®
CPU. For complete information about interfaces,
This user manual is divided into nine chapters to describe the following device characteristics:
Architectural Overview
Describes the ZNEO CPU’s features and benefits, architecture, and control registers.
Address Space
Introduces the ZNEO CPU’s unified memory address space, with a memory map illustrating how the available memory areas are addressed.
Assembly Language Introduction
Briefly introduces some of the assembly language terminology used in the following chapters and lists ZNEO CPU instructions in functional groups.
Operand Addressing
Explains ZNEO CPU operand addressing and data sizes.
UM018809-0611Manual Objectives
ZNEO® CPU Core
User Manual
xiv
Interrupts
Introduces the use of vectored and polled interrupts to service interrupt requests from
peripherals or external devices.
System Exceptions
Explains system exceptions and the events which cause the processor overflow, stack
overflow, divide-by-zero, divide overflow, and illegal instruction.
Software Traps
Explains the software trap instruction.
Instruction Opcodes
Numerical list of ZNEO CPU instruction opcodes and syntax.
Instruction Set Reference
Alphabetical list of ZNEO CPU instruction descriptions, with syntax and opcodes.
Manual Conventions
The following manual conventions provide clarity and ease of use.
Notations specific to assembly language, address operands, opcodes, and instruction
descriptions are explained in the chapters discussing those topics.
Courier Typeface
User-typed commands, code lines and fragments, bit names, equations, hexadecimal
addresses, and executable items are distinguished from general text by the use
Courier typeface. Where the use of the font is not indicated (for example, Index)
of the
the name of the entity is presented in upper case.
For example, Internal RAM begins at
Binary Values
Binary values are designated by an uppercase ‘B’ suffix. For readability, underscore ‘_’
characters separate large values into four-digit groups, except in program statements.
For example, 8-bit binary value
FFFF_0000H.
0100_0010B.
Hexadecimal Values
Hexadecimal values are designated by an uppercase ‘H’ and appear in the Courier typeface. For readability, underscore ‘_’ characters separate lar ge values into four-digit groups,
except in program statements as illustrated in the below examples:
Manual ObjectivesUM018809-0611
®
ZNEO
Example 1: R1 is set to F8H.
Example 2: 32-bit hexadecimal value 1234_5678H
CPU Core
User Manual
Bit Numbering
Bits are numbered in order of significance, from 0 to n–1 where 0 indicates the least significant bit and n indicates the total number of bits.
For example, 8 bits of a memory byte are numbered from 0 to 7.
Registers, memory bytes, and binary values are illustrated with the highest-numbered bit
on the left and the lowest-numbered bit on the right.
xv
For example, Bit 6 of the value
0100_0000B is 1.
Brackets
In text, square brackets, [ ], indicate one or more bits of a register, memory location, or
bus. A colon between bit numbers indicates a range of bits. A comma between bit numbers
indicates individual bits as given below:
Example 1: ADDR[31:0] refers to bit 31 through bit 0 of the ADDR bus or memory loca-
tion. ADDR[31] is the most significant bit (msb), and ADDR[0] is the least significant bit
(lsb). ADDR[31:24] is the most significant byte (MSB), and ADDR[7:0] is the least significant byte (LSB).
Example 2: If the value of R1[7:0] is 0100_0010B, the bits R1[6,2] are both 1.
Braces
The curly braces, { }, indicate a single register, memory address or bus created by concatenating combination of smaller registers, addresses, buses or individual bits.
For example, the 32-bit effective address {
hexadecimal value (
FFFFH) and a 16-bit direct address. FFFFH is the most significant
FFFFH, ADDR[15:0]} consists of a 16-bit
word (16 bits) and ADDR[16:0] is the least significant word of the resulting 32-bit
address.
Use of the Words Set, Reset and Clear
The word set indicates a 1 is stored in a register or memory bit or flag. The words reset or
clear indicates a 0 is stored in a register or memory bit or flag.
Use of the Terms LSB, MSB, lsb and msb
In this document, the terms LSB and MSB, when appearing in upper case, mean least significant byte and most significant byte, respectively. The lowercase forms (lsb and msb) mean least significant bit and most significant bit, respectively.
UM018809-0611Manual Objectives
ZNEO® CPU Core
Caution:
Warning:
User Manual
xvi
Use of Initial Uppercase Letters
Initial uppercase letters designate settings, modes, and conditions in general text:
Example 1: Stop mode.
Example 2: The receiver forces the SCL line to Low.
Example 3: The Master can generate a Stop condition to abort the transfer.
Use of All Uppercase Letters
The use of all uppercase letters designates assembly mnemonics or the names of states and
hardware commands.
Example 1: The bus is considered BUSY after the Start condition.
Example 2: A START command triggers the processing of the initialization sequence.
Safeguards
It is important to understand the following safety terms:
Indicates that a procedure or file may become corrupted if you do not follow directions.
Indicates that you are in a situation that could cause bodily injury. Before you work on
any equipment, be aware of the hazards involved with electrical circuitry and be familiar with standard practices for preventing accidents.
Manual ObjectivesUM018809-0611
Architectural Overview
Zilog’s ZNEO CPU meets the continuing demand for faster and more code-efficient
microcontrollers. ZNEO CPU’s architecture greatly improves the execution
code developed using higher-level programming languages like ‘C’ language
Features
The key features of ZNEO CPU architecture include:
•
Highly efficient register-based architecture with sixteen 32-bit registers. All register
operations are 32 bits wide
ZNEO
User Manual
efficiency of
.
®
CPU Core
1
•
Up to 4 GB linear address space (16 MB on current devices) with multiple internal
and external memory and I/O buses
•
Short 16-bit addressing for internal RAM, I/O, and 32K of nonvolatile memory
•
Instructions using memory can operate on 8-bit, 16-bit, or 32-bit values
•
Support for 16-bit memory paths (internal and external)
•
Pipelined instruction fetch, decode, and execution
•
Bus arbiter supports simultaneous instruction and memory access (when possible)
Other features of the ZNEO CPU include:
•
Direct register-to-register architecture allows each 32-bit register to function as an
accumulator. This improves the execution time and decreases the memory required for
programs.
•
Expanded stack support:
–Push/Pop instructions use one 32-bit register as Stack Pointer
–Single-instruction push and pop of multiple registers
–Stack Pointer overflow protection
–Predecrement/postincrement Load instructions simplify the use of multiple stacks
–Link and Unlink operations with enhanced Frame Pointer-based instructions for
efficient access to arguments and local variables in subroutines
•
Program Counter overflow protection
•
User-selectable bus bandwidth control for DMA and CPU sharing
UM018809-0611Architectural Overview
ZNEO® CPU Core
User Manual
2
Program Control
ZNEO CPU is controlled by a program stored in memory as object code. An object code is
a sequence of numerical opcode and operand bytes. An opcode specifies an instruction to
perform while operands specify the data addresses to be operated upon. Numerical object
code is rarely used to write programs. Instead, programs is written in a symbolic assembly
language using easily remembered (mnemonic) instructions. A program called an assembler translates assembly language into object code.
This user manual provides details about using ZNEO CPU instructions in both object code
and assembly language. Those interested in writing assembly language can skip object
code details handled by the assembler.
Programmers using high-level languages like ‘C’ require this manual while writing optimized routines in assembly language. Otherwise, the compiler or interpreter’s documentation should describe processor-specific details affecting program operation.
Processor Block Diagram
The ZNEO CPU consists of following two major functional blocks:
•
Fetch Unit
•
Execution Unit
The Fetch and Execution units access memory through a bus arbiter. The Execution Unit
is subdivided into the Instruction State Machine, Program Counter, Arithmetic Logic Unit
(ALU), and ALU registers. Figure 1 on page 3 displays the ZNEO CPU architecture.
Architectural OverviewUM018809-0611
ZNEO
Fetch Unit
Instruction and
Operand Fetch
Instruction State Machine
Arithmetic Logic Unit (ALU)
32-bit ALU Registers, R0-R15
Bus Arbiter
16
Internal
Non-volatile
Memory
16
Internal
RAM
8/16
Internal I/O
8/16
External
Memory
Interface
Program
Counter
Control
Registers
Execution Unit
User Manual
®
CPU Core
3
Fetch Unit
The Fetch Unit’s primary function is to fetch opcodes and operand words (including
immediate data) from memory. The Fetch Unit also fetches interrupt vectors. The Fetch
Unit is pipelined and operates semi-independently from the execution unit. This Unit performs a partial decoding of the opcode to determine the number of bytes to fetch for the
operation.
The Fetch Unit operation sequence functions as follows:
1. Fetch the first 2-byte opcode word.
2. Determine number of remaining opcode and operand words (one or two).
3. Fetch the remaining opcode and operand words.
4. Present the opcode and operands to the Instruction State Machine.
A ZNEO CPU instruction is always 1, 2, or 3 words long, including operands, and must be
aligned on an even address.
Figure 1. ZNEO CPU Block Diagram
UM018809-0611Architectural Overview
ZNEO® CPU Core
Note:
User Manual
4
Execution Unit
The Execution Unit performs the processing functions required by the instruction opcodes
and operands which it receives from the Fetch Unit.
Instruction State Machine
The Instruction State Machine is the controller for the ZNEO CPU Execution Unit. After
the initial operation decode by the Fetch Unit, the Instruction State Machine takes over
and completes the instruction. The Instruction State Machine generates effective addresses
and controls memory read and write operations.
Program Counter
The Program Counter contains a counter and adder to monitor the address of the current
instruction and calculates the next instruction address. According to the number of bytes
fetched by the Fetch Unit, the Program Counter increments automatically. The adder
increments and handles Program Counter jumps for relative addressing. The initial value
of the program counter is programmable through the RESET vector.
refer to the ZNEO product specification that is specific to your device for the RESET vector location.
Programs cannot address the Program Counter directly but the instruction
LEA Rd, 4(PC) can be used to load the current Program Counter value (the next instruc-
tion address) into an ALU Register. The JP, CALL, and related instructions are used to
alter the program counter value.
The I/O memory register described in Program Counter Overflow Register on page 9 provides access to the program counter overflow feature.
Arithmetic Logic Unit
The Arithmetic Logic Unit (ALU) performs arithmetic and logical operations on data.
arithmetic operations including addition, subtraction, and multiplication. Logical operations include binary logic operations, bit shifting, and bit rotation.
ALU Registers
The ZNEO CPU provides 16 highly efficient 32-bit registers associated with the ALU.
The 16 ALU registers are named from R0 to R15.
These registers have the following characteristics:
•
The CPU can access ALU registers more quickly than ordinary internal or external
memory.
Architectural OverviewUM018809-0611
®
Note:
ZNEO
•
All 32 bits of a source or destination ALU Register are used for arithmetic and logical
operations.
•
When an 8-bit or 16-bit memory read is performed, the value is extended to 32-bits in
the destination register. Unsigned (zero) or Signed extension can be specified.
•
When an 8-bit or 16-bit memory write is performed, the source register’ s value is trun-
cated (only the least significant 8 or 16 bits are stored in memory.)
•
The CALL, IRET, LINK, POP, POPM, PUSH, PUSHM, RET, TRAP, and UNLINK
instructions; system interrupts; and exceptions use Register R15 as the Stack Pointer.
If not used, R15 behaves like any other ALU Register.
•
The LINK, UNLINK, and some LD operations use Register R14 as a Frame Pointer. If
not used, R14 behaves like any other ALU Register.
CPU Core
User Manual
5
Instruction Cycle Time
Instruction cycle times vary from instruction to instruction. Instructions are pipelined
which means the current instruction executes while the next instruction is being fetched.
This allows higher performance at a specific clock speed.
Instruction Fetch Cycles
The following equation is used to calculate the minimum number of cycles required to
fetch an instruction into the CPU:
In the above equation, the following points are true:
•
Bus wait states is configured on a bus to accommodate memory specifications. The
number of wait states is added to each memory read or write on that bus.
For details about wait states, refer to the ZNEO product specification that is specific to
your device .
•
The opcode bytes value can be 2, 4 or 6, depending on the instruction. Immediate
operands, if any, are included in the opcode fetch, so they do not affect execution
cycles.
•
The bus bytes value can be 1 or 2, for fetches from an 8-bit or 16-bit bus, respectively.
For more details, see the Bus Widths
UM018809-0611Architectural Overview
section on page 19.
ZNEO® CPU Core
Note:
User Manual
6
Execution Cycles
Instructions always begin at an even address; therefore, instruction fetches are not subject
to uneven alignment delays.
An instruction fetch delay cycle can occur if the Fetch and Execution Units request access
to the same bus on the same cycle. In this case, the bus arbiter gives precedence to the
Execution Unit. This kind of delay can be avoided by storing instructions and data in different memory spaces; for example, instructions in ROM or Flash and data in RAM.
The minimum instruction execution time for most CPU instructions is one system clock
cycle. Additional cycles are required for shift, multiply, divide operations, and operations
which read or write memory locations. Table 1 lists minimum Execution Unit cycle times
for the various instructions. The symbol bus_time is described in the text following the
table, as other factors that affect execution of some instructions.
Table 1. Instruction Execution Cycles
InstructionOperand TypesMinimum Execution Unit Cycles
In the above equation, the following points can be considered:
–Bus wait states is configured for a bus to accommodate memory specifications.
The number of wait states is added to each memory read or write on that bus.
–The ceiling function rounds up to the nearest integer. This accounts for a 1-byte
access on a 2-byte bus, which takes a full memory access cycle, not 1/2 cycle.
–The data bytes value can be 1, 2 or 4, depending on the size of the addressed data
(for direct or register-indirect addressed memory).
–The bus bytes value can be 1 or 2, for fetches from an 8-bit or 16-bit bus, respec-
tively.
An unaligned 16-bit or 32-bit read or write requires additional cycles. For more
details, see the Bus Widths
section on page 19.
UM018809-0611Architectural Overview
ZNEO® CPU Core
Note:
Note:
Note:
User Manual
8
•
•
For details about wait states, refer to the ZNEO product specification that is specific to
your device .
Control Registers
For LD and LEA instructions, a delay cycle is inserted if a register is loaded immediately before it is used for the base address in a register-indirect instruction.
If execution of an instruction ends before all the next instruction words are fetched,
the Execution Unit delays for the number of cycles required by the Fetch unit to complete the instruction fetch. After an ILL or TRAP instruction executes, the entire next
instruction must be fetched.
The ZNEO CPU and internal peripheral control registers are accessed in the I/O memory
space starting at
FF_E000H (24-bit address space devices). Table 2 lists control registers
common to all Zilog devices that incorporate the ZNEO CPU. In this table, “X” indicates
an undefined hex digit value.
For complete information about peripheral control registers for a particular device, refer to
the device specific Product Specification.
I/O memory locations can be accessed using a 16 bit address operand. For more details, see
the Direct Memory Addressing section on page 29.
Architectural OverviewUM018809-0611
Program Counter Overflow Register
CZSVBF1 CIRQE IRQE Flags Register
Bit
0
Bit
7
Master Interrupt Enable
Chained Interrupt Enable
User Flag 1
Blank Flag
Overflow Flag
Sign Flag
Zero Flag
Carry Flag
The Program Counter Overflow Register (PCOV) implements program counter overflow
protection. For more details, see the Program Counter Overflow
Stack Pointer Overflow
The Stack Pointer Overflow Register (SPOV) is used to provide stack pointer overflow
protection. For more details, see the Stack Overflow
IRET, POP, PUSH, RET and TRAP instructions, system interrupts and exceptions use the
ALU Register. R15 is used as the Stack Pointer.
Flags Register (FLAGS)
®
ZNEO
section on page 50.
section on page 50. CALL, ILL,
CPU Core
User Manual
9
This byte register contains the status information regarding the most recent arithmetic,
logical, bit manipulation or rotate and shift operation. The Flags Register contains six bits
of status information that are set or cleared by CPU operations. Five of the bits (C, Z, S, V
and B) can be tested with conditional jump instructions. The
rupt Enable flag, and the CIRQE bit is the Chained Interrupt Enable flag. Figure 2 displays
the flags and their bit positions in the Flags Register.
IRQE bit is the Master Inter-
Figure 2. Flags Register
Interrupts, System Exceptions, and the software Trap (TRAP) instruction write the value
of the Flags Register to the stack. Executing an Interrupt Return (IRET) instruction
restores the value saved on the stack into the Flags Register.
UM018809-0611Architectural Overview
ZNEO® CPU Core
User Manual
10
Flag settings depend on the data size of the result, which can be 8 bits (Byte), 16 bits
(Word), or 32 bits (Quad, the default). For instructions with destinations in memory, the
mnemonic suffix determines the destination size. If the destination is a register, Flags are
based on the 32-bit result. For more information, see the Memory Data Size
section on
page 30.
Carry Flag
The Carry (C) flag is 1 when the result of an arithmetic operation generates a carry out of
or a borrow into the most significant bit (msb) of the data. Otherwise, the Carry flag is 0.
Some bit rotate or shift instructions also affect the Carry flag. Bit [31] is considered msb
for register destinations; the msb for a memory destination depends on the data size.
Zero Flag
For arithmetic and logical operations, Zero (Z) flag is 1 if the result is 0. Otherwise, the
Zero flag is 0. If the result of testing bits is
0, Zero flag is 1; otherwise, the Zero flag is 0.
Also, if the result of a rotate or shift operation is
0, the Zero flag is 1; otherwise, the Zero
flag is 0. The test considers 32 bits for a register destination or the destination size for a
memory destination.
Sign Flag
The Sign (S) flag stores the value of the most significant bit (msb) of a result following an
arithmetic, logical, rotate, or shift operation. For signed numbers, the ZNEO CPU uses
binary two’s complement to represent the data and perform the arithmetic operations. A 0
in the msb position identifies a positive number; therefore, the Sign flag is also 0. A 1 in
the most significant position identifies a negative number; therefore, the Sign flag is also
1. Bit [31] is considered msb for register destinations; the msb for a memory destination
depends on the data size.
Overflow Flag
For signed arithmetic, rotate or shift operations, the Overflow (V) flag is 1 when the result
is greater than the maximum possible number or less than the minimum possible number
which is represented with the specified data size in signed (two’s complement) form. For
signed data size ranges, see Table 14
occurs. Following logical operations, the Overflow flag is 0.
Following addition operations, the Overflow flag is 1 when the operands have the same
sign, but the result has the opposite sign. Following subtraction operations, the Overflow
flag is 1 if the two operands are of opposite sign and the sign of the result is same as the
sign of the source operand. Following shift/rotation operations, the Overflow flag is 1 if
the sign bit of the destination changed during the last bit shift iteration.
on page 32. The Overflow flag is 0 if no overflow
Architectural OverviewUM018809-0611
®
ZNEO
CPU Core
User Manual
Blank Flag
For some arithmetic, logical, and load operations, the Blank (B) flag is set to 1 if a tested
operand value is 0 before the operation. Otherwise,
operands might be tested, but which operands are tested depends on the operation being
performed. See the instruction descriptions for details.
B is 0. Both source and destination
11
Unlike other flags, the
B flag can be altered by POP and some LD instructions. 8-bit or 16-
bit memory operands are tested after unsigned or signed extension, depending on the
instruction
The
the following statement executes,
. For more information, see the Resizing Data section on page 31.
B flag is useful for operations involving a null-terminated strings. For example, after
Z is set if the tested byte is a carriage return (0DH), or B
is set if the byte is zero.
CP.B (R6), #0DH
User Flag
The User Flag (F1) are available as general-purpose status bits. The User Flag is unaffected by arithmetic operations and must be set or cleared by instructions. The User Flag
must not be used with conditional Jumps. The User Flag is 0 after initial power-up or
Reset.
Chained Interrupt Enable Flag
The Chained Interrupt Enable flag (CIRQE) is used to enable or disable chained-interrupt
optimization, which allows program control to pass directly from one interrupt service
routine to another while omitting unneeded stack operations. For more information, see
the Returning From a Vectored Interrupt
Whenever a vectored interrupt or system exception occurs, the previous state of the
flag is copied to
CIRQE after the Flags Register is pushed onto the stack. This disables
interrupt chaining if interrupts are globally disabled (
rupt or system exception occurs.
section on page 44.
IRQE
IRQE=0) when a nonmaskable inter-
The
CIRQE flag is unaffected by other operations, but it may be set or cleared by instruc-
tions, if desired. The
CIRQE flag cannot be used with conditional Jumps. The CIRQE flag
is 0 after initial power-up or Reset.
Master Interrupt Enable Flag
The Master Interrupt Enable bit (IRQE) globally enables or disables interrupts. For more
information, see the Interrupts
chapter on page 41.
Condition Codes
The C, Z, S, V, and B flags control the operation of the conditional jump (JP cc) instruc-
tions. Sixteen frequently useful functions of the flag settings are encoded in a 4-bit field
UM018809-0611Architectural Overview
ZNEO® CPU Core
Note:
User Manual
12
called the condition code (cc), which are assembled into each conditional jump opcode.
Table 3 summarizes condition codes and their assembly language mnemonics.
Some binary condition codes are expressed by more than one mnemonic.
The result of the flag test operation determines if the conditional jump executes.
Table 3. Condition Codes
Assembly
BinaryHex
00000BBlankB = 1
00011LTLess Than(S XOR V) = 1
00102LELess Than or Equal(Z OR (S XOR V)) = 1
00113ULEUnsigned Less Than or Equal(C OR Z) = 1
01004OVOverflowV = 1
01015MIMinusS = 1
01106ZZeroZ = 1
01106EQEqualZ = 1
01117CCarryC = 1
01117ULTUnsigned Less ThanC = 1
10008NBNot BlankB = 0
10019GEGreater Than or Equal(S XOR V) = 0
1010AGTGreater Than(Z OR (S XOR V)) = 0
1011BUGTUnsigned Greater Than(C OR Z) = 0
1100CNOVNo OverflowV = 0
1101DPLPlusS = 0
1110ENZNon-ZeroZ = 0
1110ENENot EqualZ = 0
1111FNCNo CarryC = 0
1111FUGEUnsigned Greater Than or
MnemonicDefinition
Equal
Flag Test Operation
(Jump if T rue)
C = 0
Architectural OverviewUM018809-0611
®
Note:
ZNEO
CPU Core
User Manual
CPU Control Register (CPUCTL)
Bits [1:0] of the CPU Control Register (see Table 4 on page 13) control access to the
ZNEO CPU buses through DMA bandwidth selection.
For more details about the available peripheral control and data registers, and additional
information about DMA operation, refer to the device specific Product Specification.
Table 4. CPU Control Register
Bit76543210
Field
Reset
R/W
Address
Note: R = Read-only; R/W = Read/Write; R/W0 = Read/Write to 0.
11111111
RRRRRRR/WR/W
ReservedDMABW
FFFF_E012H
13
Bit
Position Description
[7:2]Reserved; must be zero.
[1:0]DMA Bandwidth Selection (DMABW)
The ZNEO CPU can be configured to support four levels of Direct Memory Access (DMA) Con troller bus bandwidth. Write one of the fo llowing values to DMABW[1:0] to se lect the portion of
bus bandwidth allocated to DMA operations:
00 = DMA can consume 100% of the bus bandwidth
01 = DMA is allowed one transaction for each CPU operation
10 = DMA is allowed one transaction for every two CPU operations
11 = DMA is allowed one transaction for every three CPU operations
UM018809-0611Architectural Overview
ZNEO® CPU Core
User Manual
14
Architectural OverviewUM018809-0611
Address Space
The ZNEO CPU has a unique memory architecture with a unified address space. It supports memory and I/O up to four buses:
•
Internal Non-Volatile Memory (Flash, EEPROM, EPROM, or ROM)
The ZNEO CPU Fetch Unit and Execution Unit can access separate buses at the same
time. The CPU can access memories with either 8-bit or 16-bit bus widths. ZNEO CPU
uses 32-bit addressing internally. Therefore, the CPU is capable of addressing up to 4 GB
of addresses.
ZNEO
User Manual
®
CPU Core
15
Current ZNEO CPU products ignore address bits [31:24], providing a 24-bit address space
with 16 MB (16,777,216 bytes) of unique memory addresses. Address bits [31:24] must
be written appropriately for the addressed space to allow for possible future expansion.
The CPU also provides instructions which use 16-bit addressing. 16-bit addresses are sign
extended by the CPU to access the highest and lowest 32 KB of the available address
space.
Example: The 16-bit address FEFFH resolves to FF_FEFFH in the 24-bit address space.
Most CPU instructions also use Arithmetic and Logic Unit (ALU) registers for either
source or destination data. See the ALU Registers
The ZNEO CPU address space includes the following features:
•
Memory Map
•
Internal Nonvolatile Memory
•
Internal RAM
•
I/O Memory
•
External Memory
•
Endianness
•
Bus Widths
section on page 4.
UM018809-0611Address Space
ZNEO® CPU Core
Internal Non-Volatile
External Memory Interface
00_0000H
FF_8000H
FF_E000H
FF_FFFFH
FF_xxxxH
Data Addresses
Jump Addresses
(Execution Unit)
(Fetch Unit)
Internal Bus (One of Three)
External Bus
00_xxxxH
00_0xxxH
FF_xxxxH
xxxxH
Device-Specific Boundary
16-Bit Address Sp ace
00_7FFFH
Internal I/O &
Control Registers
Option Bits and Vectors
Memory
External Memory Interface
Internal RAM
Reserved
User Manual
16
Memory Map
Figure 3 displays a memory map of the ZNEO CPU. It displays the location of internal
nonvolatile memory, internal RAM, and internal I/O Memory. External memory can be
accessed at addresses not occupied by internal memory or I/O.
Figure 3. ZNEO CPU Memory Map (24 Significant Address Bits)
Address SpaceUM018809-0611
To determine the amount of internal RAM and internal nonvolatile memory available for
Note:
Note:
the specific device and for details about the available option bits and vectors, refer to the
ZNEO product specification that is specific to your device .
Internal Nonvolatile Memory
Internal nonvolatile memory consists of executable program code, constants, and data.
The ZNEO CPU assembler provides configurable address range mnemonics (ROM and
EROM) that can be specified to locate data and program elements in nonvolatile memory.
ROM selects nonvolatile memory in the 16-bit address space, while EROM selects nonvolatile memory in the 32-bit address space. For more details about data space and segment definitions, refer to the assembler documentation.
ZNEO
User Manual
®
CPU Core
17
For each product within the ZNEO CPU family, a block of memory beginning at address
00_0000H is reserved for option bits and system vectors (RESET, trap, interrupts, System
Exceptions; etc.). Table 5 provides an example reserved memory map for a ZNEO CPU
product with 24 interrupt vectors.
Internal RAM
Internal RAM is employed for data and stacks. However, internal RAM can also contain
program code for execution. Most ZNEO CPU devices contain some internal RAM. The
base (lowest address) and top (highest address) of internal RAM are a function of the
amount of internal RAM available.
To determine the amount and location of internal RAM, refer to the ZNEO product specification that is specific to your device .
UM018809-0611Address Space
ZNEO® CPU Core
Note:
User Manual
18
I/O Memory
The ZNEO CPU assembler provides a configurable address range mnemonic (RAM) that
can be specified to locate data and (possibly) program elements in the RAM space
accessed using 16-bit addressing. For more details about data space and segment definitions, refer to the assembler documentation.
ZNEO CPU supports 8 KB (8,192 bytes) of internal I/O Memory space located at
addresses
addresses are reserved for control of the ZNEO CPU, the on-chip peripherals, and the I/O
ports.
For descriptions of the peripheral and I/O control registers, refer to the ZNEO product
specification that is specific to your device . Attempts to read from unavailable I/O Memory addresses return
no effect.
FF_E000H through FF_FFFFH (in the 24-bit address space). The I/O Memory
FFH. Attempts to write to unavailable I/O Memory addresses produce
The ZNEO CPU assembler provides a configurable address range mnemonic, IODATA,
that can be specified to locate an address in the reserved I/O Memory space or (if present)
external I/O configured in the adjacent 16-bit addressable memory space. For more details
about data space and segment definitions, refer to the assembler documentation.
I/O Memory Precautions
Some control registers within the I/O Memory provide read-only or write-only access.
When accessing these read-only or write-only registers, ensure that the instructions do not
attempt to read from a write-only register or, conversely, write to a read-only register.
External Memory
ZNEO CPU products support external data and address buses for connecting to additional
external memories and/or memory-mapped peripherals. The external addresses can be
used for storing program code, data, constants, stack, etc. The results of reading from or
writing to unavailable external addresses are undefined.
The ZNEO CPU assembler’s EROM and ERAM address range mnemonics can be configured to include external memory configured in 32-bit addressed memory. These mnemonics can be used to locate data and program elements in nonvolatile or RAM memory, as
required. For more information about data space and segment definitions, refer to the
assembler documentation.
Address SpaceUM018809-0611
Endianness
FF_0080H
FF_0081H
FF_0082H
FF_0083H
MSB
LSB
Address
of Quad
FF_0080H
FF_0081H
MSB
LSB
Address
of Word
The ZNEO CPU accesses data in Big Endian order; which means the address of a multibyte Word or Quad points to the most significant byte (MSB). Figure 4 displays the Endianness of the ZNEO CPU.
ZNEO
User Manual
®
CPU Core
19
Figure 4. Endianness of Words and Quads
Bus Widths
The ZNEO CPU can access 8-bit or 16-bit wide memories. The data buses of the internal
nonvolatile memory and internal RAM are 16-bits wide. The internal peripherals are a mix
UM018809-0611Address Space
of 8-bit and 16-bit peripherals. The external memory bus can be configured as an 8-bit or
16-bit memory bus.
If a 16-bit or 32-bit operation is performed on a 16-bit wide memory, the number of memory accesses depends on the alignment of the address. If the address is even, a 16-bit operation takes one memory access and a 32-bit operation takes two memory accesses. If the
address is odd (unaligned), a 16-bit operation takes two memory accesses and a 32-bit
operation takes three memory accesses. Figure 5 displays this behavior for 16-bit and 32bit access.
ZNEO® CPU Core
MSB
LSB
FF_0080HFF_0081H
MSB
LSB
FF_0082H
FF_0081H
Aligned 16-Bit Access
Unaligned 16-Bit Access
MSB
LSB
FF_0080HFF_0081H
FF_0082HFF_0083H
MSB
LSB
FF_0081H
FF_0082H
FF_0083H
FF_0084H
Aligned 32-Bit Access
Unaligned 32-Bit Access
FF_0080H
FF_0083H
FF_0085H
FF_0080H
User Manual
20
Figure 5. Alignment of 16-Bit and 32-Bit Operations on 16-Bit Memories
Address SpaceUM018809-0611
Assembly Language Introduction
LOOP:SUBR5, R7;Subtract
Label
(Optional)
Instruction
Mnemonic
Destination
Operand
Source
Operand
Comment
(Optional)
Assembly language uses mnemonic symbols to represent instruction opcodes. Operands
such as register names and immediate data is represented symbolically, numerically, as
expressions, or by labels defined elsewhere in the program.
Figure 6 displays a typical assembly language statement.
ZNEO
User Manual
®
CPU Core
21
Figure 6. Example Assembly Language Statement
An assembly statement can include one or more the following elements:
Label. An optional text string used to refer to this statement elsewhere in the program. A
string is considered a label definition if it is not an assembler keyword, and it either begins
a line or is followed by a colon. The label definition identifies the address of the instruction that follows it.
Instruction Mnemonic. The mnemonic code for the desired operation.
Destination Operand. The destination location for the operation. In assembly, the desti-
nation operand is always first if both operands are specified.
Source Operand. The source location or immediate data for the operation.
Comment. An optional text field ignored by the assembler. Comments are used to
describe the flow of a program so it is easier to understand and maintain later.
Instead of instruction mnemonics, some assembly statements contain assembler directives
(also called pseudo-ops), which are not translated into object code. Directives are used to
select memory segments, allocate storage in memory, define macros, and control the
assembly process.
Example Assembly Language Source
An assembly language program is written in a plain text file called as source file, which
contains a sequence of assembly language statements and directives.
Below is an example of an assembly source file:
SEGMENT NEAR_TEXT ; Directive to place the following statements
UM018809-0611Assembly Language Introduction
ZNEO® CPU Core
User Manual
22
; in data (RAM space) memory
Str_Data: ; Make Str_Data label equal to current addr.
DB "NEVAR" ; Directive to allocate and initialize data
; bytes
Str_Length EQU $ - Str_Data ; Equate Str_Length to current
assembly
; address ("$") minus Str_Data address.
Blank_Data: ; Allocate an uninitialized data block
DS Str_Length ; that is the same size as the Str_Data block.
SEGMENT CODE ; Directive to put the following statements in
; instruction (ROM space) memory
REVERSE: ; Routine to reverse a block of data
LD R8, #Str_Data ; Load R8 with 1st address in Str_Data block
LD R12, #Blank_Data+Str_Length ;Next addr. after Blank_Data
LOOP: ; Start of loop
LD.UB R5,(R8++) ; Load byte pointed to by R8 into R5 LSB
; Increment R8 after load.
LD.B (--R12),R5 ; Decrement R12, then
; Load byte pointed to by R12 with R5 LSB
CP R12, #Blank_Data ; Did we write all the bytes?
JP NZ,LOOP ; Repeat until Blank_Data block contains
; reversed copy of Str_Data bytes
For details about assembly instructions, see the Instruction Set Reference chapter on
page 65. For details about operand addressing and data sizes, see the Operand Addressing
chapter on page 27.
For information about how program flow can be interrupted, see the Interrupts
chapter on
page 41, System Exceptions on page 49, and Software Traps on page 53.
For details about assembly language syntax, expressions, directives, and using the assem-
bler, refer to the Zilog Developer Studio II – ZNEO User Manual (UM0171)
.
ZNEO CPU Instruction Classes
ZNEO CPU instructions can be divided functionally into the following groups:
•
Arithmetic
•
Logical
•
Bit Manipulation
•
Rotate and Shift
Assembly Language IntroductionUM018809-0611
®
•
Load
•
CPU Control
•
Program Control
ZNEO
CPU Core
User Manual
Tables 6 through 12 list the instructions for each of the above groups and the number of
operands required for each instruction. Some instructions appear in more than one table as
these instructions can be considered members of more than one category. The abbreviations dst and src refer to destination and source operands, respectively.
Table 6. Arithmetic Instructions
MnemonicOperandsInstructionPage
ADCdst, srcAdd with Carry68
ADDdst, srcAdd71
CPdst, srcCompare86
CPCdst, srcCompare with Carry89
CPCZdstCompare to Zero with Carry92
CPZdstCompare to Zero94
DECdstDecrement96
INCdstIncrement108
MULdst, srcMultiply (32 bit)125
NEGdstNegate127
SBCdst, srcSubtract with Carry149
SDIVdst, srcSigned Divide (32 bit)152
SMULdst, srcSigned Multiply (64 bit)158
SUBdst, srcSubtract169
UDIVdst, srcUnsigned Divide (32 bit)180
UDIV64dst, srcUnsigned Divide (64 bit)182
UMULdst, srcUnsigned Multiply (64 bit)184
TCMdst, srcTest Complement Under Mask172
TMdst, srcTest Under Mask175
Table 9. Rotate and Shift Instructions
MnemonicOperandsInstructionPage
RLdstRotate Left147
SLLdst, srcShift Left Logical154
SLLXdst, srcShift Left Logical, Extended156
SRAdst, srcShift Right Arithmetic160
SRAXdst, srcShift Right Arithmetic,
Extended
SRLdst, srcShift Right Logical164
SRLXdst, srcShift Right Logical, Extended166
Most ZNEO CPU instructions operate on one or two registers, or one register and one
memory address. Operands following the instruction specify which register or memory
address to use.
Example. The assembly language statement below loads one 32-bit register with data
from another:
LD R7, R8
The first operand almost always specifies the destination, and the second operand (if any)
specifies the source for the operation. In this example, the R7 register is loaded with the
value from R8 register.
ZNEO
User Manual
®
CPU Core
27
There are four kinds of operand addressing, each of which is described in this chapter:
•
Immediate Data, in which the value specified by the operand is used for operation.
•
Register Addressing, in which the specified 32-bit register is used for operation.
•
Direct Memory Addressing, in which the value specified by the operand addresses a
memory location that is used for the operation. This section introduces the following
topics:
–Memory Data Size
–Resizing Data
These topics also apply to Register-Indirect memory addressing.
•
Register-Indirect Memory Addressing, in which the specified 32-bit register and
optional offset point to a memory location that is used for the operation. This section
covers the following topics specific to register-indirect addressing:
–Loading an Effective Address
–Using the Program Counter as a Base Address
–Memory Address Decrement and Increment
–Using the Stack Pointer (R15)
–Using the Frame Pointer (R14)
This chapter also describes Bit Manipulation
page 39).
UM018809-0611Operand Addressing
(see page 37) and Jump Addressing (see
ZNEO® CPU Core
User Manual
28
Immediate Data
An Immediate Data operand specifies a source value to be used directly by the instruction.
Example. The assembly language statement below loads ALU Register R7 with the value
42H:
LD R7, #42H
The hash mark prefix (#) on the second (source) operand indicates to the assembler that
the value is Immediate Data, so this example loads the R7 register with the value
Immediate data is stored as part of the instruction opcode. Depending on the opcode, an
immediate data value can be of the same size as the destination (8, 16 or 32 bits), or it may
contain fewer bits to shorten the opcode.
A destination-sized immediate operand (imm syntax symbol) is used directly by the operation. A shorter immediate operand must be considered signed (simm) or unsigned (uimm).
A signed immediate value is sign-extended to the destination size before it is used. An
unsigned immediate operand is ze ro-e x tended to the destination size before it is used. For
more information, see the Memory Data Size
section on page 31.
section on page 30 and the Resizing Data
42H.
An immediate value does not address data memory, so it cannot be used as the destination
operand. Immediate data is read by the Fetch Unit, so it is not affected by the constraints
described in the I/O Memory Precautions
Register Addressing
A Register operand specifies a 32-bit Arithmetic and Logic Unit (ALU) register to be used
with the instruction. ALU registers are the CPU’s high-speed work space, much faster than
ordinary internal or external memory. There are 16 ALU registers, named R0 to R15. See
the ALU Registers
As mentioned previously , the following assembly language statement loads the destination
register, R7, with data from the source register, R8:
LD R7, R8
Depending on the instruction, a register name can be used for either the source or destination operand, or both. Each register is 32-bits (four bytes) wide, and all 32 bits of a register
are used unless the register’s value is loaded into an 8-bit or 16-bit memory location.
The ZNEO CPU assembler recognizes FP as a synonym for R14 and SP as a synonym for
R15. For details, see the Using the Frame Pointer (R14)
the Stack Pointer (R15) section on page 36. The UDIV64 instruction uses a 64-bit RRd
register pair operand that employs two 32-bit ALU registers. See the UDIV64
page 182 for details.
section on page 18.
section on page 4 for details.
section on page 37 and the Using
section on
Operand AddressingUM018809-0611
Direct Memory Addressing
Note:
A Direct Memory operand specifies a memory address to be used by the instruction.
Example. The following assembly language statement loads ALU register R7 with the
value in memory address
LD.SB R7, B002H
Any data operand which does not contain an immediate value (#n) or register name (Rn) is
assumed to be a memory address. Depending on the instruction, a direct memory address
can be used in either the source or destination operand, but a destination’s effective
address must be a writable memory or I/O location.
ZNEO CPU uses 32-bit memory addresses, but it includes instruction opcodes which
accept 16-bit addresses. A 16-bit address operand in object code is sign-extended by the
CPU (see the Resizing Data
feature splits the 16-bit address range between the highest and lowest 32K blocks of the 16
GB address space. Table 13 provides the 16-bit address ranges for object code.
0000_B002H:
section on page 31) to create the effective address used. This
ZNEO
User Manual
®
CPU Core
29
Table 13. 16-Bit Addressing (Object Code Only)
16-Bit Address Range32-Bit Effective AddressesMemory Space
0000H to 7FFFH0000_000H to 0000_7FFFHROM
8000H to FFFFHFFFF_8000H to FFFF_FFFFHRAM and I/O
Effective addresses are expressed as 32-bit values. Current devices ignore address bits
[31:24], providing a 24-bit address space.
Internal RAM and I/O memory falls in the range
FF_8000H to FF_FFFFH on devices that ignore address bits [31:24]), so 16-bit address-
(
FFFF_8000H to FFFF_FFFFH
ing provides efficient access to internal RAM and I/O memory.
The ZNEO CPU assembler does not automatically use 16-bit addressing if an unmodified
16-bit address is specified, as in the previous example. In this case the assembler selects
16-bit or 32-bit addressing to ensure the address is used as specified.
However, you can append address range mnemonics to specify whether the assembler
should use 16-bit or 32-bit addressing. The RAM, IODAT A, and ROM mnemonics tell the
assembler to use 16-bit addressing, as shown in the following example statements:
LD.SB R7, B002H:RAM ; Effective address is FFFF_B002H
LD.SB R7, E002H:IODATA ; Effective address is FFFF_E002H
LD.SB R7, 3002H:ROM ; Effective address is 0000_3002H
UM018809-0611Operand Addressing
ZNEO® CPU Core
User Manual
30
The ERAM and EROM address space suffixes tell the assembler to use 32-bit addressing,
as shown in the following statements. A full 32-bit address can access external memory or
memory-mapped I/O anywhere in the 4 GB address space.
LD.SB R7, B002H:EROM ; Effective address is 0000_B002H
LD.SB R7, B002H:ERAM ; Effective address is 0000_B002H
The assembler uses memory space mnemonics only to select an appropriate address size
(16 or 32 bit). The assembler does not check an absolute address to make sure it actually
resides in the specified space, but the assembler generates a warning if a label is used in a
space other than the space in which it was declared. See the Address Space
page 15 for more information about memory spaces.
Memory Data Size
The ZNEO CPU’s default data size is 32 bits (Quad). Any instruction that addresses an 8bit or 16-bit value in memory must use a mnemonic suffix to specify the data size. The
previous examples use the ‘.B’ suffix to tell the CPU that only 8 bits (one byte) must be
loaded. The following data size suffixes can be used (using LD as an example):
section on
LD (No Suffix). Read or write 32 bits (four bytes). In a read, for example, the byte at the
specified effective address loads into bits [31:24] of the destination register . The three subsequent memory bytes load into bits [23:16], [15:8], and [7:0] of the destination register,
in that order.
LD.W. Read or write 16 bits (two bytes). In an unsigned read, for example, bits [31:16] of
the destination register are cleared, the byte at the specified effective address loads into
bits [15:8] of the register, and the byte at the next (+1) address loads into bits [7:0] of the
register.
LD.B. Read or write 8 bits (one byte). In an unsigned read, for example, bits [31:8] of the
destination register are cleared, and the byte at the specified effective address loads into
bits [7:0] of the register.
Figure 7
on page 31 displays the mapping of register bytes to memory bytes for different
data sizes. When 8-bit or 16-bit memory is read or written, the high-order bits are filled or
truncated as described in the Resizing Data
section on page 31.
Operand AddressingUM018809-0611
®
ALU RegistersMemory Space
7:015:823:1631:24Bits:
FFFF_7005H
(Effective Address)
FFFF_7006H
FFFF_7007H
FFFF_7004H
7:015:823:1631:24Bits:
FFFF_7009H
(Effective Address)FFFF_7008H
7:015:823:1631:24Bits:
FFFF_700AH (Effective Address)
8-Bit
16-Bit
32-Bit
ZNEO
CPU Core
User Manual
31
Figure 7. Mapping of Register to Memory Bytes
Resizing Data
When an 8-bit or 16-bit memory location is written, the value from the source register is
truncated, so only the least-significant 8 or 16 bits of the register value are written, respectively. The source register itself is not changed. When an 8-bit or 16-bit memory location
UM018809-0611Operand Addressing
is read, the value from memory must be extended to a full 32 bits before it is used or stored
in a register.
One of the following two kinds of data extension must be used:
Unsigned (Zero) Extension. The upper bits of the new 32-bit value are filled with zeroes.
Unsigned extension is invoked by including a ‘U’ in the mnemonic suffix. For example,
the following instruction loads the byte at
with zeroes:
LD.UB R10,7002H
Signed Extension.
The upper bits of the new 32-bit value are filled with ones or zeroes,
FFFF_7002H into R10[7:0] and fills R10[31:8]
depending on the source value’s most-significant (sign) bit, to preserve the sign of the
loaded value. Signed extension is invoked by including an ‘S’ in the mnemonic suffix.
For example, the following instruction loads the byte at address
bits R10[7:0] and copies bit 7 of that byte into each bit of R10[31:8].
FFFF_7002H into register
ZNEO® CPU Core
User Manual
32
LD.SB R10,7002H
By default, the ZNEO CPU assembler uses an unsigned instruction opcode if the extension type is not specified for an 8- or 16-bit memory read. The EXT instruction is provided
for extending 8-bit or 16-bit values contained in a register.
The CPU uses ordinary two’s complement notation to represent signed values. In this
notation, the negative of a number is its binary complement, plus one. The most significant bit (msb) represents the sign—a one in the msb indicates that the number is negative.
Y ou can use signed or unsigned instructions with a particular memory location. Ensure the
correct usage of extension type whenever a memory location is read.
Table 14 lists data sizes, suffixes, and ranges for signed and unsigned values.
Table 14. Data Sizes for Memory Read
Signed or
SizeBits
Byte 8Unsigned.UB 0 to FF0 to 255
Word 16Unsigned.UW0 to FFFF0 to 65,535
Quad 32Unsigned(none)0 to FFFF_FFFF0 to 4,294,967,295
UnsignedMnemonic SuffixRange (Hex)Range (Decimal)
Signed.SB 80 to FF,
00 to 7F
Signed.SW8000 to FFFF,
0000 to 7FFF
Signed(none)8000_0000 to
FFFF_FFFF,
0000_0000 to
7FFF_FFFF
–128 to –1,
0 to 127
–32,768 to –1,
0 to 32,767
–2,147,483,648 to –1,
0 to 2,147,483,647
Register-Indirect Memory Addressing
A register-indirect operand uses an address contained in an ALU register, plus an optional
offset, to address data in a memory location.
Example. The following assembly-language statement loads the destination register, R10,
with data from a memory byte pointed to by register R12, plus an offset.
LD.UB R10, 4(R12)
Figure 8 displays this example. It reads a base address value from R12, adds the signed
offset, 4, to create an effective address in memory, and then loads register R10 with the
value at that address. The parentheses indicate a register-indirect operand.
Operand AddressingUM018809-0611
®
LD.UB R10,4(R12)
42H
FFFF_7006H
R12FFFF_7002H
4 + FFFF_7002H
32-Bit ALU Registers
Memory Space
Value Loaded:
42H
—
—
R11—
R13—
0000_0042HR10
(Effective Address)
Note:
ZNEO
CPU Core
User Manual
33
Depending on the instruction, register-indirect addressing can be used for either the source
or destination operand, but a destination’s effective address must be a writable memory or
I/O location. The range allowed for the signed offset depends on the instruction used. For
the LD, CLR, CPZ, CPCZ, INC, and DEC instructions, the register-indirect offset range is
–4,096 to +4,095. For other instructions that accept an indirect offset, the range is –8,192
to +8,191.
For allowed JP and CALL offsets, see the Jump Addressing section on page 39.
Several register-indirect instructions have alternate opcodes that do not accept an offset,
and therefore use fewer opcode words. When the offset is omitted in a register-indirect
operand, the ZNEO CPU uses the shorter instruction opcode if one is available.
Loading an Effective Address
The following assembly language statement is a an example of how you can initialize a
register with a base address:
LD R6, #FFFFB002H
Addresses in the range FFFF_8000H to FFFF_FFFFH are common because that is where
I/O memory and internal RAM are addressed, but using a 32-bit LD to initialize a register
Figure 8. Register-Indirect Memory Addressing Example
UM018809-0611Operand Addressing
ZNEO® CPU Core
User Manual
34
is not necessary. The ZNEO® CPU assembler automatically uses a shorter LD opcode if
possible.
The LEA mnemonic is provided as an alternative to the immediate LD instruction.
Example. The following statement performs the same initialization as in the previous
example:
LEA R6, FFFFB002H
LEA and LD accept the memory space notation described in Direct Memory Addressing
on page 29, so the following statements are equivalent to the two previous examples:
Once a register is initialized with a base address, the LEA instruction can be used to generate a new effective address based on that register value.
Example. If the value in register R8 is FFFF_7002H, the following assembly language
statement loads register R7 with the value
LEA R7, 4(R8)
FFFF_7006H:
This LEA operation loads the effective address indicated by the source operand, while a
similar LD instruction would load the contents of the address. The allowed offset range for
a register-based LEA operand is –8,192 to +8,191.
Using the Program Counter as a Base Address
Some LD and LEA instructions use the Program Counter (PC) as the base address for indirect addressing with an offset. Normally these instructions are used to access a data block
declared in line with the program.
For example, the following statements declare a variable and load it into register R7:
DATA: DB 00H, 00H, 00H, 42H
LD R7, DATA(PC)
The ZNEO CPU assembler automatically calculates the correct relative offset to access
the labeled address using PC as a base address. If a constant (non-label) offset is used with
PC in assembly language, the assembler measures the offset from the start of the current
instruction. The actual offset used in object code is a signed 14-bit value measured from
the end of the current instruction, but the assembler makes this adjustment automatically.
A program can use LEA to load the actual PC contents into a register. The following statements both load the PC value (the next instruction’s address) into register R5:
LEA R5, NEXT(PC)
NEXT: LEA R5, 4(PC)
A PC-based address cannot be used for the destination operand. The allowed offset range
for a PC-based LD or LEA operand is –8,192 to +8,191.
Operand AddressingUM018809-0611
If the required offset for a PC-based instruction exceeds the allowed range, the assembler
Note:
may silently convert the instruction to use the 32-bit immediate addressing mode.
Memory Address Decrement and Increment
In certain circumstances, a register-indirect LD operation can automatically decrement or
increment the base address register. A decrement is selected by adding a ‘--’ (doubleminus) prefix to the destination register name. The decrement always takes place before
the load is performed. This is called predecrement.
Example. The following statement decrements the base address in register R5, then loads
the memory location pointed to by R5 with the 32-bit contents of R6:
LD (--R5), R6
ZNEO
User Manual
®
CPU Core
35
Predecrement is supported only for destination operands. An LD store using predecrement
is similar to a PUSH, except the LD mnemonic allows a value in any register to be used as
the base address (See the Using the Stack Pointer (R15)
section on page 36 for more infor-
mation).
An increment is selected by adding a ‘++’ (double-plus) suffix to the source or destination
register name. The increment always takes place after the load is performed. This is called
postincrement.
Example. The following statement loads the memory location pointed to by register R5
with the contents of R6, then increments the base address in R5:
LD (R5++), R6
Postincrement can also be used for source operands. For example, the following statement
loads register R6 with the contents of the memory location pointed to by R5, then increments the base address in R5:
LD R6, (R5++)
An LD read using postincrement is similar to a POP, except the LD mnemonic allows a
value in any register to be used as the base address. The predecrement and postincrement
features can be used to implement high-level stack data structures independent of the
Stack Pointer. To help ensure that the next base address is valid, the increment or decrement amount varies with the size of the LD operation.
This is illustrated in the following example statements:
LD.B (--R5), R6 ; Decrement R5 by 1 and store 1 byte
LD.W (--R5), R6 ; Decrement R5 by 2 and store 2 bytes
LD (--R5), R6 ; Decrement R5 by 4 and store 4 bytes
Predecrement or postincrement operands cannot include an offset.
UM018809-0611Operand Addressing
ZNEO® CPU Core
User Manual
36
Using the Stack Pointer (R15)
Stack operations are a special kind of register-indirect memory access. The ZNEO CPU
system stack is implemented using ALU Register R15 as the Stack Pointer (SP). R15 can
be addressed like any register, but because of its Stack Pointer role it would be awkward to
use for any other purpose. The ZNEO CPU assembler recognizes SP as a synonym for
R15.
The system program startup routine initializes R15 to point to the highest address in internal RAM, plus 1. Subsequent PUSH, PUSHM, CALL, and LINK instructions; interrupts,
system exceptions, and traps all decrement SP before they store data on the stack. POP,
POPM, RET , UNLINK, and IRET instructions all increment SP to release stack space as it
is no longer needed. A program can also allocate or release stack space by changing the
register R15 (SP) value directly.
A system exception is provided to help keep the stack from overwriting other data; see the
Stack Overflow
POPM instructions to store and retrieve data from the stack.
section on page 50. Software can use the PUSH, POP, PUSHM, and
PUSH decrements SP and stores the source value onto the stack. POP loads the last value
on the stack into the specified register and increments SP. The assembler uses predecrement and postincrement LD opcodes to implement most PUSH and POP instructions.
PUSH and POP can be used with 8-, 16-, or 32-bit data sizes. 8-bit and 16-bit POP instructions can be either Unsigned or Signed.
When a 16-bit or 32-bit value is pushed onto the stack, the low-order bytes are pushed first
to store the value in the ZNEO CPU’s normal big-endian fashion.
Example
A 16-bit value is stored with bits [7:0] in the value’ s higher -addressed byte, and bits [15:8]
in the value’s base address byte.
If the stack is located on a 16-bit bus, an assembly language program might improve stack
performance by maintaining an even SP value—for example, by avoiding the single-byte
PUSH.B and POP.B instructions. This may require some effort, especially if the program
includes compiled C routines or any other code that does not preserve stack alignment.
The PUSHM and POPM instructions push or pop multiple registers with a single instruction. For example, the following statements push R0, R5, R6, R7 and R13 onto the stack
(in reverse numerical order), and then pop the same registers (in numerical order, so
pushes and pops remain symmetrical):
PUSHM <R0, R5-R7, R13>
POPM <R0, R5-R7, R13>
Operand AddressingUM018809-0611
The PUSHM and POPM instructions always push or pop all 32 bits of each register. The
ZNEO CPU assembler uses the PUSHMHI, PUSHMLO, POPMLO, and POPMHI
opcodes to implement PUSHM and POPM.
Using the Frame Pointer (R14)
Subroutines often use the stack for temporary variable space. For example, a CALL
sequence begins by pushing arguments onto the stack before calling the subroutine. When
the subroutine starts, it stores a copy of SP in another register called the Frame Pointer
(FP) and decrements SP to create stack space for local variables. When the subroutine is
finished, it copies FP back into SP and returns. Finally, the calling routine deallocates the
stack space it used for arguments.
The ZNEO CPU provides the LINK and UNLINK instructions to help program this
sequence. These instructions use register R14 as the FP register. The ZNEO CPU assembler recognizes FP as a synonym for R14.
ZNEO
User Manual
®
CPU Core
37
LINK is used at the beginning of a subroutine to copy the SP contents to FP and d ecrement
SP as needed. UNLINK copies FP back to SP, releasing the allocated space. LINK pushes
R14 on the stack before changing it, and UNLINK pops R14 after it is done, so routines
not using LINK or UNLINK can use R14 normally.
While the subroutine executes, it can access its arguments and variables using registerindirect addressing with the FP register. For constant (non-label) offsets in the range –32
to +31, the assembler uses special opcodes that make FP-based accesses more efficient.
Bit Manipulation
The ZNEO CPU does not provide any special instructions to address only one bit in memory, but individual bits are easily manipulated using masked logical instructions.
The following sections introduce the most basic bit manipulation techniques. The instructions used here are AND, OR, TM, and TCM. Other useful bit, logic and shift operations
are listed by groups in the ZNEO CPU Instruction Classes
Clearing Bits (Masked AND)
The logical AND instruction (discussed on page 74) stores a 1 bit only if the corresponding bit is set in both the source and destination. In effect, if the source (mask) bit is 0, the
destination bit is cleared. If the mask bit is 1, the destination bit is not changed.
section on page 22.
Example. The following assembly language statements initialize register R15 and then
clear bit 5 of that register:
LD R15, #FFFFFF70H ; LSB = 0111_0000B
AND R15, #FFFFFFDFH ; Clear R15 bit 5
UM018809-0611Operand Addressing
ZNEO® CPU Core
0 1 1 1 0 0 0 0
R15[7:0] = 70H
1 1 0 1 1 1 1 1
MASK = FFFF_FFDFH
0 1 0 1 0 0 0 0
R15[7:0] = 50H
Bit
5
Bit
32
AND R15, #FFFFFFDFH; Clear Bit 5 of Register 15
1 1 1 1 1 1 1 11 1 1 1 1 1 1 11 1 1 1 1 1 1 1
Bit
0
1 1 1 1 1 1 1 11 1 1 1 1 1 1 11 1 1 1 1 1 1 1
1 1 1 1 1 1 1 11 1 1 1 1 1 1 11 1 1 1 1 1 1 1
User Manual
38
This leaves the value FFFF_FF50H in register R15. Figure 9 displays how this example
clears only one bit of register R15.
Figure 9. Masked Logic Example: Clearing a Bit
Setting Bits (Masked OR)
The logical OR instruction stores a 0 bit only if the corresponding bit is clear in both the
source and destination. In effect, if the source (mask) bit is 1, the destination bit is set. If
the mask bit is 0, the destination bit is not changed.
Example. The following assembly language statements initialize register R15 and then set
bits [2,1] of that register:
LD R15, #00000070H ; LSB = 0111_0000B
OR R15, #00000006H ; Set R15 bits 1 and 2
This leaves the value 0000_0076H (LSB = 0111_0110B) in register R15.
Testing Bits (TM and TCM)
The TM instruction performs an internal AND to test mask-selected bits in the destination
register, but does not changes the source or destination register contents. Instead, TM sets
the
Z flag if the tested destination bits are all 0.
To select a bit to test, set the corresponding bit in the source (mask) operand as given in
the example below.
Example. The following assembly language statements initialize register R15 and then
test bit 2 of that register:
Operand AddressingUM018809-0611
LD R15, #00000070H ; LSB = 0111_0000B
TM R15, #00000004H ; Test bit 2
JP Z, BIT_IS_CLEAR
This leaves R15 unchanged, but sets the Z flag as R15[2] is clear.
Note:
ZNEO
User Manual
®
CPU Core
39
The TCM instruction (Test Complement under Mask, discussed on page 172
ments the destination value before ANDing it to the mask. In effect, TCM is identical to
TM except it sets the
Example . The following assembly language statements initialize register R15 and then
test bits [2,1] of that register:
LD R15, #00000070H ; LSB = 0111_0000B
TCM R15, #00000006H ; Test bits 1 and 2
JP Z, BITS_ARE_ONES
As a result, R15 remains unchanged but clears the Z flag because neither bit R15[2,1] is 1.
Jump Addressing
The ZNEO CPU jump instructions (JP and CALL), are used to alter the program flow.
These instructions alter the Program Counter, which indicates the next instruction to be
fetched. A few considerations are listed below.
•
All instructions must begin on an even address.
•
Instruction fetches bypass the internal I/O space. The result of an instruction fetch is
not defined in the range
devices that ignore address bits [31:24]).
) comple-
Z flag if the tested destination bits are all 1.
FFFF_E000H–FFFF_FFFFH (FF_E000H–FF_FFFFH on
•
A small device-specific address block starting at 0000_0000H is reserved for CPU
option bits and interrupt, trap, or exception vectors.
For details about option bits and vectors, refer to the ZNEO product specification that is
specific to your device .
Assembly language stat ements us e a label, expression, or numeric value to indicate the 32bit jump destination. The ZNEO CPU assembler analyzes the address and determines the
best address mode to use in the assembled object code.
In object code, following two jump address modes are available:
Direct Address. The JP, JP cc, or CALL opcode includ es four operand bytes containing
the 32-bit jump destination address. The destination address is written directly to the Program Counter to indicate the next instruction. Bit [0] of the operand is ignored.
UM018809-0611Operand Addressing
ZNEO® CPU Core
User Manual
40
Relative Address. The JP, JP cc, or CALL opcode includes a signed relative offset field
of 8, 12, 16, or 24 bits, which is added to the Program Counter’s contents. Table 15 provides the relative address operand ranges. For jumps within the same module, the assembler uses the most efficient offset size. For relative jumps across modules, the assembler
uses a default offset size that can be configured at assembly time.
Table 15. Relative Jump Offset Ranges
Operand BitsOffset Range
8–128 to +127
12–2,048 to +2,047
16–32,768 to +32,767
24–8,388,608 to +8,388,607
Operand AddressingUM018809-0611
Interrupt s
Note:
Note:
Peripherals use an interrupt request (IRQ) signal to get the CPU’s attention when it needs
to perform some action, such as moving peripheral data or exchanging status and control
information.
There are two ways to handle interrupt requests:
ZNEO
User Manual
®
CPU Core
41
Vectored Interrupts
interrupt service routine (ISR). The ISR must end with an Interrupt Return (IRET) instruction.
Polled Interrupts
the software tests the device’s interrupt request bits periodically. If action is required, the
software uses CALL and RET to invoke the appropriate service routine.
Interrupts are generated by internal peripherals, external devices (through the port pins) or
software. The Interrupt Controller prioritizes and handles individual interrupt requests
before passing them to the ZNEO CPU. The interrupt sources and trigger conditions are
device dependent.
To determine available interrupt sources (internal and external), triggering edge options,
and exact programming details, refer to the ZNEO Product Specification that is specific to
your device.
Vectored Interrupts
Each ZNEO CPU interrupt is assigned an interrupt vector that points to the appropriate
service routine for that interrupt. Vectors are stored in a reserved block of 4-byte memory
quads in the nonvolatile memory space. Each interrupt vector is a 32-bit pointer (service
routine address) stored in a memory quad.
. Asserting the IRQ signal forces the CPU to execute the corresponding
. Vectored interrupts are disabled (globally or only for the device), and
For interrupt vector locations, refer to the ZNEO Product Specification that is specific to
your device.
Interrupt Enable and Disable
Vectored interrupts are globally enabled and disabled by executing the Enable Interrupts
(EI) and Disable Interrupts (DI) instructions, respectively. These instructions affect the
UM018809-0611Interrupts
ZNEO® CPU Core
Note:
User Manual
42
Master Interrupt Enable flag (IRQE) in the FLAGS register in I/O memory . It is possible to
enable or disable interrupts by writing to the Flags Register directly. You can enable or
disable the individual interrupts using control registers in the Interrupt Controller.
For information about the Interrupt Controller, refer to the ZNEO Product Specification
that is specific to your device.
Interrupt Processing
When an enabled interrupt occurs, the ZNEO CPU performs the following tasks to pass
control to the corresponding interrupt service routine:
1. Push the Flags Register, including the Master Interrupt Enable bit (
IRQE), onto the
stack.
2. Push
00H (so SP alignment is not changed).
3. Push PC[7:0] (Program Counter bits [7:0]) onto the stack.
4. Copy the state of the
IRQE flag into the Chained Interrupt Enable flag (CIRQE).
5. Push PC[15:8] onto the stack.
6. Push PC[23:16] onto the stack.
7. Push PC[31:24] onto the stack.
8. Disable interrupts (clear
IRQE).
9. Fetch interrupt vector bits [31:24] into PC[31:24].
10. Fetch interrupt vector bits [23:16] into PC[23:16].
11. Fetch interrupt vector bits [15:8] into PC[15:8].
12. Fetch interrupt vector bits [7:0] into PC[7:0].
13. Begin execution at the new Program Counter address specified by the Interrupt Vector.
Figure 10 displays the effect of vectored interrupts on the Stack Pointer and the contents of
the stack.
Interrupts UM018809-0611
ZNEO
Top of StackStack Pointer
FLAGS[7:0]
PC[15:8]
PC[7:0]
Stack Pointer
Stack Pointer and Stack
Before an Interrupt
Stack Pointer and Stack
After an Interrupt
PC[23:16]
PC[31:24]
00H
—
User Manual
®
CPU Core
43
Figure 10. Effects of an Interrupt on the Stack
Example. Figure 11displays an example of addresses used during an interrupt operation.
In this example, the interrupt vector quad address is
vector address contained by that quad (
0023_4567H) is loaded into the Program Counter .
The execution of the interrupt service routine begins at
0000_0014H. The 32-bit interrupt
0023_4567H.
UM018809-0611Interrupts
ZNEO® CPU Core
Memory
Interrupt Vector Quad
Interrupt
Vector
Table
Interrupt Service
Routine First
Vector[23:16] = 23H
Vector[15:8] = 45H
0023_4567H
0000_0014H
0000_0015H
Vector[7:0] = 67H
0000_0016H
0000_0017H
Vector[31:24] = 00H
Quad Base Address
Address
Instruction
User Manual
44
Interrupts UM018809-0611
Figure 11. Interrupt Vectoring Example
Returning From a Vectored Interrupt
If no interrupts are pending or the Chained Interrupt Enable Flag (CIRQE) is 0, executing
the Interrupt Return (IRET) instruction at the end of an interrupt service routine results in
the following operations:
1. Pop PC[31:24] from the stack.
2. Pop PC[23:16] from the stack.
3. Pop PC[15:8] from the stack.
4. Pop PC[7:0] from the stack.
5. Increment SP by 1 (so SP alignment is not changed).
®
Caution:
ZNEO
CPU Core
User Manual
6. Pop the Flags register, including the Master Interrupt Enable bit (IRQE), from the
stack. This returns the
IRQE bit to its state before the interrupt occurred (assuming the
contents of the stack are not altered by the interrupt service routine).
7. Begin execution at the new Program Counter address.
If the
CIRQE flag is 1 and one or more vectored interrupts are pending, executing the IRET
instruction results in the following operation:
1. Disable interrupts (clear the IRQE flag).
2. Load the Program Counter directly from the vector table quad for the highest-priority
pending interrupt.
3. Begin execution at the new Program Counter address.
45
This chained-interrupt optimization omits unneeded pop and push cycles when program
control passes directly from one interrupt service routine to another.
Whenever a vectored interrupt or system exception occurs, the previous state of the
flag is copied to the
CIRQE flag after the Flags Register is pushed onto the stack. As a
result, interrupt chaining is disabled if interrupts are globally disabled (
nonmaskable interrupt or system exception occurs.
Programs that branch to interrupt service routines directly—for example, by executing a
PUSHF followed by a CALL—must set or clear the
terrupt chaining, respectively. Otherwise, the IRET that ends the routine might chain to
another interrupt unexpectedly.
The following assembly language statements clear the
LD.UB R5, FLAGS ;Read the current FLAGS value
AND R5, #11111101B ;Clear bit 1 (CIRQE)
LD.B FLAGS, R5 ;Write back with CIRQE flag cleared
Interrupt Priority and Nesting
The Interrupt Controller assigns a specific priority to each IRQ signal. When two IRQ signals are asserted at the same time, the higher priority interrupt service routine is executed
first. An interrupt service routine enables the vectored interrupt nesting, which allows
higher priority requests to interrupt the request being serviced.
IRQE
IRQE=0) when a
CIRQE flag to enable or disable in-
CIRQE flag:
Observe the following steps during the interrupt service routine to enable vectored interrupt nesting:
1. Push the current value of the Interrupt Enable Registers in I/O memory onto the stack.
UM018809-0611Interrupts
ZNEO® CPU Core
Note:
Note:
User Manual
46
2. Configure the Interrupt Enable Registers to disable lower priority interrupts.
3. Execute an EI instruction to enable vectored interrupts.
4. Proceed with the interrupt service routine processing.
5. After processing is complete, execute a DI instruction to disable interrupts.
6. Restore the Interrupt Enable Registers values from the stack.
7. Execute an IRET instruction to return from the interrupt service routine.
For information about Interrupt Priority and Interrupt Enable Registers, refer to the ZNEO
Product Specification that is specific to your device.
Software Interrupt Generation
Software can generate a vectored interrupt request directly by writing to the Interrupt
Request Registers in I/O memory. The Interrupt Controller and CPU handle software
interrupts in the same manner as hardware-generated interrupt requests.
To generate a Software Interrupt, write 1 to the appropriate interrupt request bit in the
selected Interrupt Request Register.
Example. The following instruction writes 1 to Bit 5 of Interrupt Request Register 1
(IRQ1SET):
LD R5, #00100000B ; Load mask for bit 5
OR.B IRQ1SET:IODATA, R5 ; Set interrupt request bit 5
If an interrupt at Bit 5 is enabled and there are no higher priority interrupt requests pending, program control gets transferred to the interrupt service routine specified by the corresponding interrupt vector.
For more information about the Interrupt Controller and Interrupt Request registers, refer
to the ZNEO Product Specification that is specific to your device.
Polled Interrupts
The ZNEO CPU supports polled interrupt processing. Polled interrupts are used when it is
not desirable to enable vectored interrupts for one or more devices. If interrupts are disabled for a device (or globally), no action is taken after the device asserts its IRQ signal
unless software explicitly polls (tests) the corresponding interrupt bit.
Interrupts UM018809-0611
®
Caution:
Note:
ZNEO
CPU Core
User Manual
Polling is performed in a frequently-executed section of code, such as the main loop of an
interactive program. For processor-intensive applications, there can be a trade-off between
the responsiveness of polled interrupts and the overhead of frequent polling.
To poll the bits of interest in an Interrupt Request register, use the Test Under Mask (TM)
or similar bit test instruction. If the bit is 1, perform a software call or jump to the interrupt
service routine. The interrupt service routine must clear the Interrupt Request Bit (by writing 1 to the bit) in the Interrupt Request Register and then return or branch back to the
main program.
Example. The following example outlines the sequence of a polling routine:
INCLUDE "device.INC" ; Include device-specific label
; definitions
LD R0, #00100000B ; Load mask for bit 5
TM.B IRQ1, R0 ; Test for 1 in IRQ1 Bit 5
JP Z, NEXT ; If no IRQ, go to NEXT
CALL SERVICE ; If IRQ, call the interrupt
; service routine.
NEXT:
;[Insert additional program code here.]
47
SERVICE: ; Process interrupt request
;Service routine code here.
LD.B IRQ1, R0 ; Write a 1 to clear IRQ1 bit 5
RET ; Return to address after CALL
Do not use IRET when returning from a polled interrupt service routine.
For information about the Interrupt Request registers, refer to the ZNEO Product Specification that is specific to your device.
UM018809-0611Interrupts
ZNEO® CPU Core
User Manual
48
Interrupts UM018809-0611
System Exceptions
Note:
System exceptions are similar to Vectored Interrupts; however, exceptions are generated
by the CPU and cannot be masked or disabled. There are five ZNEO CPU events that generate system exceptions; each is listed below and described in this chapter.
•
Program Counter Overflow
•
Stack Overflow
•
Divide-by-Zero
•
Divide Overflow
•
Illegal Instruction
ZNEO
User Manual
®
CPU Core
49
It is possible for individual ZNEO CPU products to generate system exceptions in addition
to those listed above.
To determine if your device generates other system exceptions, refer to the ZNEO product
specification that is specific to your device .
Following a system exception, the Flags and Program Counter are pushed on the stack.
The Program Counter value that is pushed onto the stack points to the next instruction (not
the instruction that generated the system exception).
The system exception vector is stored in a reserved memory quad at
nonvolatile memory space. The vector is a 32-bit pointer (service routine address) stored
in the 4-byte quad. When an exception occurs, the vector replaces the value in the Program
Counter (PC). Program execution continues with the instruction pointed to by the new PC
value.
0000_0008H in the
Symbolic Operation of System Exception
A symbolic operation of system exceptions is exemplified below.
SP
SP – 1
(SP)
Flags
SP – 5
SP
PC
(SP)
PC
Vector
UM018809-0611System Exceptions
ZNEO® CPU Core
Note:
Caution:
Note:
User Manual
50
Program Counter Overflow
The Program Counter Overflow exception can be used to restrict program execution to the
memory space below a certain address. On each instruction fetch, the 32-bit PC value is
compared to the value in the Program Counter Overflow register (PCOV) in I/O memory.
If the PC value is greater than the PCOV value, a Program Counter Overflow system
exception is generated after the instruction fetch completes. After a Program Counter
Overflow occurs, the
EXCP) is set to 1. After the first PCOV exception has executed, no additional PCOV
exceptions are generated until the
the bit to 0.
For detailed information regarding the System Exception register (SYSEXCP), refer to the
ZNEO product specification that is specific to your device .
PCOVF bit in the System Exception register in I/O memory (SYS-
PCOVF bit is cleared. Writing 1 to the PCOVF bit clears
The IRET instruction must not be used to end a PCOV exception service routine. After
a PCOV exception occurs, the Program Counter value on the stack points to an address
following the presumably invalid instruction that was fetched.
To set up Program Counter Overflow Protection, initialize PCOV to the highest address
that you intend to use for program instructions.
Stack Overflow
The Stack Overflow exception can be used to help restrict stack growth to the memory
space above a certain address. Whenev er the re gister R15 Stack Pointer (SP) is changed,
its value is compared to the value in the Stack Pointer Overflow register (SPOV) in I/O
memory. If the SP value is less than the SPOV value, a Stack Pointer Overflow system
exception is generated after the current instruction completes.
After a Stack Pointer Overflow occurs, the
I/O memory (SYSEXCP) is set to 1. After the first SPOV exception has executed, no additional SPOV exceptions are generated until the
SPOVF bit clears the bit to 0.
SPOVF bit in the System Exception register in
SPOVF bit is cleared. Writing 1 to the
For more information about the System Exception register (SYSEXCP), refer to the ZNEO
product specification that is specific to your device .
System ExceptionsUM018809-0611
®
Caution:
Note:
ZNEO
CPU Core
User Manual
Observe the following steps to set up Stack Overflow Protection.
1. Initialize the Stack Pointer (SP) to its starting location (the highest RAM address +1).
2. Initialize SPOV to the lowest address to which it is safe for the stack to extend, minus
at least 12 bytes to allow room for interrupt completion.
An SPOV exception does not block writes to the stack. When initializing the SPOV register, you must provide for at least 12 additional bytes of stack data that might be written
below the programmed address. This occurs if an interrupt generates a Stack Overflow on
the first byte it pushes. In this case the interrupt pushes 5 additional bytes and the exception itself must push six more before the exception handler can start.
The 11-byte allowance described here is not sufficient if user code manipulates the Stack
Pointer (register R15), either directly or by using the LINK instruction. The allowance
must be increased to accommodate the largest expected decrement of SP.
51
Divide-by-Zero
If the divisor is zero during execution of a divide instruction (UDIV or SDIV), the ZNEO
CPU generates a Divide-by-Zero system exception. After a Divide-by-Zero has occurred,
the
DIV0 bit in the System Exception register in I/O memory (SYSEXCP) is set to 1. After
the first Divide-by-Zero system exception has executed, no additional Divide-by-Zero
system exceptions are generated until the
bit to 0.
For more information about the System Exception register (SYSEXCP), refer to the ZNEO
product specification that is specific to your device .
Divide Overflow
If execution of a divide instruction (UDIV64) results in an overflow, the ZNEO CPU generates a Divide Overflow system exception. After a Divide Overflow has occurred, the
DIVOVF bit in the System Exception register in I/O memory (SYSEXCP) is set to 1. After
the first Divide Overflow system exception has executed, no additional Divide Overflow
system exceptions are generated until the
clears the bit to 0.
DIV0 bit is cleared. Writing 1 to DIV0 clears the
DIVOVF bit is cleared. Writing 1 to DIVOVF
UM018809-0611System Exceptions
ZNEO® CPU Core
Note:
Note:
Note:
Caution:
User Manual
52
For more information about the System Exception register (SYSEXCP), refer to the ZNEO
product specification that is specific to your device .
Illegal Instruction
If the Program Counter addresses any unimplemented opcode, the ZNEO CPU generates
an Illegal Instruction system exception.
memory word, so the
instruction.
The Break opcode (BRK, 0000H) operates as an ILL exception if On-Chip Debugger
(OCD) breaks are disabled. For details about the OCD, refer to the ZNEO product specification that is specific to your device.
FFFFH is the default value of an unprogrammed
FFFFH opcode is defined as the Illegal Instruction Exception (ILL)
An illegal instruction invokes the System Exception vector at
0000_0008H in memory.
An ILL is similar to other system exceptions except the Program Counter does not increment before it is pushed onto the stack, so the Program Counter value on the stack points
to the instruction that caused the exception.
After an illegal instruction exception occurs, the
in I/O memory (
SYSEXCP) is set to 1. After the first ILL exception has executed, addi-
tional ILL exceptions will not push the Program Counter again until the
Writing 1 to the
ILL bit clears the bit to 0. For more information, see the description of the
ILL bit in the System Exception register
ILL bit is cleared.
ILL instruction on page 106.
For more information about the System Exception register (SYSEXCP), refer to the ZNEO
product specification that is specific to your device .
An IRET instruction must not be performed to end an illegal instruction exception service routine. As the stack contains the Program Counter value of the illegal instruction,
the IRET instruction returns the code execution to this illegal instruction.
System ExceptionsUM018809-0611
Sof tware Traps
Note:
The TRAP Vector instruction allows software to invoke any vectored service routine, par-
ticularly software-defined traps. The TRAP instruction executes the pointed service routine by the specified vector . Software traps use the same vector space as system exceptions
and interrupts. Like other vectors, the 32-bit trap vector value is stored in a memory quad.
ZNEO
User Manual
®
CPU Core
53
Possible vectors are numbered from 0 to 255 (
includes memory quads
address is 4
Example. The following instruction executes a software-defined service routine pointed
Vector.
to by Vector 255 stored in quad
TRAP #FFH
0000_0000H to 0000_03FCH. Each vector quad’s physical
0000_03FCH:
0H to FFH). The possible vector space
A software trap service routine must execute an IRET instruction to return from the trap.
Other vectors not used by the CPU or peripherals are available for software-defined traps.
For example, Vector 255 (vector quad
input error handling routine, which is then invoked by a
0000_03FCH) is initialized with a pointer to a user-
TRAP FFH instruction.
For a list of vectors used by the CPU and internal peripherals, refer to the ZNEO product
specification that is specific to your device .
A TRAP instruction is used with exception or interrupt vectors but the TRAP instruction
does not sets any register bits in I/O memory that the corresponding service routine is
likely to inspect. For more information, see the Software Interrupt Generation
section on
page 46.
Some locations in the vector space may be reserved by the CPU for other uses. For exam-
ple, a typical ZNEO CPU uses the memory quad at
fore, Vector 00 is not available for service routines. Software can use the instruction
#01
to invoke the RESET vector at 0000_0004H. For more information, see the TRAP
0000_0000H for option bits; there-
TRAP
instruction on page 178.
UM018809-0611Software Traps
ZNEO® CPU Core
User Manual
54
Software TrapsUM018809-0611
Instruction Opcodes
This chapter provides a complete list of ZNEO CPU instruction opcodes.
Each instruction opcode listed in this chapter consists of one, two or three 16-bit words. T o
abbreviate the listing, certain bit positions are represented symbolically by function.
Table 16 lists the bit field symbols used.
Unary operation (UOP) number: 00B=CLR, 01B=CPZ, 10B=INC, 11B=DEC.
dDestination register number.
sSource register number.
mRegister mask for PUSHM, POPM.
iImmediate operand bits.
cCondition code.
rRelative offset (in Words).
vVector number.
wSelect Word or Quad (0=16, 1=32 bits)
bSelect Byte or Word (0=8 bits, 1=16 bits)
zSelect extension (0=Unsigned, 1=Signed)
+Select pointer predecrement or postincrement.
For a destination pointer: 0=predecrement, 1=postincrement.
For a source pointer: 0=no increment, 1=postincrement
xDon't care digit (ignored by CPU).
ZNEO
User Manual
®
CPU Core
55
Table 17 lists the abbreviations used in place of register names or explicit values in this
chapter. Normal assembly syntax for operands is described in the Operand Addressing
chapter on page 27.
UM018809-0611Instruction Opcodes
ZNEO® CPU Core
User Manual
56
Table 17. Operand Symbols
Operand AbbreviationMeaning
addr16, addr3216- or 32-bit direct address.
cc44-bit condition code.
imm32Immediate destination-sized operand with the specified number of bits.
uimm8Unsigned immediate short operand with the specified number of bits.
simm16Signed immediate short operand with the specified number of bits.
maskRegister mask (list of ALU registers).
vector88-bit vector number.
RsSource register name.
RdDestination register name.
srcSource operand.
dstDestination operand.
soff14, soff13, soff6Signed indirect address (pointer) offset.
relRelative jump offset.
Table 18 lists instructions by opcode. Unimplemented opcodes are shaded in grey.
0000 0000 0000 0010PUSHFPush Flags Register .
0000 0000 0000 0011POPFPop Flags Register.
0000 0000 0000 0100ATMDisable Interrupts and DMA during next three
instructions.
0000 0000 0000 0101NOFLAGSDisable write to FLAGS on next instruction.
0000 0000 0000 0110—Unimplemented
0000 0000 0000 0111—Extend prefix used to select extended function
for next ADD, SUB, CP, CPZ, SRR, SRA, SLL,
or UDIV instruction.
This chapter provides detailed description of the assembly language instructions available
with the ZNEO CPU.
Instruction Notation
Tables 19 and 20 list the symbolic notation for expressions and other miscellaneous symbols used to describe the operation of ZNEO CPU instructions. For general notation
details, see Manual Conventions on page xiv. For operand notation details, see the Oper-
and Addressing section on page 27. The operand abbreviations are explained in Table 17
on page 56.
ZNEO
User Manual
®
CPU Core
65
Numerical and Expression Notation
T able 19 lists symbols and operators used in expressions in this document. This is a subset
of operators recognized by the assembler. For more details, refer to the assembler documentation.
Table 19. Symbols Used in Expressions
SymbolDefinition
$During assembly, returns the current address.
HHexadecimal number suffix.
BBinary number suffix.
xB, xHBinary or hexadecimal “don’t care” digit (ignored by CPU).
%Alternate hexadecimal number prefix.
Modulus operator (remainder of division) when preceded and followed by spaces.
*Multiplication operator (in assembly source).
/Divisio n op er at or.
+Addition operator.
–Subtraction operator. Minus sign or negation when used as unary prefix.
~One’s complement unary operator.
!=Not equal relational operator. True if terms are not equal.
UM018809-0611Instruction Set Reference
ZNEO® CPU Core
User Manual
66
Miscellaneous Abbreviations
Table 20 lists additional symbols used in the instruction set descriptions.
Table 20. Abbreviations Used in Text and Tables
SymbolDefinition
dstDestination Operand.
srcSource Operand.
RdDestination Register.
RsSource Register.
ccCondition Code.
An arrow (indicates assignment of a value. Fo r ex am p le,
dst dst + src indicates that sum of the operands is stored in the destination location.
A double arrow () indicates the exchange of two values.
Multiplication sign (arithmetic); repeated operation count.
CIRQEChained Interrupt Enable.
IRQEMaster Interrupt Enable.
*Flag bit state depends on result of operation.
–Flag bit state is not affected by operation.
0Flag bit is cleared to 0.
1Flag bit is set to 1.
SPStack Pointer.
PCProgram Counter.
FPFrame Pointer.
Instruction Set ReferenceUM018809-0611
Example Description
The instruction sets described on the following pages are organized alphabetically by
mnemonic abbreviation. An example instruction is provided below.
MNEMONIC
Definition
Definition of instruction mnemonic.
Syntax
Simplified description of assembly coding.
ZNEO
User Manual
®
CPU Core
67
Operation
Symbolic description of the operation performed.
Description
Detailed description of the instruction operation.
Flags
Information about how the CPU flags are affected by instruction operation.
Syntax and Opcodes
A table providing assembly syntax and corresponding opcodes.
Example
A sample code example using the instruction.
UM018809-0611Mnemonic
ZNEO® CPU Core
Note:
User Manual
68
ADC
Definition
Syntax
Operation
Description
Add with Carry
ADC dst, src
dstdst + src + C
The source operand and the Carry (C) flag are added to the destination operand using signed
(two’s-complement) addition. The sum is stored in the destination operand. The contents of the
source operand are not affected. This instruction is used in multiple-precision arithmetic to
include the carry from the addition of low-order operands into the addition of high-order operands.
The Zero (Z) flag is set only if the initial state of the Z flag is 1 and the result is 0. This instruction
is generated by using the Extend prefix,
Flags
76543210
CZSVBCIRQE IRQE
*****–––
Legend
C= Set to 1 if the result generated a carry; otherwise set to 0.
Z= Set to 1 if Z is initially 1 and the result is zero; otherwise set to 0.
S= Set to 1 if the result msb is 1; otherwise set to 0.
V= Set to 1 if an arithmetic overflow occurs; otherwise set to 0.
B= Set to 1 if the initial destination or source value is 0; otherwise set to 0.
CIRQE = No change.
IRQE= No change.
0007H, with the ADD opcodes.
Flags are set based on the memory destination size, or 32 bits for register destinations.
Add the source operand to the destination operand. Perform signed (two’ s-complement) addition.
Store the sum in the destination operand. The contents of the source operand are not affected.
Flags
76543210
CZSVBCIRQE IRQE
*****–––
Legend
C= Set to 1 if the result generated a carry; otherwi se set to 0.
Z= Set to 1 if the result is zero; otherwise, set to 0.
S= Set to 1 if the result msb is 1; otherwise set to 0.
V= Set to 1 if an arithmetic overflow occurs; otherwise set to 0.
B= Set to 1 if the initial destination or source value is 0; otherwise set to 0.
CIRQE = No change.
IRQE= No change.
Flags are set based on the memory destination size, or 32 bits for register destinations.
The source operand is logically ANDed with the destination operand. An AND operation stores a
1 when the corresponding bits in the two operands are both 1; otherwise the operation stores a 0.
The result is written to the destination. The contents of the source are unaffected. Table 21 summarizes the AND operation.
Table 21. Truth Table for AND
dstsrc Result (dst)
000
100
010
111
Flags
76543210
CZSVBCIRQE IRQE
–**0*–––
Legend
C= No change.
Z= Set to 1 if the result is zero; otherwise, set to 0.
S= Set to 1 if the result msb is 1; otherwise set to 0.
V= Cleared to 0.
B= Set to 1 if the initial destination or source value is 0; otherwise set to 0.
CIRQE = No change.
IRQE= No change.
AND InstructionUM018809-0611
Flags are set based on the memory destination size, or 32 bits for register destinations.
Block all interrupt and DMA requests during execution of the next 3 instructions.
Description
ZNEO
User Manual
®
CPU Core
77
The Atomic instruction forces the ZNEO CPU to execute the next three instructions as a single
block (that is, atom) of operations. During execution of these next three instructions, all interrupts and DMA requests are prevented. This allows operations to be performed on memory locations that might otherwise be changed or used during the operation by interrupts or DMA.
Flags
Flags are not affected by this instruction.
Syntax and Opcodes
Instruction, OperandsWord 0Word 1Word 2
ATM0004H
Example
The following example tests a bit used to lock a resource, then sets the bit if it is clear. ATM
ensures that the tested bit can be set before another routine tests it.
LD R7, #00000010B;Load mask for bit 1Object Code: 3702
ATM;Block interrupt/DMA requests Object Code: 0004
TM.B B047H:RAM, R7;Test semaphore with bit mask Object Code: 7657 B047
JP NZ, Msg1_In_Use;JP if resource is in useObject Code: EE xx
OR.B B047H:RAM, R7;Else set masked bit
; to lock resource
Object Code: 7357 B047
UM018809-0611ATM Instruction
ZNEO® CPU Core
Note:
User Manual
78
BRK
Definition
Syntax
Operation
Description
On-Chip Debugger Break
BRK
None
If the Break capability is enabled, execution of the BRK instruction initiates an On-Chip Debugger break at this address. If the Break capability is not enabled, the BRK instruction operates as
an Illegal Instruction Exception (ILL).
Refer to the ZNEO product specification that is specific to your device for information
regarding the On-Chip Debugger.
Flags
Flags are not affected by this instruction.
Syntax and Opcodes
Instruction, OperandsWord 0Word 1Word 2
BRK0000H
BRK InstructionUM018809-0611
CALL
Definition
Syntax
Operation
CALL Procedure
CALL dst
SPSP4
(SP)PC
PCdestination address
ZNEO
User Manual
®
CPU Core
79
Description
A CALL instruction decrements the Stack Pointer (R15) by four and stores the current Program
Counter value on the top of the stack. The pushed PC value points to the first instruction following the CALL instruction. Then the destination address is loaded into the Program Counter and
execution of the procedure begins. After the procedure completes, it uses a RET instruction to
pop the previous PC value and return from the procedure.
In assembly language, the destination is specified as a label or 32-bit address operand. When possible, the ZNEO CPU assembler automatically calculates a relative offset and generates relative
CALL opcodes to produce more efficient object code. For a relative CALL, the destination
address is the PC value plus two times the relative operand value.
In the CALL (Rs) syntax, if the contents of Rs are odd the least significant bit is discarded, so that
the call destination address is always an even number.
To invoke a 32-bit addressed call explicitly, use the CALLA instruction.
The CALLA instruction decrements the Stack Pointer (R15) by four and stores the current Program Counter value onto the top of the stack. The pushed PC value points to the first instruction
following the CALLA instruction. Then the 32-bit immediate operand is loaded into the Program
Counter and execution of the procedure begins. After the procedure completes, it uses a RET
instruction to pop the previous PC value and return from the procedure.
If the immediate operand is odd, the least significant bit is discarded so that the call destination
address is always an even number.
The CALLA instruction is used to explicitly invoke the 32-bit immediate call opcode in situations when a fixed opcode size is desired, such as a jump table.
1. The ZNEO CPU assembler uses an LD opcode to implement CLR Rd.
1
CLR InstructionUM018809-0611
Examples
ZNEO
User Manual
®
CPU Core
83
Before:
CLR B032H:RAM;Object code: ADA8 B032 or ADAE B032
After:
Before: R7=FFFF_B023H, FFFF_B023H=FCH
CLR.B (R7);Object code: AC07
After:
FFFF_B032H=8BF7_47AFH
FFFF_B032H=0000_0000H
FFFF_B023H=00H
UM018809-0611CLR Instruction
ZNEO® CPU Core
Note:
User Manual
84
COM
Definition
Syntax
Operation
Complement
COM dst
dst
Description
~dst
The contents of the destination operand are complemented (one’s complement). All 1 bits are
changed to 0 and all 0 bits are changed to 1.
Flags
76543210
CZSVBCIRQE IRQE
0**0*–––
Legend
C= Cleared to 0.
Z= Set to 1 if the result is zero; otherwise, set to 0.
S= Set to 1 if the result msb is 1; otherwise set to 0.
V= Cleared to 0.
B= Set to 1 if the initial destination value was 0; otherwise set to 0.
CIRQE = No change.
IRQE= No change.
Flags are set based on the 32-bit destination register value.
Syntax and Opcodes
Instruction, OperandsWord 0Word 1Word 2
COM Rd{454H, Rd}
COM InstructionUM018809-0611
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.