Prog 16C
Prog 16C
Prog 16C
TM
REVISION RECORD
VERSION
1.0 1.1
RELEASE DATE
December 2000 February 2001
SUMMARY OF CHANGES
First release. Changed BAL/Bcond to 16 MByte. Minor claricatons/corrections. Product release for CR16B/C.
3.1
March 2002
ii
PREFACE
This Programmers Reference Manual presents the programming model for the CompactRISC CR16C microprocessor core. The key to system programming, and a full understanding of the characteristics and capabilities of the CompactRISCTM Toolset, is understanding the programming model. The information contained in this manual is for reference only and is subject to change without notice. No part of this document may be reproduced in any form or by any means without the prior written consent of National Semiconductor Corporation.
National Semiconductor is a registered trademark and CompactRISC is a trademark of National Semiconductor Corporation. All other brand or product names are trademarks or registered trademarks of their respective holders iii
CONTENTS
Chapter 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 Chapter 2 2.1 2.2 2.3
INTRODUCTION NATIONALS COMPACTRISC TECHNOLOGY .............................................. 1-1 CR16C 16-BIT COMPACTRISC PROCESSOR CORE ................................... 1-1 THE COMPACTRISC ARCHITECTURE ......................................................... 1-2 REDUCED MEMORY REQUIREMENTS ........................................................ 1-3 SCALABLE ARCHITECTURE FROM 8 TO 64 BITS ....................................... 1-4 MODULAR EXTENSIONS ............................................................................... 1-4 DEVELOPMENT TOOLS ................................................................................. 1-5 PROGRAMMING MODEL COMPATIBILITY WITH CR16A AND CR16B .................................................. 2-1 DATA TYPES ................................................................................................... 2-1 REGISTER SET ............................................................................................... 2-2 2.3.1 General-Purpose Registers .................................................................. 2-3 2.3.2 Dedicated Address Registers ............................................................... 2-3 2.3.3 The Processor Status Register ............................................................ 2-4 2.3.4 The Configuration Register .................................................................. 2-6 INSTRUCTION SET ......................................................................................... 2-8 MEMORY ORGANIZATION ........................................................................... 2-12 2.5.1 Data References ................................................................................ 2-13 2.5.2 Stacks ................................................................................................ 2-14 ADDRESSING MODES ................................................................................. 2-15 EXCEPTIONS INTRODUCTION .............................................................................................. 3-1 INTERRUPT HANDLING ................................................................................. 3-2 TRAPS ............................................................................................................. 3-3 DETAILED EXCEPTION PROCESSING ......................................................... 3-4 3.4.1 Instruction Endings ............................................................................... 3-4 3.4.2 The Dispatch Table .............................................................................. 3-5 3.4.3 Acknowledging an Exception ............................................................... 3-6
CONTENTS-v
2.4 2.5
Exception Service Procedures ............................................................. 3-9 Returning from Exception Service Procedures .................................... 3-9 Priority Among Exceptions ................................................................. 3-10 Nested Interrupts ................................................................................ 3-12
RESET ........................................................................................................... 3-13 ADDITIONAL TOPICS DEBUGGING SUPPORT ................................................................................. 4-1 4.1.1 Instruction Tracing ................................................................................ 4-1 4.1.2 The Breakpoint Instruction ................................................................... 4-2 4.1.3 User Programmable Breakpoint Features ............................................ 4-3 4.1.4 Example Breakpoints ......................................................................... 4-13 4.1.5 In-System Emulator (ISE) .................................................................. 4-14 4.1.6 Hardware Debug Mode ...................................................................... 4-15 4.1.7 Debug Control and Status Registers .................................................. 4-15 CACHE SUPPORT ........................................................................................ 4-20 4.2.1 Instruction Cache Operation .............................................................. 4-20 4.2.2 Instruction Cache Invalidation ............................................................ 4-21 4.2.3 Data Cache Operation ....................................................................... 4-22 4.2.4 Data Write Operation ......................................................................... 4-23 4.2.5 Data Cache Invalidation and Coherence Support .............................. 4-23 4.2.6 Data Cache Monitoring ...................................................................... 4-24 INSTRUCTION EXECUTION ORDER ........................................................... 4-24 4.3.1 The Instruction Pipeline ...................................................................... 4-25 4.3.2 Serializing Operations ........................................................................ 4-26 INSTRUCTION SET INSTRUCTION DEFINITIONS ......................................................................... 5-1 DETAILED INSTRUCTION LIST ..................................................................... 5-3
4.2
4.3
Appendix A INSTRUCTION EXECUTION TIMING Appendix B INSTRUCTION SET ENCODING Appendix C STANDARD CALLING CONVENTIONS Appendix D COMPARING CR16C WITH CR16A/B INDEX
CompactRISC CR16C Programmers Reference Manual CONTENTS-vi
Chapter 1 INTRODUCTION
1.1
1.2
INTRODUCTION 1-1
2. Instruction Set Enhancements Double-word support for most instructions improve optimizations for data and code access above the rst 64K. - load and store - move and movex/z - arithmetic (compare, add, subtract) - logic (AND, OR, XOR) - shifts (arithmetic and logical) Expanded push/pop instructions allow up to eight registers with a separate bit to determine if the return address should also be pushed/popped to/from the stack expanded load/store multiple instructions to allow up to 8 registers. optional mac instruction 3. Addressing Modes Enhancements Index addressing mode for better support of relocatable code Register pair relative addressing mode, with efcient instruction encoding for all memory access instructions, improves optimizations for data and code access above the rst 64K. 4. System Features User/supervisor mode Illegal address trap (address out of range) Cache support Enhanced debug features, with up to eight hardware breakpoints 5. Speed Improvements Enhanced pipelining of data transfers Faster/deterministic multiply (single cycle 8*8) To ensure a seamless transition for existing CompactRISC users, the CR16C provides a conguration bit, CFG.SR, that permits exclusive use of only small registers. This mode is backward compatible with the large programing model of the CR16B. The small programing model of the CR16B, which is backward compatible with the CR16A, is no longer supported.
1.3
INTRODUCTION 1-2
For example: The CR16C executes an optimized instruction set with up to 33 internal registers grouped in 16 general-purpose registers, four dedicated address registers, a processor status register, a conguration register and up to 11 debug-control registers. The CR16C has a three-stage pipeline that is used to obtain a peak performance of 50 Million Instructions Per Second (MIPS) at a clock frequency of 50 MHz. The CR16C core includes a pipelined integer unit that supports a peak execution speed of one instruction per each internal cycle, with a 100 Mbyte/sec pipelined bus. The CR16C performs fast multiply operations using a 16-bit by 8-bit hardware multiplier. In general, the CompactRISC architecture supports little-endian memory addressing. This means that the byte order in the CR16C is from the least signicant byte (LSB) to the most signicant byte (MSB).
1.4
INTRODUCTION 1-3
are saved as 32-bit operands on the stack. CompactRISC instructions operate on 8-, 16- and 32-bit data. Non-aligned accesses are allowed. Dedicated data type conversion instructions speed data access to mixed size data. With smaller code size and variable length instructions and data, the CompactRISC family provides more efcient use of smaller, lower cost, lower bandwidth memories. Smaller memory enables the designer to choose between several potential advantages: Reduced costs Many more system elements integrated with on-chip memory Fewer pins to access minimum-sized off-chip memory Larger amounts of on-chip memory than similar processors, at the same cost.
1.5
1.6
MODULAR EXTENSIONS
The CompactRISC technology was designed to be easily extended. This means that specialized functions needed by specic applications can be easily added to a single-chip design. A modular internal bus provides predened processor and I/O interfaces to the core bus and the peripheral bus. These buses are designed for maximum exibility. The core bus is a high-speed bus and can be used to connect performance-demanding functions to the CPU such as fast on-chip memory, DMA channels, and
INTRODUCTION 1-4
additional coprocessor units such as a DSP. The peripheral bus is a simple, lower speed bus for less demanding peripherals such as counters, timers, PWM lines and MICROWIRE serial interfaces. Using a template approach, it is easy to create small, cost-effective custom systems. It is also easy to expand the functionality of CompactRISC core-based systems to include any number of application specic features.
1.7
DEVELOPMENT TOOLS
High-level development tools are essential to rapid, modern design. The CompactRISC architecture is well supported with a comprehensive Cbased development and debug environment available from National and third party vendors. Key software development components include an optimizing C compiler, a macro assembler, run-time libraries, librarian and a graphical source-level debugger with enhanced simulation capabilities. In addition, an integrated, multiple core, graphical debugger supports debugging of multiple CompactRISC/DSP cores on a single die. On the hardware side, the CompactRISC architecture has modular ISE (In System Emulator) support from third-party development system vendors, and various development boards for all current product offerings. The CR16C supports a NEXUS class 1 compliant on-chip debug module. With this interface, every debugger that uses the industry standard NEXUS API can be used for CR16C-based System-on-a-Chip (SOC) designs. The CompactRISC architecture is also well supported with Real-Time Operating Systems (RTOS) from third party vendors. As a package, these tools simplify the task of designing and developing advanced embedded systems in high level languages such as ANSI-C.
INTRODUCTION 1-5
2.1
2.2
DATA TYPES
The CompactRISC family of processors are little-endian machines. As such, the LSB always resides in the lower address, both for address and data variables.
The integer data type is used to represent integers. Integers may be signed or unsigned. Three integer sizes are supported: 8-bit (1 byte), 16bit (1 word) and 32-bit (1 double-word). Signed integers are represented as binary 2s complement numbers, with values in the range 27 to 27 1, 215 to 2151 and 231 to 2311, respectively. Unsigned numbers have values in the range 0 to 281, 0 to 2161 and 0 to 2321, respectively. The Boolean data type is represented as an integer (either a byte or a word). The value of its least signicant bit represents one of two logical values: true (integer 1) or false (integer 0). Bits other than the least signicant bit are not interpreted.
2.3
REGISTER SET
This section describes the register set of the CR16C. The format of each register is illustrated and described in detail. Bits/Registers specied as reserved must be written as 0, and return undened results when read. Non-implemented registers are read as zero. The internal registers of the CR16C are grouped by function: 16 general-purpose registers including four double registers: Two available for use in index addressing mode One used as a return address pointer One used as the stack pointer Four dedicated address registers One Processor Status Register One Conguration Register Five debug registers supporting two debug channels. Optionally, additional sets of four debug registers for each pair of auxiliary debug channels. Figure 2-1 shows the internal registers of the CR16C. Dedicated Address Registers
31 23 15 PC ISPL USPL INTBASEL 0
General-Purpose Registers
15 R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 RA SP 0
Conguration Register
15 CFG 0 31
Debug Registers
31 DCRH CAR0H CAR1H 15 DBS DCRL DSR CAR0L CAR1L 0
The number of debug registers depends on the conguration of the chip Figure 2-1. CR16C Internal Registers
CompactRISC CR16C Programmers Reference Manual PROGRAMMING MODEL 2-2
The value in the PC Register points to the rst byte of the instruction currently being executed. CR16C instructions are aligned to even addresses, thus the least signicant bit of the PC is always 0. At reset, the PC is initialized to 0 or an alternative predetermined value. The value of the PC prior to reset is saved in the (R1,R0) general-purpose register pair.
The ISP points to the lowest address of the last item stored on the interrupt stack. This stack is used by the hardware when interrupts or exceptions occur. This stack pointer is accessible as the ISP Processor Register for initialization. The interrupt stack can exist in the entire address range. The ISP cannot be used for any purpose other than the automatic storage of registers on the interrupt stack during an exception, and the restoration of these registers during a RETX. The interrupt stack grows downward in memory. See Section for additional details. The most signicant 8 bits of ISP and the least signicant bit of ISP are forced to 0. The USP points to the lowest address of the last item stored on the user stack. This stack is used when the program stack is used for supervisor and user level processes. This stack also grows downward in memory. See The program stack on page 2-14 for more information. If the USP points to an illegal address (any address greater than 0x00FF_FFFF) the execution of a stack modifying instruction (PUSH or POP) an IAD trap. The INTBASE Register holds the address of the dispatch table for interrupts and traps. The dispatch table can be located anywhere in the supported addresses range. The most signicant 8 bits of INTBASE and the least signicant bit of INTBASE are forced to 0. See Chapter 3 for more information.
15 reserved
12
11 I
10 P
9 E
8 res
7 N
6 Z
5 F
4 res
3 U
2 L
1 T
0 C
Figure 2-2. PSR Register At reset, bits 0 through 11 of the PSR are cleared to 0, except for the PSR.E bit, which is set to 1. In addition, the value of each bit prior to reset is saved in the R2 general-purpose register. Bits Z, C, L, N, and F in the PSR have a dedicated condition code in conditional branch instructions. Any conditional branch instruction can cause a branch in program execution, based on the value of one or more of these PSR bits. For example, one of the Bcond instructions, BEQ (Branch EQual), causes a branch if the PSR.Z ag is set. Refer to the Bcond instruction in Section 5.1 on page 5-1 for details.
Bits 4 and 8 have a constant value of 0. Bits 12 through 15 of the PSR are reserved. The other bits are described below. In general, status bits are modied only by specic instructions. Otherwise, status bits maintain their values throughout instructions which do not implicitly affect them.
Bit C
The Carry bit indicates whether a carry or borrow occurred after addition or subtraction. It can be used with the ADDC and SUBC instructions to perform multiple-precision integer arithmetic calculations. It is cleared to 0 if no carry or borrow occurred, and set to 1 if a carry or borrow occurred. The Trace bit causes program tracing. When the T bit is set to 1, a Trace (TRC) trap is executed after every instruction. Refer to Section 4.1.1 on page 4-1 for more information on program tracing. The T bit is automatically cleared to 0 when a trap or an interrupt occurs. The T bit is used in conjunction with the P bit (see below). When a hardware debug module is present in the system, the value of the T bit is ignored. The Low ag is set by comparison operations. In integer comparison, the L ag is set to 1, if the second operand (Rdest) is less than the rst operand (Rsrc) when both operands are interpreted as unsigned integers. Otherwise, it is cleared to 0. Refer to the specic compare instruction in Section 5.1 on page 5-1 for details. The User Mode bit is set to indicate that the User Stack Pointer is being used as the Stack Pointer. This bit can only be set by the Jump USR instruction. This bit is cleared before any exception processing, such as an interrupt or a trap. When this bit is clear, the supervisor stack pointer is used. The USP Register is accessed as a processor register when the User Mode bit is not set. When the User Mode bit is set, Load Processor Register LPR) operations are not permitted. The value of this bit is output on signal SFUSR from the core. The Flag bit is a general condition ag which is set by various instructions. It may be used to signal exceptional conditions or to distinguish the results of an instruction (e.g., integer arithmetic instructions use it to indicate overow from addition or subtraction). It is also set, or cleared, as a result of a Test, Set or Clear bit instruction. The Zero bit is set by comparison operations. In integer comparisons, it is set to 1 if the two operands are equal. Otherwise, it is cleared to 0. Refer to the specic compare instruction in Section 5.1 on page 5-1 for details. The Negative bit is set by comparison operations. In integer comparison, it is set to 1 if the second operand (Rdest) is less than the rst operand (Rsrc), when both operands are interpreted as signed integers. Otherwise, it is cleared to 0. Refer to the specic compare instruction in Section 5.1 on page 5-1 for details.
Bit T
Bit L
Bit U
Bit F
Bit Z
Bit N
Bit E
The local maskable interrupt Enable bit affects the state of maskable interrupts. When this bit and the PSR.I bits are 1, all maskable interrupts are accepted. When this bit is 0, only the non-maskable interrupt is accepted. See Section 3.2 on page 3-2. There are two dedicated instructions that set and clear the E bit: the Enable Interrupts instruction (EI) sets it to 1; the Disable Interrupts instruction (DI) clears it to 0. This pair can be used to locally disable maskable interrupts, regardless of the global state of maskable interrupts which is determined by the value of the PSR.I bit. See also Section 3.2 on page 3-2.
Bit P
The Trace (TRC) trap Pending bit is used together with the T bit to prevent a TRC trap from occurring more than once for any instruction. It is cleared when no TRC trap is pending. It is set when a TRC trap is pending. See Sections 3.4.4 on page 3-9 and 4.1.1 on page 4-1 for more information. When a hardware debug module is present in the system the value of the P bit is ignored. The global maskable Interrupt enable bit affects the state of maskable interrupts. This bit is set using the LPR instruction. When this bit and the PSR.E bits are 1, all maskable interrupts are accepted. When this bit is 0, only the non-maskable interrupt is accepted. This bit is cleared to 0 on reset. In addition, it is automatically cleared when an interrupt or DBG trap occurs.
Bit I
15-10 reserved
9 SR
8 ED
7 0
6 0
5 LIC
4 IC
3 LDC
2 DC
1 0
0 0
Figure 2-3. Conguration Register All CFG bits are cleared on reset. The CFG control bits are described in detail below.
Bit DC
If the Data Cache bit is set to 1, the data cache is accessible for data read and write operations. If the DC bit is cleared to 0, the data cache is disabled.
Bit LDC
If the Lock Data Cache line bit is set to 1, a missing line, which cannot be replaced, is locked into the cache after it is placed. If LDC is cleared to 0, the line can be replaced. If the Instruction Cache bit is set to 1, the instruction cache is accessible for instruction fetches. If the IC bit is cleared to 0, the instruction cache is disabled. If the Lock Instruction Cache line bit is set to 1, a missing instruction is locked into the instruction cache after it is placed. It is not replaced as long as LIC remains 1. The Extended Dispatch bit determines the size of an entry in the Interrupt Dispatch Table. Each entry holds the address of the appropriate exception handler. When ED is set, the Interrupt Dispatch Table contains 32-bit elements, each occupying two adjacent words. When ED is cleared, the Interrupt Dispatch Table contains 16-bit elements. This implies that when ED is clear, all exception handlers must start in the rst 128K of the address space. On reset, the bit is cleared. The location of the Interrupt Dispatch Table is determined by INTBASE, independent of the setting of the ED bit. The Short Register bit is set to enable the register pairing used to maintain compatibility with code developed for the CR16B large model. As opposed to using the extended versions of R12, R13 and R14, only the lower 16 bits of these registers are used, and are paired together as register pairs for double operations. The (R14, R13) register pair is used as the extended RA. In addition, when this bit is set, address displacements relative to a single register are supported with offsets of 0 and 14 bits in place of the index addressing with these displacements. See Index mode on page 2-16 for additional details.
Bit IC
Bit LIC
Bit ED
Bit SR
2.4
INSTRUCTION SET
The following table summarizes the CR16C instruction set. Chapter 5 and Appendix B describe each instruction in detail. Also refer to Instructions Table Glossary on page 2-11.
Operands Rsrc/imm, Rdest Rsrc, Rdest Rsrc, Rdest Rsrc, RPdest Rsrc, RPdest imm, RPdest RPsrc, RPdest
with sign extension with zero extension with sign extension with zero extension immediate to register-pair between register-pairs
INTEGER ARITHMETIC ADD[U]i Rsrc/imm, Rdest ADDCi Rsrc/imm, Rdest ADDD RPsrc/Imm,RPdest MACQW MACSW MACUW MULi MULSB MULSW MULUW SUBi SUBD SUBCi Rsrc1 Rsrc2, RPdest Rsrc1 Rsrc2, RPdest Rsrc1 Rsrc2, RPdest Rsrc/imm, Rdest Rsrc, Rdest Rsrc, RPdest Rsrc, RPdest Rsrc/imm, Rdest RPsrc/imm, RPdest Rsrc/imm, Rdest
Add Add with carry Add with RP or immediate. Multiply signed Q15: RPdest := RPdest + Rsrc1 * Rsrc2 Multiply signed and add result: RPdest := RPdest + Rsrc1 * Rsrc2 Multiply unsigned and add result: RPdest := RPdest + Rsrc1 * Rsrc2 Multiply: Rdest(8) := Rdest(8) * Rsrc(8)/Imm Rdest(16) := Rdest(16) * Rsrc(16)/Imm Multiply: Rdest(16) := Rdest(8) * Rsrc(8) Multiply: RPdest := RPdest(16) * Rsrc(16) Multiply: RPdest := RPdest(16) * Rsrc(16); Subtract: (Rdest := Rdest Rsrc) Subtract: (RPdest := RPdest RPsrc/imm) Subtract with carry: (Rdest := Rdest Rsrc)
Mnemonic
Operands
Description Compare Compare Compare Compare Rdest Rsrc RPdest-RPsrc Rsrc to 0 and branch if EQUAL Rsrc to 0 and branch if NOT-EQUAL
INTEGER COMPARISON CMPi Rsrc/imm, Rdest CMPD RPsrc/imm, RPdest BEQ0i Rsrc, disp BNE0i Rsrc, disp LOGICAL AND BOOLEAN ANDi Rsrc/imm, Rdest ANDD RPsrc/imm, RPdest ORi Rsrc/imm, Rdest ORD RPsrc/imm, RPdest Scond Rdest XORi Rsrc/imm, Rdest XORD RPsrc/imm, RPdest SHIFTS ASHUi ASHUD LSHi LSHD
Logical AND: Rdest := Rdest & Rsrc/Imm Logical AND: RPdest := RPsrc & RPsrc/Imm Logical OR: Rdest := Rdest | Rsrc/Imm Logical OR: Rdest := RPdest | RPsrc/Imm Save condition code as boolean Logical exclusive OR: Rdest := Rdest ^ Rsrc/Imm Logical exclusive OR: Rdest := RPdest ^ RPsrc/Imm
Arithmetic left/right shift Arithmetic left/right shift Logical left/right shift Logical left/right shift
BIT OPERATIONS SBITi Iposition, disp(Rbase) Iposition, disp(RPbase) Iposition, (Rindex)disp(RPbasex) Iposition, abs Iposition, (Rindex)abs CBITi Iposition, disp(Rbase) Iposition, disp(RPbase) Iposition, (Rindex)disp(RPbasex) Iposition, abs Iposition, (Rindex)abs TBIT Rposition/imm, Rsrc TBITi Iposition, disp(Rbase) Iposition, disp(RPbase) Iposition, (Rindex)disp(RPbasex) Iposition, abs Iposition, (Rindex)abs PROCESSOR LPR LPRD SPR SPRD REGISTER MANIPULATION Rsrc, Rproc RPsrc, Rprocd Rproc, Rdest Rprocd, RPdest
Load processor register Load double processor register Store processor register Store double processor register
Mnemonic
Operands
JUMPS AND LINKAGE Bcond disp9 disp17 disp25 BAL RPlink, disp25 BR disp9 disp17 disp25 EXCP vector Jcond RPtarget JAL RA, RPtarget, JUMP JUSR RETX PUSH POP POPRET RPlink,RPtarget RPtarget RPtarget imm,Rsrc, RA imm, Rdest, RA imm, Rdest, RA
Trap (vector) Conditional Jump to a large address Jump and link to a large address Jump Jump and set PSR.U Return from exception Push imm number of registers on user stack, starting with Rsrc and possibly including RA Restore imm number of registers from user stack, starting with Rdest and possibly including RA Restore registers (similar to POP) and JUMP RA
LOAD AND STORE LOADi disp(Rbase), Rdest abs,Rdest (Rindex)abs, Rdest (Rindex)disp(RPbasex), Rdest disp(RPbase), Rdest LOADD disp(Rbase), RPdest abs, RPdest (Rindex)abs, RPdest (Rindex)disp(RPbasex), RPdest disp(RPbase), RPdest STORi Rsrc, disp(Rbase) Rsrc, disp(RPbase) Rsrc, abs Rsrc, (Rindex)disp(RPbasex) Rsrc, (Rindex)abs STORD RPsrc, disp(Rbase) RPsrc, disp(RPbase) RPsrc, abs RPsrc, (Rindex)disp(RPbasex) RPsrc, (Rindex)abs STOR IMM imm4, disp(Rbase) imm4, disp(RPbase) imm4, (Rindex)disp(RPbasex) imm4, abs imm4, (Rindex)abs LOADM imm3 LOADMP STORM STORMP imm3 imm3 imm3
Load (register relative) Load (absolute) Load (absolute index relative) Load (register relative index) Load (register pair relative) Load (register relative) Load (absolute) Load (absolute index relative) Load (register pair index relative) Load (register pair relative) Store (register relative) Store (register pair relative) Store (absolute) Store (register pair relative index) Store (absolute index) Store (register relative) Store (register pair relative) Store (absolute) Store (register pair index relative) Store (absolute index relative) Store 4 bit immediate value in memory
Load 1 to 8 registers (R2-R5, R8-R11) from memory starting at (R0) Load 1 to 8 registers (R2-R5, R8-R11) from memory starting at (R1, R0) Store 1 to 8 registers (R2-R5, R8-R11) to memory starting at (R1) Store 1 to 8 registers (R2-R5, R8-R11) to memory starting at (R7, R6)
Mnemonic
Operands
Description Cache Invalidate Disable maskable interrupts Enable maskable interrupts Enable maskable interrupts and wait for interrupt No operation Wait for interrupt
2.5
MEMORY ORGANIZATION
The CR16C provides access to 16M ofmemory. The memory is a uniform linear address space numbered sequentially starting at 0. CR16C data addressing is always byte-related (i.e., data can be addressed at byteresolution). The instructions, by contrast, are always word-aligned, and therefore instruction addresses are always even. Memory can be logically divided into the following regions (see Figure 2-4): 0 - 1M-64K (0 through 0E_FFFF16) This region can be accessed efciently for data-manipulation using all addressing modes. Therefore, it should be used for RAMs. There are no restrictions on code in this region. 1M-64K - 16M-64K (0F_000016 through 0FE_FFFF16) This region can be accessed for data-manipulation using all addressing modes. However there are some limitations and disadvantages when accessing data in this region (accessing data in absolute mode requires a longer instruction, a label in this region cannot be used as a displacement and moving or adding a data label to a register pair requires a longer instruction). There are no restrictions on code in this region. Therefore, use this address range for code and infrequently used data. 16M-64K - 16M-1K (0FF_000016 through 0FF_FBFF16) This region is reserved for I/O devices and peripherals. Loads, stores and bit operations using absolute addressing mode in this range are as efcient as in the range 0 - 1M-64K. This is because the core maps absolute addresses 0F_0000 through 0F_FFFF to 0FF_0000 through 0FF_FFFF. 16M-1K - 16M-1 (0FF_FC0016 through 0FF_FFFF16) This region is reserved for the Interrupt Controller Unit and its acknowledge address, as well as other internal uses. For more information on the addressing modes see Sections 2.6 and 6.2 as well as Appendix B.
Address 00_000016 000F_000016 Data1 and Code 16 MBytes Code + Data (a) Byte at Address A Bit Number 7 0 (b) Word at Address A Bit Number 15 0 PROGRAMMING MODEL 2-13
~ ~
Far2 Data and Code
~ ~
1 Efcient data access 2 Less efcient data access (Notation used in National CompactRISC Toolset. For notation used in other toolsets, see the appropriate documentation)
Byte Address
A+1
in Memory
Data references
The CR16C supports references to memory by the LOAD and STOR instructions, as well as TBIT, SBIT, CBIT, PUSH, POP, LOADM and STORM. Bytes, words and double-words can be referenced on any boundary.
2.5.2 Stacks
A stack is a one-dimensional data structure. Values are entered and removed, one item at a time, at one end of the stack, called the top-ofstack. The stack consists of a block of memory, and a variable called the stack pointer. The CR16C supports two types of stacks: the interrupt stack and the program stack.
The processor uses the interrupt stack to save and restore the program state during the exception handling. This information is automatically pushed, by the hardware, onto the interrupt stack before entering an exception service procedure. On exit from the exception service procedure, the hardware pops this information from the interrupt stack. See Chapter 3 for more information. The interrupt stack pointer is accessed via the ISP Register. The program stack is normally used by programs at runtime, to save and restore register values upon procedure entry and exit. It is also used to store local and temporary variables. The program stack is accessed via the SP general-purpose register. Note that this stack is handled by software only, e.g., the CompactRISC C Compiler generates code that pushes data onto, and pops data from, the program stack. Only PUSH, POP and POPRET instructions adjust the SP automatically; otherwise, software must manage the SP during save and restore operations. To support multi-tasking operating systems, support is provided for a two-level program stack: a user stack and a supervisor stack. The user stack pointer is accessed via the USP Register. The PSR contains a user mode status bit (PSR.U). When this user mode bit is set, the user stack pointer is used in place of SP for all operations. In addition, while in user mode, the PSR.U bit is read only. User mode is entered using the JUSR instruction, which causes a jump to the user program and entrance to user mode by setting the PSR.U bit. User mode is exited on any exception processing. While not in user mode, the user stack pointer can be accessed using the LPRD and SPRD instructions. Using the user stack can save memory required for the stack, since supervisor information can be saved instead on the supervisor stack each time a task is saved. An output signal is provided from the core (SFUSR) to indicate if the core is currently in user or supervisor mode. This may be used by a memory protection unit for checking accessed addresses in the various modes. Both stacks expand toward address zero in memory.
2.6
ADDRESSING MODES
The CR16C supports these addressing modes: register/pair, immediate, relative, absolute, and indexaddressing. Memory is accessed by the generic load and store instructions, along with bit operations. These operations are supported with one or more of these modes. When register pairs are used, the lower bits are in the lower index register and the upper bits are in the higher index register. When CFG.SR=0, the double-word registers R12, R13, RA and SP are also considered register pairs. For more details, see Section 2.3.1. All references to register pairs should use parentheses. With a register pair, the lower numbered register pair should be on the right. For example, jump (r5, r4) load $4(r4,r3), (r6,r5) load $5(r12), (r13)
Register/pair mode
In register/pair mode, the operand is located in a general-purpose register, or in a general-purpose register pair (see Section 2.3.1). For example, the following instruction adds the contents of the low order byte of register r1 to the contents of the low order byte of r2, and places the result in register r2. ADDB r1, r2
Immediate mode
In immediate mode, the operand is a constant value which is specied within the instruction. For example, the following instruction multiplies the value of r4 by 4 and places the result in r4: MULW $4, r4
Relative mode
In relative mode, the operand is obtained using a relative displacement value encoded in the instruction. This displacement is relative to the current Program Counter (PC) or general-purpose register or register pair. In branch instructions, the displacement is always relative to the current value of the PC Register. For example the following instruction causes an unconditional branch to an address 10 ahead of the current PC. BR *+10 In load, store and bit operations, the displacement value is relative to the contents of a general-purpose register or register pair. For example, the following instruction loads the data contained at an address 12 higher than the contents of r5 into r6. LOADW 12(r5), r6
The following example loads the contents of memory at the address of the register pair (r5, r4) plus 4 into the register pair (r7, r6). r7 receives the high word and r6 receives the low word. LOADD 4(r5, r4), (r7, r6)
Absolute mode
In absolute mode, the operand is located in memory, and its address is specied explicitly within the instruction (normally 20 or 24 bits). For example, the following instruction loads the byte at addresses 4000 into the lower 8 bits of register 6. LOADB 4000, r6
Index mode
In index mode, the operand is located in memory. This mode supports load, store and bit operations, and is provided in order to handle relocatable code. CFG.SR must be 0 to use this addressing mode. Register R12 or R13 is used to hold a base index address to which absolute or relative mode addresses are added. For example the following instruction loads the word at address (r12) + (r5,r4) + 4 into r6. LOADW [r12]4(r5,r4), r6 For relative mode instructions, the memory address is obtained using the value of either R12 or R13, and adding the value of a register pair and a displacement. The displacement can be a 14 or 20-bit unsigned value, which is encoded in the instruction. For absolute mode instructions, the memory address is obtained using the value of either R12 or R13, and adding a 20-bit absolute address label which is encoded in the instruction. For a more detailed explanation, see Section B.2 on page B-2. For data addressing, Table 2-1 summarizes the size of the instruction along with the displacement sizes supported. Note that index addressing mode is not available when CFG.SR is set. Table 2-1. Instruction Sizes Supported Instruction Size Instructions Data relative to 1 Word register pair Load/Store (b/w/d) register index abs
b
Instruction Size Instructions Data relative to 1 Word register pair (c/s/t)bit(b/w) Store Imm register indexb abs
a. when CFG.SR = 1 b. when CFG.SR = 0
disp0
The data addressing modes supported for all instructions are identical in two and three-word formats. The instructions encoded in one word give priority to addressing relative to a register pair.
Chapter 3 EXCEPTIONS
This chapter briey describes exceptions and how they are handled, and provides detailed information on exception processing.
3.1
INTRODUCTION
Program exceptions are conditions that alter the normal sequence of instruction execution, causing the processor to suspend the current process and execute a special service procedure, often called a handler.
An exception resulting from the activity of a source external to the processor is known as an interrupt; an exception which is initiated by some action or condition in the program itself is called a trap. Thus, an interrupt need have no relationship to the executing program, while a trap is caused by the executing program and recurs each time the program is executed. The CR16C recognizes twelve exceptions: nine traps and three types of interrupts. The exception-handling technique employed by an interrupt-driven processor determines how fast the processor can perform input/output transfers, the speed for transfers between tasks and processes, and the software overhead required for both these activities. Thus, to a large extent, it determines the efciency of a processors multi-programming and multi-tasking (including real-time) capabilities. Exception-handling in the CR16C uses a dispatch table. This table contains an entry for each exception, which holds the address of the exception handler. Once an exception is encountered, the processor uses the exception number to access the table and extract the handler address.
Stack types
The CR16C features an interrupt stack, a supervisor stack and a user stack. The processor uses the interrupt stack solely for saving the PC and the PSR Register values during exception processing. This process occurs in hardware, without software intervention. The software uses the supervisor and user stacks to save register values and to pass parameters upon subroutine entry and subroutine calls. These stacks are managed by software using the PUSH, POP and POPRET instructions.
EXCEPTIONS 3-1
This stack architecture provides the following benets: The essentials of the processors state (PC and PSR) are saved correctly on the interrupt stack, even during nested, non-maskable interrupts. This process does not need to rely on disabling interrupts to allow software to save PC and PSR values on the interrupt stack. As the processor saves just the PC and PSR when exceptions occur, interrupt latency is kept at a minimum. During exception handling, the software need only save the registers it modies, thus minimizing interrupt response time, and saving memory.
When an exception occurs, the CPU automatically preserves the state of the program immediately prior to the handling of the exception: a copy of the PC and the PSR is made and pushed onto the interrupt stack. The contents of the PSR is adjusted for exception processing. The interrupt exception number is then used to obtain the address of the exception service procedure from the dispatch table, which is then called. The RETX instruction returns control to the interrupted program, and restores the contents of the PSR and the PC registers to their previous status. See RETX Return from Exception on page 5-52.
3.2
INTERRUPT HANDLING
The CR16C provides three types of interrupts: non-maskable (NMI), maskable, and In-System Emulator (ISE).
NMI are used for events which require immediate handling to preserve system integrity (such as an imminent power failure), and cannot be disabled. NMI use vector number 1 in the dispatch table. When an NMI is detected, the CR16C performs an interrupt-acknowledge bus cycle to address 0FF_FF0016, and discards the byte that is read during that bus cycle. Maskable interrupts are disabled whenever PSR.E or PSR.I are 0. PSR.I serves as the global interrupt mask, while PSR.E serves as a local interrupt mask. PSR.E can be easily changed with the EI and DI instructions (see EI Enable Maskable Interrupts on page 5-20 and DI Disable Maskable Interrupts on page 5-19). PSR.E is used when interrupt-disabling is needed for a short period of time (e.g. when a read-modify-write sequence of instructions, accessing a semaphore, must not be interrupted by another task). On receipt of a maskable interrupt, the processor determines the vector number by performing an interrupt acknowledge bus cycle in which a byte is read from address 0FF_FE0016. This byte contains a number in the range 16-127 (the vector), which is used as an index in the dispatch table to nd the address of the appropriate interrupt handler. Control is then transferred to that interrupt handler.
Maskable interrupts
EXCEPTIONS 3-2
ISE interrupts cannot be disabled; they are reserved for system debug implementation. ISE interrupts use vector number 15 in the dispatch table. When an ISE interrupt is detected, the CR16C performs an interrupt-acknowledge bus cycle to address 0FF_FC0016, and discards the byte that is read during that bus cycle.
3.3
TRAPS
The CR16C recognizes the following traps:
Breakpoint (BPT) Supervisor Call (SVC) Flag (FLG) Division by Zero (DVZ) Undened Instruction (UND)
BPT is used for program debugging. Caused by the EXCP BPT instruction. SVC temporarily transfers control to supervisor software, typically to access facilities provided by the operating system. It is caused by the EXCP SVC instruction. FLG Indicates various computational exceptional conditions. it is caused by the EXCP FLG instruction. DVZ indicates an integer division by zero. It is caused by the EXCP DVZ instruction, which can be used by integer division emulation code to indicate this exception. UND indicates undened opcodes. It is caused by an EXCP UND instruction, or an attempt to execute any of the following: any undened instruction; the EXCP instruction when a reserved eld is specied in the dispatch table (i.e., reserved trap number). an LPR/LPRD when PSR.U bit is set. IAD indicates that an illegal address was detected. For the CR16C, this trap is generated whenever an address outside the address range of 0 to 16M-1 is detected. Wraparound can happen either when the 16M boundary is crossed in a positive direction or when the 00__0000 address is crossed in a negative direction - and the resulting address yields in the illegal space. Both are trapped and agged as illegal operations. This is done primarily for reasons of future compatilbity so that the address range of the CR16C can easily be increased beyond 16M to maintain binary compatibility, without any issues of wraparound compatibility.
EXCEPTIONS 3-3
The CR16C also provides an optional input for external illegal address detection, which can be used in the system to protect (unused) memory areas from being accessed by the core - this is not required in an AHB system like the CR16CPlus which provides an error response on the bus.
TRC occurs before an instruction is executed when the PSR.P bit is 1. It is used for program debugging and tracing. See Chapter 4. A DBG trap occurs as a result of a breakpoint detected by the hardwarebreakpoint module, or by an external instruction-execute breakpoint using the tag mechanism through the BRKL line. It is used for instructionexecution and data-access breakpoints. See Chapter 4. DBG, TRC and BPT traps can also generate an interrupt acknowledge cycle for observability purposes, to alleviate the design of an ISE. This option can be selected by setting ADBG, ATRC, and ABPT bits respectively in the DCR Register. The addresses driven on the bus during these cycles are 0FF_FC0216 (DBG), 0FF_FC0C16 (TRC) and 0FF_FC0E16 (BPT) respectively. See Chapter 4.
3.4
EXCEPTIONS 3-4
EXCEPTIONS 3-5
15/31 INTBASE 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 n = 16 to 127 reserved NMI reserved reserved reserved SVC DVZ FLG BPT TRC UND reserved IAD reserved DBG ISE INTn
Non-Maskable Interrupt
Supervisor Call Trap Divide by Zero Trap Flag Trap Breakpoint Trap Trace Trap Undened Instruction Trap Illegal Address Trap
EXCEPTIONS 3-6
Table 3-1. Interrupt ACK Vector Address Address FF_FE00 FF_FF00 FF_FC00 FF_FC02 FF_FC0C FF_FC0E Type INT NMI ISE ADBG ATRC ABPT Description maskable interrupt - mapped to ICU non-maskable interrupt; for observability in-system emulation trap alternate debug trap alternate trace trap alternate break point trap
For NMIs or traps, the exception number is set as the vector, to be used while accessing the dispatch table. 5. When CFG.ED is 1, reads the dispatch table double-word entry at address (INTBASE) + vector 4. When CFG.ED is 0, reads the singleword entry from (INTBASE) + vector 2 The dispatch table entry is used to call the exception handler and is interpreted as a pointer that is loaded into bits 1 through 16. If CFG.ED = 1, it is also loaded into bits 17 through 23 of the PC. Bit 0 of the PC is cleared. See Figure 3-3. The pointer is stored in the dispatch table in little-endian format. For a double-word entry, the lower address word contains address bits 1 through 16, and the upper address word contains address bits 17 through 23.
~
16 (Push) PC(16-1) PC (23-17) PSR(11-0) (Push) (Push)
~
Return Address Return Address Saved Status
Interrupt Stack
EXCEPTIONS 3-7
Vector
Absolute Address
PC(16-1) PC(23-17)=0
Vector
PC(23-1)
Figure 3-3. Transfer of Control During an Exception Acknowledge Sequence Table 3-2 summarizes how each type of exception is acknowledged. Table 3-2. Summary of Exception Processing Instruction Completion Status Before start of instruction Suspended Suspended Before start of instruction Before start of instruction Before start of instruction Cleared PSR Bits PC Saved Next Current Current Next Next Next Before After Saving PSR Saving PSR None Nonea None
a
Exception
a. If a TRC trap is used in conjunction with these exceptions, the trap handler may need to clear the P bit of the PSR, which is saved on stack, to prevent a redundant trace exception. For more information, refer to Sections 3.4.5 and 4.1.1 on page 4-1.
EXCEPTIONS 3-8
The exception service procedure can use software to simulate execution of the suspended instruction. After it calculates and writes the results of the suspended instruction, it should modify the ags in the copy of the PSR which were saved on the interrupt stack, and update the PC saved on the interrupt stack to point to the next instruction to be executed. The exception service procedure can then execute the RETX instruction. The CR16C begins executing the instruction following the suspended instruction. For example, when a UND trap occurs, software can be used to perform the appropriate corrective actions.
The suspended instruction can be retried after the exception service procedure has corrected the trap condition that caused the suspension. In this case, the exception service procedure should execute the RETX instruction at its conclusion; then the CR16C retries the suspended instruction. A debugger takes this action when it encounters an EXCP BPT instruction that was temporarily placed in another instructions location in order to set a breakpoint. In this case, exception service procedures should clear the PSR.P bit to prevent a TRC trap from occurring again.
EXCEPTIONS 3-9
EXCEPTIONS 3-10
IAD Pending ? No NMI Pending ? No Interrupt Pending ? No ISE Pending ? No PSR.P = 1 ? No Begin Instruction Execution
Yes
Yes
Yes
Yes
Yes
PSR.P := 0
Yes
PSR.P := PSR.T
Yes
Update PC
Process Exception
Before executing an instruction, the CR16C checks for pending DBG, IAD, interrupts and TRC traps, in that order. It responds to the interrupts in order of descending priority (i.e., rst non-maskable interrupts, then maskable interrupts and lastly, ISE interrupts). If no interrupt is pending and PSR.P is 1 (i.e., a TRC trap is pending), then the CR16C clears PSR.P and processes the TRC trap. If no TRC trap or interrupt is pending, the CR16C begins executing the instruction by copying PSR.T to PSR.P. While executing an instruction, the CR16C may detect a trap.
First, the CR16C checks for a UND trap or a PCMATCH (if enabled), then it looks for any of the following mutually exclusive traps: SVC, DVZ, FLG or BPT. The CR16C responds to the rst trap it detects by suspending the current instruction and executing the trap. If an undened instruction is detected, then no data references are performed for the instruction. If no exception is detected while the instruction is executing, the instruction is completed (i.e., values are changed in registers and memory, except for PSR.P, which was changed earlier) and the PC is updated to point to the next instruction. While the CPU executes an instruction, it checks for enabled debug and address error conditions. If the CPU detects an enabled addresscompare, a DBG trap remains pending until after the instruction is completed. If an invalid address is detected, the IAD trap becomes pending and the CPU responds to it before executing the next instruction.
Single-stepping through instructions (TRC) is also subject to interrupt prioritizing, as the P and T bits are both cleared when exceptions are being handled. Therefore, exceptions occurring during an instruction are served before the single-step handler (TRC). The interrupt nesting level is limited only by the amount of memory that is available for the interrupt stack.
3.5
RESET
A reset occurs when the appropriate signal is activated. Reset must be used at power-up to initialize the CR16C. As a result of a reset operation: All instructions currently being executed are terminated. Results and ags normally affected by the terminated instruction are unpredictable. The results of instructions, whose execution started but have not yet ended, may not be written to their destinations. Any pending interrupts and traps are eliminated. For correct operation, maskable interrupts as well as ISE and NMI, must be inactive by the time the reset signal is deactivated, to avoid being serviced immediately after the reset period. Upon reset, the following operations are executed: PC(16-1) current values are stored in R0, and PC(23-17) current values are stored in R1. The current value of the PSR is stored in R2. The following internal registers are cleared to 0: PC, CFG, and PSR, except for PSR.E, which is set to 1. When no hardware debug module is present in the system, processor registers DBS and DCR are also cleared to 0. Otherwise, refer to the hardware debug documentation for information on clearing these registers. After reset, the processor begins normal execution at memory location 0 (or another memory location when set by hardware). The reserved bits in these registers and the contents of all other registers are unpredictable. Note that some uncertainty exists as to which PC is saved at reset in R0, R1 and R2. In case of sequential instructions, the address saved may also be that of the next sequential instruction to be executed, as well as the currently interrupted instruction. In case of instruction flow change (e.g. BR, BAL, JAL), the address saved may also be that of the jump or branch target.
EXCEPTIONS 3-13
4.1
DEBUGGING SUPPORT
The following CR16C features make program debugging easier: Instruction tracing Soft break generation by breakpoint instruction (EXCP BPT) User programmable breakpoint features: - Instruction address match - Instruction address range match - Data access - Data access range - Combination of the above (complex breakpoints) External instruction tag during fetch to break before execution ISE support signals The Processor Status Register (PSR), the Debug Base Register (DBS), the Debug Control Register (DCR), the Debug Status Register (DSR), and the Compare-Address Registers (CAR) control/s and monitor the debug and trace features.
For more information on the different exception priorities, see Figure 3-4. on page 3-11. If any other trap or interrupt is requested during execution of a traced instruction, its entire service procedure is allowed to complete before the TRC trap occurs. For example, if a UND trap is detected while tracing is enabled, the TRC trap occurs after execution of the RETX instruction that marks the end of the UND service procedure. The UND service procedure can use the PC value, saved on top of the interrupt stack, to determine the location of the instruction. The UND service procedure is not affected, whether instruction tracing was enabled or not.
Trap handlers for exceptions which cause instruction suspension (UND, BPT, DVZ, FLG and SVC), may need to clear the copy of the PSR.P bit, saved on the interrupt stack, before resuming execution. This must be done if the exception service replaces the exception invocation instruction with code for execution, and attempts to re-execute that location, according to the saved PC on stack. Otherwise, when attempting to reexecute that location, the processor performs a redundant trace exception before executing the said instruction, since the PSR.P bit is set in the restored PSR. Note the following: LPR (on PSR) and RETX instructions cannot be reliably traced because they may alter the PSR.P bit during their execution. If instruction tracing is enabled while the WAIT or EIWAIT instruction is executed, a trace trap occurs after the next interrupt, when the interrupt service procedure returns.
by one Compare Address Register (CARn) in conjunction with two mask bits to mask out up to three of the least signicant bits of the CARn register. Requires a single debug channel. Data Access Breakpoint Range Breakpoint/Watchpoint on a data access (read/write/read-or-write) to a specic address range. The address range is dened by utilizing an Compare Address register pair to specify a start and end address. Requires two debug channels. Complex Breakpoint Breakpoint/Watchpoint upon the detection of a complex breakpoint/watchpoint condition. Two CARs are combined to specify the conditions of a complex breakpoint/watchpoint.
The breakpoint logic can be set up to generate a breakpoint upon the execution of an instruction, fetched from one specied address. This address, used for comparison, can be specied by one Compare Address Register (CARn). In addition, the conguration bits in the corresponding Debug Control Register (DCRn) must be set up to enable a single instruction breakpoint as follows: The PC Match enable bit (PCn) must be set to 1 to select an instruction breakpoint. The Address Mask bits (MSKn) must be cleared to 0. The Enable Address Range Breakpoint (EARn) bit must be cleared to 0 to disable an address range breakpoint. The Data Write and Data Read Address Match Enable bits (DWRn and DRDn) must be cleared to 0 to disable a data access breakpoint. The Debug Enable bit (DEN) must be set to 1 to enable the breakpoint logic. Figure 4-1 shows an example for using the compare logic x and y for the detection of two single instruction breakpoints.
Memory
The breakpoint logic can be set up to generate a breakpoint upon the execution of an instruction, fetched from a small address range, specied by the address value stored in CARn in conjunction with two Address Mask bits (MSKn). These bits mask out up to three of the least signicant bits of CARn. The masked-out CARn bits are then treated as dont care by the address compare logic. This allows the tool to dene a break range of up to 8 bytes by only utilizing one CAR. The DCRn must be congured as follows to enable a masked instruction breakpoint: The PCn bit must be set to 1 to select an instruction breakpoint. The MSKn[1:0] bits must be set to select an address range of the desired size. The EARn bit must be cleared to 0 to disable an address range breakpoint. The DWRn and DRDn bits must be cleared to 0 to disable a data access breakpoint. The DEN bit must be set to 1 to enable the breakpoint logic. Note: The least signicant bit of the address bus during instruction fetches is always 0, as instruction fetches are always performed on word-aligned addresses. Figure 4-2 shows an example for using the compare logic n for the detection of a masked instruction breakpoint, covering two one-word instructions, occupying 4 bytes of address locations in memory.
Memory
Figure 4-2. Masked Instruction Breakpoint (4-Byte Address Range = Two Instruction Word Range)
The breakpoint logic can be set up to generate a breakpoint upon the execution of an instruction fetched from a specied address range. In order to specify this address range, two CARs (CARn and CARn+1, with n being an even number) are combined. The conguration bits in (DCRn+1) are ignored. Only the conguration bits in DCRn must be set up to enable the conditions for an instruction breakpoint range, as follows: The PCn bit must be set to 1 to select an instruction breakpoint. The MSKn[1:0] bits must be cleared to 0. The EARn bit must be set to 1 to enable an address range breakpoint. The DWRn and DRDn bits must be cleared to 0 to disable a data access breakpoint. The DEN bit must be set to 1 to enable the breakpoint logic. Figure 4-3 shows an example for using compare logic n and m for the detection of a range instruction breakpoint between (and including) instructions x and y.
Instruction x
Memory
Instruction Watchpoints
Note: This feature can only be used with the optional external hardware debugger SDI+. The address compare logic can be used for detecting watchpoints instead of breakpoints. The instruction watchpoint works the same as the instruction breakpoint with this exception: when the tagged instruction reaches the execution stage of the pipeline, program execution continues in real-time, instead of stopping, while the CR16C asserts the respective SFDBGEVP output. In addition, the Breakpoint/Watchpoint pending ag in the DSR is set to 1 to indicate a watchpoint hit. The watchpoint hit is agged by the SFDBGEVP output and the Watchpoint pending bit, as soon as the instruction has been completed. To specify an instruction watchpoint, the Watchpoint Enable bit (WPEn) must be set to 1, along with the other conguration bits used to specify watchpoint conditions (see WPEn on page 4-18).
If the CR16C performs a data transfer to/from an address for which a data access breakpoint has been set, the CR16C enters debug mode after it has completed execution of this instruction (i.e., after all data for this instruction has been transferred). Optionally, the respective SFDBGEVP output can also be utilized to signal this event to an external hardware debug tool. The breakpoint logic can be set up to trigger a breakpoint either on a data read access, a data write access, or both.
The breakpoint logic can be set up to generate a breakpoint upon execution of a data transfer from/to one specied address. This address, used for comparison, can be specied by one CARn. In addition, the conguration bits in the corresponding DCRn must be set up to enable the desired data access breakpoint, as follows: The DWRn and/or DRDn bits must be set to 1 to disable a data access breakpoint on a data read access, a data write access or both. The PCn bit must be cleared to 0 to disable an instruction breakpoint. The MSKn[1:0] bits must be cleared to 0. The EARn bit must be cleared to 0 to disable an address range breakpoint. The DEN bit must be set to 1 to enable the breakpoint logic. Figure 4-4 shows an example for using the compare logic n and m for the detection of two, independent data access breakpoints at the address of breakpoint x and y respectively.
Memory
Data transfers include all transfers but instruction fetches. CompactRISC CR16C Programmers Reference Manual ADDITIONAL TOPICS 4-8
The breakpoint logic can be set up to generate a breakpoint on the data transfer from or to a small address range, specied by the address value stored in the CARn in conjunction with two address mask bits (MSKn). These mask bits mask out up to three least signicant bits of CARn. The masked-out CARn bits are then treated as dont care by the address compare logic. This allows denition of a breakpoint range of up to 8 bytes by only utilizing one CAR. This can be useful to set up a data access breakpoint to a data structure which occupies up to 8 bytes in memory. DCRn must be congured as follows to enable a masked data access breakpoint: The DWRn and DRDn bits must be set to enable the desired type of data access breakpoint. The MSKn[1:0] bits must be set to select an address range of the desired size. The EARn bit must be cleared to 0 to disable an address range breakpoint. The PCn bit must be cleared to 0 to disable an instruction breakpoint. The DEN bit must be set to 1 to enable the breakpoint logic. Figure 4-5 shows an example for using the compare logic n for the detection of a masked instruction breakpoint, covering 4 bytes of data in memory.
Data x.3 (MSB) DCRn CARn Data x.1 MSKn[1:0] = 102 Data x.0 (LSB) Data x.2 Break Range
Memory
Figure 4-5. Masked Data Access Breakpoint (e.g for Double Data Type)
The breakpoint logic can be set up to generate a breakpoint upon the execution of a data transfer from/to one specied address range. In order to specify this address range, two CARs (CARn and CARn+1 with n being an even number) are combined. The conguration bits in the (DCRn+1) are ignored. Only the conguration bits in the DCRn must be set up to enable the conditions for the data access breakpoint range, as follows: The DWRn and/or DRDn bits must be set to 1 to disable a data access breakpoint on a data read access, a data write access or both.
The EARn bit must be cleared to 0 to disable an address range breakpoint. The PPCn bit must be cleared to 0 to disable an instruction breakpoint. All three MSKn bits must be cleared to 0. The DEN bit must be set to 1 to enable the breakpoint logic. Figure 4-6 shows an example for using the compare logic n and m for the detection of an access to data within a range between (and including) address x and y.
Data Byte x
Memory
To specify a data access watchpoint, the Watchpoint Enable bit (WPn) must be set to 1, along with the other conguration bits used to specify the watchpoint conditions (see Data Access Watchpoints on page 4-10).
Complex Breakpoints
Two CARs can also be combined to form a complex breakpoint. A complex breakpoint hit is a sequence of two successive breakpoints. When the rst breakpoint condition is conrmed as true, this event is held pending while the CR16C continues operation without interference. When, subsequently, the second breakpoint condition occurs, the CR16C is stopped and enters debug mode if an external debug module is present. When no external debug module is present, a DBG trap is triggered. In order to dene both breakpoint conditions, the same pair of CARs is used as for breakpoint ranges. However, both DCRs are used to dene the two breakpoint conditions. Thus, a complex breakpoint can be dened as: A sequence of two instruction breakpoints (single and masked) A sequence of two data access breakpoints (single and masked) A sequence of an instruction breakpoint followed by a data access breakpoint (single and masked). This type of breakpoint can be used, for example, to break on a data access, performed by a specied task (instruction). A sequence of a data access breakpoint followed by an instruction breakpoint (single and masked). To specify a complex breakpoint, the address compare logic for both breakpoints should be set up as follows:. The PCn, DWRn and/or DRDn bits must be set to enable the desired type of breakpoints. The WPn bit must be cleared to 0 The MSKn[1:0] bits must be set to specify the desired range. The Complex Breakpoint Enable bit (ESQ) must be set to 1. The EARn bit must be cleared to 0. (Note: When the ESQ bit is set to 1, it overrides the EAR bit if also set to 1. This enables a complex breakpoint and disables a breakpoint range. The DEN bit must be set to 1 to enable the watchpoint logic. Figure 4-7 shows the sequence logic for complex breakpoints.
Condition 1 true
false
Condition 2 true
false
CR16C enters
Debug Mode
If the pin count on a part is limited, it is recommended that its line be multiplexed with the PLI line in the system interface. When an external hardware debug module is present, the CR16C enters the hardware debug mode before the tagged instruction is executed.
The CR16C core works with the following sequence: Execute until a hardware break occurs: Option 1 (same address): Set DCR.PC = 1; DCR.DEN = 1 (i.e., set DEN again) Go (RETX - same address - the instruction where the Breakpoint occurred is executed) Option 2 (different address): Clear DCR.PC = 0; DCR.DEN = don't care (clear breakpoint mask) Set DCR.PC = 1; DCR.DEN = 1 (i.e., set PC/DEN again) Modify PC on stack Go (RETX - different address)
On reset, the CR16C stores the contents of the PSR in R2, bits 23 through 17 of the PC in R1, and bits 16 through 1 of the PC in R0.
15
EVT[7:0]
7
reserved
BANK[1:0]
BANK
Debug BANK Select. This bit selects the currently accessible Debug Register Bank. A pair of debug channels consisting of CARn, CARn+1 DCR and DSR is mapped into the core debug register space, accessible via LPR/SPR instructions. The debug registers selected are calculated by n = BANK * 2. Debug EVenT. There is one EVT bit for every debug channel. This bit is a logic OR of the bits DSRb.BRDn, DSRb.BWRn and DSRb.BPCn bits. For debug channel 0, the DSR0.EXF bit is also part of the equation. The EVT bits are cleared when all corresponding source bits are cleared.
EVT
31
reserved
24
23
CARn
31
CARn
When address range matching is enabled (DCR0.EAR), the conguration of the address range matching is provided in the conguration bits for comparator 0: PC, CWR, CRD, and DEN. The CAR mask bits are independent of the address range match enable. Using the compare-address match for memory locations accessed by the CBIT, SBIT, and TBIT instructions requires special care. If both read and write breakpoints are enabled (both DCR.CRD and DCR.CWR are set), only the read breakpoint is acknowledged, setting just the DSR.BRD status bit.
If an unaligned transaction is used to access a word variable (i.e., Addr0 = 1), only the byte containing the relevant bit to be tested and modied is read and/or written. DCR should be programmed to match the appropriate byte for a match breakpoint to occur. The DCR is cleared on reset (SFDBGRSTP goes active high). The format of DCRL and DCRH is shown in Figures 4-10 and 4-11.
15
14
13
12
11
10 9 8
DEN1 CRD1 CWR1 PC1 WPE1 ESQ MSK1 DEN0 CRD0 CWR0 PC0 WPE0 EAR
MSK0
31
reserved
24
23
DBGL
22
res
21
20
19
18
17
res
16
EFB
MSKn
Address Mask debug channel n. The MSKn[1:0] bits select a mask for the CARn registers, according to Table 4-1. Table 4-1. Address Mask Bit Function MSKn Function Bit 1 0 0 1 1 Bit 0 0 1 0 1 no mask mask CARn[0] mask CARn[1:0] mask CARn[2:0]
These are valid for both compare-address matching and during PCmatch. In addition, the masks are functional when the EAR bit is set.
EAR
Enable Address Range Breakpoint. Enables breaking on a PC or address match in the range between CARn and CARn+1 within the same debug register block (b). CARn+1 >= range >= CARn. When set, conguration parameters for CARn are used for the range breakpoint. Enable Complex (Sequential) Breakpoint. Enables a complex breakpoint using the CARn and CARn+1 of the same debug block in sequence. A breakpoint is executed if the condition for breakpoint n+1 occurs after the condition for breakpoint n.
ESQ
WPEn
Watchpoint Enable debug channel n. This bit is only available in hardware debug mode. When set, enables generation debug event outputs on detection of a debug event. PC Match or Compare-Address Match channel n. When set, enables generation of a DBG trap on a PC match on the corresponding CAR. When clear, enables generation of a DBG trap on a compare-address match. Compare-Address on Write channel n. When set, enables address comparison for write operations. Compare-Address on Read channel n. When set, enables address comparison for read operation. Debug Condition Enable channel n. Enables either the compare-address match or PC match condition, depending on the value of the PC bit for the corresponding CAR. Both DEN0 and DEN1 are cleared when a PC match occurs and DSR.BPC is set, or when address-match is achieved, and either DSR.BRD or DSR.BWR is set. These bits are also cleared when an externally tagged instruction reaches execution and DSR.EXF is set. Enable Tag-at-Fetch Breakpoint. Enables breaking by an external device on an instruction tagged during the fetch phase. EFB is cleared when the tagged instruction reaches execution, and DSR.EXF is set. This bit is also cleared when a PC match occurs and DSR.BPC is set, or when address-match is achieved, and either DSR.BRD or DSR.BWR is set. This bit is only available in DCR0.
PCn
EFB
ABPT
Alternate behavior on BPT. Performs an Interrupt-Acknowledge cycle for BPT, and calculates the dispatch table entry based on INTBASE = 0, and 32-bit entries. This bit is only available in DCR0.
ATRC
Alternate behavior on TRC. Performs an Interrupt-Acknowledge cycle for TRC and calculates the dispatch table entry based on INTBASE = 0, and 32-bit entries. This bit is only available in DCR0.
ADBG
Alternate behavior on DBG. Performs an Interrupt-Acknowledge cycle for DBG and calculates the dispatch table entry based on INTBASE = 0, and 32-bit entries. This bit is only available in DCR0.
AISE
Alternate behavior on ISE. Calculates dispatch table for ISE based on INTBASE = 0, and 32-bit entries. ISE always performs an Interrupt-Acknowledge cycle. This bit is only available in DCR0.
DBGL
Debug-In-System-Emulation Support Lock. A set-once bit (cleared only by reset) that locks the ABPT, ATRC, ADBG, AISE bits in DCR, and the ON bit in DBGCFG. Note: DBGCFG is a chip-level debug-conguration register, used to control the behavior of the whole part, for debugging purposes. This register resides outside the core, and is described in each part-specic specication or user manual. This bit is only available in DCR0.
Program Counter channel n. Set when a PC match is detected for the corresponding CARn. Write channel n. Set when a compare-address match is detected for a data write for the corresponding CARn. Read channel n. Set when a compare-address match is detected for a data read for the corresponding CARn. Fetch-tagged Execution breakpoint. Set when an instruction which was tagged during the fetch stage reaches the execution phase. This bit is only available in DSR0.
4.2
CACHE SUPPORT
The CR16C supports integration of an Instruction Cache (IC) and a Data Cache (DC), although the cache itself is not provided as part of the core. The contents of the IC and DC are automatically loaded by the CR16C to maintain copies of recently used instructions and data values. The contents of the IC and DC can also be locked to hold copies of selected memory locations. This section describes the organization and operation of the IC and DC support. The conguration register contains conguration bits to enable an IC and a DC. In addition, lines within the cache may be locked. Instructions are provided to invalidate either or both caches, and to determine if the entire cache or only unlocked lines should be invalidated.
IC disabled
If the IC is disabled, then the instruction fetch bypasses the IC, and the contents of the IC are unaffected. Instructions are read directly from external memory, and are transferred to the instruction queue through the IC. If the IC is not present, the main data bus is connected to the instruction cache data bus directly. If an IC is present but is currently disabled, these signals are connected together through the cache. If the IC is enabled for an instruction fetch, then bits of the address of the instruction in the PC are decoded to select the set of cache lines where the instruction may be stored. The selected set is read, and the tags and validity bits are compared with the relevant bits of the address of the instruction. The lower bits of the address in the PC identify the word and the corresponding validity bit in each line of the selected set. If one of the tags matches and the selected word is valid, then the instruction is transferred directly to the instruction queue for execution. Otherwise, the missing data is read from external memory, as described below. If the instruction is not in the IC and if the contents of all lines in the set are locked, the IC is considered disabled and data from the main bus is used.
IC enabled
IC hit
If the instruction is not in the IC, and if at least one of the lines in the set is not locked, then: If the tag of either line in the set matches the address in the PC, then that line is selected for updating. If neither tag matches, and at least one of the lines in the set is not locked, then the unlocked line is selected for replacement. both lines are unlocked, then the least recently used line is selected for replacement. Any missing data is read from external memory and transferred to the instruction queue for execution, regardless of whether the selected line is replaced or merely updated.
Instruction prefetching
After the CR16C has completed fetching a missing instruction from external memory, the IC may continue to prefetch sequential words in the same line. The memory from which the data is fetched can limit the number of words that can be prefetched. The IC stops prefetching under any of the following conditions: When memory indicates that the maximum number of words has been prefetched When the end of the IC line is reached When a non-sequential fetch is issued or When a cache invalidation request is issued. Whenever the cache is invalidated by a CINV instruction, the SFICIVP signal is asserted. In addition, the SFSELINVP signal is asserted if only the unlocked lines need to be invalidated.
DC disabled
If the DC is disabled, then the data read bypasses the DC, and the contents of the DC are unaffected. The data that is read from external memory is used to execute the instruction. If the DC is enabled for a data read, then bits of the address of the data are decoded to select the set of lines where the instruction may be stored. The selected set is read and the tags are compared with the most signicant bits of the address; the lower bits are used to determine the corresponding validity bit in each line of the selected set. If one of the tags matches and the word is valid, then the data is used to execute the instruction. Otherwise, the missing data is read from external memory, as described below. If the data is not in the DC, and if the contents of both lines in the set are locked to xed locations that do not match the address of the data, then the DC is considered disabled and data is read from an external memory. If the data is not in the DC, and if at least one of the lines in the set is not locked, then: If the tag of a line in the set matches the address in the data, then that line is selected for updating. If no tag matches, and At least one of the lines in the set is not locked, then the unlocked line is selected for replacement. All lines are unlocked, then the least recently used line is selected for replacement. Any missing data is read from external memory and used to execute the instruction, regardless of whether the selected line is being replaced or merely updated.
DC enabled
DC hit
4.3
Figure 4-13 shows these states and the transitions between them.
Reset
Reset
No Reset Interrupt or Trap Executing Instructions Service Call Complete Processing Exception
Interrupt
Reset
When the reset input signal is activated, the CR16C enters the reset state. In this state, the contents of certain dedicated registers are initialized, as detailed in Section 3.5 on page 3-13. When the reset signal is deactivated, the CR16C enters the executinginstructions state. In this state, the CR16C executes instructions repeatedly until an exception is recognized, a WAIT instruction is executed or an EIWAIT instruction is executed. When an exception is recognized, the CR16C enters the processing exception state in which it saves the PC and the PSR contents. The processor then reads an absolute code-address from the interrupt dispatch table and branches to the appropriate exception service procedure. Refer to Section 3.4 on page 3-4 for more information. To process maskable interrupts, the CR16C also reads a vector value from an Interrupt Control Unit (ICU). After successfully completing all data references required to process an exception, the CR16C reverts to the executing instructions state.
Executing instructions
Processing exception
When a WAIT or an EIWAIT instruction is executed, the CR16C enters the waiting for interrupt state and becomes idle. When an interrupt is detected, the processor enters the processing exception state.
Instruction fetches
The CR16C fetches an instruction only after all previous instructions have been completely fetched. It may, however, begin fetching the instruction before all of the source operands have been read, and before the results have been written for previous instructions. The source operands for an instruction are read only after all data reads and data writes from previous instructions have been completed. Figure 4-14 shows this process, and the order of precedence of memory reference for two consecutive instructions. The arrows indicate the order of precedence between operations in and between instructions.
Instruction n+1
Overlapping operations
As a consequence of overlapping operations for several instructions, the CR16C may fetch an instruction but not execute it (e.g., if the previous instruction causes a trap). The CR16C reads source operands and writes destination operands for executed instructions only. The CR16C does not check for dependencies between fetching the next instruction and writing the results of the previous instructions. Special care is therefore required when executing self-modifying code.
Dependencies
5.1
INSTRUCTION DEFINITIONS
The name of each operand appears in bold italics, and indicates its use. In addition, the valid addressing modes, access class and length are specied for each operand. The addressing mode may be: reg (register), procreg (processor register), imm (immediate), abs (absolute) rel (relative), or idx (index relative)The reg and rel addressing modes are followed by a specier rp (register pair) or r (register). The imm addressing mode is followed by a maximum bit size specier. Many instructions support multiple imm sizes for efcient code memory usage. For more details, see Section ADDRESSING MODES on page 2-15 and Appendix B.2.1 on page B-3 for denitions of the imm formats. The access class may be read, write, rmw (read-modify-write), addr (address) or disp (displacement). The access class is followed by a data length attribute specier. See Figure 5-1.
Data Length
Name
ADDi ADDUi
Add Integer
ADDB, ADDW, ADDD, ADDUB, ADDUW
Short Description Valid Mnemonic Forms Operands Addressing Mode Access Classes
ADDi Syntax
src, dest reg/imm reg read.i rmw.i src, dest reg/imm reg read.i rmw.i
ADDUi
Data Length Attribute Speciers Figure 5-1. Instruction Header Format The data length attribute specier species how the operands are interpreted, and represents a character that is incorporated into the name of the actual instruction. The i specier stands for B (byte), or W (word) in the actual instruction name. In the access class, the L (long) specier stands for the long, 24-bit address/displacement.Each instruction denition is followed by a detailed example of one or more typical forms of the instruction. In each example, all the operands of the instruction are identied, both those explicitly stated in Assembly language and those that are implicitly affected by the instruction. For each example, the values of operands before and after execution of the instruction are shown. Often the value of an operand is not changed by the instruction. When the value of an operand changes, its eld is highlighted in gray. See Figure 5-2.
Description of Example
Instruction Name
Unchanged by Execution
This example adds the low-order byte of register R0 to the low-order byte of register R3, and places the result in the low-order byte of register R3. The remaining bytes of R3 are not affected. xx9F16 (-9710) xx6216 (+9810) enzfltc addb r0, r3 r3 PSR xx9F16 (-9710) xx0116 (+110) enz0lt1
r0
r0
r3 PSR
Changed by Execution
Figure 5-2. Instruction Example Format The least signicant digit of the least signicant byte is the right-most digit. Values are expressed in terms of a radix in a subscript to the value. An x represents a binary digit or a hexadecimal digit (4 bits) that is either ignored or unchanged.
5.2
ADDi ADDUi
Add Integer ADDi, ADDUi (Add Integer) ADDB, ADDW, ADDD, ADDUB, ADDUW
ADDi src, reg.r/imm4/16 read.i dest reg.r rmw.i
ADDD
src, dest reg.rp/imm4/16/20/32 reg.rp read.D rmw.D src, reg.r/imm4/16 read.i dest reg.r rmw.i
ADDUi
The ADDi, ADDD and ADDUi instructions add the src and dest operands, and place the result in the dest operand.
Flag
During execution of an ADDi or ADDD instruction, PSR.C is set to 1 on a carry from addition, and cleared to 0 if there is no carry. PSR.F is set to 1 on an overow from addition, and cleared to 0 if there is no overow. PSR ags are not affected by the ADDUi instruction. None Adds the low-order byte of register R0 to the low-order byte of register R3, and places the result in the low-order byte of register R3. The remaining bytes of R3 are not affected. xx9F16 (-9710) xx6216 (+9810) enzfltc addb r0, r3 r3 PSR xx9F16 (-9710) xx0116 (+110) enz0lt1
Trap Example
r0
r0
r3 PSR
The ADDCi instructions add the src operand, dest operand and the PSR.C ag, and place the sum in the dest operand.
Flag
PSR.C is set to 1 if a carry occurs, and cleared to 0 if there is no carry. PSR.F is set to 1 if an overow occurs, and cleared to 0 if there is no overow. None 1. Adds 32, the low-order byte of register R0, and the PSR.C ag contents, and places the result in the low-order byte of register R0. The remaining bytes of register R0 are unaffected. xx0F16 (+1510) enzflt1 addcb $32, r0 xx3016 (+4810) enz0lt0
Trap Example
r0 PSR
r0 PSR
2. Adds the contents of registers R5 and R0, and the contents of the PSR.C ag, and places the result in register R0. FFFF16 (-110) 003016 (+4810) enzflt1 addcw r5, r0 r0 PSR FFFF16 (-110) 003016 (+4810) enz0lt1
r5
r5
r0 PSR
ANDD
The ANDi/ANDD instruction performs a bitwise logical AND operation on the src and dest operands, and places the result in the dest operand.
None None ANDs the low-order bytes of registers R0 and R11 and places the result in the low-order byte of register R11. The remaining byte of register R11 is unaffected.
r0 r11
xx16 xx16
100100102 011101112
r0 r11
xx16 xx16
100100102 000100102
Arithmetic Shift
ASHUB, ASHUW, ASHUD
ASHUD
The ASHUi instruction performs an arithmetic shift on the dest operand as specied by the count operand. Both operands are interpreted as signed integers. The sign of count determines the direction of the shift. A positive count species a shift to the left; a negative count species a shift to the right. The absolute value of the count species the number of bit positions to shift the dest operand. The count operand value must be in the range 7 to +7 if ASHUB is used; in the range 15 to +15 if ASHUW is used; and in the range 31 to +31 if ASHUD is used. Otherwise, the result is unpredictable. If the shift is to the left, high-order bits (including the sign bit) shifted out of dest are lost, and low-order bits emptied by the shift are lled with zeros. If the shift is to the right, low-order bits shifted out of dest are lost, and high-order bits emptied by the shift are lled from the original sign bit of dest. Note that for ASHUD, if the dest operand consists of two registers (dest+1,dest), then in addition to what is described above for all ASHUi instructions, shifts have the following effects: A shift to the left causes high-order bits to be shifted out of dest register to dest+1 register. A shift to the right causes low-order bits of dest+1 register to be shifted out to dest register.
None None 1. Shifts the low-order byte of register R5 two bit positions to the left. The remaining byte of register R5 is unaffected. ashub $2, r5
r5
xx16
000111112
r5
xx16
011111002
2. Reads a byte from register R4. Based on this value, it shifts the loworder byte of register R6 accordingly. The remaining byte of register R6 is unaffected. 111111102 (-210) 111110002 111111102 (-210) 111111102
r4 r6
xx16 xx16
ashub r4, r6
r4 r6
xx16 xx16
The address (bits 23 to 1) of the next sequential instruction is rst stored in the link operand. Then, program execution continues at the address specied by dest, sign extended to 25 bits, plus the current contents of the PC register. as follows: PC <- (PC+ sext_25(disp)). The result is stored in PC before being used. If the resulting PC value is less than 0x00_0000 or greater than 0xFF_FFFF, this instruction causes an IAD trap. If the link operand is (ra), with CFG.SR=0, or (era,ra), with CFG.SR=1, the instruction size is 4 bytes; otherwise, it is 6 bytes.
None None Saves bits 23 through 1 of the PC register of the next sequential instruction in register RA, and passes execution control to the instruction labeled L by adding 00F6C16 to the current PC register. PC L
(A00416)
PC L
(A00416)
era,ra
xxxxxxxx16
era,ra
Bcond
Conditional Branch Bcond (Conditional Branch) BEQ, BNE, BCS, BCC, BHI, BLS, BGT,
BLE, BFS, BFC, BLO, BHS, BLT, BGE
dest disp disp Table 5-1. If the condition specied by cond is true, the Bcond instruction causes a branch in program execution. Program execution continues at the location specied by dest, sign extended to 25 bits, plus the current contents of the Program Counter. If the condition is false, execution continues with the next sequential instruction. Table 5-1 summarizes the different addressing calculations.BR/BRcond Target Addressing Methodology Displacement Size (Signed) 9 bits 17 bits 25 bits Inst Size 2 4 6 Address Range Address Calculation Bcond
0 - 16M PC <- (PC + sign extend to 25(disp)) 0 - 16M PC <- (PC + sign extend to 25(disp)) 0 - 16M PC <- (PC + disp)
cond is a two-character condition code that describes the state of a ag, or ags, in the PSR register. If the ag(s) is/are set as required by the specied cond, the condition is true; otherwise, the condition is false. Table 5-2 describes the possible cond codes and the related PSR ag settings.
Flag Trap
None None Table 5-2. cond Codes and PSR Settings cond Code EQ NE CS CC HI LS GT LE Condition Equal Not Equal Carry Set Carry Clear Higher Lower or Same Greater Than Less Than or Equal To True State Z ag is 1 Z ag is 0 C ag is 1 C ag is 0 L ag is 1 L ag is 0 N ag is 1 N ag is 0
The assembler encodes the displacement by dividing it by two. The CR16C expands this encoding by multiplying the value by two. The least signicant bit of the displacement is always 0. CompactRISC CR16C Programmers Reference Manual INSTRUCTION SET 5-10
cond Code FS FC LO HS LT GE
Condition Flag Set Flag Clear Lower Higher or Same Less Than Greater Than or Equal To
Examples
1. Passes execution control to the instruction labeled LOOP by adding FFFF6816 to the PC register, if the PSR.Z and PSR.L ags are 0. PC LOOP
(900016)
PC LOOP
(900016)
PSR
PSR
2. Passes execution control to a non-sequential instruction if the PSR.Z ag is 0. The instruction passes execution control by adding 16 to the PC register. 009FF016 (4094410) bne *+16 xxxx16 en0fltc 00A00016 (4096010) xxxx16 en0fltc
PC *+16
(A00016)
PC *+16
(A00016)
PSR
PSR
3. Passes execution control to a non-sequential instruction if the PSR.Z ag is 0. The instruction passes execution control by adding 4090 to the PC register. 01F22016 (12752010) bne *+4090 xxxx16 en0fltc 02021A16 (58810) xxxx16 en0fltc
PC *+4090
(02021A16)
PC *+4090
(02021A16)
PSR
PSR
4. Passes execution control to a non-sequential instruction if the PSR.Z ag is 0. The instruction passes execution control by adding 1507344 to the PC register. 009FF016 (4094410) bne *+1507344 xxxx16 en0fltc 17A00016 (154828810) xxxx16 en0fltc
PC *+1507344
(17A00016)
PC *+1507344
(17A00016)
PSR
PSR
BCond0i
The BCond0i instruction compares the signed contents of src to 0, and branches upon equality or non-equality (according to cond) as shown in Table 5-3. The target address is determined by adding the 5-bit displacement (unsigned even 2-32) to the current value of the program counter. Only forward branching is supported. The instruction performs byte or word compares according to the i indicator. Table 5-3. Conditional Branch Cond Code EQ NE Condition Equal Not Equal True State Rn is equal to 0 Rn is not equal to 0
None None Compares the low-order byte in register R0 to 0 and since the lower byte of R0 is 0, branches to the instruction at address *+16 by adding 16 to the PC register. 009FF016 (4094410) beq0b r0, *+16 r0 *+16
(A00016)
PC
PC r0 *+16
(A00016)
xx0016 xxxx16
The assembler encodes the displacement by dividing it by two and subtracting one. The CR16C reverts this encoding by adding one and the multiplying the value by two, the least signicant bit of the displacement is always 0 CompactRISC CR16C Programmers Reference Manual INSTRUCTION SET 5-13
.BR
BR
dest is an even integer, sign extended to 25 bits and added to the current contents of the PC register. The result is loaded into the PC register. Program execution continues at the location specied by the updated PC register. Table 5-1 describes the detailed address calculation performed for the BR instruction.
None None 1. Passes execution control to the instruction at address *+16 by adding +16 to the PC register. 009FF016 (4094410) xxxx16 00A00016 (4096010) xxxx16
PC LOOP (A00016)
PC br *+16
LOOP (A00016)
2. Passes execution control to a non-sequential instruction. The instruction passes execution control by adding 1507344 to the PC register. 009FF016 (4094410) xxxx16 17A00016 (154828810) xxxx16
PC *+1507344
(17A00016)
PC br *+1507344 *+1507344
(17A00016)
For further examples, see the description of the BCond instruction. The Branch command executes the same way as BCond, since the condition is effectively always true.
CBITi
The CBITi instruction loads the dest operand from memory, clears the bit specied by position, and stores it back into memory location dest, in an uninterruptable manner. The position operand value must be in the range 0 to +7 if CBITB is used, and 0 to +15 if CBITW is used; otherwise, the result is unpredictable. As there is no native support for clearing a bit in a double-length core register when CFG.SR=0, the ANDD instruction should be used. See Table 5-4 for addressing modes.
Before the specied bit is modied, its value is stored in PSR.F. None 1. Clears bit in position 5 in a byte operand at address 9 (R1). r1 200916
(memory)
r1 200916
(memory)
PSR
PSR
r8 200416
(memory)
PSR
PSR
009F16 enzfltc
009716 enz11tc
PSR
PSR
Table 5-4. CBIT/SBIT/TBIT and STOR Imm Addressing Methodology Instr DisplaceAddress Length ment Range range (Byte) 0 0 to 64K 1 0 to 1M 1 0 to 16K 1 0 to 16K 1 0 to 1M 1 0 to 1M 1 0 to 1M - 1 0 to 1M - 1
d
Address Calculation Rpbase Rbase + zext24(disp16) Rbase + zext24(disp20) Rindex + (RPbasex) + zext24(disp14)
2 4 6 4 4 6 6 4 4 6
64K+16K Rbase + zext24(disp14) 16M 1M 16M 1M 16M Rindex + (RPbasex) + zext24(disp20) Rbase + zext24(disp20) Rindex + zext24(disp20) zext24(abs20) | remape abs24
[Rindex]disp20(RPbasexa)b idx disp20(Rbase) [Rindex]abs20b abs20 abs24 rel idx abs abs
0 to 16M -1
a. RPbasex - Base register pair for relative addressing only: (R1,R0), (R3,R2), (R5,R4), (R7,R6), (R9,R8), (R11,R10), (R4,R3), (R6,R5) b. when CFG.SR = 0 c. when CFG.SR = 1 d. The 1M addressable range is split into (0x0 to 1M-64k) and (16M-64k to 16M) e. If (abs20 > 0xEFFFF) the resulting address is logically ORed with 0xF00000 i.e. addresses from 1M-64k to 1M are re-mapped by the core to 16M-64k to 16M.
CINV
Cache Invalidate
CINV
CINV options
The CINV instruction invalidates the contents of the on-chip instruction cache and/or data cache. CINV can invalidate either the entire contents, or only the unlocked entries, of the on-chip caches. options are specied by listing the letters I, D, and/or U. These options are independent of one another. The I option invalidates the instruction cache; the D option invalidates the data cache. If both I and D are specied, then both caches are invalidated. The U option invalidates only the unlocked lines in the listed cache(s). If the U option is not specied, the entire cache/caches is/are invalidated.
None None 1. Invalidates the unlocked lines in the instruction cache. cinv [i,u] 2. Invalidates all lines in both the instruction cache and the data cache. cinv [i,d] 3. Invalidates all unlocked lines in both the instruction cache and the data cache. cinv [i,d,u]
Compare Integer
CMPB, CMPW, CMPD
CMPD
The CMPi/D instruction subtracts the src1 operand from the src2 operand, and sets the PSR.Z, PSR.N, and PSR.L ags to indicate the comparison result. The PSR.N ag indicates the result of a signed integer comparison; the PSR.L ag indicates the result of an unsigned comparison. Both types of comparison are performed.
Flag
PSR.Z is set to 1 if src1 equals src2; otherwise it is cleared to 0. PSR.N is set to 1 if src1 is greater than src2 (signed comparison); otherwise it is cleared to 0. PSR.L is set to 1 if src1 is greater than src2 (unsigned comparison); otherwise it is cleared to 0. None Compares low-order bytes in registers R0 and R3. xxFF16 (signed: -110) (unsigned: +25510) cmpb r0, r3 r3 PSR xx7E16 (+12610) enzfltc r3 PSR xx7E16 (+12610) e00f1tc xxFF16 (signed: -110) (unsigned: +25510)
Trap Example
r0
r0
DI
DI
PSR.E is cleared to 0. None Clears the PSR.E bit to 0. PSR enzfltc di PSR 0nzfltc
EI
EI
PSR.E is set to 1. None Sets the PSR.E bit to 1. PSR enzfltc ei PSR 1nzfltc
EIWAIT
Exception
EXCP
The EXCP instruction activates the trap specied by the vector operand. The return address pushed onto the interrupt stack is the address of the EXCP instruction itself. Specifying an EXCP with a reserved vector operand results in an Undened (UND) exception.
Flag Trap
None The traps that occur are determined by the value of the vector operand, as shown in Table 5-5. Table 5-5. Exception Traps Vector SVC DVZ FLG BPT UND otherwise
a
Trap Name Supervisor Call Division by Zero Flag Breakpoint Undened Instruction reserved
a. If any other vector is encoded, a UND trap is called; this includes DBG/ISE/IAD/TRC
Example
Jcond
Conditional Jump
JEQ, JNE, JCS, JCC, JHI, JLS, JGT, JLE, JFS, JFC, JLO, JHS, JLT, JGE
Jcond dest reg.rp addr.L
If the condition specied by cond is true, the Jcond instruction causes a jump in program execution. Program execution continues at the address specied in the dest register by loading register bits 22 through 0 into bits 23 through 1 of the PC register. Bit 0 of the PC is cleared to 0. If the condition is false, execution continues with the next sequential instruction. cond is a two-character condition code that describes the state of a ag or ags in the PSR. If the ag/s is/are set as required by the specied cond, the condition is true; otherwise, the condition is false. Table 5-6 describes the possible cond codes and the related PSR ag settings: Table 5-6. cond Codes and Related Flags cond Code EQ NE CS CC HI LS GT LE FS FC LO HS LT GE Condition Equal Not Equal Carry Set Carry Clear Higher Lower or Same Greater Than Less Than or Equal To Flag Set Flag Clear Lower Higher or Same Less Than Greater Than or Equal To True State Z ag is 1 Z ag is 0 C ag is 1 C ag is 0 L ag is 1 L ag is 0 N ag is 1 N ag is 0 F ag is 1 F ag is 0 Z and L ags are 0 Z or L ag is 1 Z and N ags are 0 Z or N ag is 1
Flag Trap
None None
Example
Loads the address held in R3, R4 into the bits 1 through 23 of the PC register. Program execution continues at that address, if the PSR.Z and PSR.L ags are 0. r3 r4 PC 100416 000c16 0A909816 en0f0tc jlo (r4,r3) PC PSR r3 100416 000c16 18200816 (C100416 2) en0f0tc
PSR
Program execution continues at the address specied in the dest register, by loading register bits 22 through 0 into bits 23 through 1 of the PC register. Bit 0 of the PC register is cleared to 0. Bits 23 through 1 of the address of the next sequential instruction are stored in the link operand. If the link operand is (ra) when CFG.SR=0, or (era,ra) when CFG.SR=1, the instruction size is 2 bytes; otherwise, it is 6 bytes.
None None loads the address held in R3 into the PC register. Program execution continues at that address. The address of the next sequential instruction is stored in register RA. jal (ra, era), (r4,r3)
r3 r4 PC ra,era
r3 r4 PC ra,era
Jump
JUMP, JUSR
JUSR
Program execution continues at the address specied in the dest operand , by loading the operands bits 22 through 0 into bits 23 through 1 of the PC register. Bit 0 of the PC register is cleared to 0. JUSR continues program execution in user mode. This is indicated by setting the PSR.U bit in addition to the JUMP.
None for JUMP, but PSR.U is set for JUSR instruction. None loads the address held in R4, R3 into bits 23 through 1 of the PC register. Program execution continues at that address. r3 r4 PC 100416 000c16 0A909816 jump (r4,r3) PC r3 100416 000c16 18200816 (C100416 2)
Load Integer
LOADB, LOADW, LOADD
LOADD
The LOADi/LOADD instruction loads the src operand from memory, and places it in the dest operand. Table 5-7 describes the addressing methodology for the instruction.
Table 5-7. LOAD/STOR Memory Addressing Methodology Addr. Data Displacement Mode Length Length Range Range (Byte)
2 2 4 6 6 2 4 6 2 4 6 6 b w/d b/w/d b/w/d b/w/d b/w/d b/w/d b/w/d b/w/d b/w/d b/w/d b/w/d rel.rp rel.rp rel.rp rel.rp rel.rp idx idx idx rel.r rel.r rel.r rel.r 0 to 13 even numbers from 0 to 26 0 to 64K - 1 0 to 1M - 1 -(1M - 1) to -1 0 0 to 16k1 0 to 1M1 0 0 to 16k1 0 to 1M1 -(1M - 1) to -1 16M 16M 16M 16M 16M 16M 16M 16M 64K
Instr.
Addressing Modes
disp4(RPbase) disp4(RPbase) disp16(RPbase) disp20(RPbase) -disp20(RPbase)a [Rindex]disp0(RPbasexb)c [Rindex]disp14(RPbasexb)c [Rindex]disp20(RPbasexb)c disp0(Rbase)d disp14(Rbase)d disp20(Rbase) -disp20(Rbase)a
Address Calculation RPbase + zext24(disp4) RPbase + zext24(disp4) RPbase + zext24(disp16) RPbase + zext24(disp20) zext24(Rbase) + sext24(-disp20) Rpbasex + Rindex RPbasex + Rindex + zext24(disp14) RPbasex + Rindex + zext24(disp20) zext24(Rbase)
zext24(Rbase) + sext24(-disp20)
Addressing Modes
[Rindex]abs20c abs20 abs24
Instr.
a. This displacement format may not be supported in future versions of the CPU. It is included for assembly level, backward compatibility with CR16B. b. RPbasex - Base register pair for relative addressing only: (R1,R0), (R3,R2), (R5,R4), (R7,R6), (R9,R8), (R11,R10), (R4,R3), (R6,R5) c. Supported when CFG.SR= 0 d. Supported when CFG.SR= 1 e. The 1M addressable range is split into (0x0 to 1M-64k) and (16M-64k to 16M). f. If (abs20 > 0xEFFFF) the resulting address is logically ORed with 0xF00000 i.e. addresses from 1M-64k to 1M are re-mapped by the core to 16M-64k to 16M.
None None 1. Loads a byte operand in address 9 (R5) to the low-order byte of register R7. The remaining byte of register R7 is unaffected. r5 200916
(memory)
r7 2.
r7
Loads a word operand in address 632 to register R9. 63216 loadw 0x632, r9 (memory) r9
63216
(memory)
009816 xxxx16
009816 009816
r9
3. Loads a word operand in address 1A000216 to register R7. The address is formed by adding 1000016 to the value in R4, concatenated with the value in R5. r4 r5 1A000216 (memory) r7 000216 001916 AA5516 xxxx16 loadw 0x10000(r5,r4),r7 r4 r5 1A000216
(memory)
r7
4. Loads a word operand in address 3000216 to register R7. The address is formed by adding 3000016 to the value in R4. r4 3000216 (memory) r7 000216 AA5516 xxxx16 loadw 0x30000(r4),r7 r4 3000216
(memory)
r7
LOADM
The LOADM and LOADMP instructions load adjacent registers from memory. count reflects the total number of words to be loaded in the range 1 to 8. LOADM operates over the first 64K of memory and LOADMP operates over the entire memory range. The instruction always operates on a fixed set of registers as described below. For LOADM: R0 contains the address of the rst word in memory to be loaded; R2 is loaded with the lowest address word; R3 through R5 and then R8 through R11 are loaded from the next count1 consecutive addresses. R0 is adjusted (incremented) by 2 for each word loaded, and therefore points to lower 16-bits of the next unread word in memory at the transfer-end. The address does not wrap around i.e., if R0 points to the end of the 64k addressable range LOADM overows to addresses 0x010000 and following. For LOADMP: (R1, R0) contains the address of the rst word in memory to be loaded; R2 is loaded with the lowest address word; R3 through R5 and then R8 through R11 are loaded from the next count1 consecutive addresses. (R1, R0) is adjusted (incremented) by 2 for each word loaded, and therefore points to the next unread word in memory at the transfer-end. This instruction is not interruptible.
Flag Trap
None None
LPRD
The LPR/LPRD instruction copies the src operand to the processor register specied by dest. For the LPR instruction, if dest is ISPL or INTBASEL the least signicant bit (bit 0) of the address is 0. If dest is INTBASEH, ISPH, USPH, CAR0H, or CAR1H bits 8 through 15 are always written as 0. For the LPRD instruction, if dest is ISP or INTBASE the least signicant bit (bit 0) of the address is 0. If dest is INTBASE, ISP, USP, CAR0, or CAR1 bits 24 through 31 are always written as 0. On a LPRD of a 16-bit register, the upper 16 bits of the src ignored.The processor registers in Table 5-8 may be loaded: Table 5-8. Loadable Processor Registers Register Processor Status Register Conguration Register Interrupt Base Register Interrupt Base Low Register Interrupt Base High Register Interrupt Stack Pointer Register Interrupt Stack Pointer Low Register Interrupt Stack Pointer High Register User Stack Pointer Register User Stack Pointer Low Register User Stack Pointer High Register Debug Status Register Debug Condition Register Debug Condition Low Register Debug Condition High Register DCRL DCRH USPL USPH DSR DSR DCR ISPL ISPH USP INTBASEL INTBASEH ISP LPR PSR CFG LPRD PSR CFG INTBASE are
Register Compare Address 0 Register Compare Address 0 Register Low Compare Address 0 Register High Compare Address 1 Register Compare Address 1 Register Low Compare Address 1 Register High
LPR
LPRD CAR0
Refer to REGISTER SET on page 3-1 and to INSTRUCTION SET on page 6-1 for more information on these registers.
PSR ags are affected by loaded values except for the U bit. When PSR.U is set, this instruction causes an UND trap. Loads register PSR from register R1. r1 PSR 000016 enzfltc lpr r1, psr r1 PSR 000016 00000002
LSHD
The LSHi/LSHD instruction performs a logical shift on the dest operand as specied by the count operand. The count operand is interpreted as a signed integer; the dest operand is interpreted as an unsigned integer. The sign of count determines the direction of the shift. A positive count species a left shift; a negative count species a right shift. The absolute value of count gives the number of bit positions to shift the dest operand. The count operand value must be in the range 7 to +7 if LSHB is used, 15 to +15 if LSHW is used and 31 to +31 if LSHD is used; otherwise, the result is unpredictable. All bits shifted out of dest are lost, and bit positions emptied by the shift are lled with zeros. For LSHD, if the dest operand consists of two actual registers (dest+1,dest), in addition to what is described regarding all LSHi instructions, a shift to the left causes high-order bits to be shifted out of dest register to dest+1 register, and a shift to the right causes low-order bits of dest+1 register to be shifted out to dest register. Note: The LSHi or LSHD instruction with a positive count is not natively supported by the core. It is mapped by the assembler to the corresponding ASHUi or ASHUD instruction, respectively.
None None 1. Shifts the low-order byte of register R1 four bit positions to the left. The remaining byte of register R1 is unaffected. lshb $4, r1
r1
xx16
111111102
r1
xx16
111000002
2. Reads a byte from register R5. Based on this value, it shifts the loworder byte of register R7. The remaining byte of register R7 is unaffected. r5 r7 xx16 xx16 111111112 111111102 lshb r5, r7 r5 r7 xx16 xx16 111111112 011111112
MACSW
The MACSW instruction multiplies the src1 operand by the src2 operand and adds the result to the dest operand. The two src operands are interpreted as signed 16-bit integers. The result is viewed as a signed 32-bit integer. During the addition, the result may overow or underow. In this case, the result is set (saturated) to the largest positive (+231-1) or largest negative (-231) number.
None None Multiplies register R4 by register R5, and adds the result to the register pair (R1,R0). DFFB16 (-200516) (-819710) macsw r4,r5,(r1,r0) DFFB16 (-200510) (-819710)
r4
r4
r5
400A16 (+1639210)
r5
400A16 (+1639210)
r0
001016
r0
7FDE16
r1
100016 (+26843547210)
r1
07FD16 (+13405385410)
MACUW
The MACUW instruction multiplies the src1 operand by the src2 operand and adds the result to the dest operand. The two src operands are interpreted as unsigned 16-bit integers. The result is viewed as unsigned 32bit integer. During the addition the result may overow. In this case, the result is set (saturated) to the largest positive (+232-1) number.
None None Multiplies register R4 by register R5, and adds the result to the register pair (R1,R0). 200516 (819710) macsw r4,r5,(r1,r0) 200510 (819710)
r4
r4
r5
400A16 (+1639210)
r5
400A16 (+1639210)
r0
001016
r0
804216
r1
100016 (26843547210)
r1
180216 (40281709010)
MACQW
The MACQW instruction multiplies the src1 operand by the src2 operand and adds the result to the dest operand. The two src operands are interpreted as 16-bit signed fractional numbers (Q15 format). The result is viewed as a 32-bit fractional number. During the multiplication or addition, the result may overow or underow. In either case, the result is set (saturated) to the largest positive (1) or largest negative (-1) number.
None None Multiplies register R4 by register R5, and adds the result to the register pair (R1,R0). C00016 (-400016) (-0.510) macqw r4,r5,(r1,r0) C00016 (-400010) (-0.510)
r4
r4
r5
200016 (+0.2510)
r5
200016 (+0.2510)
r0
800016
r0
800016
r1
400016 (+0.500015258810)
r1
300016 (+0.375015258810)
MOVi
Move Integer
MOVB, MOVW, MOVD
MOVi src, dest reg.r/imm4/16reg.r read.i write.i src, dest reg.rp/imm4/16/20/32reg.rp read.D write.D
MOVD
The MOVi instruction copies the src operand to the dest operand.
None None 1. Copies the contents of register R0 to register R6. r0 r6 123416 xxxx16 movw r0, r6 r0 r6 123416 123416
3. Sets register pair (R9, R8) to the value $0x1700A716. r8 r9 xxxx16 xxxx16 movd $0x1700A7, (r9,r8) r8 r9 00A716 001716
MOVXi
MOVXB, MOVXW
MOVXW
The MOVXB instruction converts the signed integer src operand to the word dest operand. The MOVXW instruction converts the signed integer src operand to the double-word dest operand. The sign is preserved through sign extension.
None None These examples copy the low-order byte of register R8 to the low-order byte of register R0, and extend the sign bit of the byte through the highorder bits of register R0. 1. Illustrates negative sign extension. xxF016 (low byte: 1610) xxxx16 xxF016 (low byte: 1610) FFF016 (1610)
r8
r8 movxb r8, r0 r0
r0
r8
r8 movxb r8, r0 r0
r0
MOVZi
MOVZB, MOVZW
src, dest reg.r reg.rp read.W write.DThe MOVZB instruction converts the unsigned integer src operand to the unsigned word dest operand. The MOVZW instruction converts the unsigned integer src operand to the unsigned double-word dest operand. The high-order bits are lled with zeros. MOVZW
None None Copies the low-order byte of register R8 to the low-order byte of register R0, and sets the high-order bits of register R0 to zero. xxFF16 (low byte: +25510) movzb r8, r0 xxxx16 xxFF16 (low byte: +25510) 00FF16 (+25510)
r8
r8
r0
r0
Multiply Integer
MULB, MULW
The MULi instruction multiplies the src operand by the dest operand and places the result in the dest operand. Both operands are interpreted as signed integers. If the resulting product cannot be represented completely in the dest operand, the high-order bits are truncated.
None None Multiplies register R5 by R0, and places the result in register R0. 000516 (+510) 000A16 (+1010) 000516 (+510) 003216 (+5010)
r5
r5 mulw r5, r0 r0
r0
MULSB
The MULSB instruction multiplies the 8-bit src operand by the 8-bit dest operand, and places the 16-bit result in the dest register. Both source and destination operands are viewed as signed 8-bit integers, and the result is a signed 16-bit integer.
None None Multiplies signed register R8 by R0, and places the result in register R0. BB16 (-4510) 3A16 (-5810) BB16 (-4510) F05E16 (-261010)
r8
r8 mulsb r8, r0 r0
r0
MULSW
The MULSW instruction multiplies the 16-bit src operand by the 16-bit dest operand, and places the 32-bit result in the dest operand. Both source and destination operands are viewed as signed 16-bit integers, and the result is a signed 32-bit integer.
None None Multiplies signed register R8 by R0, and places the result in registers (R1, R0). DFFB16 (-200516) 400A16 xxxx16 DFFB16 (-200516) 7FCE16 F7FD16 (-802803216)
r8
r8
r0 r1
r0 r1
MULUW
The MULUW instruction multiplies the 16-bit src operand by the 16-bit dest operand, and places the 32-bit result in the dest operand. Both source and destination operands are viewed as unsigned 16-bit integers, and the result is an unsigned 32-bit integer.
None None Multiplies unsigned register R8 by R2, and places the result in registers (R3, R2). 200516 (+819710) 400A16 (+1639410) xxxx16 (+x10) 200516 (+819710) 803216 080216 (+13438161910)
r8
r8
r2 r3
r2 r3
No Operation
NOP
The NOP instruction passes control to the next sequential instruction. No operation is performed. Note: The NOP instruction is not natively supported by the core. It is mapped by the assembler to ADDUB $0x0, r0 (single word instruction).
Bitwise Logical OR
ORB, ORW, ORD
ORD
The ORi/ORD instruction performs a bitwise logical OR operation on the src and dest operands, and places the result in the dest operand.
None None ORs the low-order bytes of registers R5 and R7, and places the result in the low-order byte of register R7. The remaining byte of register R7 is unaffected.
r5 r7
xx16 xx16
110110002 000010112
orb r5, r7
r5 r7
xx16 xx16
110110002 110110112
POPrt
POPrt
POPrt
write.LThe POPrt instruction can restore up to eight adjacent registers plus the RA from the program stack. The registers are dened by src register, with up to seven more adjacent registers (e.g., src, src+1, src+2, src+3, src+4, src+5, src+6, src+7) and the RA. count reects the total number of words to restore, excluding the RA. The count operand is in the range 1 to 8. src is loaded with the value residing at the lowest address (top of stack) and the RA register, if loaded, at the highest address. The stack pointer (SP) is adjusted (incremented) accordingly. Note that a double-word register is considered 2 words long. This instruction is not interruptible. After the POP operation has ended, the processor can return control to a calling routine, according to the rt switch in the instruction. rt Switch none RET Operation no-return Return Implied Instruction -JUMP RA
Depending on the format, the following registers are saved: In the three operand format, the instruction restores up to eight adjacent registers and the RA register. In the two operand format, the instruction restores up to eight adjacent registers. In the one operand format, the instruction restores only the RA register from the stack. Note: The parameters to POPrt should not indicate a restore of registers R15 (SP) and beyond. This constrains the permitted count values as shown below:
RA is part of the instruction it refers to (ra) if CFG.SR = 0 and to (ra, era) otherwise CompactRISC CR16C Programmers Reference Manual INSTRUCTION SET 5-47
When CFG.SR = 1, parameters meeting the following condition are invalid: if cnt + starting register number > 15 When CFG.SR = 0, parameters meeting the following conditions are invalid:
The POPrt instruction does not change the contents of memory locations indicated by an asterisk (*). However, information that is outside the stack should be considered unpredictable for other reasons.
None None 1. Pops three registers, starting with R3, from the stack: PC SP r3 r4 r5 001000 (stack) 001002 (stack) 001004 (stack) 00F03416 0000100016 XXXX16 XXXX16 XXXX16 2F5016 pop $3,R3 PC SP r3 r4 r5 001000 (stack) 001002 (stack) 001004 (stack) 00F03616 0000100616 2F5016 107E16 35EC16 xxxx16 xxxx16 xxxx16
107E16 35EC16
2. Pops eight words from the stack starting with R8, pops RA, and executes a JUMP RA: 866BD816 (ra x 2} 0003100A16 000016 000116 000216 000316 107E2F5016 000335EC16 004335EC16 xxxx16 xxxx16 xxxx16 xxxx16 xxxx16 xxxx16 xxxx16 xxxx16 xxxx16 xxxx16
PC SP r8 r9 r10 r11 r12 r13 ra 0309f8 (stack) 0309FA (stack) 0309FC (stack) 0309FE (stack) 031000 (stack) 031002 (stack) 031004 (stack) 031006 (stack) 031008 (stack) 03100A (stack)
00F03416 000309f816 XXXX16 XXXX16 XXXX16 XXXX16 XXXXXXXX16 XXXXXXXX16 XXXXXXXX16 000016 000116 000216 000316 2F5016 107E16 35EC16 000316 35EC16 004316 popret $8,R8,RA
PC SP r8 r9 r10 r11 r12 r13 ra 309f8 (stack) 309FA (stack) 309FC (stack) 309FE (stack) 031000 (stack) 031002 (stack) 031004 (stack) 031006 (stack) 031008 (stack) 03100A (stack)
PUSH
PUSH
PUSH
read.LThe PUSH instruction saves up to eight adjacent registers plus the RA on the program stack. The registers are dened by src register, with up to seven more adjacent registers (e.g., src, src+1, src+2, src+3, src+4, src+5, src+6, src+7) and the RA. count reects the total number of words to save, excluding the RA. The count operand is in the range 1 to 8. src is loaded with the value residing at the lowest address (top of stack) and the RA register, if saved, at the highest address. The stack pointer (SP) is adjusted (decremented) accordingly. Note that a double-word register is considered two words long. This instruction is not interruptible. Register pairs stored within a single PUSH instruction comply with littleendian methodology. Depending on the format, the following registers are saved: In the three operand format, the instruction saves up to eight adjacent registers and the RA register. In the two operand format, the instruction saves up to eight adjacent registers. In the one operand format, the instruction saves only the RA register from the stack.
Flag Trap
None None
RA is part of the instruction it refers to: (ra) if CFG.SR = 0, and (ra, era), otherwise. CompactRISC CR16C Programmers Reference Manual INSTRUCTION SET 5-50
Example
Pushes three registers, starting with R5, on the stack: SP r5 r6 r7 001000 (stack) 001002 (stack) 001004 (stack) 0000100616 2F5016 107E16 35ED16 XXXX16 XXXX16 XXXX16 push $3,r5 SP r5 r6 r7 001000 (stack) 001002 (stack) 001004 (stack) 0000100016 2F5016 107E16 35ED16 2F5016 107E16 35ED16
The RETX instruction returns control from a trap service procedure. The following steps are performed: 1. The instruction pops a 32-bit value from the interrupt stack, copying bits 22 - 0 to bits 23 - 1 of the PC. 2. The instruction then pops a 16-bit value from the interrupt stack into the PSR register. The RETX instruction does not change the contents of memory locations indicated by an asterisk (*). However, information that is outside the stack should be considered unpredictable for other reasons.
All PSR ag states are restored from the stack. None Returns control from an interrupt service procedure. 0013200816 (9900416 2) 0000100616 084516 xxxx16 xxxx16 xxxx16
000916 84516
SBITi
SBITW
The SBITi instruction loads the dest operand from memory, sets the bit position specied by position, and stores it back into memory location dest, in an uninterruptable manner. The position operand value must be in the range 0 to +7 if SBITB is used, and 0 to +15 if SBITW is used; otherwise, the result is unpredictable. As there is no native support for setting a bit in a double length core register, the ORD instruction should be used with SR=0. See Table 5-4.
Before the specied bit is modied, its value is stored in PSR.F. None 1. Sets bit in position 5 in a byte operand at address 9 (R1). r1 200916
(memory)
r1 200916
(memory)
PSR
PSR
r8 200416
(memory)
PSR
PSR
xx9116 enzfltc
xx9916 enz0ltc
PSR
PSR
Scond
Save Condition as Boolean Scond (Save Condition as SNE, SCS, SCC, SHI, SLS, SGT, SEQ, Boolean)
SLE, SFS, SFC, SLO, SHS, SLT, SGE
Scond dest reg.r write.W
The Scond instruction sets the dest operand to the integer value 1 if the condition specied in cond is true, and clears it to 0 if the condition is false. cond is a two-character condition code that species the state of a ag or ags in the PSR register. If the ag(s) is/are set as required by the specied cond, the condition is true; otherwise, the condition is false. Table 5-9 describes the possible cond codes and the related PSR ag settings: Table 5-9. cond Codes and Related PSR Flags cond Code EQ NE CS CC HI LS GT LE FS FC LO HS LT GE Condition Equal Not Equal Carry Set Carry Clear Higher Lower or Same Greater Than Less Than or Equal To Flag Set Flag Clear Lower Higher or Same Less Than Greater Than or Equal To True State Z ag is 1 Z ag is 0 C ag is 1 C ag is 0 L ag is 1 L ag is 0 N ag is 1 N ag is 0 F ag is 1 F ag is 0 Z and L ags are 0 Z or L ag is 1 Z and N ags are 0 Z or N ag is 1
Flag Trap
None None
Examples
r0 PSR
xxxx16 en1fltc
seq r0
r0 PSR
2. Sets register R2 to 1 if the PSR.Z and PSR.L ags are 0, and to 0 if they are not both 0. 000016 (False) en1f1tc
r2 PSR
xxxx16 en1f1tc
slo r2
r2 PSR
SPRD
The SPR/SPRD instruction copies the processor register specied by the src operand to the dest operand. On a SPRD of a 16 bit register, the upper 16 bits of the dest are loaded with 0. The processor registers in Table 5-10 may be stored: Table 5-10. Storable Processor Registers Register Processor Status Register Conguration Register Interrupt Base Register Interrupt Base Low Register Interrupt Base High Register Interrupt Stack Pointer Register Interrupt Stack Pointer Low Register Interrupt Stack Pointer High Register User Stack Pointer Register User Stack Pointer Low Register User Stack Pointer High Register Debug Status Register Debug Condition Register Debug Condition Low Register Debug Condition High Register Compare Address 0 Register Compare Address 0 Register Low Compare Address 0 Register High CAR0L CAR0H DCRL DCRH CAR0 USPL USPH DSR DSR DCR ISPL ISPH USP INTBASEL INTBASEH ISP SPR PSR CFG SPRD PSR CFG INTBASE
Register Compare Address 1 Register Compare Address 1 Register Low Compare Address 1 Register High
SPR
SPRD CAR1
CAR1L CAR1H
Refer to REGISTER SET on page 3-1 and to INSTRUCTION SET on page 6-1 for more information on these registers.
None None 1. Copies the INTBASEL register to register R0. intbase intbasel r0 0000010016 010016 xxxx16 intbase spr intbase, r0 intbasel r0 0000010016 010016 010016
intbase intbaseh r1
Store Integer
STORB, STORW, STORD
STORD
STORi
The STORi instruction stores the src operand in the dest memory operand. Table 5-7 describes the addressing options for the rst and second formats of the instruction. The third format of the instructions allows storing an unsigned 4-bit immediate operand (in the range of 0 to 15) into the dest memory operand. The addressing options for this format are described in Table 5-4.
None None 1. Copies the contents of register R0 to the word at address 912016. r0 912016 567816 xxxx16 storw r0, 0x9120 r0 912016 567816 567816
2. Stores the low-order byte of R7 at address 3000216. The address is formed by adding 3000016 to the value in R4. r7 r4 3000216 (memory) xx5516 000216 xx16 storb r7,0x30000(r4) r7 r4 3000216
(memory)
3. Stores the low-order byte of R7 at address 1A000216. The address is formed by adding 1000016 to the value in R4, concatenated with the value in R5. r7 r4 r5 1A000216 (memory) xx5516 000216 xx1916 xx16 storb r7,0x10000(r5,r4) r7 r4 r5 1A000216
(memory)
4. Copies the contents of register R3 to the non-aligned word at address 9 (R5). r3 r5 200816 (memory) 200A16 (memory) AA5516 200016 storw r3,9(r5) xxxx16 r3 r5 200816 (memory) 200A16 (memory) AA5516 200016 55xx16
xxxx16
xxAA16
5. Stores the immediate value of 0x5 to the word at address 912016. 912016 xxxx16 storw $5, 0x9120 912016 000516
6. Stores the immediate value of 0x7 to the word at address 4 (R1). r1 200416 (memory) 200016 storw $7,4(r1) xxxx16 200416 (memory) 000716 r1 200016
7. Stores the immediate value of 0x7 to the non-aligned word at address 3 (R1). r1 200216 (memory) 200416 (memory) 200016 xxxx16 storw $7,3(r1) r1 200216 (memory) 200416 (memory) 200016 07xx16
xxxx16
xx0016
8. Copies the contents of register R12 to the double-word at address 912016 r12 1234567816 stord (r12), 0x9120 xxxx16 (memory) r12 1234567816
912016
912016 912216
567816 123416
912216
xxxx16
STORM
STORMP
The STORM and STORMP instructions store adjacent registers to memory. count reflects the total number of words to be stored where count is in the range from 1 to 8. The instructions always operate on a fixed set of registers. For STORM: R1 contains the target address of the rst word in memory; R2 is stored into the lowest address word; R3 through R5 and then R8 through R11 are stored into the next count-1 consecutive addresses. R1 is adjusted (incremented) by 2 for each word stored, and therefore points to the next unwritten word in memory at the transfer-end. The address does not wrap around i.e. if R1 points to the end of the 64k addressable range STORM will overow to addresses 0x010000 and following. For STORMP: (R7,R6) contains the target address of the rst word in memory; R2 is stored into the lowest address word; R3 through R5 and then R8 through R11 are stored into the next count-1 consecutive addresses. (R7,R6) is adjusted (incremented) by 2 for each word stored, and therefore points to the next unwritten word in memory at the transfer-end. This instruction is not interruptible.
Flag Trap
None None
Example
Stores three registers into memory. r1 r2 r3 r4 001000 (memory) 001002 (memory) 001004 (memory) 100016 2F5016 107E16 35EC16 storm $3 XXXX16 001000 (memory) 001002 (memory) 001004 (memory) 2F5016 r1 r2 r3 r4 100616 2F5016 107E16 35EC16
XXXX16 XXXX16
107E16 35EC16
Subtract Integer
SUBB, SUBW, SUBD
SUBD
The SUBi and SUBD instructions subtract the src operand from the dest operand, and place the result in the dest operand.
Flag
During execution of an SUBi or SUBD instruction, PSR.C is set to 1 if a borrow occurs, and cleared to 0 if no borrow occurs. PSR.F is set to 1 if an overow occurs, and cleared to 0 if there is no overow. None 1. Subtracts the low-order byte of register R0 from the low-order byte of register R1, and places the result in the low-order byte of register R1. The remaining byte of register R1 is not affected. xx0116 (+110) xx7F16 (+12710) enzfltc subb r0, r1 r1 PSR xx0116 (+110) xx7E16 (+12610) enz0lt0
Trap Examples
r0
r0
r1 PSR
2. Subtracts the word in register R7 from the word in register R8, and places the result in register R8. FFFE16 (210) 100016 (+409610) enzfltc subw r7, r8 r8 PSR FFFE16 (210) 100216 (+409810) enz0lt0
r7
r7
r8 PSR
SUBCi
SUBCB, SUBCW
The SUBCi instruction subtracts the sum of the src operand and the PSR.C ag from the dest operand, and places the result in the dest operand.
Flag
PSR.C is set to 1 if a borrow occurs and cleared to 0 if there is no borrow. 0 PSR.F is set to 1 if an overow occurs and cleared to 0 if there is no overow. None Subtracts the sum of 32 and the PSR.C ag value from the low-order byte of register R1, and places the result in the low-order byte of register R1. The remaining byte of register R1 is not affected. xx5016 (+8010) enzflt1 xx2F16 (+4710) enz0lt0
Trap Example
r1 PSR
subcb $32, r1
r1 PSR
TBIT
Test Bit
TBIT, TBITB, TBITW
TBIT offset, reg.r/imm4 read.W offset, imm4 read.i src reg.r read.W src abs/rel.r/rel.rp/idx read.i
TBITi
The TBIT instruction copies the bit located in register or memory location src at the bit position specied by offset, to the PSR.F ag. The direct memory format of the instruction supports byte and word operations (TBITB, TBITW), while the register-sourced format supports only word operations. The offset value must be in the range of 0 through 15 for a word operand, and in the range of 0 through 7 for a byte operand. As there is no native support for testing a bit in a double-length core register with SR=0, an ANDD/CMPD instruction sequence should be used. See Table 5-4.
PSR.F is set to the value of the specied bit. None 1. Copies bit in position 3, in register R1 to the PSR.F ag. r1 PSR 0016 000010002 enzfltc tbit $3, r1 r1 PSR 0016 000010002 enz1ltc
2. Copies bit in position 3, in memory location 8 (R1) to the PSR.F ag. r1 200816
(memory)
r1 200816
(memory)
PSR
PSR
3. Copies bit in position 5, in memory location 0 (R8) to the PSR.F ag. r8 200816 r8 200816
200816
(memory)
0016
001000002 enzfltc
200816
(memory)
0016
001000002 enz1ltc
PSR
PSR
4. Copies bit in position 5, in memory location 3000216 to the PSR.F ag. 3000216
(memory)
0016
001000002 enzfltc
3000216
(memory)
0016
001000002 enz1ltc
PSR
PSR
The WAIT instruction suspends program execution until an interrupt occurs. An interrupt restores program execution by passing it to an interrupt service procedure. When the WAIT instruction is interrupted, the return address saved on the stack is the address of the instruction following the WAIT instruction.
XORi
XORD
The XORi instruction performs a bitwise logical exclusive OR operation on the src and dest operands, and places the result in the dest operand.
None None XORs the low-order bytes of registers R1 and R2, and places the result in the low-order byte of register R2. The remaining byte of R2 is unaffected. r1 r2 xx16 xx16 111100002 100101012 xorb r1, r2 r1 r2 xx16 xx16 111100002 011001012
Timing factors
Under optimal conditions, the CR16C performs one instruction per clock cycle. At 50 MHz, this translates to 50 MIPS (Million Instructions Per Second). However, under a typical workload, unavoidable delays are caused by the pipeline and memory. Each access to memory, when there are zero wait states, takes one clock cycle. This means that the data arrives one clock cycle after the address was issued. The access time for off-chip memory depends on the speed and conguration of the off-chip memory. During an instruction fetch when a load or a store instruction accesses external memory, additional clock cycles may be added depending on the conguration of the CPU, i.e., the existence and depth of a write buffer, and the speed and conguration of the off-chip memory.
A-1
To calculate the total program execution time in clock cycles, combine the following: 1. The number of clock cycles required to execute each instruction. 2. Delays in clock cycles, caused by contention for memory and stalled execution of instructions in the pipeline. 3. The number of clock cycles required to handle exceptional conditions, such as interrupts.
IF
IF[15:0]
16
IR[15:0]
EXT[31:0]
ID
Decoder
EX
DIR
DISP
A-2
The IF stage
The CR16C fetches the rst word of an instruction directly into the Instruction Register (IR) if the IR is idle. If it is not idle and a fetch is executed, the next instruction is stored in the next available Fetch register until the IR is free again. The consecutive words of a two- or three-word instruction are directly fetched into the upper or lower half of the 32-bit Extension register (EXT). Initiating the fetch cycle is controlled by the ID stage, such that at the end of the fetch cycle, the IR and, depending on the length of the instruction, EXT hold a valid instruction. The Instruction Decode (ID) stage uses two registers, IR and EXT to decode the current instruction. In combination, these registers hold the instructions opcode and the displacement, absolute address or immediate value. The ID stage is fully loaded with a complete instruction before decode begins. At the end of the decode stage the execution control registers are loaded. Instructions are executed in the Execution (EX) stage. The currently executing instruction is held in the Decoded Instruction Register (DIR) and the corresponding displacement or constant is held in the DISP register until execution ends. The operations performed during execution depend on the instruction. If it is an arithmetic or logic instruction: The Arithmetic/Logic Unit (ALU) or the shifter computes the result of the instruction. The result is written to the destination register. If it is a load instruction: The ALU computes the effective memory address. The memory operand is read. The memory operand is written to the destination register. If it is a store instruction: The ALU computes the effective memory address. The source operand is written to memory. If it is a branch or jump instruction: The ALU computes the target address. The target address is written to the PC register. Source operands are read in the ID stage and results are written only in the EX stage. The instruction latency, when there are no delays, is usually three clock cycles (from fetch until execution end).
The ID stage
The EX stage
A-3
Instruction completion
The instruction execution state machine signals End of Instruction (EOI) when it starts the last cycle of an instruction. For non-data-transfer related instructions, this indicates that the current instruction terminates after this cycle. Data transfer instruction completion may be delayed, if the data transfer is not completed, until the RDY signal is asserted for the last transferred data portion. At best, the CR16C pipeline proceeds to the next stage once every clock. The core fetches a new instruction, or continues to fetch the second word of a previously fetched instruction, whenever the IF stage is going to be empty the following cycle. The conditions for issuing a new fetch cycle can be one of the following: 1. The pipeline has been ushed (e.g., during a Branch instruction) and therefore all of its stages are empty. 2. The currently executing instruction ends during this cycle. 3. Either the Instruction Register (IR) is free and IF contains the rst word of an instruction, or the Extension Register (EXT) is free and IF contains the second word of an instruction. (e.g., when the fetch phase takes more than a clock due to bus latencies). In such cases, the core performs the following operations: It schedules the currently decoded instruction, if one exists, to be transferred to the EX stage. It schedules the transfer of the previously fetched instruction (rst or second word), residing in the IF register into the decode stage (ID or EX respectively). It schedules a new instruction fetch cycle that results in loading a new instruction word into the IF register. The following sections describe most of the delays that may occur during execution of a program, and which should be considered when evaluating a programs execution time.
Branch delays
Upon execution of a non-conditional branch or jump instruction, or a conditional branch instruction that is true, subsequent instructions in the sequence may already have entered the pipeline, i.e., been fetched and possibly decoded. These instructions are discarded, and clock cycles are added in which the target address for the branch instruction is fetched and decoded. These added clock cycles are called a branch delay. For example, even if no wait state is needed while the memory from which instructions are fetched is accessed, the overall delay for a branch is three clock cycles for a single word target instruction plus potential additional cycles if the target instruction is longer.
Data delays
A data delay occurs whenever the contents of a memory location are loaded into a register (using a load instruction) or when the contents of a register are stored in memory (using a store instruction). The length of the delay, i.e., the number of clock cycles that must be added, depends on the CPU, system congurations and the alignment of the data. A load instruction is executed in two cycles. In the rst cycle, the effective memory address is calculated and sent on the address bus. When memory is accessed without wait states, the data is returned on the data bus and stored in the appropriate register in the next cycle. A store instruction is executed in two cycles. In the rst cycle, the effective memory address is calculated and sent on the address bus. In the next cycle, the contents of the register are sent on the data bus. All data is aligned as required, without performance penalties. When a serializing instruction is executed, all instructions residing in the IF stage and in the ID stage are discarded. Instructions that follow are not fetched from memory until the execution is complete. This causes a delay while the instructions following the serializing instruction are fetched. See Section 4.3.2 on page 4-26 for more information on serializing instructions.
Load delays
Store delays
A-5
IF
IF[15:0]
16
IR[15:0]
EXT[31:0]
ID
Decoder
EX
DIR
DISP
Arithmetic instructions
Table A-1. Execution Times for Arithmetic Instructions Instruction ADDi, ADDCi, ADDUi, ANDi, ASHUi, CMPi, LSHi, MOVi, MOVX, MOVZ, ORi, Scond, SUBCi, SUBi, NOP, TBIT and XORi. ASHUD, LSHD,CMDD,ADDD MOVXW, MOVZW MOVD MULB MULW
CompactRISC CR16C Programmers Reference Manual
Table A-1. Execution Times for Arithmetic Instructions Instruction MULSB MULSW MULUW MACSW, MACUW MACQW Clock Cycles in EX Stage 2 4 4 6 7
A-7
Load or store instructions may be stalled in the EX stage for additional cycles while an instruction fetch is in process. This may occur when instructions that require wait states are fetched from memory, e.g., offchip memory. In this case, additional clock cycles may be added to the number shown in the table. depending on the speed at which memory can be accessed. When zero wait states are used, the number of additional cycles that are needed to execute each load or store instruction depends on operand alignment on the word boundary. Table A-2. Execution Times for Load/Store Instructions Clock Cycles in EX Stage (Zero Wait States) 2 3 2 4 3 5 2 2 2 3 3 4 Memory Alignment aligned non-aligned aligned non-aligned aligned non-aligned aligned non-aligned aligned non-aligned aligned non-aligned Bus Accesses in EX Stage (Zero Wait States) 1 1 1 2 2 3 1 1 1 2 2 3
Instruction LOADB LOADB LOADW LOADW LOADD LOADD STORB STORB STORW STORW STORD STORD
These instructions access the memory a multiple number of times, depending on the number of registers needing save or restore. Also, these instructions perform a pointer adjustment, which requires an extra clock in the store instructions. Each such access may be stalled in the EX stage for additional cycles while an instruction fetch is in process. This may occur when instructions that require wait states are fetched from memory, e.g., off-chip memory. In this case, additional clock cycles may be added to the number shown in the table, depending on the speed at which memory can be accessed.
A-8
When zero wait states are used, the number of additional cycles needed to execute the instructions depends on the operation length itself, and on operand alignment on the word boundary. Table A-3. Execution Times for PUSH, POP/POPRET, LOADM and STORM Instruction PUSH[N]/ STORM[N] PUSH[N}, RA Na Memory Clock Cycles in EX Bus Accesses Address / Stack Stage (Zero Wait States) in EX Stage Alignment N+1 N+2 N+1 N+3 N+2 2N+2 2N+3 N+2 2N+2 2N+3 +1b Aligned Not word aligned Aligned Not word aligned Aligned Not word aligned Aligned Not word aligned always N N+1 N N+2 N 1.5N 0.5(3N+1) N 1.5N 0.5(3N+1) -
LOADM[N] / POP[N]
2,4,6,8,10 1,3,5,7,9
Bit manipulation instructions perform a read-modify-write cycle on memory operands. As a result, the general timing for such an instruction is based on load timing, execution timing, and some store timing (somewhat shortened because of internal parallelism). Just as in load and store, the instructions may be stalled in the EX stage for additional cycles while an instruction fetch is in process. This may occur when instructions that require wait states are fetched from memory, e.g., offchip memory. In this case, additional clock cycles may be added to the number shown in the table, depending on the speed at which memory can be accessed. When zero wait states is used, the number of additional cycles that is needed to execute the instructions depends on the operation length itself, and on operand alignment on the word boundary.
A-9
Table A-4. Execution Times for Bit Manipulation Instructions Instruction SBITi/CBITi TBITi Clock Cycles in EX Stage (Zero Wait States) 4 3 Bus Accesses in EX Stage 2 1
Control instructions
Some of the control instructions listed in Table A-5 also cause a pipeline ush and serialized execution of the next instruction. This delays execution, because clock cycles must be added to fetch and decode the instructions that follow the serializing instructions. Table A-5. Execution Times for Control Instructions Instruction LPR SPR JUMP, BAL, JAL, BR Bcond Compare & Branch RETX WAIT, EIWAIT EI, DI Clock Cycles in EX Stage 2 1 1 1 2 5 1 1 Pipeline Flush Condition Always Never Always When condition is true When condition is true Always Always, by interrupt Never
The interrupt or trap latency of the CR16C for a given interrupt or trap, in clock cycles, is the sum of the following: The longest execution time for a load or store instruction, or the specic long CR16 instruction (SBIT/CBIT, TBITi, PUSH, POP, LOADM, STORM) The time in clock cycles shown in Table A-6 for the specic exception The time it takes to fetch the rst instruction in the interrupt handler Additional clock cycles required as a result of wait states on the bus, hold requests, disabled interrupts or interrupt nesting.
A-10
Table A-6. Execution Times for Interrupts and Traps Clock Cycles in EX Stage Interrupt or Trap CFG.ED=0 (16-bit dispatch table) 12 11 9 9 9 CFG.ED=1 (32-bit dispatch table) 13 12 10 10 10
For ISE, TRC, DBG and BPT, if AISE, ATRC, ADBG and ABPT bits in the CFG registers are set (respectively), then the execution time is that of ISE/NMI for Large Model the 32-bit dispatch table (12 cycles). See Section 4.1.5 on page 4-14 for more details.
A-11
B.1 INTRODUCTION
Instructions may have zero to four operands, and are encoded using one, two or three words. All instructions must be word-aligned. The most frequently used instructions are encoded into one word. These instructions have zero to three operands and use the basic formats, shown in Figure B-1. 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
op code op code op code op code operand 3 operand 2 operand 2 operand 1 operand 1 operand 1
Figure B-1. Basic Instruction Structure: First Word The operands are typically encoded in 4-bit elds, starting from the least signicant bit of the word. The opcode typically uses all available bits, starting from the most signicant bits of the word. Instructions using 16-bit displacements or 20-bit labels require an additional word in the instruction. In these cases, the second word typically contains bits 15 to 0 of the displacement or label, as shown in Figure B2 below.
15 14 13 12 11 10 9
B-1
Certain less frequently used operations using a 20/24-bit displacement/label or a 32-bit immediate use three-word encoding. In these cases, the rst word is used as an escape to indicate that the following two words contain the instruction. These two words then use the two-word instruction format with an opcode and operands in the rst word, and a displacement/label or immediate in the second word.
byte 3
p4_4 p3_4
byte 5
byte 4
p1_24( p1_24 p2_4 19:16) (23:20) p1_24( p1_24 p2_4 19:16) (23:20)
3a escape3a_24 4 5 6 7 8 9 10 11 12 13 14 15 16 17 param0 param0_24 param3 param3_20 param31_20 param34 param34_16 param4 param4_20 param41_20 param431 param44 param44_16 param44_14
p4_4
p1_24(15:1)
p1_24(15:1)
2 4
p1_20 p1_20
p3_16
p1_20 p1_20
opcode8
p2_4 p2_4
p3 p1_4 5:4
B-2
16
byte 0
p2_4 p1_4
byte 3
p2_4 p2_5
p1_4 p1_4
p4_16
op- p1_8( p1_8(4: p2_4 code4 8:5) 1) op- p1_8( p1_8(4: p2_4 code4 8:5) 1) opcode12 p1_4 p3_16(15:1) 1 6 p2_32
a. The rst word of the instruction is an escape code, and pt_4 is the expansion opcode.
B-3
Parameter
Value 1
Meaning RA used R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12_L R13_L RA_L SP_L R1,R0 R2,R1 R3,R2 R4,R3 R5,R4 R6,R5 R7,R6 R8,R7 R9,R8 R10,R9 R11,R10 R12_L,R11 R12 R13 RA SP R12 + R1,R0 R12 + R3,R2 R12 + R5,R4 R12 + R7,R6
Description
reg(4)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
register number
least signicant 16 bits of R12 least signicant 16 bits of R13 least signicant 16 bits of RA least signicant 16 bits of (U)SP (if PSR.U set: use USP_L else SP_L) register pair
rp(4)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
if CFG.SR set: use R13_L, R12_L if CFG.SR set: use RA_L, R13_L if CFG.SR set: use (U)SP_L, RA_L (if PSR.U set: use USP_L else SP_L) if CFG.SR set: use (U)SP_H, (U)SP_L ( if PSR.U set: use USP else SP ) reduced register pair
rrp(4)a
0 1 2 3
B-4
Parameter
Value 4 5 6 7 8 9 10 11 12 13 14 15
Meaning R12 + R9,R8 R12 + R11,R10 R12 + R4,R3 R12 + R6,R5 R13 + R1,R0 R13 + R3,R2 R13 + R5,R4 R13 + R7,R6 R13 + R9,R8 R13 + R11,R10 R13 + R4,R3 R13 + R6,R5 if CFG.SR set: prp is reg
Description
DCR reserved CAR0 reserved CAR1 reserved CFG PSR INTBASE reserved ISP reserved USP reserved DBS DSR DCRL DCRH CAR0L CAR0H CAR1L CAR1H CFG PSR processor registers for LPR/SPR
B-5
Parameter
Value 10 11 12 13 14 15
Description
vect
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 DBG ISE eq ne cs cc hi ls gt le fs fc lo hs lt ge always uc IAD SVC DVZ FLG BPT TRC UND
exception vector
cond(4)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
compare conditions
B-6
Parameter pos(3)
Value 0 1 2 3 4 5 6 7
Meaning bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 bit8 bit9 bit10 bit11 bit12 bit13 bit14 bit15 Opcode Extension data at address rp data at address rrp data at address reg jump to address of rp shifted once left
pos(4)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
bit position
for byte ops bit 0 for byte ops bit 1 for byte ops bit 2 for byte ops bit 3 for byte ops bit 4 for byte ops bit 5 for byte ops bit 6 for byte ops bit 7 used as an extension to an opcode for codes encoded in three words.
0-15
absolute address - used as explicit address pointer index register relative - the contents of an index register is added to the address 0-15 0-8,10, 12-15 9 11 For Store Immediate In arithmetic operations, when parameter type is source, used as immediate values interpreted as -1 used as escape code to 16 bit immediate format
B-7
Value
Meaning signedb immediate value unsigned immediate value signedb immediate value
Description
immediate value used as displacement- added to other source or destination parameters displacement value shifted once left - multiplied by 2 displacement value add 1 and shift once left for beq0/bne0 disp4 commands (+2 to +32) 0-13 14 15 treated as a positive displacement for store/load word/double-word operations shift once left escape used to denote a prp register mode operation with disp0 used as escape code to displacement 16 format disp of 8 bits is always signed and shifted by 1 (mult by 2) treated as escape to displacement16 format (format #22) for branches, disp of 8 bits or more is signed and shifted by 1 (mult by 2) for loads, stores and bitops, disp(n) is always unsigned and not shifted!
disp8
-disp20
-220
to -1
a. When CFG.SR =1, the index addressing mode is not supported. All instructions using "rrp" or "rs" cause undened behavior.
b. The assembler must allow unsigned values for logic operations such as AND, OR, XOR using this encoding.
An x in the opcode value denotes bit positions reserved for parameters, as determined by the format. Due to the structure of the opcode assignment, items such as the format type, byte/word command, arithmetic/logical operations, and eld placement are readily available from a limited decode.
CompactRISC CR16C Programmers Reference Manual INSTRUCTION SET ENCODING B-8
15 12 23
1 2 3
dest imm dest dest dest dest dest dest dest dest rp rp reg reg reg rp reg rp
15/16 1/2
15
15/16 1/2
15 15 15 15 15
1 1 1 1 1
15
15/16 1/2
15
15/16 1/2
15 12 23
15/16
15
15/16
15
15/16
15
15/16
15 1 1
B-9
Opcode (15:0) 0000 0000 0001 0100 0110 0100 xxxx xxxx 0110 0101 xxxx xxxx 0000 1011 xxxx xxxx 0110 0010 xxxx xxxx 0110 0011 xxxx xxxx 0110 0110 xxxx xxxx 0110 0111 xxxx xxxx 0011 1000 xxxx xxxx 0011 1001 xxxx xxxx 0011 1100 xxxx xxxx 0011 1101 xxxx xxxx 0011 1110 xxxx xxxx 0011 1111 xxxx xxxx 0000 0000 0001 0100 0000 0000 0011 xxxx 0011 1010 xxxx xxxx 0011 1011 xxxx xxxx
Instruction Name macsw mulb imm4/16,reg mulb reg,reg mulsb reg,reg mulsw reg,rp muluw reg,rp mulw imm4/16,reg mulw reg,reg subb imm4/16,reg subb reg,reg subcb imm4/16,reg subcb reg,reg subcw imm4/16,reg subcw reg,reg subd rp,rp subd imm32,rp subw imm4/16,reg subw reg,reg
p1 pt1 pm1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 src2 dest dest dest dest dest dest dest dest dest dest dest dest dest dest dest dest dest reg reg reg reg rp rp reg reg reg reg reg reg reg reg rp rp reg reg
p2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 32 4 4
pt2 pm2 p3 pt3 pm3 p4 pt4 pm4 src1 reg src src src src src src src src src src src src src src src src src imm reg reg reg reg imm reg imm reg imm reg imm reg rp imm imm reg 4 res 0 4 ope 12 4 dest rp 4 ope 15
fmt ln # 1
15/16
15 15 15 15
15/16
15
15/16
15
15/16
15
15/16
15 1 23
15/16
15
15 23
15/16
15
15/16
15
1/2
B-10
Opcode (15:0) 0010 0001 xxxx xxxx 0010 0010 xxxx xxxx 0010 0011 xxxx xxxx 0000 0000 0100 xxxx 0000 0000 0001 0100 0010 0100 xxxx xxxx 0010 0101 xxxx xxxx 0010 0110 xxxx xxxx 0010 0111 xxxx xxxx 0000 0000 0101 xxxx 0000 0000 0001 0100 0000 1000 xxxx xxxx 0010 1000 xxxx xxxx 0010 1001 xxxx xxxx 0010 1010 xxxx xxxx 0010 1011 xxxx xxxx 0000 0000 0110 xxxx 0000 0000 0001 0100
Instruction Name andb reg,reg andw imm4/16,reg andw reg,reg andd imm32,rp andd rp,rp orb imm4/16,reg orb reg,reg orw imm4/16,reg orw reg,reg ord imm32,rp ord rp,rp Scond (reg) xorb imm4/16,reg xorb reg,reg xorw imm4/16,reg xorw reg,reg xord imm32,rp xord rp,rp
p1 pt1 pm1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 dest dest dest dest dest dest dest dest dest dest dest dest dest dest dest dest dest dest reg reg reg rp rp reg reg reg reg rp rp reg reg reg reg reg rp rp
p2 4 4 4 32 4 4 4 4 4 32 4 4 4 4 4 4 32 4
pt2 pm2 p3 pt3 pm3 p4 pt4 pm4 src src src src src src src src src src src reg imm reg imm rp imm reg imm reg imm rp 4 ope 9 4 ope 11
fmt ln # 15
15/16
15
23
1
15/16
15
15/16
15
23
1 15
15/16
cond imm src src src src src src imm reg imm reg imm rp 4 ope 10
15
15/16
15
23
3 count imm 3 count imm 4 count reg 5 count imm 5 count imm 4 count reg 4 count imm 4 count imm 4 count reg 3 count imm 4 count reg 5 count imm 4 count reg
B-11
Opcode (15:0) 0100 1001 xxxx xxxx 0100 0110 xxxx xxxx
p2
fmt ln # 15 15 1 1
dest (rrp)
20 dest abs 20 dest abs 24 dest abs 4 4 4 4 4 4 dest (prp) dest (reg) dest dest dest (rp) (rp) (rp)
dest (rrp)
20 dest abs 20 dest abs 24 dest abs 4 4 4 4 4 4 dest (prp) dest (reg) dest dest dest (rp) (rp) (rp)
dest (rrp)
ope 10
20 dest abs 20 dest abs 24 dest abs 4 4 dest (prp) dest (reg)
B-12
Opcode (15:0) 0111 0110 xxxx xxxx 0111 0001 xxxx xxxx 0000 0000 0001 0001 0000 0000 0001 0001 0111 0111 xxxx xxxx 0111 010x xxxx xxxx 0000 0000 0001 0001 0000 0110 xxxx xxxx 0000 0111 xxxx xxxx 0111 1010 10xx xxxx 0000 0000 0001 0000 0111 1010 0xxx xxxx 0111 1011 0xxx xxxx 0000 0000 0001 0000 0000 0000 0001 0000 0111 1011 1xxx xxxx 0111 1000 xxxx xxxx 0000 0000 0001 0000 0111 1010 11xx xxxx 0000 0000 0001 0001 0111 1110 xxxx xxxx 0111 1001 xxxx xxxx 0000 0000 0001 0001 0000 0000 0001 0001 0111 1111 xxxx xxxx 0111 110x xxxx xxxx 0000 0000 0001 0001
Instruction Name sbitw (rp) disp0 sbitw (rp) disp16 sbitw (rp) disp20 sbitw (rrp) disp20 sbitw abs20 sbitw abs20 rel sbitw abs24 tbit cnt tbit reg, reg tbitb (prp) disp14 tbitb (reg) disp20 tbitb (rp) disp0 tbitb (rp) disp16 tbitb (rp) disp20 tbitb (rrp) disp20 tbitb abs20 tbitb abs20 rel tbitb abs24 tbitw (prp) disp14 tbitw (reg) disp20 tbitw (rp) disp0 tbitw (rp) disp16 tbitw (rp) disp20 tbitw (rrp) disp20 tbitw abs20 tbitw abs20 rel tbitw abs24
p2 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4
pt2 pm2 p3 pt3 pm3 p4 pt4 pm4 pos imm pos imm 16 dest disp pos imm 20 dest disp pos imm 20 dest disp pos imm pos imm pos imm pos imm pos reg 1 dest rs 4 ope 11 4 4 ope 9
fmt ln # 15 16 2 2 12 13 3 15 15 17 1 2 3 3 2 2 3 1 1 2 3 1 2 3 3 2 2 3 2 3 1 2 3 3 2 2 3
dest (rrp)
ope 10
20 dest abs 20 dest abs 24 dest abs 4 4 4 4 4 4 4 4 src src reg reg
dest (prp) dest (reg) dest dest dest (rp) (rp) (rp)
pos imm 14 dest disp pos imm 20 dest disp pos imm pos imm 16 dest disp pos imm 20 dest disp pos imm 20 dest disp pos imm pos imm pos imm pos imm 14 dest disp pos imm 20 dest disp pos imm pos imm 16 dest disp pos imm 20 dest disp pos imm 20 dest disp pos imm pos imm pos imm 1 dest rs 4 ope 15 4 4 ope 13 ope 14 4 ope 12 1 dest rs 4 ope 15 4 4 ope 13 ope 14 4 ope 12
2 9 10 2 2 7 8 3 17 2 15 16 2 2 12 13 3
dest (rrp)
20 dest abs 20 dest abs 24 dest abs 4 4 4 4 4 4 dest (prp) dest (reg) dest dest dest (rp) (rp) (rp)
dest (rrp)
B-13
dest disp*2+ dest disp*2+ dest disp*2+ dest disp*2+ cond cond cond imm imm imm
bne0w disp4 (2-32) 4 bra cond disp8 br cond disp16 bra cond disp24 excp jal (ra,rp) jal (rp,rp) Jcondb (rp) pop pop ret push retx
a
a. This includes BR (condition := always) b. This includes JUMP (condition := always) and JUSR (condition := UC)
20 src
B-14
Opcode (15:0) 1000 0110 10xx xxxx 0000 0000 0001 0010 0000 0000 0001 1000 1010 1111 xxxx xxxx 0000 0000 0001 0010 0000 0000 0001 1000 1010 xxxx xxxx xxxx 0000 0000 0001 0010 1000 0111 xxxx xxxx 1000 110x xxxx xxxx 0000 0000 0001 0010 0000 0000 1010 0xxx 0000 0000 1010 1xxx 1001 1110 xxxx xxxx 1000 0110 11xx xxxx 0000 0000 0001 0010 0000 0000 0001 1000 1001 1111 xxxx xxxx 0000 0000 0001 0010 0000 0000 0001 1000 1001 xxxx xxxx xxxx 0000 0000 0001 0010 1000 1001 xxxx xxxx 1000 111x xxxx xxxx 0000 0000 0001 0010 1111 1110 xxxx xxxx 1100 0110 01xx xxxx 0000 0000 0001 0011 0000 0000 0001 1001 1111 1111 xxxx xxxx 0000 0000 0001 0011 0000 0000 0001 1001 1111 xxxx xxxx xxxx 0000 0000 0001 0011 1100 1000 xxxx xxxx 1100 101x xxxx xxxx
Instruction Name loadd (prp) disp14 loadd (reg) disp20 loadd (reg) -disp20 loadd (rp) disp16 loadd (rp) disp20 loadd (rp) -disp20 loadd (rp) disp4 loadd (rrp) disp20 loadd abs20 loadd abs20 rel loadd abs24 loadm (reg) loadmp (rp) loadw (prp) disp0 loadw (prp) disp14 loadw (reg) disp20 loadw (reg) -disp20 loadw (rp) disp16 loadw (rp) disp20 loadw (rp) -disp20 loadw (rp) disp4 loadw (rrp) disp20 loadw abs20 loadw abs20 rel loadw abs24 storb (prp) disp0 storb (prp) disp14 storb (reg) disp20 storb (reg) -disp20 storb (rp) disp16 storb (rp) disp20 storb (rp) -disp20 storb (rp) disp4a
p1 4 4 4 4 4 4 4 4 20 20 24
pt1 src src src src src src src src src src src
pm1 p2 (prp) (reg) (reg) (rp) (rp) (rp) (rp) (rrp) abs abs abs 4 4 4 4 4 4 4 4 4 4 4
pt2 pm2 p3 pt3 pm3 p4 pt4 pm4 fmt# ln dest dest dest dest dest dest dest dest dest dest dest rp rp rp rp rp rp rp rp rp rp rp 1 src rs 4 ope 11 14 src 20 src 20 src 4 ope disp disp disp 0F disp disp 4 4 ope ope 8 8 17 2 2 2 3 3 2 3 3 1 3 2 2 3 1 1 1 2 3 3 2 3 3 1 3 2 2 3 1 2 3 3 2 2 2 1 2 2 2
20 src 20 src 4
20 src
3 count imm 3 count imm 4 4 4 4 4 4 4 4 4 20 20 24 4 4 4 4 4 4 4 4 4 src src src src src src src src src src src src (prp) (prp) (reg) (reg) (rp) (rp) (rp) (rp) (rrp) abs abs abs 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 dest reg dest reg dest reg dest reg dest reg dest reg dest reg dest reg dest reg dest reg dest reg dest reg src src src src src src src src src src src reg reg reg reg reg reg reg reg reg reg reg 1 dest rs 4 ope 0E 1 src rs 4 ope 15 4 ope 0E disp disp disp 0F disp disp 4 4 ope 12 ope 12
18 17 2 2
20 src 20 src 4
20 src
dest (prp) dest (prp) dest (reg) dest (reg) dest dest dest dest dest (rp) (rp) (rp) (rp) (rrp) abs abs
20 dest 20 dest
B-15
Opcode (15:0) 0000 0000 0001 0011 1000 0110 00xx xxxx 0000 0000 0001 0010 1000 0010 xxxx xxxx 1000 0011 xxxx xxxx 0000 0000 0001 0010 0000 0000 0001 0010 1000 0001 xxxx xxxx 1000 010x xxxx xxxx 0000 0000 0001 0010 1110 1110 xxxx xxxx 1100 0110 10xx xxxx 0000 0000 0001 0011 0000 0000 0001 1001 1110 1111 xxxx xxxx 0000 0000 0001 0011 0000 0000 0001 1001 1110 xxxx xxxx xxxx 0000 0000 0001 0011 1100 0111 xxxx xxxx 1100 110x xxxx xxxx 0000 0000 0001 0011 0000 0000 1011 0xxx 0000 0000 1011 1xxx 1101 1110 xxxx xxxx 1100 0110 11xx xxxx 0000 0000 0001 0011 0000 0000 0001 1001 1101 1111 xxxx xxxx 0000 0000 0001 0011 0000 0000 0001 1001 1101 xxxx xxxx xxxx 0000 0000 0001 0011 1100 1001 xxxx xxxx 1100 111x xxxx xxxx 0000 0000 0001 0011
Instruction Name storb abs24 storb imm (prp) disp14 storb imm (reg) disp20 storb imm (rp) disp0 storb imm (rp) disp16 storb imm (rp) disp20 storb imm (rrp) disp20 storb imm abs20 storb imm abs20 rel storb imm abs24 stord (prp) disp0 stord (prp) disp14 stord (reg) disp20 stord (reg) -disp20 stord (rp) disp16 stord (rp) disp20 stord (rp) -disp20 stord (rp) disp4 stord (rrp) disp20 stord abs20 stord abs20 rel stord abs24 storm (reg) stormp (rp) storw (prp) disp0 storw (prp) disp14 storw (reg) disp20 storw (reg) -disp20 storw (rp) disp16 storw (rp) disp20 storw (rp) -disp20 storw (rp) disp4 storw (rrp) disp20 storw abs20 storw abs20 rel storw abs24
p1
pt1
pm1 p2 abs 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
pt2 pm2 p3 pt3 pm3 p4 pt4 pm4 fmt# ln src reg 4 ope 7 3 17 4 ope 0 2 15 16 4 4 ope ope 1 2 2 2 12 1 dest rs 4 4 ope 0E ope 3 13 3 18 17 4 4 ope ope 8 8 2 2 3 2 3 1 2 3 3 2 2 3 1 2 3 3 2 3 3 1 3 2 2 3 1 1 1 2 3 3 2 3 3 1 3 2 2 3
24 dest 4 4 4 4 4 4
dest (prp) dest (reg) dest dest dest dest (rp) (rp) (rp) (rrp) abs abs abs
src imm 14 dest disp src imm 20 dest disp src imm src imm 16 dest disp src imm 20 dest disp src imm 20 dest disp src imm src imm src imm src src src src src src src src src src src src rp rp rp rp rp rp rp rp rp rp rp rp 1 dest rs 4 ope 11
dest (prp) dest (prp) dest (reg) dest (reg) dest dest dest dest dest (rp) (rp) (rp) (rp) (rrp) abs abs abs
3 count imm 3 count imm 4 4 4 4 4 4 4 4 4 dest (prp) dest (prp) dest (reg) dest (reg) dest dest dest dest dest (rp) (rp) (rp) (rp) (rrp) abs abs abs 4 4 4 4 4 4 4 4 4 4 4 4 src src src src src src src src src src src src reg reg reg reg reg reg reg reg reg reg reg reg 1 dest rs 4 ope 15 4 ope 0E
18 17 4 4 ope 12 ope 12 2 2
B-16
Opcode (15:0) 1100 0110 00xx xxxx 0000 0000 0001 0011 1100 0010 xxxx xxxx 1100 0011 xxxx xxxx 0000 0000 0001 0011 0000 0000 0001 0011 1100 0001 xxxx xxxx 1100 010x xxxx xxxx 0000 0000 0001 0011
Instruction Name
p1
pt1
pm1 p2 4 4 4 4 4 4 4 4 4
pt2 pm2 p3 pt3 pm3 p4 pt4 pm4 fmt# ln src imm 14 dest disp src imm 20 dest disp src imm src imm 16 dest disp src imm 20 dest disp src imm 20 dest disp src imm src imm src imm 1 dest rs 4 ope 3 4 4 ope ope 1 2 4 ope 0 17 2 15 16 2 2 12 13 3 2 3 1 2 3 3 2 2 3
storw imm (prp) disp14 4 storw imm (reg) disp20 4 storw imm (rp) disp0 storw imm (rp) disp16 storw imm (rp) disp20 storw imm (rrp) disp20 storw imm abs20 storw imm abs20 rel storw imm abs24 4 4 4 4
dest (prp) dest (reg) dest dest dest dest (rp) (rp) (rp) (rrp) abs abs abs
B-17
4 dest ci
ope 10 ope 11 ope 14 ope 15 ope ope ope ope ope ope 0 1 2 3 6 7
ope 10
B-18
Opcode (15:0) 0000 0000 0001 1001 0000 0000 0001 1001 0000 0000 0001 1001 0000 0000 0001 101x 0000 0000 0001 11xx 0000 0000 1000 xxxx 0000 0000 111x xxxx 0000 1001 0xxx xxxx 1000 0000 xxxx xxxx 1100 0000 xxxx xxxx 1111 1111 1111 1111
Instruction Name res - undened trap res - undened trap res - undened trap res - undened trap res - undened trap res - undened trap for coprocessor inst res - undened trap res - undened trap res - undened trap res - undened trap res - undened trap
p1 pt1 pm1
p2
fmt ln # 3 3 3 3 3
ci
imm
32 cinst imm
23
3 1 2
15 15
1 1 1
B-19
C-1
Example 1
For CFG.SR=1: bal (era,ra), get_next # call the subroutine "get_next" or jal (era,ra), (r8,r7) # call the subroutine whose address is stored in the pair R7, R8
C-2
Qualifying arguments
A qualifying argument may be one of the following types: Integer type, pointer type Aligned structure whose size is less than, or equal to, four bytes. 32-bit long integer types and pointers are considered two-word structures, in this context. The least signicant word of a multi-word structure is always stored rst.
The algorithm
The following algorithm determines how parameters are passed to a given routine: 1. The parameter list is scanned from left to right. 2. A qualifying argument is allocated to the next free register in ascending order, i.e., R2 is allocated before R3, etc. Multi-word structures use a register pair. The least signicant word is allocated to the rst register, and the most signicant word to the next consecutive register. 3. If a parameter cannot be passed in a register (either because it is not qualied, or because the registers have been entirely allocated to previous parameters), then this parameter is passed on the stack, least signicant byte rst.
For CFG.SR=1: movw $5, r0 jump (era,ra) # pass return value # return to caller
The only exception to this rule is a function that returns a structure. In this case, the calling function must store the address of a structure in R0. The called function then uses R0 as a pointer to store the resulting structure.
Address 0
Top of Stack
Stack Pointer (SP)
Stack Space
Bottom of Stack
C-4
A subroutine can allocate space on the stack by decrementing the value of the SP to adjust the top of stack. When this subroutine returns, it must restore the SP to its previous value, thereby releasing the temporary space that it had occupied on the stack during its lifetime.
Scratch Registers
Any of these registers can be freely modied by any subroutine without rst saving a backup of their previous value. The caller cannot assume that their value will remain the same after a subroutine has returned. If for any reason the caller needs to keep this value, the scratch register must be saved on the stack before calling the subroutine and restored after the subroutine has returned.
Safe Registers
Before using any of these registers, a subroutine must rst store its previous value on the stack. Upon returning to the caller the subroutine must restore this value. The caller can always assume that these registers will not be used by any subroutine that it has called. When CFG.SR = 1, the calling convention denes R0 through R6 as scratch registers. All other general-purpose registers, including ERA, RA and SP, are safe.
Exception
The interrupt/trap subroutine is an exception to the rule for using scratch registers. This kind of subroutine must always save and restore every scratch register that may be used during the interrupt trap. This is because there is no real caller. The interrupt, or trap, suspends another subroutine which is not aware of, or prepared for, this interception. To protect it, its scratch registers must be saved and restored so that the interrupt, or trap, is transparent.
C-5
D-1
General-Purpose Registers
15 R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13/ERA 0 RA SP 0
INTBASEH INTBASEL
Conguration Register
15 CFG 0
Debug Registers
20 15 DCR DSR CARL
CARH
General-Purpose Registers
15 R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 RA SP 0
Conguration Register
15 CFG 0 31
Debug Registers
31 DCRH CAR0H CAR1H 15 DBS DCRL DSR CAR0L CAR1L 0
D-2
In the CR16B, the three dedicated address registers, PC, ISP and INTABSE, are 21 bits wide. However, the ve most signicant bits of the ISP registers are always cleared. In the CR16C, these registers are all 24 bits. A short register bit allows use of the registers as in the CR16B; the extended version of R12, R13 and R14 is effectively disabled. In the Debug Control Register, there is also an option to use a separate Compare Address Register, either independently or as the second part of a range compare. In addition, support for a cache is included with instruction and data cache enable bits.
PSR
A user mode status bit has been added to indicate whether the processor is currently in user mode, or is using the user stack.
In response to user feedback, and to facilitate simple DSP algorithms, a basic set of Multiply and Accumulate instructions has been included in the instruction set: MACSW MACUW MACQW
Relative addressing
Addressing relative to a register pair has been expanded to allow any register pair as the base address, across the entire address range. Direct access using 20 and 24-bit labels is also provided across all data operations. Improved support for relocatable code and index addressing mode has been added. This allows the location of data to be determined at runtime. Code is written only with relative jumps and data may be located in two regions; for example, one for the RAM and one for ash. The following instructions have an expanded meaning: PUSH/POP/POPRET now operate on up to eight registers with a separate bit for determining if RA should be pushed/popped to/from the stack. This avoids two consecutive stack operations, which often occur. Load/Store Multiple now allows a count of up to eight registers, and permits a register pair to contain the source and destination. The former Load/Store Multiple instruction, which uses a single register pointer, is still supported but now with a count of eight. All restrictions have been removed from bit and Store Immediate operations regarding which registers can be used to store the address displacements. Additional addressing modes are provided.
Retired instructions
Since the CR16B small programming model is no longer supported directly, the following instructions are no longer necessary: bal (reg) disp17 jal (reg,reg) Jcond (reg) jump (reg) POPRET small model
The Bcond1i instruction is no longer implemented by the CR core. The Bcond1i assembly instruction is converted by the assembler to a cmp and bcond instruction.
Peripherals can be mapped into the last 64K of the address space. This allows RAM to start at address 0 and increase as much as necessary, without requiring holes in the memory decode logic. For coding ef-
D-4
ciency, access to this address space can be accomplished with the 20-bit absolute addressing mode as double-word commands by mapping the last 64K in the rst MB of memory to the last 64K of the 16M space.
For ISE, TRC, DBG and BPT, if AISE, ATRC, ADBG and ABPT bits in the CFG registers are set (respectively), then the execution time is that of ISE/NMI for Large Model the 32-bit dispatch table (12 cycles). See Section 4.1.5 on page 4-14 for more details.
D-5
INDEX
A
absolute addressing mode 2-16 acknowledge exception 3-6 ADDCi instructions 5-5 ADDi instructions 5-4 addition integer instructions, ADD[U]i 5-4 integer with carry instructions, ADDCi 5-5 with carry 2-5 address compare 4-19 registers, dedicated 2-3 address-compare match, write bit, DSR.BWR 4-19 addressing mode absolute 2-16 immediate 2-15 in instructions 5-1 register 2-15 relative 2-15 ADDUi instructions 5-4 ANDi instructions 5-6 arithmetic shift instructions, ASHUi 5-7 ASHUi instructions 5-7 unconditional, instruction, BR 5-14 BRD, compare address bit in DSR 4-19 breakpoint generation 4-1 trap, BPT 3-3, 3-12 BWR, write, address-compare match bit in DSR
4-19
C
C, carry bit in PSR 2-5 cache invalidation instruction, CINV 5-17 on-chip 2-6 CAR register 4-1 carry bit, PSR.C 2-5 CFG register 2-6 CINV instruction 4-21, 4-23 CINV instruction 5-17 clock cycle A-1 CLRBi instructions 5-15 CMP0BCondi instructions 5-13 CMPi instructions 5-17, 5-18 compare address bit in DSR BRD 4-19 compare-address PC match enable bits 4-18 comparison integer instructions, CMP0BCondi 5-13 integer instructions, CMPi 5-18 operations 2-5 cond, condition code 5-55 conditional instructions branch, Bcond 5-10 jump, Jcond 5-23 save, Scond 5-55 configuration register, see also CFG 2-6 convert sign integer to double-word, MOVXi 5-39 sign integer to word, MOVXB 5-39 unsigned integer to unsigned double-word, MOVZi 5-40 unsigned integer to unsigned word, MOVZB 5-40
B
BAL instruction 5-9 Bcond instructions 5-10 bits, reserved 2-2 bitwise logical AND instructions, ANDi 5-6 OR instructions, ORi 5-46 boolean data type 2-1 boolean, instructions to save condition as, Scond 5-55 borrow, see also carry 2-5 BPC, PC bit in DSR 4-19 BPC, PC match bit in DSR 4-19 BPT trap 3-3, 3-12 BR instruction 5-14 branch and link instruction, BAL 5-9 CompactRISC CR16C Programmers Reference Manual
INDEX 1
A-1
D
data length attribute specifier in instructions 5-1 organization 2-12 types 2-1 write accesses 4-23 data cache, DC bit, CFG.DC 2-6, 4-23 invalidation 4-23 lock bit, CFG.LDC 2-7 DBG trap and exception service procedures 3-9 DC, data cache bit in CFG 2-6, 4-23 invalidation 5-17 DCR register 4-1, 4-16 debug control register, DCR 4-16 features 4-1 dedicated address registers 2-3 delays during instruction execution A-1 DEN, address-compare and PC match enable bit in DCR 4-18 DI instruction 5-19 DISABLE instruction 2-6 dispatch table, IDT in SF architecture 3-1 see also IDT 3-1 division by zero trap, DVZ 3-3 DSR register 4-1 DVZ trap 3-3
acknowledge 3-6, 3-8 defined 3-1 handler 3-1 instruction, EXCP 5-22 priority 3-10 processing 3-4 processing table 3-8 processing, flowchart 3-11 return instruction, RETX 5-52 service procedure 3-9 EXCP instruction and serialized instructions 4-26 EXCP instruction 3-9, 5-22 executing-instructions operating state 4-24 execution program suspension instruction, EIWAIT 521 program suspension instruction, WAIT 5-68 timing for instructions A-1
F
F flag bit of PSR 2-5, 5-66 fetch instruction 4-20 stage in integer pipeline, IF flag bit, PSR.F 2-5, 5-66 FLG trap 3-3
2-4
G
general purpose registers
2-3
H
handler exception
3-1
E
E, local maskable interrupt enable bit in PSR EI instruction 5-20 EIWAIT instruction 5-21 ENABLE instruction 2-6 encoding, instruction set B-1 exception
2-6
I
I, maskable interrupt enable bit of PSR IC, instruction cache bit in CFG 2-7, 4-21
2-6
INDEX 2
invalidation 5-17 ICU, interrupt control unit 4-25 ID, stage in integer pipeline A-1 IDT, interrupt dispatch table 3-1, 4-25 IF stage in integer pipeline 2-4 immediate addressing mode 2-15 instruction decoding, stage in integer pipeline, ID A-1 dependency 4-26 endings 3-4 execution order 4-1, 4-24 execution timing A-1 fetch 4-20 format 5-1 latency, defined A-1 parallel execution 4-25 pipeline execution 4-25 serial execution 4-26 set, encoding B-1 suspended, completion 3-9 throughput, defined A-1 tracing 4-1 instruction cache, IC bit, CFG.IC 2-7, 4-21 invalidation 4-21 lock bit, CFG.LIC 2-7 In-System Emulator interrupt, see ISE interrupt INTBASE register 2-4 integer addition instructions, ADD[U]i 5-4 addition with carry instructions, ADDCi 5-5 arithmetic shift instructions, ASHUi 5-7 comparison instructions, CMP0BCondi 5-13 comparison instructions, CMPi 5-18 convert to unsigned 5-40 data type 2-1 load instructions, CLRBi 5-15 load instructions, LOADi 5-27 load instructions, SETBi 5-53 logical shift integer instructions, LSHi 5-33 move instructions, MOVi 5-38 multiplication instructions, MULi 5-35, 5-36, 5-37, 5-41 multiplication instructions, SMULB 5-42 multiplication instructions, SMULW 5-43 multiplication instructions, UMULW 5-44 pipeline organization A-2 sizes 2-1 store instructions, STORi 5-59 subtract with carry instructions, SUBCi 5-65 subtraction instruction, SUBi 5-64 internal register 2-2 interrupt CompactRISC CR16C Programmers Reference Manual
defined 3-1 dispatch table, IDT 3-1 maskable 2-6 maskable, DI instruction 5-19 maskable, EI instruction 5-20 non-maskable 2-6, 3-2 priority 3-10 stack pointer, see also ISP register 2-4 stack, and RETX instruction 5-52 stack, description 2-14 stack, during exception 3-2, 3-9 vector, see also, dispatch table, INTBASE
22
5-
wait for interrupt instruction, EIWAIT 5-21 wait for interrupt instruction, WAIT 5-68 invalidation data cache 4-23 instruction cache 4-21 of caches, CINV 5-17 ISE interrupt 3-2 ISE support 4-1 ISP register 2-4
J
JAL instruction 5-25 Jcond instructions 5-23 jump conditional, instructions, Jcond 5-23 jump and link instruction, JUMP 5-25, 5-26 JUMP instruction 5-26
L
L, low flag of PSR 2-5 latency, instruction A-1 LDC, lock data cache line bit in CFG 2-7 LIC, lock instruction cache line bit in CFG 2-7 link after branch instruction, BAL 5-9 load integer instructions, CLRBi 5-15 integer instructions, LOADi 5-27 integer instructions, SETBi 5-53 processor register instruction, LPR 5-31, 557 LOADi instructions 5-27 lock data cache line bit, CFG.LDC 2-7 instruction cache line bit, CFG.LIC 2-7 INDEX 3
logical AND instructions, ANDi 5-6 exclusive OR instructions, XORi 5-69 OR instructions, ORi 5-46 shift integer instructions, LSHi 5-33 low flag, PSR.L 2-5 LPR instruction and PSR.P bit 4-2 and serialized instructions 4-26 LPR instruction accessing DCR, DSR 4-3 description 5-31, 5-57 LRU, least recently used DC line replacement 4-21, 4-23 LSHi instructions 5-33
negative bit, PSR.N 2-5, 2-7 no operation instruction, NOP 5-45 non-maskable interrupt 3-2 NOP instruction 5-45
O
on-chip caches, control by CFG register 2-6 operand access class and length in instructions in instructions 5-1 OR logical exclusive, instructions, XORi 5-69 ORi instructions 5-46
5-1
M
maskable interrupt enable bit, PSR.E 2-6 maskable interrupt 3-2 maskable interrupt disable instruction, DI 5-19 maskable interrupt enable bit, PSR.I 2-6 maskable interrupt enable instruction, EI 5-20 memory organization 2-12 references using LOAD and STORE 2-14 model, programming 2-1 move integer instructions, MOVi 5-38 with sign extension instruction, MOVXB 5-39 with sign extension instruction, MOVXi 5-39 MOVi instructions 5-38 MOVXB instruction 5-39 MOVXi instruction 5-39 MOVZB instruction 5-40 MOVZi instructions 5-40 MULi instructions 5-35, 5-36, 5-37, 5-41 multiplication integer instructions, MULi 5-35, 5-36, 5-37, 5-41 integer instructions, SMULB 5-42 integer instructions, SMULW 5-43 integer instructions, UMULW 5-44
P
P, trace trap pending bit in PSR 2-6, 4-1 parallel processing in pipeline 4-25 PC match and compare-address enable bits 4-18 PC match bit, DSR.BPC 4-19 PC register bit, DSR.BPC 4-19 match 4-1 match enable bits in DCR 4-18 pipeline organization, integer A-2 pipelined instruction execution 4-25 priority, exception 3-10 processing-an-exception operating state 4-24 processor registers and load instruction, LPR 5-31, 557 status register, see also PSR 2-4, 3-2 program execution time A-1 modes 2-1 stack 2-14 PSR register and CMPi instructions 5-17, 5-18 and DI instruction 5-19 and exceptions 3-2 description 2-4
N
N, negative bit in PSR
2-5, 2-7
INDEX 4
R
R0, R1 registers 2-4 references to memory 2-14 register addressing mode 2-15 configuration, see also CFG 2-6 dedicated address 2-3 general purpose 2-3 internal 2-2 relative addressing mode 2-15 reserved bits 2-2 reset 3-13, 4-24 resume execution after EIWAIT 5-21 resume execution after WAIT 5-68 return from exception instruction, RETX 5-52 RETX instruction after exceptions 3-2 and serialized instructions 4-26 tracing 4-2 RETX instruction description 5-52 in exception service procedure 3-9 RST signal 3-13
integer instructions, STORii 5-59 STORi instructions 5-59 SUBCi instructions 5-65 SUBi instructions 5-64 subtraction integer instruction, SUBi 5-64 with carry 2-5 supervisor call trap, SVC 3-3 suspend execution instruction, EIWAIT 5-21 suspend execution instruction, WAIT 5-68 SVC trap 3-3
T
T, trace bit in PSR 2-5, 4-1 TBIT instruction 2-13, 2-14, 5-66 test bit instruction, TBIT 5-66 throughput, instruction defined A-1 timing instruction execution A-1 trace bit, PSR.T 2-5, 4-1 trap pending bit, PSR.P 2-6, 4-1 trap TRC, description 3-4 trap, TRC 4-2 tracing instructions 4-1 program 2-5 trap defined 3-1 list and descriptiohns 3-3 table with vecor for each type 5-22 trace, TRC 2-6 TRC trap description 3-4 in exception service procedure 3-9 in instruction tracing 4-2 pending bit, PSR.P 2-6
S
save, on condition instructions, Scond 5-55 Scond instructions 5-55 SETBi instructions 5-53 shift arithmetic, instructions, ASHUi 5-7 logical, integer instructions, LSHi 5-33 sign extension plus move instruction, MOVXB 539 sign extension plus move instruction, MOVXi 539 signed integer data type 2-1 SMULB instructions 5-42 SMULW instructions 5-43 SP general purpose register 2-3 SPR instruction accessing DCR, DSR 4-3 stack interrupt and program 2-14 interrupt, during exception 3-2, 3-9 interrupt, in RETX instruction 5-52 store CompactRISC CR16C Programmers Reference Manual
U
UMULW instructions 5-44 unconditional branch instruction, BR 5-14 UND trap 3-3 definition 3-9 undefined instruction trap, UND 3-3 INDEX 5
2-1
V
vector interrupt table
5-22
W
WAIT instruction 4-25, 5-68 waiting-for-an-interrupt operating state
4-24
X
XORi instructions
5-69
Z
Z, zero bit in PSR zero bit, PSR.Z 2-5
2-5
INDEX 6