To provide the most up-to-date information, the revision of our documents on the World Wide Web will be
the most current. Your printed copy may be an earlier revision. To verify you have the latest information
available, refer to:
http://www.freescale.com
The following revision history table summarizes changes contained in this document.
Revision History
Revision
Number
3.0April, 2002Incorporated information covering HCS12 Family of 16-bit MCUs throughout the book.
4.0March, 2006Reformatted to Freescale publication standards.
This manual describes the features and operation of the core (central
processing unit, or CPU, and development support functions) used in all
HCS12 microcontrollers. For reference, information is provided for the
M68HC12.
1.2 Features
The CPU12 is a high-speed, 16-bit processing unit that has a programming
model identical tothat of theindustry standard M68HC11central processor
unit (CPU). The CPU12 instruction set is a proper superset of the M68HC11
instruction set, and M68HC11 source code is accepted by CPU12
assemblers with no changes.
Section 1. Introduction
•Full 16-bit data paths supports efficient arithmetic operation and
high-speed math execution
•Supports instructions with odd byte counts, including many
single-byte instructions. This allows much more efficient use of ROM
space.
•An instruction queue buffers program information so the CPU has
immediate access to at least three bytes of machine code at the start
of every instruction.
•Extensive set of indexed addressing capabilities, including:
–Using the stack pointer as an indexing register in all indexed
operations
–Using the program counter as an indexing register in all but auto
increment/decrement mode
–Accumulator offsets using A, B, or D accumulators
–Automatic index predecrement, preincrement, postdecrement,
and postincrement (by –8 to +8)
S12CPUV2 Reference Manual, Rev. 4.0
Freescale Semiconductor15
1.3 Symbols and Notation
The symbols and notation shown here are used throughout the manual.
More specialized notation that applies only to the instruction glossary or
instruction set summary are described at the beginning of those sections.
1.3.1 Abbreviations for System Resources
A— Accumulator A
B— Accumulator B
D— Double accumulator D (A : B)
X— Index register X
Y— Index register Y
SP— Stack pointer
PC— Program counter
CCR — Condition code register
S — STOP instruction control bit
X — Non-maskable interrupt control bit
H — Half-carry status bit
I — Maskable interrupt control bit
N — Negative status bit
Z — Zero status bit
V — Two’s complement overflow status bit
C — Carry/Borrow status bit
S12CPUV2 Reference Manual, Rev. 4.0
16Freescale Semiconductor
1.3.2 Memory and Addressing
M— 8-bit memory location pointed to by the effective
M : M+1— 16-bit memory location. Consists of the contents of the
M~M+3
M
(Y)~M(Y+3)
M
(X)
M
(SP)
M
(Y+3)
PPAGE— Program overlay page (bank) number for extended
Page— Program overlay page
X
H
X
L
( )— Content of register or memory location
$— Hexadecimal value
%— Binary value
address of the instruction
location pointed to by the effective address
concatenated with the contents of the location at the
nexthighermemoryaddress. The most significant byte
is at location M.
— 32-bit memory location. Consists of the contents of the
effective address of the instruction concatenated with
thecontentsofthenextthreehighermemorylocations.
The most significant byte is at location M or M
(Y)
.
— Memory locations pointed to by index register X
— Memory locations pointed to by the stack pointer
— Memory locations pointed to by index register Y plus 3
memory (>64 Kbytes).
— High-order byte
— Low-order byte
S12CPUV2 Reference Manual, Rev. 4.0
Freescale Semiconductor17
1.3.3 Operators
+
–
•
+
⊕
×
÷
M
⇒
⇔
—
Addition
—
Subtraction
—
Logical AND
—
Logical OR (inclusive)
—
Logical exclusive OR
—
Multiplication
—
Division
—
Negation. One’s complement (invert each bit of M)
—
:
Concatenate
Example: A : B means the 16-bit valueformedbyconcatenating 8-bit accumulator A with 8-bit accumulator B.
A is in the high-order position.
—
Transfer
Example: (A) ⇒ M means the content of accumulator A is
transferred to memory location M.
—
Exchange
Example: D ⇔ X means exchange the contents of D with
those of X.
S12CPUV2 Reference Manual, Rev. 4.0
18Freescale Semiconductor
1.3.4 Definitions
Logic level 1 is the voltage that corresponds to the true (1) state.
Logic level 0 is the voltage that corresponds to the false (0) state.
Set refers specifically to establishing logic level 1 on a bit or bits.
Cleared refers specifically to establishing logic level 0 on a bit or bits.
Asserted means that a signal is in active logic state. An active low signal
changes from logic level 1 to logic level 0 when asserted, and an active
high signal changes from logic level 0 to logic level 1.
Negated means that an asserted signal changes logic state. An active low
signal changes from logic level 0 to logic level 1 when negated, and an
active high signal changes from logic level 1 to logic level 0.
ADDR is the mnemonic for address bus.
DATA is the mnemonic for data bus.
LSB means least significant bit or bits.
MSB means most significant bit or bits.
LSW means least significant word or words.
MSW means most significant word or words.
A specific bit location within a range is referred to by mnemonic and
number. For example, A7 is bit 7 of accumulator A.
A range of bit locations is referred to by mnemonic and the numbers that
definetherange. For example,DATA[15:8]formthehigh byte ofthedata
bus.
S12CPUV2 Reference Manual, Rev. 4.0
Freescale Semiconductor19
S12CPUV2 Reference Manual, Rev. 4.0
20Freescale Semiconductor
Reference Manual — S12CPUV2
2.1 Introduction
This section describes the CPU12 programming model, register set, the
data types used, and basic memory organization.
2.2 Programming Model
The CPU12 programming model, shown in Figure 2-1, is the same as that
of the M68HC11 CPU. The CPU has two 8-bit general-purpose
accumulators (A and B) that can be concatenated into a single 16-bit
accumulator (D) for certain instructions. It also has:
•Two index registers (X and Y)
Section 2. Overview
•16-bit stack pointer (SP)
•16-bit program counter (PC)
•8-bit condition code register (CCR)
7
15
15
15
15
15
AB
70
D
IX
IY
SP
PC
NSXH IZVC
Figure 2-1. Programming Model
0
8-BIT ACCUMULATORS A AND B
OR
0
16-BIT DOUBLE ACCUMULATOR D
0
INDEX REGISTER X
0
INDEX REGISTER Y
0
STACK POINTER
0
PROGRAM COUNTER
CONDITION CODE REGISTER
S12CPUV2 Reference Manual, Rev. 4.0
Freescale Semiconductor21
2.2.1 Accumulators
General-purpose8-bitaccumulatorsAandBare used to hold operands and
results of operations. Some instructions treat the combination of these two
8-bit accumulators (A : B) as a 16-bit double accumulator (D).
Most operations can use accumulator A or B interchangeably. However,
there are a few exceptions. Add, subtract, and compare instructions
involving both A and B (ABA, SBA, and CBA) only operate in one direction,
so it is important to make certain the correct operand is in the correct
accumulator. The decimal adjust accumulator A (DAA) instruction is used
after binary-coded decimal (BCD) arithmetic operations. There is no
equivalent instruction to adjust accumulator B.
2.2.2 Index Registers
16-bit index registers X and Y are used for indexed addressing. In the
indexed addressing modes, the contents of an index register are added to
5-bit, 9-bit, or 16-bit constants or to the content of an accumulator to form
the effective address of the instruction operand. The second index register
is especially useful for moves and in cases where operands from two
separate tables are used in a calculation.
2.2.3 Stack Pointer
TheCPU12supportsan automatic program stack.Thestackisused to save
system context during subroutine calls and interrupts and can also be used
for temporary data storage. The stack can be located anywhere in the
standard 64-Kbyte address space and can grow to any size up to the total
amount of memory available in the system.
The stack pointer (SP) holds the 16-bit address of the last stack location
used. Normally, the SP is initialized by one of the first instructions in an
application program. The stack grows downward from the address pointed
to by the SP. Each time a byte is pushed onto the stack, the stack pointer is
automatically decremented, and each time a byte is pulled from the stack,
the stack pointer is automatically incremented.
When a subroutine is called, the address of the instruction following the
calling instruction is automatically calculated and pushed onto the stack.
Normally, a return-from-subroutine (RTS) or a return-from-call (RTC)
instruction is executed at the end of a subroutine. The return instruction
S12CPUV2 Reference Manual, Rev. 4.0
22Freescale Semiconductor
loads the program counter with the previously stacked return address and
execution continues at that address.
When an interrupt occurs, the current instruction finishes execution. The
address of the next instruction is calculated and pushed onto the stack, all
the CPU registers are pushed onto the stack,theprogramcounter is loaded
with the address pointed to by the interrupt vector, and execution continues
at that address. The stacked registers are referred to as an interrupt stack
frame. The CPU12 stack frame is the same as that of the M68HC11.
NOTE:These instructions can be interrupted, and they resume execution once the
interrupt has been serviced:
2.2.4 Program Counter
The program counter (PC) is a 16-bit register that holds the address of the
nextinstructiontobeexecuted.Itisautomaticallyincrementedeachtimean
instruction is fetched.
• REV (fuzzy logic rule evaluation)
• REVW (fuzzy logic rule evaluation (weighted))
• WAV (weighted average)
2.2.5 Condition Code Register
The condition code register (CCR), named for its five status indicators,
contains:
•Five status indicators
•Two interrupt masking bits
•STOP instruction control bit
S12CPUV2 Reference Manual, Rev. 4.0
Freescale Semiconductor23
The status bits reflect the results of CPU operation as it executes
instructions. The five flags are:
•Half carry (H)
•Negative (N)
•Zero (Z)
•Overflow (V)
•Carry/borrow (C)
The half-carry flag is used only for BCD arithmetic operations. The N, Z, V,
and C status bits allow for branching based on the results of a previous
operation.
In some architectures, only a few instructions affectconditioncodes,so that
multiple instructions must be executed in order to load and test a variable.
Since most CPU12 instructions automatically update condition codes, it is
rarely necessary to execute an extra instruction for this purpose. The
challenge in using the CPU12lies in finding instructions thatdo not alter the
condition codes. The most important of these instructions arepushes,pulls,
transfers, and exchanges.
2.2.5.1 S Control Bit
It is always a good idea to refer to an instruction set summary (see
Appendix A. Instruction Reference) to check which condition codes are
affected by a particular instruction.
The following paragraphs describe normal uses of the condition codes.
There are other, more specialized uses. For instance, the C status bit is
usedto enable weighted fuzzy logic rule evaluation. Specialized usages are
described in the relevant portions of this manual and in Section 6.
Instruction Glossary.
Clearing the S bit enables the STOP instruction. Execution of a STOP
instruction normally causes the on-chip oscillator to stop. This may be
undesirableinsomeapplications.Ifthe CPU encounters a STOP instruction
while the S bit is set, it is treated like a no-operation (NOP) instruction and
continues to the next instruction. Reset sets the S bit.
S12CPUV2 Reference Manual, Rev. 4.0
24Freescale Semiconductor
2.2.5.2 X Mask Bit
XIRQ input is an updated version of the NMI input found on earlier
The
generations of MCUs. Non-maskable interrupts are typically used to deal
with major system failures, such as loss of power. However, enabling
non-maskableinterruptsbeforeasystemisfullypoweredandinitializedcan
lead to spurious interrupts. The X bit provides a mechanism for enabling
non-maskable interrupts after a system is stable.
By default, the Xbit is set to 1 during reset. As longas the X bitremains set,
interrupt service requests made via the
XIRQ pin are not recognized. An
instruction must clear the X bit to enable non-maskable interrupt service
requests made via the
XIRQ pin. Once the X bit has been cleared to 0,
software cannot reset it to 1 by writing to the CCR. The X bit is not affected
by maskable interrupts.
2.2.5.3 H Status Bit
When an
XIRQ interrupt occurs after non-maskable interrupts are enabled,
both the X bit and the I bit are set automatically to prevent other interrupts
from being recognized during the interrupt service routine. The mask bits
are set after the registers are stacked, but before the interrupt vector is
fetched.
Normally, a return-from-interrupt (RTI) instruction at the end of the interrupt
service routine restores register values that were present before the
interrupt occurred. Since the CCR is stacked before the X bit is set, the RTI
normally clears the X bit, and thus re-enables non-maskable interrupts.
While it is possible to manipulate thestackedvalue of X so that X issetafter
an RTI, there is no software method to reset X (and disable
XIRQ) once X
has been cleared.
The H bit indicates a carry from accumulator A bit 3 during an addition
operation. The DAA instruction uses the value of the H bit to adjust a result
in accumulator A to correct BCD format. H is updated only by the add
accumulator A to accumulator B (ABA), add without carry (ADD), and add
with carry (ADC) instructions.
2.2.5.4 I Mask Bit
The I bit enables and disables maskable interrupt sources. By default, the I
bit is set to 1 during reset. An instruction must clear the I bit to enable
maskable interrupts. While the I bit is set, maskable interrupts can become
S12CPUV2 Reference Manual, Rev. 4.0
Freescale Semiconductor25
2.2.5.5 N Status Bit
pending and are remembered, but operation continues uninterrupted until
the I bit is cleared.
When an interrupt occurs after interrupts are enabled, the I bit is
automatically set to prevent other maskable interrupts during the interrupt
service routine. The I bitis set after the registersare stacked, but before the
first instruction in the interrupt service routine is executed.
Normally, an RTI instruction at the end of the interrupt service routine
restores register values that were present before the interrupt occurred.
Since the CCR is stacked before the I bit is set, the RTI normally clears the
Ibit,andthusre-enables interrupts. Interrupts can bere-enabledbyclearing
the I bit within the service routine.
TheNbitshowsthestateof the MSB of the result. N ismostcommonlyused
in two’s complement arithmetic, where the MSB of a negative number is 1
and the MSB of a positive number is 0, but it has other uses. For instance,
if the MSB ofa register or memory location is used as a status flag, the user
can test status by loading an accumulator.
2.2.5.6 Z Status Bit
2.2.5.7 V Status Bit
2.2.5.8 C Status Bit
The Z bit is set when all the bits of the result are 0s. Compare instructions
perform an internal implied subtraction, and the condition codes, including
Z, reflect the results of that subtraction. The increment index register X
(INX), decrement index register X (DEX), increment index register Y (INY),
and decrement index register Y (DEY) instructions affect the Z bit and no
other condition flags. These operations can only determine = (equal) and ≠
(not equal).
The V bit is set when two’s complement overflow occurs as a result of an
operation.
The C bit is set when a carry occurs during addition or a borrow occurs
duringsubtraction. The C bit also acts as an error flag for multiply and divide
S12CPUV2 Reference Manual, Rev. 4.0
26Freescale Semiconductor
2.3 Data Types
operations.Shiftandrotate instructions operatethroughtheCbit to facilitate
multiple-word shifts.
The CPU12 uses these types of data:
•Bits
•5-bit signed integers
•8-bit signed and unsigned integers
•8-bit, 2-digit binary-coded decimal numbers
•9-bit signed integers
•16-bit signed and unsigned integers
•16-bit effective addresses
•32-bit signed and unsigned integers
Negative integers are represented in two’s complement form.
Five-bit and 9-bit signed integers are used only as offsets for indexed
addressing modes.
Sixteen-bit effective addresses are formed during addressing mode
computations.
Thirty-two-bit integer dividends are used by extended division instructions.
Extended multiply and extended multiply-and-accumulate instructions
produce 32-bit products.
2.4 Memory Organization
ThestandardCPU12addressspaceis64Kbytes.SomeM68HC12devices
support a paged memory expansion scheme that increases the standard
space by means of predefined windows in address space. The CPU12 has
special instructions that support use of expanded memory.
Eight-bit values can be stored at any odd or even byte address in available
memory.
S12CPUV2 Reference Manual, Rev. 4.0
Freescale Semiconductor27
Sixteen-bit values are stored in memory as two consecutive bytes; the high
byte occupies the lowest address, but need not be aligned to an even
boundary.
Thirty-two-bit values are stored in memory as four consecutive bytes; the
high byte occupies the lowest address, but need not be aligned to an even
boundary.
All input/output (I/O) and all on-chip peripherals are memory-mapped. No
special instruction syntax is required to access these addresses. On-chip
registers and memory typically are grouped in blocks which can be
relocated within the standard 64-Kbyte address space. Refer to device
documentation for specific information.
2.5 Instruction Queue
The CPU12 uses an instruction queue to buffer program information. The
mechanism is called a queue rather than a pipeline because a typical
pipelined CPU executes more than one instruction at the same time, while
the CPU12 always finishes executing an instruction before beginning to
execute another. Refer to Section 4. Instruction Queue for more
information.
S12CPUV2 Reference Manual, Rev. 4.0
28Freescale Semiconductor
Reference Manual — S12CPUV2
3.1 Introduction
Addressing modes determine how the central processor unit (CPU)
accesses memory locations to be operated upon. This section discusses
the various modes and how they are used.
3.2 Mode Summary
Addressing modes are an implicit part of CPU12 instructions. Refer to
Appendix A. Instruction Reference for the modes used by each
instruction. All CPU12 addressing modes are shown in Table 3-1.
The CPU12 uses all M68HC11 modes as well as new forms of indexed
addressing. Differences between M68HC11and M68HC12 indexed modes
are described in 3.9 Indexed Addressing Modes. Instructions that use
more than one mode are discussed in 3.10 Instructions Using Multiple
Modes.
Section 3. Addressing Modes
3.3 Effective Address
Each addressing mode except inherent mode generates a 16-bit effective
address which is used during the memory reference portion of the
instruction. Effective address computations do not require extra execution
cycles.