Motorola reserves the right to make changes without further notice to any products
herein. Motorola makes no warranty, representation or guarantee regarding the
suitability of its products for any particular purpose, nor do es Motorola assume any
liability arisin g out of the app lication or u se of any pr oduct or ci rcuit, a nd sp ecifica lly
disclaims any and all liability, including without limitation consequ ential or incidental
damages. "Typical" parameters which may be provided in Motorola data sheets and/or
specifications can and do vary in different applications and actual performance may
vary over time. All operating parameters, including "Typicals" must be validated for
each customer application by customer’s technical experts. Motorola does not convey
any license under its patent rights nor the rights of others. Motorola products are not
designed, intended, or authorized for use as components in systems intended for
surgical implant into the body, or other applications intended to support or sustain life,
or for any other application in which the failure of the Motorola product could create a
situation where personal injury or death may occur. Should Buyer purchase or use
Motorola products for any such unintended or unauthorized application, Buyer shall
indemnify and hold Motorola and its officers, employees, subsidiaries, af filiates, and
distributors harmless against all claims, costs, damages, and expenses, and
reasonable attorney fees a rising out of, directly or indirectly, any claim of personal
injury or death associated with such unintended or unauthorized use, even if such claim
alleges that Motorola was negligent regarding t he design or manufacture of the part.
Motorola, Inc. is an Equal Opportunity/Affirmative Action Employer.
The CPU08 is the central processor unit (CPU) of the Motorola
M68HC08 Family of microcontroller units (MCU). The fully object code
compatible CPU08 offers M68HC05 users increased performance with
no loss of time or software investment in their M68HC05-based
applications. The CPU08 also appeals to users of other MCU
architectures who need the CPU08 combination of speed, low power,
processing capabilities, and cost effectiveness.
CPU08 — Rev. 3.0Reference Manual
MOTOROLAGeneral Description 19
General Description
1.3 Features
CPU08 features include:
•Full object-code compatibility with M68HC05 Family
•16-bit stack pointer with stack manipulation instructions
•16-bit index register (H:X) with high-byte and low-byte
manipulation instructions
•8-MHz CPU standard bus frequency
•64-Kbyte program/data memory space
•16 addressing modes
•78 new opcodes
•Memo ry-to-memory data moves without using accumulator
•Fast 8-bit by 8-bit multiply and 16-bit by 8-bit divide instructions
•Enhanced binary-coded decimal (BCD) data handling
•Expandable internal bus definition for extension of addressing
•Flexible internal bus definition to accommodate CPU
•Low-power stop and wait modes
1.4 Programming Model
The CPU08 programming model consists of:
•8-bit accumulator
•16-bit index register
•16-bit stack pointer
•16-bit program counter
range beyond 64 Kbytes
performance-enhancing peripherals such as a direct memory
access (DMA) controller
•8-bit condition code register
See Figure 2-1. CPU08 Programming Model .
Reference ManualCPU08 — Rev. 3.0
20General Descri ptio nMOTOR OLA
1.5 Me mory Space
Program memory space and data memory space are cont iguous over a
64-Kbyte addressing range. Addition of a page-switching peripheral
allows extension of the addressing range beyond 64 Kbytes.
1.6 Addressing Modes
The CPU08 has a total of 16 addressing modes:
•Inherent
•Immediate
•Direct
•Extended
General Description
Memory Space
•Indexed
–No offset
–No offset, post increment
–8-bit offset
–8-bit offset, post increment
–16-bit offset
•Stack pointer
–8-bit offset
–16-bit offset
•Relative
•Memory-to-memory (four modes)
Refer to Sectio n 4 . Addres sing Mo des for a detail ed descriptio n of the
CPU08 addressing modes.
CPU08 — Rev. 3.0Ref erence Manual
MOTOROLAGeneral Description 21
General Description
1.7 Arithmetic Instructions
The CPU08 arithmetic functions include:
•Addition with and without carry
•Subtraction with and without carry
•A fast 16-bit by 8-bit unsigned division
•A fast 8-bit by 8-bit unsigned multiply
1.8 Binary-Coded Decimal (BCD) Arithmetic Support
To support binary-coded decimal (BCD) arithmetic applications, the
CPU08 has a de cimal adjust accumulator (DAA) instruction a nd a nibble
swap accumulator (NSA) instruction.
1.9 High-Level Language Support
The 16-bit index register, 16-bit stack pointer, 8-bit signed branch
instructions, and associated instructions are designed to support the
efficient use of high-level language (HLL) compilers with the CPU08.
1.10 Low-Power Modes
The WAIT and S TOP instr uctions red uce th e po w er consum ption of th e
CPU08-based MCU. The WAIT instruction stops only the CPU clock and
therefore us es more pow er than the STOP instru ction, which stops both
the CPU clock and the peripheral clocks. In most modules, clocks can
be shut off in wait mode.
Figure 2-1 shows the five CPU08 registers. The CPU08 registers are
not part of the memory map.
70
AACCUMULATOR (A)
15870
HXINDEX REGISTER (H:X)
150
STACK POINTER (SP)
150
PROGRAM COUNTER (PC)
70
V11H I NZC
TWO’S COMPLEMENT OVERFLOW
FLAG (V)
ZERO FLAG (Z)
HALF-CARRY FLAG (H)
NEGATIVE FLAG (N)
INTERRU PT MASK (I )
CONDITION CODE
REGISTER (CCR)
CARRY/BORROW FLAG (C)
Figure 2-1. CPU08 Programming Model
Reference ManualCPU08 — Rev. 3.0
24ArchitectureMOTOROLA
2.3.1 Accumulator
2.3.2 Index Register
Architecture
CPU08 Registers
The accumulator (A) shown in Figure 2-2 is a general-purpose 8-bit
register. The central processo r unit (CPU ) uses the accumulator to hol d
operands and results of arithmetic and non-arithmetic operations.
Bit 7654321Bit 0
Read:
Write:
Reset:XXXXXXXX
X = Indeterminate
Figure 2-2. Accumulator (A)
The 16-bit index register (H:X) shown in Figure 2-3 allows the user to
index or address a 64-Kbyte memory space. The concatenated 16-bit
register is called H:X. The upper byte of the index register is called H.
The lower byte of the index register is called X. H is cleared by reset.
When H = 0 and no instructions that affect H are used, H:X is functionally
identical to the IX register of the M6805 Family.
In the indexed addressing mod es, the CPU uses the conten ts of H:X to
determine th e effective ad dress of th e operand . H:X can also serv e as a
temporary data storage location. See 4.3.5 Indexed, No Offset;
4.3.6 Indexed, 8-Bit Offs et; and 4.3.7 Indexed, 16-Bit Offset.
Bit 151413121110987654321Bit 0
Read:
Write:
Reset:X XXXXXXXXXXXXXXX
X = Indeterminate
Figure 2-3. Index Register (H:X)
CPU08 — Rev. 3.0Ref erence Manual
MOTOROLAArchitecture 25
Architecture
2.3.3 Stack Pointer
NOTE:The reset stack pointer (RSP) instruction sets the least significant byte
The stack pointer (SP) shown in Figure 2-4 is a 16-bit register that
contains the addr ess of the next location on the stack. During a reset, the
stack pointer is preset to $00FF to provide compatibility with the M6805
Family.
to $FF and does not affect the most significant byte.
The address in the stack pointer decremen ts as data is pushe d onto the
stack and increments as data is pulled from the stack. The SP always
points to the next available (empty) byte on the stack.
The CPU08 ha s stack poin ter 8- and 16-bit offse t addressing m odes that
allow the stack pointer to be used as an index register to access
temporary variab les on the stack. The CPU uses the contents in the SP
register to determine the effective address of the operand. See
NOTE:Although pres et to $00FF, the loca tion of the sta ck is arbi trary and may
be relocated by the user to anywhere that random-access memory
(RAM) resides within the memory map. Moving the SP out of page 0
($0000 to $00FF) will free up address space, which may be accessed
using the efficient direct addressing mode.
Reference ManualCPU08 — Rev. 3.0
26ArchitectureMOTOROLA
2.3.4 Program Counter
The program counter (PC) shown in Figure 2-5 is a 16-bit register that
contains the address of the next instruction or operand to be fetched.
Normally, the address in the pr ogra m counte r auto matical ly incre ments
to the next sequential memory location every time an instruction or
operand is fetched. Jump, branch, and interrupt operations load the
program counter with an address other than that of the next sequential
location.
During reset, the PC is loaded with the contents of the reset vector
located at $FFFE and $FFFF. This represents the address of the first
instruction to be executed after the reset state is exited.
Architecture
CPU08 Registers
Bit 151413121110987654321Bit 0
Read:
Write:
Reset:Loaded with vector from $FFFE and $FFFF
Figure 2-5. Program Counter (PC)
CPU08 — Rev. 3.0Ref erence Manual
MOTOROLAArchitecture 27
Architecture
2.3.5 Condition Code Register
The 8-bit condition code register (CCR) shown in Figure 2-6 contains
the interrupt mask and five flags that indicate the result s of the instruction
just executed. Bits five and six are permanently set to logic 1.
Read:
Write:
Reset:X11X1XXX
X = Indeterminate
V — Overflow Flag
Bit 7654321Bit 0
V11H I NZC
Figure 2-6. Condition Code Register (CCR)
The CPU sets the overflow flag when a two's complement overflow
occurs as a result of an operation. The overflow flag bit is utilized by
the signed branch instructions:
Branch if greater than, BGT
Branch if greater than or equal to, BGE
Branch if less than or equal to, BLE
Branch if less than, BLT
This bit is set by th ese instr uctions, although its r esulting value h olds
no meaning:
Arithmetic shift left, ASL
Arithmetic shift right, ASR
Logical shift left, LSL
Logical shift right, LSR
Rotate left through carry, ROL
Rotate right through carry, ROR
H — Half-Carry Flag
The CPU sets the half-carry fla g when a carr y occurs betwee n bits 3
and 4 of the accumulator during an add-without-carry (ADD) or
add-with-carry (ADC) operation. The half-carry flag is required for
Reference ManualCPU08 — Rev. 3.0
28ArchitectureMOTOROLA
CPU08 Registers
binary-coded (BCD) arithmetic operations. The decimal adjust
accumulator (DAA) instruction uses the state of the H and C flags to
determine the appropriate correction factor.
I — Interrupt Mask
When the interrupt mask is set, all interrupts are disabled. Interrupts
are enabled when the interrupt mask is cleared. When an interrupt
occurs, the interr upt mask is automatica lly set after the CPU reg isters
are saved on the stack, but before the interrupt vector is fetched.
NOTE:To maintain M6805 compatibility, the H register is not stacked
automatically . If the interrupt service routine uses X (and H is not clea r),
then the user must stack and unstack H using the push H (index register
high) onto stack (PSHH) and pull H (index register high) from stack
(PULH) instructions within the interrupt service routine.
Architecture
If an interrupt occurs while the interrupt mask is set, the interrupt is
latched. Interrupts in or der of priority are ser viced as soon as the I bit
is cleared.
A return-from-interrupt (RTI) instruction pulls the CPU registers from
the stack, restoring the interrupt mask to its cleared state. After any
reset, the interrupt mask i s set and can only be clea red by a sof tware
instruction. See Section 3. Resets and Interrupts.
N — Negative Flag
The CPU sets t he negative fl ag when an ar it hmet ic ope rati on , log ical
operation, or data manipulation produces a negative result.
Z — Zero Flag
The CPU sets the zero flag when an arithmetic operation, logical
operation, or data manipulation produces a result of $00.
C — Carry/Borrow Flag
The CPU sets the carry/borrow flag when an addition operation
produces a carry out of bit 7 of the accumulator or when a subtraction
operation requires a borrow. Some logical operations and data
manipulation instructions also clear or set the carr y/borrow flag (as in
bit test and branch instructions and shifts and rotates).
CPU08 — Rev. 3.0Ref erence Manual
MOTOROLAArchitecture 29
Architecture
2.4 CPU08 Functional Description
This subsection is an overview of the architectur e of the M68HC08 CPU
with functional descriptions of the major blocks of the CPU.
The CPU08, as shown in Figure 2-7, is divided into two main blocks:
•Control unit
•Execution unit
The control unit contains a finite state machine along with miscellaneou s
control and timing logic. The outputs of this block drive the execution
unit, which contains the arithmetic logic unit (ALU), registers, and bus
interface.
CONTR OL UNIT
CONTROL
SIGNALS
EXECUTION UNIT
STATUS
SIGNALS
ADDRESS BUS
Figure 2-7. CPU08 Block Diagram
INTERNAL
DATA BUS
INTER NAL
Reference ManualCPU08 — Rev. 3.0
30ArchitectureMOTOROLA
2.4.1 Internal Timing
Architecture
CPU08 Functional Description
The CPU08 derives its timing from a 4-phase clock, each phase
identified as either T1, T2, T3, or T4. A CPU bus cycle consists of one
clock pulse from each phase, as shown in Figure 2-8. To simplify
subsequent diagrams, the T clocks have been combined into a single
signal called the CPU clock. The start of a CPU cycle is defined as the
leading edge of T1, though the address associated with this cycle does
not drive the address bus until T3. Note that the new address leads the
associated data by one-half of a bus cycle.
For example, the data read associated with a new PC value generated
in T1/T2 of cycle 1 in Figure 2-8 would not be read into the control unit
until T2 of the next cycle.
T1
T2
T3
T4
CYCLE 1CYCLE 2
T2 T3 T4 T1 T2 T3 T4
CPU CLOCK
INTERNAL
ADDRESS BUS
INTERNAL
DATA BUS
T1
EXECUTE
CYCLE N
ADDR. CYCLE N
DATA CYCLE
Figure 2-8. Internal Timing Detail
CPU08 — Rev. 3.0Ref erence Manual
MOTOROLAArchitecture 31
Architecture
2.4.2 Control Unit
The control unit consists of:
•Sequencer
•Control store
•Random control logic
These blocks make up a finite state machine, which generates all the
controls for the execution unit.
The sequencer provides the next state of the machine to the control store
based on the contents of the instruction register (IR) and the current state
of the machine. The control store is strobed (enabled) when the next state
input is stable, producing an output that represents the decoded next state
condition for the execution unit (EU). This result, with the help of some
random logic, is used to generate the control signals that configure the
execution unit. The random logic selects the appropriate signals and adds
timing to the outputs of the control store. The control unit fires once per bus
cycle but runs almost a full cycle ahead of the execution unit to decode
and generate all the controls for the next cycle. The sequential nature of
the machine is shown in Figure 2-9.
The sequencer also contains and controls the opcode lookahead
register, which is used to prefetch the n ext sequential i nstruction. Timin g
of this operation is discussed in 2.4.4 Instruction Execution.
Reference ManualCPU08 — Rev. 3.0
32ArchitectureMOTOROLA
Architecture
CPU08 Functional Description
2.4.3 Execution Unit
CPU CLOCK
IR/CO NTROL UNIT
STATE INPUT
CONTROL UNIT
STROBE
CONTROL UNIT
OUTPUT TO
EXECUTION UNIT
INTERNAL
ADDRESS BUS
INTERNAL
DATA BUS
T2T3T4T1T2T3T4
T1
CYCLE N STATE
CYCLE N STROBE
CYCLE N
EU CONTROL
ADDRESS
CYCLE N
FETCH/DECODE
CYCLE N
EXECUTE
CYCLE N
Figure 2-9. C ont ro l Uni t Ti min g
T1T2T3T4
DATA CYCLE N
The execution unit (EU) contains all the registers, the arithmetic logic
unit (ALU), and the bus interface. Once per bus cycle a new address is
computed by passin g selected register values along th e internal address
buses to the address buffers. Note that the new address leads the
associated data by one half of a bus cycle. The execution unit also
contains some special function logic for unusual instructions such as
DAA, unsigned multiply (MUL), and divide (DIV).
2.4.4 Instruction Execution
Each instruction has defined execution boundaries and executes in a
finite number of T 1-T2-T3-T 4 cycles. All instructions are responsible fo r
fetching the next opcode into the opcode lookahead register at some
time during executio n. The opcode lo okahead register is copi ed into the
instruction register during the last cycle of an instruction. This new
instruction beg ins executing durin g the T1 cl ock after it has b een loade d
into the instruction register.
CPU08 — Rev. 3.0Ref erence Manual
MOTOROLAArchitecture 33
Architecture
Note that all instructions are also responsible for incrementing the PC
after the next instruction prefetch is under way. Therefore, when an
instruction finishes (that is, at an instruction boundary), the PC will be
pointing to the byte following the opcode fetche d by the ins tructi on . An
example sequence of instructions concerning address and data bus
activity with respect to instruction boundaries is shown in Figure 2-10.
A signal from the control unit, OPCODE LOOKAHEAD, indicates the
cycle when the next opcode is fetched. Another control signal,
LASTBOX, indicates the last cycle of th e currently e xecuting instr uction.
In most cases, OPCODE LOOKAHEAD and LAST BOX are active at the
same time. For some instructions, however, the OPCODE
LOOKAHEAD signal is asserted earlier in the instruction and the next
opcode is prefetch ed and held i n th e lookahe ad re gi ster u ntil the en d of
the currently executing instruction.
In the instruction boundaries example (Figure 2-10) the OPCODE
LOOKAHEAD and LASTBOX are asserted simultaneously during TAX
and increment INCX execution, but the load accumulator from memory
(LDA) indexed with 8-bit offset instruction prefetches the next opcode
before the last cycle. Refer to Figure 2-11. The boldface instructions in
3.5.4Allocating Scratch Space on the Stack . . . . . . . . . . . . . . . .53
CPU08 — Rev. 3.0Reference Manual
MOTOROLAResets and Interrupts 37
Resets and Interrup ts
3.2 Introduction
The CPU08 in a microcontroller executes instructions sequentially. In
many applications it is necessary to execute sets of instructions in
response to requests from various peripheral devices. These requests
are often asynchronous to the execution of the main program. Resets
and interrupts are both types of CPU08 exceptions. Entry to the
appropriate service routine is called exception processing.
Reset is required to initialize the device into a known state, including
loading the prog ram counter (PC) with the address of the firs t instruction.
Reset and interrupt operations share the common concept of vector
fetching to force a new starting point for further CPU08 operations.
Interrupts provide a way to suspend normal program execution
temporarily so that the CPU08 can be freed to service these requests.
The CPU08 can pro c ess up t o 128 separ ate int erru pt sou rces incl u ding
a software interrupt (SWI).
On-chip peripheral systems generate maskable interrupts that are
recognized only if th e global interrupt mask bi t (I bit) in the condition co de
register is clear (reset is non-maskable). Maskable interrupts are
prioritized according to a default arrangement. (See Table 3-2 and
3.5.1 Interr upt Sou rces and Priori ty.) When inter rupt cond itions occur
in an on-chip perip heral system, an interrupt sta tus flag is set to indicate
the condition. When the user’s program has properly responded to this
interrupt request, the status flag must be cleared.
Reference ManualCPU08 — Rev. 3.0
38Resets and InterruptsMOTOROLA
3.3 Elements of Reset and Interrupt Processing
Reset and interru pt processing is handled in d iscrete, though some times
concurrent, tasks. It is comprised of interrupt recognition, arbitration
(evaluating interr upt priority), stacking of the mach ine state, and fetching
of the appropriate vector. Interrupt processing for a reset is comprised of
recognition and a fetch of the reset vector only. These tasks, together
with interrupt masking and returning from a service routine, are
discussed in this subsection.
3.3.1 Recognition
Reset recognition is asynchronous and is recognized when asserted.
Internal resets are asynchronous with instruction execution except for
illegal opcode and illegal address, which are inherently
instruction-synchronized. Exiting the reset state is always synchronous.
Resets and Interrupts
Elements of Reset and Interrupt Processing
All pending interrupts ar e recognized by the CPU08 durin g the last cycle
of each instruction. Interrupts that occur during the last cycle will not be
recognized by the CPU08 until the last cycle of the following instruction.
Instruction execution cannot be suspended to service an interrupt, and
so interrupt latency calculations must include the execution time of the
longest instruction that could be encountered.
When an interrupt is recognized, an SWI opcode is forced into the
instruction registe r in place of what would have been the next instructi on.
(When using th e C PU 08 with the direct mem ory access (DMA ) modu le,
the DMA can suspend instruction operation to service the peripheral.)
Because of the opcode “lookahead” pre fetch mech anism, at in structio n
boundaries th e program counter (P C) always points to t he address of the
next instruction to b e executed plus one. The pr esence of an in terrupt i s
used to modify the SW I flow such that instead of stacking this P C value,
the PC is decremented bef ore being stacked. Af ter interrupt servicing is
complete, the return-from-interrupt (RTI) instruction will unstack the
adjusted PC and use it to prefetch the next instruction again. After SWI
interrupt servicing is complete, the RTI instruction then fetches the
instruction following the SWI.
CPU08 — Rev. 3.0Ref erence Manual
MOTOROLAResets and Interrupts 39
Resets and Interrup ts
3.3.2 Stacking
To maintain object code compatibility, the M68HC08 interrupt stack
frame is identical to that of the M6805 Family, as shown in Figure 3- 1.
Registers are stacked in the order of PC, X, A, and CCR. They are
unstacked in reverse order. Note that the condition code re gister (CCR)
I bit (internal mask) is not set until after the CCR is stacked du ring cycle 6
of the interrupt stacking procedure. The stack pointer always points to
the next available (empty) stack location.
UNSTACKING
ORDER
5
1
4
2
3
3
2
4
1
5
70
•
•
•
CONDITION CODE REGISTER
ACCUMULATOR
INDEX REGISTER (LOW BYTE X)
PROGRAM COUNTER HIGH
PROGRAM COUNTER LOW
(1)
•
•
STACKING
ORDER
1. High byte (H) of index register is not stacked.
•
$00FF (DEFAULT ADDRESS
ON RESET)
Figure 3-1. Interrupt Stack Frame
Reference ManualCPU08 — Rev. 3.0
40Resets and InterruptsMOTOROLA
Resets and Interrupts
Elements of Reset and Interrupt Processing
NOTE:To maintain compatibility with the M6805 Family, H (the high byte of the
index register) is not stacked dur ing interrupt pro cessing. If the inter rupt
service routine modifies H or uses the indexed addressing mode, it is
the user’s responsibility to save and restore it prior to returning.
See Figure 3-2.
IRQINTPSHH
|
|Inter ru pt se rv ic e ro ut ine
|
|
PULH
RTI
3.3.3 Arbitration
Figure 3-2. H Register Storage
All reset sources always have equal and highest priority and cannot be
arbitrated. Interrupts are latched, and arbitration is performed in the
system integration module ( SIM) at the start of interr upt processing. The
arbitration result is a constant that the CPU08 uses to determine which
vector to fetch. Once an interrupt is latched by the SIM, n o other interrupt
may take precedence, rega rdless of pr iority, unti l the latc hed interru pt is
serviced (or the I bit is cleared). See Figure 3 -3.
CPU08 — Rev. 3.0Ref erence Manual
MOTOROLAResets and Interrupts 41
Resets and Interrup ts
BUS CYCLE #
1
2
3
4
5
6
INTERRUPT PROCESSING
7
8
1
LAST CYCLE OF
CURRENT INSTRUCTION
FETCH (REDUNDANT)
INTER RUPT HIGH BYTE
INTE RRUPT LOW BYTE
(A)
COMPLETE NE XT
INSTRUCTION (B)
STACK PCL
STACK PCH
STACK X
STACK A
STACK CCR
FETCH VECTOR
FETCH VECTOR
RTI
COMPLETE NEXT
INSTRUC TION
FETCH (REDUNDANT)
UNSTACK CCR
UNSTACK A
UNSTACK X
UNSTACK PCH
UNSTACK PCL
FETCH NEXT
INSTRUCTION (B)
INTERRUPT
PENDING?
NOTE 1
NO
YES
BUS CYCLE #
1
2
3
4
5
6
7
START INTERRUPT
PROCESSING
FETCH INTERRUPT
9
SERVICE ROUTINE
EXECUTE INTERRUPT
SERVICE ROUTINE
FIRST INSTRUCTION
FIRST CYCLE OF
NEXT INSTRUCT ION (B )
Note 1. Interrupts that occur before this point are recognized.
Figure 3-3. Interrupt Processing Flow and Timing
Reference ManualCPU08 — Rev. 3.0
42Resets and InterruptsMOTOROLA
3.3.4 Masking
Resets and Interrupts
Elements of Reset and Interrupt Processing
Reset is non-maskable. All other interrupts can be enabled or disabled
by the I mask bit in the CCR or by local mask bits in the periphera l control
registers. The I bit may also be mo dified by execution of the set inter rupt
mask bit (SEI) , clear i nte rrup t mask bit (CLI ), or tr ans fer accumu la tor to
condition code regi ster (TAP) instructions. The I bit is modified in the firs t
cycle of each instruction (these are all 2-cycle instructions). The I bit is
also set during interrupt processing (see 3.3.1 Recognition) and is
cleared during the second cycle of the RTI instruction when the CCR is
unstacked, provided that the stacked CCR I bit is not modified at the
interrupt service routine. (See 3.3.5 Returning to Calling Program.)
In all cases where the I bit can be modified, it is modified at least one
cycle prior to the last cycle of the instruction or operation, which
guarantees that the new I-bit state will be effective prior to execution of
the next instr uction. Fo r ex ample, if a n inte rrupt is recogni zed durin g the
CLI instruction, the load accumulator fro m memory (LDA) in struction will
not be executed before the interrupt is serviced. See Figure 3-4.
CLI
LDA #$FF
INT1 PSHH
|
|
|
PULH
RTI
INT1 Interrupt Service
Routine
Figure 3-4. Interrupt Recognition Example 1
Background
Routine
CPU08 — Rev. 3.0Ref erence Manual
MOTOROLAResets and Interrupts 43
Resets and Interrup ts
If an interrupt is pending upon exit from the original interrupt service
routine, it will also be serviced before the LDA instruction is executed.
Note that the LDA op code is pr efetche d by both the INT 1 and INT 2 RTI
instructions. However, in the case of the INT1 RTI prefetch, this is a
redundant operation. See Figure 3-5.
CLI
LDA #$FF
INT1 PSHH
|
|
PULH
RTI
INT2 PSHH
|
|
PULH
RTI
INT1 Interrupt Service
Routine
INT2 Interrupt Service
Routine
Figure 3-5. Interrupt Recognition Example 2
Background
Routine
Similarly, in Figure 3-6, if an interrupt is recognized during the CLI
instruction, it will be serviced before the SEI instruction sets the I bit in
the CCR.
CLI
SEI
INT1 PSHH
|
|
PULH
RTI
INT1 Interrupt Service
Routine
Figure 3-6. Interrupt Recognition Example 3
Reference ManualCPU08 — Rev. 3.0
44Resets and InterruptsMOTOROLA
3.3.5 Returning to Calling Program
When an interrupt has been serviced, the RTI instruction terminates
interrupt processing and returns to the program that was running at the
time of the in terrupt. In servicing the inte rru pt, som e o r all of the CP U08
registers will have changed. To continue the former pr ogra m as though
uninterrupte d, the registers must be restored to the values present at the
time the former progra m was inter rupted. The RTI in struction take s care
of this by pulling (loading) the saved register values from the stack
memory. The last value to be pulled from the stack is the program
counter, which causes processing to resume at the point where it was
interrupted.
Unstacking the CCR generally clea rs the I bit, which is cleared du ring the
second cycle of the RTI instruction.
Resets and Interrupts
Elements of Reset and Interrupt Processing
NOTE:Since the return I bit state comes from the stacked CCR, the user, by
setting the I bit in the stacked CCR, can block all subsequent interrupts
pending or otherwise, regardless of priority, from within an interrupt
service routine.
LDA#$08
ORA1,SP
STA1,SP
RTI
This capability can be useful in handling a transient situation where the
interrupt handler detects that the background program is temporarily
unable to cope with the interrupt load and needs some time to recover.
At an appropriate juncture, the background program would reinstate
interrupts after it has recovered.
CPU08 — Rev. 3.0Ref erence Manual
MOTOROLAResets and Interrupts 45
Resets and Interrup ts
3.4 Reset Processing
Reset forces the microcontroller unit (MCU) to assume a set of initial
conditions and to begin executing instructions from a predetermined
starting address. For the M68HC08 Family, reset assertion is
asynchronous with instruction execution, and so the initial conditions can
be assumed to take effect almost immediately after applying an active
low level to the reset pin, regardless of whether the clock has started.
Internally, reset is a clocked process, and so reset negation is
synchronous with an internal clock, as shown in Figure 3-7, which
shows the internal timing for exiting a pin reset.
CPU CLOCK
INTER NAL
ADDRESS BUS
INTER NAL
DATA BUS
RESET PIN
T3 T4 T1 T2 T3 T4 T1 T2 T3 T4 T1 T2 T3 T4 T1 T2 T3 T4 T1 T2 T3 T4
INDETERMINATE
INDETERMINATE
RESET PIN SAMPLING
$FFFF$FFFE
PCH
Figure 3-7. Exiting Reset
The reset system is able to actively pull down the reset output if
reset-causing conditions are detected by internal systems. This feature
can be used to reset external peripherals or other slave MCU devices.
Reference ManualCPU08 — Rev. 3.0
46Resets and InterruptsMOTOROLA
3.4.1 Initial Conditions Established
Once the reset condition is recognized, internal registers and contr ol bits
are forced to an initial state. These initial states are de scribed througho ut
this manual. These initial states in turn control on-chip peripheral
systems to force them to known startup states. Most of the initial
conditions are independent of the operating mode. This subsection
summarizes the initial conditions of the CPU08 and input/outpu t (I/O) as
they leave reset.
3.4.2 CPU
After reset the CPU08 fetches the re set vector from locati ons $FFFE and
$FFFF (when in monitor mode, the reset vector is fetched from $FEFE
and $FEFF), loads the vector into the PC, and begins executing
instructions. The stack pointer is loaded with $00FF. The H register is
cleared to provide compatibility for existing M6805 object code. All other
CPU08 registers ar e indeterminate immediately after reset; however, the
I interrupt mask bit in the condition code register is set to mask any
interrupts, and the STOP and WAIT latches are both cleared.
Resets and Interrupts
Reset Processing
3.4.3 Operating Mode Selection
The CPU08 has two modes of operation useful to the user:
•User mode
•Monitor mode
The monitor mode is the same as user mode except that alternate
vectors are used by forcing address bit A8 to 0 instead of 1. The reset
vector is therefo re fe tched from addr esses $F EFE and FEFF i nstead of
FFFE and FF FF. T his offset a llows the CP U08 to exe cute code from th e
internal monitor firmware instead of the user code. (Refer to the
appropriate tech nical data man ual for specific infor mation regar ding the
internal monitor description.)
CPU08 — Rev. 3.0Ref erence Manual
MOTOROLAResets and Interrupts 47
Resets and Interrup ts
The mode of operation is latched on the rising edge of the reset pin. The
monitor mode is selected by connecting two port lines to Vss and
applying an over-voltage of approximately 2 x VDD to the IRQ1 pin
concurrent with the rising edge of reset (see Table 3-1). Port allocation
varies from port to port.
Table 3-1. Mode Selec tio n
IRQ1 PinPort xPort yMode
3.4.4 Reset Sources
≤ V
2 x V
DD
DD
XXUser
10Monitor
The system integr ation modu le (SIM ) ha s ma ster reset contr ol an d m ay
include, depending on devi ce implementa tion, any of the se typical r eset
sources:
•External reset (RESET pin)
•Power-on reset (P OR) circuit
•COP watchdog
•Illegal opcode reset
•Illegal address reset
•Low voltage inhibit (LVI) reset
A reset immediate ly stops exe cution of the c urrent i nstruction. All resets
produce the vector $FFFE/$FFFF and assert the internal reset signal.
The interna l reset causes all registers to return to their defaul t values and
all modules to return to their reset state.
Reference ManualCPU08 — Rev. 3.0
48Resets and InterruptsMOTOROLA
3.4.5 External Reset
A logic 0 applied to the RESET pin asserts the internal reset signal,
which halts all processing on the chip. The CPU08 and peripherals are
reset.
3.4.6 Active Reset from an Internal Source
All internal reset sources actively pull down the RESET pin to allow the
resetting of e xternal periphe ral s. Th e RES ET pin w ill be pulled do wn for
16 bus clock cycles; th e interna l reset signal will con tinue to b e asserted
for an additional 16 cycles after that. If the RESET
the end of the secon d 16 cycles, the n an exte rnal reset ha s occurr ed. If
the pin is high, the appropriate bit will be set to indicate the source of the
reset.
Resets and Interrupts
Interrupt Processing
pin is still low at the
The active reset feature allows the part to issue a reset to peripherals
and other chips within a system built around an M68HC08 MCU.
3.5 Interrupt Processing
The group of instructions executed in response to an interrupt is called
an interrupt service routine. These routines are much like subroutines
except that they are called through the automatic hardware interrupt
mechanism rather than by a subroutine call instruction, and all CPU08
registers, except the H register, are saved on the stack. Refer to the
description of the interrupt mask (I) found in 2.3.5 Cond itio n Code
Register.
An interrupt (provided it is enabled) causes normal program flow to be
suspended as soon as the currently executing instruction finishes. The
interrupt logic then pushes the contents of al l CPU08 reg isters onto the
stack, except the H register, so that the CPU08 content s can be restored
after the interrupt is finished. After stacking the CPU08 registers, the
vector for th e high est pr iori ty pendin g inter rup t sour ce is lo aded into th e
program counter an d executio n continues wit h the first instruction of the
interrupt service routine.
CPU08 — Rev. 3.0Ref erence Manual
MOTOROLAResets and Interrupts 49
Resets and Interrup ts
An interrupt is concluded with a return-from-interrupt (RTI) instruction,
which causes all CPU08 registers and the return address to be
recovered from the stack, so th at the interrupted progra m can resume as
if there had been no interruption.
Interrupts can be enabled or disabled by the mask bit (I bit) in the
condition code register and by local enable mask bits in the on-chip
peripheral control registers. The interrupt mask bits in the CCR provide
a means of controlling the nesting of interrupts.
In rare cases it may be useful to allow an interrupt routine to be
interrupted (see 3.5.3 Nesting of Multiple Interrupts). However,
nesting is discouraged because it greatly complicates a system and
rarely improves system performance.
By default, the interrupt structure inhibits interrupts during the interrupt
entry sequence by setting the interrupt mask bit(s) in the CCR. As the
CCR is recovered from the stack during the return from interrupt, the
condition code bits return to the enabled state so that additional
interrupts can be serviced.
Upon reset, the I bit is set t o inhibit a ll interr upts. After minim um system
initialization, soft ware may clear the I bit by a T AP or CLI instruction, thus
enabling interrupts.
Reference ManualCPU08 — Rev. 3.0
50Resets and InterruptsMOTOROLA
3.5.1 Interrupt Sources and Priority
The CPU08 can have 128 separate vecto rs including re set and software
interrupt (SWI), which leaves 126 inputs for independent interrupt
sources. See Table 3-2.
NOTE:Not all CPU08 versions use all available interrupt vectors.
AddressResetPriority
FFFEReset1
FFFCSWI2
FFFAIREQ[0]3
:::
Resets and Interrupts
Interrupt Processing
Table 3-2. M68HC08 Vectors
FF02IREQ[124]127
FF00IREQ[125]128
When the system integration module (SIM) receives an interrupt
request, processing begins at the next instruction boundary. The SIM
performs the priority decoding necessary if more than one interrupt
source is active at the same time. Also, the SIM encodes the highest
priority interru pt request into a con stant that the CPU08 uses to g enerate
the corresponding interrupt vector.
NOTE:The interrupt source priority for any specific module may not always be
the same in different M68HC08 versions. For details about the priority
assigned to interr upt sources in a spe cific M68HC 08 device, r efer to the
SIM section of the technical data manual written for that device.
As an instructi on, SW I has the highest p riority othe r t han reset ; once the
SWI opcode is fetched, no other inter rupt can be hon ored until the SWI
vector has been fetched.
CPU08 — Rev. 3.0Ref erence Manual
MOTOROLAResets and Interrupts 51
Resets and Interrup ts
3.5.2 Interrupts in Stop and Wait Modes
In wait mode the CPU clocks are disabled, but other module clocks
remain active. A module that is active during wait mode can wake the
CPU08 by an interrupt if the interrupt is enabled. Processing of the
interrupt begins immediately.
In stop mode, th e syste m clock s do not run. Th e syste m con trol modu le
inputs are conditioned so that they can be asynchronous. A particular
module can wake the part from stop mod e with an interrupt provided that
the module has been designed to do so.
3.5.3 Nesting of Multiple Interrupts
Under normal circumstances, CPU08 interrupt processing arbitrates
multiple pending interrupts, selects the highest, and leaves the rest
pending. The I bit in the CCR is also set, preventing nesting of interrupts.
While an interrupt is being serviced, it effectively becomes the highest
priority task for the system. When servicing is complete, the assigned
interrupt priority is re-established.
In certain systems wh ere, for example, a low priority inte rrupt contains a
long interrup t service routine, it may not be desirable to lock out all hi gher
priority interrupts while the low priority interrupt executes. Although not
generally advi sable, controll ed nesting of interrupts can be used to so lve
problems of this nature.
If nesting of interrupts is desired, the interrupt mask bit(s) must be
cleared after entering the interrupt service routine. Care must be taken
to specifically mask (disable) the present interrupt with a local enable
mask bit or clear the inte rrupt sour ce flag bef ore clearing the mask bit in
the CCR. Failure to do so will cause the same source to immediately
interrupt, which will rapidly consume all available stack space.
Reference ManualCPU08 — Rev. 3.0
52Resets and InterruptsMOTOROLA
3.5.4 Allocating Scratch Space on the Stack
In some systems, it is useful to allocate local variable or scratch space
on the stack for u se by the interr upt ser vi ce ro utine. T emp orar y stora ge
can also be obtained using the push (PSH) and pull (PUL) instructions;
however, the last-in-first-out (LIFO) structure of the stack makes this
impractical for more than one or two bytes. The CPU08 features the
16-bit add imm ediate val ue ( signed) to sta ck pointe r (A IS) i ns truction to
allocate space. T he stack pointer indexin g instructions ca n then be used
to access this data space, as demonstrated in this example.
IRQINTPSHH;Save H register
AIS#-16;Allocate 16 bytes of local storage
STA3,SP;Store a value in the second byte
* Note: The stack pointer must always point to the next
*empty stack location. The location addressed
*by 0,SP should therefore never be used unless the
*programmer can guarantee no subroutine calls from
*within the interrupt service routine.
.
.
.
LDA3,SP ;Read the value at a later time
.
.
.
AIS#16;Clean up stack
PULH;Restore H register
RTI;Return
Resets and Interrupts
Interrupt Processing
;of local space
* Note:Subroutine calls alter the offset from the SP to
*the local variable data space because of the
*stacked return address. If the user wishes to
*access this data space from subroutines called
*from within the interrupt service routine, then
*the offsets should be adjusted by +2 bytes for each
*level of subroutine nesting.
This section describes the addressing modes of the M68HC08 central
processor unit (CPU).
CPU08 — Rev. 3.0Ref erence Manual
MOTOROLAAddressing Modes 55
Addressing Modes
4.3 Addressing Modes
The CPU08 uses 16 addressing modes for flexibility in accessing data.
These addressi ng modes defi ne how the CPU finds the data req uired to
execute an instruction.
The 16 addressing modes are:
•Inherent
•Immediate
•Direct
•Extended
•Indexed, no offset
•Indexed, 8-bit offset
•Indexed, 16-bit offset
•Stack pointer, 8-bit offset
•Stack pointer, 16-bit offset
•Relative
•Memory-to-memory (four modes):
–Immediate to direct
–Direct to direct
–Indexed to direct with post increment
–Direct to indexed with post increment
•Indexed with post increment
•Indexed, 8-bit offset with post increment
Reference ManualCPU08 — Rev. 3.0
56Addressing ModesMOTOROLA
4.3.1 Inherent
Addressing Modes
Addressing Modes
Inherent instructions have no operand fetch associated with the
instruction, such as decima l adj u st accu mulato r ( DAA), cl ear i nde x high
(CLRH), and divi de (DIV ). Some o f the inher ent ins t ruction s act o n da ta
in the CPU registers, such as clear accumulator (CLRA), and transfer
condition code register to the accumulator (TPA). Inherent instructions
require no memory a ddress, and most are one byte lo ng. Tabl e 4- 1 lists
the instructions that use inherent addressing.
The assembly language statements shown here are examples of the
inherent addressing mode. In the code example and throughout this
section, bold typeface instructions are examples of the specific
addressing mode being discussed; a pound sign (#) before a number
indicates an immediate operand. The default base is decimal.
Hexadecimal numb ers are represented by a dollar sign ($) preceding the
number. Some assemblers use hexadecimal as the default numbering
system. Refer to the documentation for the particular assembler to
determine the proper syntax.
A614EX_2LDA#20;LS dividend in A
8CCLRH;Clear MS dividend
AE03LDX#3;Divisor in X
52DIV;(H:A)/X→A=06,H=02
A630EX_3LDA#$30;A = $30
87PSHA;Push $30 on stack and
LabelOperationOperandComments
;bit set ≡ $102
;decrement stack
;pointer by 1
CPU08 — Rev. 3.0Ref erence Manual
MOTOROLAAddressing Modes 57
Addressing Modes
Table 4-1. Inherent Addressing Instructions
InstructionMnemonic
Arithmetic Shift Lef tASLA, ASLX
Arithmetic Shift RightASRA, ASRX
Clear Carry BitCLC
Clear Interrupt MaskCLI
ClearCLRA, CLRX
Clear H (Index Register High)CLRH
ComplementCOMA, COMX
Decimal Adjust AccumulatorDAA
Decrement Accumulator, Branch if Not Equal ($00)DBNZA
Decrement X (Index Register Low), Branch if Not Equal ($00)DBNZX
DecrementDECA, DECX
Divide (Integer 16-Bit by 8-Bit Divide)DIV
IncrementINCA, INCX
Logical Shift LeftLSLA, LSLX
Logical Shift RightLSRA, LSRX
MultiplyMUL
NegateNEGA, NEGX
Nibble Swap AccumulatorNSA
No OperationNOP
Push Accumula to r o nt o StackPSHA
Push H (Index Register High) onto StackPSHH
Push X (Index Register Low) onto StackPSHX
Pull Accum u lator from St ac kPULA
Pull H (Index Register High) from StackPULH
Pull X (Index Register Low) from StackPULX
Rotate Left through CarryROLA, ROLX
Rotate Right through CarryRORA, RORX
Reset Stack Pointer to $00FFRSP
Return from InterruptR TI
Return from SubroutineRTS
Set Carry BitSEC
Set In te r rupt Ma skSE I
Enable IRQ and Stop OscillatorSTOP
Software In t e rruptSWI
Transfer Accumulator to Condition Code RegisterTAP
Transfer Accumulator to X (Index Register Low)TAX
Transfer Condition Code Register to Accumulator TPA
Test for Negative or ZeroTSTA, TSTX
Transfer Stack Pointer to Index Register (H:X)TSX
Transfer X (Index Register Low) to AccumulatorTXA
Transfer Index Register (H:X) to Stack PointerTXS
Enable Interrupts and Halt CPUWAIT
4.3.2 Immediate
The operand in immediate instructions is contained in the bytes
immediately following the opcode. The byte or bytes that follow the
opcode are the value of the statement rather than the address of the
value. In this case, the effe ctive address of the instructi on is specified by
the # sign and implicitly points to the byte following the opcode. The
immediate value is limited to either one or two bytes, depending on the
size of the register involved in the instruction. Table 4-2 lists the
instructions that use immediate addressing.
Immediate instructions associated with the index register (H:X) are
3-byte instructio ns: one byte for the opcode, two bytes for the immedi ate
data byte.
The example code shown he re contains two immediate in structions: AIX
(add immed iate to H:X) and CPHX (co mpare H:X with immediate val ue).
H:X is first cl eared and th en increme nted by one until i t contain s $FFFF.
Once the condition specified by the CPHX becomes true, the program
branches to START, and the process is repeated indefinitely.
26F9BNETAG;Loop until equal
20F5BRASTART;Start over
LabelOperationOperandComments
;$FFFF
Table 4-2. Immediate Addressing Instructions
InstructionMnemonic
Add with Carry Immediate Value to AccumulatorADC
Add Immediate Value to AccumulatorADD
Add Immediate Value (Signed) to Stack PointerAIS
Add Immediate Value (Signed) to Index Register (H:X)AIX
Logical AND Immediate Value with Accumulator AND
Bit Test Immediate Value with AccumulatorBIT
Compare A with Immediate and Branch if EqualCBEQA
Compare X (Index Register Low) with Immediate and Branch if EqualCBEQX
Compare Accumulator with Immediate ValueCMP
Compare Index Register (H:X) with Immediate ValueCPHX
Compare X (Index Register Low) with Immediate ValueCPX
Exc lusi ve OR Im medi ate Value with Acc umulato rEOR
Load Accumulator from Immediate ValueLDA
Load Index Register (H:X) with Immediate ValueLDHX
Load X (Index Register Low) from Immediate ValueLDX
Inclusive OR Immediate Val ueORA
Subtract with Carry Immediate ValueSBC
Subtract Immediate ValueSUB
Reference ManualCPU08 — Rev. 3.0
60Addressing ModesMOTOROLA
4.3.3 Direct
Addressing Modes
Addressing Modes
Most direct instructions can access any of the first 256 memory
addresses with only two bytes. The first byte is the opcode, and the
second is the low byte of the operand address. The high-order byte of
the effective address is assumed to be $00 and is not included as an
instruction byte (saving program memory space and execution time).
The use of d irect addr essing mode is therefore li mited to o perands in the
$0000–$00FF area of memory (called the direct page or page 0).
Direct addressing instructions take one less byte of program memory
space than the equivalent instructions using extended addressing. By
eliminating the additional memo ry access, the executi on time is redu ced
by one cycle. In the course of a long program, this savings can be
substantial. Most microcontroller units place some if not all
random-access memory (RAM) in the $0000–$00FF area; this allows
the designer to assign these locations to frequently referenced data
variables, thus saving execution time.
BRSET and BRCLR ar e 3-byte instructi ons that use dir ect addressing to
access the operand and relative addressing to specify a branch
destination.
CPHX, STHX, and LDHX are 2-byte instructions that fetch a 16-bit
operand. The most significant byte comes from the direct address; the
least significant byte comes from the direct address + 1.
Table 4-3 lists the instructions that use direct addressing.
This example code contains two direct addressing mode instructions:
STHX (store H:X in memory) and CPHX (compare H:X with memory).
The first STHX instruction initializes RAM storage location TEMP to
zero, and the second STHX instruction loads TEMP with $5555. The
CPHX instruction compares the value in H:X with the value of
RAM:(RAM + 1).
CPU08 — Rev. 3.0Reference Manual
MOTOROLAAddressing Modes 61
Addressing Modes
In this example, RAM:(RAM + 1) = TEMP = $50:$51 = $5555.
Machine
Code
5FSTARTCLRX;X = 0
8CCLRH;H = 0
3550STHXTEMP;H:X=0 > temp
455555LDHX#$5555;Load H:X with $5555
3550STHXTEMP;Temp=$5555
7550BAD_PARTCPHXRAM;RAM=temp
26FCBNEBAD_PART;RAM=temp will be
20F1BRASTART;Do it again
LabelOperationOperandComments
RAMEQU$50;RAM equate
ROMEQU$6E00;ROM equate
ORG$RAM;Beginning of RAM
TEMPRMB2;Reserve 2 bytes
ORG$ROM;Beginning of ROM
;same unless somet hing
;is very w rong!
Table 4-3. Direct Addressing Instructions
InstructionMnemonic
Add Memory and Carry to AccumulatorADC
Add Memory and AccumulatorADD
Logical AND of Memory and AccumulatorAND
Arithmetic Shift Left Memory
Arithmetic Shift Right MemoryASR
Clear Bit in MemoryBCLR
Bit Test Memory with AccumulatorBIT
Branch if Bit n in Memory ClearBRCLR
Branch if Bit n i n Me mory SetBRSET
Set Bit in MemoryBSET
Compare Direct with Accumulator and Branch if EqualCBEQ
Clear MemoryCLR
Compare Accumulator with MemoryCMP
Complement MemoryCOM
Compare Index Register (H:X) with MemoryCPHX
ASL
(1)
Reference ManualCPU08 — Rev. 3.0
62Addressing ModesMOTOROLA
Addressing Modes
Addressing Modes
Table 4-3. Direct Addressing Instructions (Continued)
InstructionMnemonic
Compare X (Index Register Low) with MemoryCPX
Decrement Memory and Branch if Not Equal ($00)DBNZ
Decrement MemoryDEC
Exclusive OR Memory with Ac c u mulatorEOR
Increment MemoryINC
JumpJMP
Jum p to Subrou tineJSR
Load Accumulator from MemoryLDA
Load Index Register (H:X) from MemoryLDHX
Load X (Index Register Low) from MemoryLDX
Logical Shift Left Memory
LSL
(1)
4.3.4 Extended
Logical Shift Right MemoryLSR
Negate MemoryNEG
Inclusive OR Accumulator and MemoryORA
Rotate Memory Left through CarryROL
Rotate Memory Right through CarryROR
Subtract Memory and Carry from AccumulatorSBC
Store Accumulator in Memo rySTA
Store Index Register (H:X) in MemorySTHX
Store X (Index Register Low) in MemoryST X
Subtr a c t Memory from AccumulatorSUB
Test Memory for Negative or ZeroTST
1. ASL = LSL
Extended instructions can access any address in a 64-Kbyte memory
map. All extende d instru ctions ar e thr ee bytes lo ng. Th e fi rst b yte is the
opcode; the second and third bytes are the most significant and least
significant bytes of the operand address. This addressing mode is
selected when m emory a bove the d irect or zero page ($ 0000–$00F F) is
accessed.
CPU08 — Rev. 3.0Reference Manual
MOTOROLAAddressing Modes 63
Addressing Modes
When using most a ssemblers, the pro grammer does n ot need to specify
whether an instruction is direct or extended. The assembler
automatically selects the short est fo rm of th e instruction. Ta ble 4-4 lists
the instructions that use the e xtended addressing mode. An exam ple o f
the extended addressing mode is shown here.
Machine
Code
5FCLRX
BE50LDX$0050;Load X direct
5FCLRX
CE6E00LDX$6E00;Load X extended
LabelOperationOperandComments
ORG$50;Start at $50
FCB$FF;$50 = $FF
ORG$6E00;Start at $6E00
FCB$FF;$6E00 = $FF
Table 4-4. Extended Addressing Instructions
InstructionMnemonic
Add Memory and Carry to AccumulatorADC
Add Memory and AccumulatorADD
Logical AND of Memory and AccumulatorAND
Bit Test Memory with AccumulatorBIT
Compare Accumulator with MemoryCMP
Compare X (Index Register Low) with MemoryCPX
Exclusive OR Memory with Ac c u mulatorEOR
JumpJMP
Jum p to Subrou tineJSR
Load Accumulator from MemoryLDA
Load X (Index Register Low) from MemoryLDX
Inclus ive OR Accumulato r w ith MemoryOR A
Subtract Memory and Carry from AccumulatorSBC
Store Accumulator in Memo rySTA
Store X (Index Register Low) in MemorySTX
Subtr a c t Memory from AccumulatorSUB
Reference ManualCPU08 — Rev. 3.0
64Addressing ModesMOTOROLA
4.3.5 Indexed, No Offset
Indexed instructions with no offset are 1-byte instructions that access
data with variable addresses. X contains the low byte of the conditional
address of the operand; H contains the high byte. Due to the addition of
the H register, this addressing mode is not limited to the first 256 bytes
of memory as in the M68HC05.
If none of the M68HC08 instructions that modify H are used
(AIX; CBEQ (ix+); LDHX; MOV (dir/ix+); MOV (ix+/dir); DIV; PULH;
TSX), then the H value will be $00, which ensures complete source code
compatibility with M68HC05 Family instructions.
Indexed, no offset instructions can move a pointer thro ugh a table or hold
the address of a frequently used RAM or input/output (I/O) location.
Table 4-5 lists instructions that use indexed, no offset addressing.
Addressing Modes
Addressing Modes
4.3.6 Indexed, 8-Bit Offset
Indexed, 8-b it offset instru cti ons are 2- byte i n structio ns tha t can a ccess
data with variabl e ad dresse s. The CPU ad ds the u nsigned bytes in H :X
to the unsigned byte following the opcode. The sum is the effective
address of the operand.
If none of the M68HC08 instructions that modify H are used
(AIX; CBEQ (ix+); LDHX; MOV (dir/ix+); MOV (ix+/dir); DIV; PULH;
TSX), then the H value will be $00, which ensures complete source code
compatibility with the M68HC05 Family instructions.
Indexed, 8-bit offset instructions are useful in selecting the kth element
in an n-elemen t table. The t able can begin anywhere and can exten d as
far as the address ma p allows. The k value would typically be i n H:X, and
the address of the beginning of the table would be in the byte following
the opcode . Using H:X in th is way, this ad dressing mode i s limited to the
first 256 addresses in memory. Tables can be located anywhere in the
address map when H:X is used as the base address, and the byte
following is the offset.
Table 4-5 lists the instructions that use indexed, 8-bit offset addre ssi ng.
CPU08 — Rev. 3. 0Reference Manual
MOTOROLAAddressing Modes 65
Addressing Modes
4.3.7 Indexed, 16-Bit Offset
Indexed, 16-b it offset instructions are 3-byte in structions that can access
data with variabl e ad dresse s at any lo cation i n memo ry. T he C PU adds
the unsigned contents of H:X to the 16-bit unsigned w ord formed by the
two bytes following the opcode. The sum is the effective address of the
operand. Th e first byte after the opcode is the most significant byte of the
16-bit offset; the second byte is the least significant byte of the offset.
As with direct and extended addressing, most assemblers determine the
shortest form of indexed ad dres sing. Tabl e 4-5 lists the instructions that
use indexed, 16-bit offset addressing.
Indexed, 16- bit offset in structions are useful in selecti ng the kth elemen t
in an n-elemen t table. The t able can begin anywhere and can exten d as
far as the address ma p allows. The k value would typically be i n H:X, and
the address of the beginn ing of the table wou ld be in the bytes following
the opcode.
This example uses th e JMP (uncondit ional jump) instr uction to show the
three different types of indexed addressing.
Machine
Code
FCJMP,X;No offset
ECFFJMP$FF,X;8-bit offset
DC10FFJMP$10FF,X;16-bit offset
LabelOperationOperandComments
;Jump to address
;pointed to by H:X
;Jump to address
;
pointed to by H:X + $FF
;Jump to address
;
pointed to by H:X + $10FF
Reference ManualCPU08 — Rev. 3.0
66Addressing ModesMOTOROLA
Addressing Modes
Addressing Modes
Table 4-5. Indexed Addressing Instructions
InstructionMnemonic
No
Offset
8-Bit
Offset
16-Bit
Offset
Add Memory and Carry to AccumulatorADC✔✔✔
Add Memory and AccumulatorADD✔✔✔
Logical AND of Memory and AccumulatorAND✔✔✔
Arithmetic Shift Left Memory
ASL
(1)
✔✔—
Arithmetic Shift Right MemoryASR✔✔—
Bit Test Memory with AccumulatorBIT✔✔✔
Clear Me mo ryCLR✔✔—
Compare Accumulator with MemoryCMP✔✔✔
Compl e ment MemoryCOM✔✔—
Compare X (Index Register Low)
with Memory
Decrement Memory and Branch if Not Equal
($00)
CPX✔✔✔
DBNZ✔✔—
Decrement MemoryDEC✔✔—
Exclusive OR Me mory with AccumulatorEOR✔✔✔
Increment MemoryINC✔✔—
JumpJMP✔✔✔
Jump to SubroutineJSR✔✔✔
Load Accumulator from MemoryLDA✔✔✔
Load X (Index Register Low) from MemoryLDX✔✔✔
Logical Shift Left Memory
LSL
(1)
✔✔—
Logical Shift Right MemoryLSR✔✔—
Negate Me mo ryNEG✔✔—
Inclusive OR Accumulator and MemoryORA✔✔✔
Rotate Memory Left through CarryROL✔✔—
Rotate Memory Right through CarryROR✔✔—
Subtract Memory and Carry from AccumulatorSBC✔✔✔
Store Accu mu lator in MemorySTA✔✔✔
Store X (Index Register Low) in MemorySTX✔✔✔
Subtract Memory from AccumulatorSUB✔✔✔
Test Memory for Negative or ZeroTST✔✔—
1. ASL = LSL
CPU08 — Rev. 3.0Reference Manual
MOTOROLAAddressing Modes 67
Addressing Modes
4.3.8 Stack Pointer, 8-Bit Offset
Stack pointer, 8-bit offset instructions are 3-byte instructions that
address operands in much the same way as indexed 8-bit offset
instructions, only the y add the 8-bit offset to the value of the stack point er
instead of the index register.
The stack pointer, 8-bit offset addressing mode permits easy access of
data on the stack. The CPU adds the unsigned byte in the 16-bit stack
pointer (SP) registe r to the unsigned byte following the opcod e. The sum
is the effective address of the operand.
If interrupts a re disa bled, th is addressi ng m ode a llows the sta ck pointe r
to be used as a second “index” register. Table 4-6 lists the instructions
that can be used in the stack pointer, 8-bit offset addressing mode.
Stack pointer relative instructions require a pre-byte for access.
Consequently, all SP relative instructions take one cycle longer than
their index relative counterparts.
4.3.9 Stack Pointer, 16-Bit Offset
Stack pointer, 16-bit offset instructions are 4-byte instructions used to
access data relative to the stack pointer with variable addresses at any
location in memory. The CPU adds the unsigned contents of the 16-bit
stack pointer register to the 16-bit unsigned word formed by the two
bytes following the opcode. The sum is the effective address of the
operand.
As with direct and extended addressing, most assemblers determine the
shortest form of stack pointer addressing. Due to the pre-byte, stack
pointer relative instructions take one cycle longer than their index
relative counterparts. Table 4-6 lists the instructions that can be used in
the stack pointer, 16-bit offset addressing mode.
Reference ManualCPU08 — Rev. 3.0
68Addressing ModesMOTOROLA
Addressing Modes
Addressing Modes
Examples of the 8-bit and 16-bit offset stack pointer addressing modes
are shown here. The first example stores the value of $20 in location
$10, SP = $10 + $FF = $10F and then decrements that location until
equal to zero. The second example loads the accumulator with the
contents of memory location $250, SP = $250 + $FF = $34F.
;decrement the
;contents of $10F
;until equal to zero
;to $00FF
;Load A with contents
;of $34F
Stack pointer, 16-bit offset instructions are useful in selecting the kth
element in an n-element table. The table can begin anywhere and can
extend anywhere in memory. With this 4-byte instruction, the k value
would typically be in the stack pointer register, and the address of the
beginning of the table is located in the two bytes following the 2-byte
opcode.
CPU08 — Rev. 3.0Reference Manual
MOTOROLAAddressing Modes 69
Addressing Modes
Table 4-6. Stack Pointer Addressing Instructions
InstructionM nemonic
Add Memory and Carry to AccumulatorADC✔✔
Add Memory and AccumulatorADD✔✔
Logical AND of Memory and AccumulatorAND✔✔
Arithmetic Shift Left Memory
Arithmetic Shift Right MemoryASR✔—
Bit Test Memory with AccumulatorBIT✔✔
Compare Direct with Accumulator and
Branch if Equal
Clear MemoryCLR✔—
Compare Accumulator with MemoryCMP✔✔
Complement MemoryCOM✔—
Compare X (Index Register Low) with MemoryCPX✔✔
Decrement Memory and Branch if
Not Equal ($00)
Decrement MemoryDEC✔—
(1)
ASL
CBEQ✔—
DBNZ✔—
8-Bit
Offset
✔—
16-Bit
Offset
Exclusive OR Memory with Ac c u mulatorEOR✔✔
Increment MemoryINC✔—
Load Accumulator from MemoryLDA✔✔
Load X (Index Register Low) from MemoryLDX✔✔
Logical Shift Left Memory
Logical Shift Right MemoryLSR✔—
Negate MemoryNEG✔—
Inclusive OR Accumulator and MemoryORA✔✔
Rotate Memory Left through CarryROL✔—
Rotate Memory Right through CarryROR✔—
Subtract Memory and Carry from MemorySBC✔✔
Store Accumulator in Memo rySTA✔✔
Store X (Index Register Low) in MemorySTX✔✔
Subtr a c t Memory from AccumulatorSUB✔✔
Test Memory for Negative or ZeroTST✔—
1. ASL = LSL
LSL
(1)
✔—
Reference ManualCPU08 — Rev. 3.0
70Addressing ModesMOTOROLA
4.3.10 Relative
Addressing Modes
Addressing Modes
All conditional branch instructions use relative addressing to evaluate
the resultant effective address (EA). T he CPU evaluates the conditional
branch destina tion by adding th e signed b yte following th e opcode to th e
contents of the program counter. If the branch condition is true, the PC
is loaded with the EA. If the branch condition is not true, the CPU goes
to the next instruction. The offse t is a signed, two’s comple ment byte that
gives a branching range of –128 to +127 bytes from the address of the
next location after the branch instruction.
Four new branch opcodes test the N, Z, and V (overflow) bits to
determine the relative signed values of the operands. These new
opcodes are BLT, B GT, BLE, and BGE and are desig ned to be used with
signed arithmetic operations.
When using most assemblers, the programmer does not need to
calculate the offset, b ecause the assembler deter mines the proper offset
and verifies that it is within the span of the branch.
Table 4-7 lists the instructions that use relative addressing.
This example contains two relative addressing mode instructions: BLT
(branch if less than, signed operation) and BRA (b ranch always).
In this example, the valu e i n th e accum ulator is com pare d to the sign ed
value –2. Because #1 is greater than –2 , the branch to TAG will not
occur.
Machine
Code
A601TAGLDA#1;A = 1
A1FE
91FA
20FEHEREBRAHERE;Branch always
LabelOperationOperandComments
CMP
BLT
#-2
TAG
;Compare with -2
;Branch if value of A
;is less th an -2
CPU08 — Rev. 3.0Reference Manual
MOTOROLAAddressing Modes 71
Addressing Modes
Table 4-7. Relative Addressing Instructions
InstructionMnemonic
Branch if Carry ClearBCC
Branch if Carry SetBCS
Branch if EqualBEQ
Branch if Greater Than or Equal (Signed)BGE
Branch if Greater Than (Signed)BGT
Branch if Half-Carry ClearBHCC
Branch if Half-Carry SetBHCS
Branch if HigherBHI
Branch if Higher or SameBHS (BCC)
Branch if Interrupt Line HighBIH
Branch if Interrupt Line LowBIL
Branch if Less Than or Equal (Signed)BLE
Branch if LowerBLO (BCS)
Branch if Lower or SameBLS
Branch if Less Than (Signed)BLT
Branch if Interrupt Mask ClearBMC
Branch if MinusBMI
Branch if Interrup t Mask Se tBMS
Branch if Not EqualBNE
Branch if PlusBPL
Branch Alway sBRA
Branch if Bit n in Memory ClearBRCLR
Branch if Bit n in Memory SetBRSET
Branch NeverBRN
Branch to SubroutineBSR
Reference ManualCPU08 — Rev. 3.0
72Addressing ModesMOTOROLA
4.3.11 Memory-to-Memory Immediate to Direct
Move immediate to direct (MOV imm /dir) is a 3-byt e, 4-cycle ad dressing
mode generally used to initialize variables and registers in the direct
page. The operand in the byte immediately following the opcode is
stored in the direct page locatio n addressed by the se cond byte following
the opcode. The MOV instruction associate d with this addressi ng mode
does not affect the accumulator value. This example shows that by
eliminating th e accum ulator from the data tran sfer pr ocess, th e numb er
of execution cycles decreases from 9 to 4 for a similar im mediate to
direct operation.
Addressing Modes
Addressing Modes
Machine
Code
* Data movement with accumulator
B750 (2 cycles)PSHA;Save current A
A622 (2 cycles)LDA#$22;A = $22
B7F0 (3 cycles)STA$F0;Store $22 into $F0
B650(2 cycles)PULA;Restore A value
9 cycles
* Data movement without accumulator
6E22F0
(4 cycles)
4.3.12 Memory-to-Memory Direct to Direct
Move direct to direct (MOV dir/dir) is a 3-byte, 5-cycle addr essing mode
generally used i n register-to -register mo vements of data fr om within the
direct page. The operand in the direct page location addressed by the
byte immediately following the opcode is stored in the direct page
location addressed by the second byte following the opcode. The MOV
instruction associated with this addressing mode does not affect the
accumulator value. As with the previous addressing mode,
Label Operation OperandComments
; value
MOV#$22,$F0 ;Location $F0
;= $22
CPU08 — Rev. 3.0Reference Manual
MOTOROLAAddressing Modes 73
Addressing Modes
eliminating the accumulator from the data transfer process reduces the
number of execution cycles from 10 to 5 for similar direct-to-direct
operations (see exam ple). This savings can be substantial for a prog ram
containing numerous register-to-register data transfers.
Machine
Code
* Data movement with accumulator
B750 (2 cycles)PSHA;Save A value
B6F0 (3 cycles)LDA$F0;Get contents
B7F1 (3 cycles)STA$F1;Location $F1=$F0
B650(2 cycles)PULA;Restore A value
10 cycles
* Data movement without accumulator
4EF0F1( 5 cycles)MOV$F0,$F1;Move contents of
Label OperationOperandComments
4.3.13 Memory-to-Memory Indexed to Direct with Post Increment
Move indexed to dire ct, post increment (MOV ix+/dir) is a 2-byte, 4-cycle
addressing mode generally used to transfer tables addressed by the
index register to a re gi ster in the d irect p age. T he ta bles can be located
anywhere in the 64-Kbyte map and can be any size. This instruction
does not affect the accumulator value. The operand addressed by H:X
is stored in the direct page l ocat ion addr essed by the byt e foll owing the
opcode. H:X is incremented after the move.
;of $F0
;$F0 to $F1
This addressing mode is effective for transferring a buffer stored in RAM
to a serial transmit register, as shown in the following example. Table 4-8
lists the memory-to-memory move instructions.
NOTE:Move indexed to direct, po st increment instr uctions will increment H if X
is incremented past $FF.
Reference ManualCPU08 — Rev. 3.0
74Addressing ModesMOTOROLA
Addressing Modes
Addressing Modes
This example illustrates an interrupt-driven SCI transmit service routine
supporting a circular buffer.
Machine
Code
55 50TX_INTLDHXPTR_OUT;Load pointer
B6 16LDASCSR1;Dummy read of
7E 18MOVX+, SCDR;Move new byte to
65 00 64CPHX#TX_B +
23 03BLSNOLOOP;If not, continue
45 00 54LDHX#TX_B;Else reset to
35 50NOLOOPSTHXPTR_OUT;Save new
80RTI;Return
LabelOperationOperandComments
SIZEEQU16;TX circular
;buffer length
SCSR1EQU$16;SCI status
;register 1
SCDREQU$18;SCI transmit
;data register
ORG$50
PTR_OUTRMB2;Circular buffer
;data out pointer
PTR_INRMB2;Circular buffer
;data in pointer
TX_BRMBSIZE;Circular buffer
*
* SCI transmit data register empty interrupt
* service routine
*
ORG$6E00
;SCSR1 as part of
;the TDRE reset
;SCI data reg.
;Clear TD R E . P o s t
;increment H:X.
;Gone past end of
SIZE
;circular buffer?
;start of buffer
;pointer value
CPU08 — Rev. 3.0Reference Manual
MOTOROLAAddressing Modes 75
Addressing Modes
4.3.14 Memory-to-Memory Direct to Indexed with Post Increment
Move direct to indexe d, post increment (MOV dir/ix+) is a 2-b yte, 4-cycle
addressing mode gene rally used to fill tables fro m registers in the direct
page. The tables can be locate d anywhere in the 64-Kbyte map and can
be any size. The instruction associated with this addressing mod e does
not affect the accumulator valu e. The operand in the direct page location
addressed by the byte imm ediately follo wing the opcode is stored in the
location addressed by H:X. H:X is incremented after the move.
An example of this addressing mode would be in filling a serial receive
buffer located in R AM fr om the recei ve data r egister . Table 4- 8 lists the
memory-to-memory move instructions.
NOTE:Move direct to indexed, post incr ement instructions will incr ement H if X
is incremented past $FF.
This example illustrates an interrupt-driven SCI receive service routine
supporting a circular buffer.
Machine
Code
LabelOperationOperandComments
SIZEEQU16;RX circular
;buffer length
SCSR1EQU$16;SCI status reg.1
SCDREQU$18;SCI receive
;data reg.
ORG$70
PTR_OUT RMB2;Circular buffer
;data out pointer
PTR_INRMB2;Circular buffer
;data in pointer
RX_BRMBSIZE;Circular buffer
*
* SCI receive data register full interrupt
* service routine
*
Reference ManualCPU08 — Rev. 3.0
76Addressing ModesMOTOROLA
Addressing Modes
Addressing Modes
Machine
Code
55 72RX_INTLDHXPTR_IN;Load pointer
B6 16LDASCSR1;Dummy read of
5E 18MOVSCDR ,X+;Move new byte from
65 00 64CPHX#RX_B +
23 03BLSNOLOOP;If not continue
45 00 54LDHX#RX_B;Else reset to
35 52NOLOOPSTHXPTR_IN;Save new
80RTI;Return
LabelOperationOperandComments
ORG$6E00
;SCSR1 as part of
;the RDRF reset
;SCI data reg.
;Clear RDRF. Post
;increment H:X.
;Gone past end of
SIZE
;circular buffer?
;start of buffer
;pointer value
Table 4-8. Memory-to-Memory Move Instructions
Move Immediate Operand to Direct Memory LocationMOV
Move Direct Memory Operand to Another Direct Memory LocationMOV
Move Indexed Operand to Direct Memory LocationMOV
Move Direct Memory Operand to Indexed Memory LocationMOV
4.3.15 Indexed with Post Increment
Indexed, no offset with post increment instructions are 2-byte
instructions that address oper ands, then increm ent H:X. X contains the
low byte of the conditional address of the operand; H contains the high
byte. The sum i s the conditional address of the operand. T his addressing
mode is generally used for table searches. Table 4-9 lists the indexed
with post increment instructions.
NOTE:Indexed with post increment instructions will increment H if X is
incremented past $FF.
InstructionMnemonic
CPU08 — Rev. 3.0Reference Manual
MOTOROLAAddressing Modes 77
Addressing Modes
4.3.16 Indexed, 8-Bit Offset with Post Increment
Indexed, 8-bit offset with post increment instructions are 3-byte
instructions that access operands with variable addresses, then
increment H:X . X con tai ns the low b y te o f t he conditi on al ad dress of the
operand; H contains the high byte. The sum is the conditional address of
the operand. As with indexed, no offset, this addressing mode is
generally used for table searches. Table 4-9 lists the indexed with post
increment instructions.
NOTE:Indexed, 8-bit offset with post increment instructions will increment H if
X is incremented past $FF.
This example use s th e CB EQ ( compare and branch if equal) instruction
to show the two different indexed with post increment addressing
modes.
* Compare contents of A with contents of location pointed to by
* H:X and branch to TAG when equal
7102LOOPCBEQX+,TAG;No offset
20FCBRALOOP;Check next location
5FTAGCLRX;Zero X
* Compare contents of A with contents of location pointed to by
* H:X + $50 and branch to TG1 when equal
615002LOOP2CBEQ$50,X+,TG1;8-bit offset
20FBBRALOOP2;Check next location
20FETG1BRATG1;Finished
LabelOperationOperandComments
Table 4-9. Indexed and Indexed, 8-Bit Offset
with Post Increment Instructions
InstructionMnemonic
Compare and Branch if Equal, Indexed (H:X)CBEQ
Compare and Branch if Equal, Indexed (H:X), 8-Bit OffsetCBEQ
Move Indexed Operand to Direct Memory LocationM OV
Move Direct Memory Operand to Indexed Memory LocationMOV
Reference ManualCPU08 — Rev. 3.0
78Addressing ModesMOTOROLA
4.4 Instruct ion Set Summary
Table 4-10 provides a summary of the M68HC08 instruction set in all
possible addressing mod es. The table show s operand constructi on and
the execution time in internal bus clock cycles of each instruction.
Table 4-10. Instruction Set Summary (Sheet 1 of 9)
AND #opr8i
AND opr8a
AND opr16a
AND oprx16,X
AND oprx8,X
AND ,X
AND oprx16,SP
AND oprx8,SP
ASL opr8a
ASLA
ASLX
ASL oprx8,X
ASL ,X
ASL oprx8,SP
OperationDescription
Add with Carry A
Add wit hout CarryA
Add Immediate Value
(Signed) to Stack Pointer
Add Immediate Value
(Signed) to Index
Register (H:X)
Logical AND A
Arithmetic Shift Left
(Same as LSL)
M is sign extended to a 16-bit value
M is sign extended to a 16-bit value
← (A) + (M) + (C)↕↕– ↕↕↕
SP
H:X
C
b7
Effect
on CCR
VH I NZC
← (A) + (M)↕↕– ↕↕↕
← (SP) + (M)
← (H:X) + (M)
← (A) & (M)0 ––↕↕–
0
b0
––––––IMMA7 ii 2
––––––IMMAF ii2
↕ ––↕↕↕
IMM
DIR
EXT
IX2
IX1
IX
SP2
SP1
IMM
DIR
EXT
IX2
IX1
IX
SP2
SP1
IMM
DIR
EXT
IX2
IX1
IX
SP2
SP1
DIR
INH
INH
IX1
IX
SP1
Mode
Address
Opcode
A9
B9
C9
D9
E9
F9
9ED9
9EE9
AB
BB
CB
DB
EB
FB
9EDB
9EEB
A4
B4
C4
D4
E4
F4
9ED4
9EE4
38
48
58
68
78
9E68
ii
dd
hh ll
ee ff
ff
ee ff
ff
ii
dd
hh ll
ee ff
ff
ee ff
ff
ii
dd
hh ll
ee ff
ff
ee ff
ff
dd
ff
ff
Cycles
Operand
2
3
4
4
3
2
5
4
2
3
4
4
3
2
5
4
2
3
4
4
3
2
5
4
4
1
1
4
3
5
CPU08 — Rev. 3.0Reference Manual
MOTOROLAAddressing Modes 79
Addressing Modes
Table 4-10. Instruction Set Summary (Sheet 2 of 9)
Source
Form
ASR opr8a
ASRA
ASRX
ASR oprx8,X
ASR ,X
ASR oprx8,SP
BCC relBranch if Carry Bit ClearBranch if (C) = 0––––––REL24 rr3
BCLR n,opr8aClear Bit n in MemoryMn
BCS rel
BEQ relBranch if EqualBranch if (Z) = 1––––––REL27 rr3
BGE rel
BGT rel
BHCC rel
BHCS rel
BHI relBranch if HigherBranch if (C) | (Z) = 0––––––REL22 rr3
BHS rel
BIH relBranch if IRQ Pin HighBranch if IRQ pin = 1––––––REL2F rr3
BIL relBranch if IRQ Pin LowBranch if IRQ pin = 0––––––REL2E rr3
BIT #opr8i
BIT opr8a
BIT opr16a
BIT oprx16,X
BIT oprx8,X
BIT ,X
BIT oprx16,SP
BIT oprx8,SP
BLE rel
BLO rel
OperationDescription
Arithmetic Shift Right↕ ––↕↕↕
Branch if Carry Bit Set
(Same as BLO)
Branch if Greater Than or
Equal To
(Signed O pe r an ds )
Branch if Greater Than
(Signed O pe r an ds )
Branch if Half Carry Bit
Clear
Branch if Half Carry Bit
Set
Branch if Higher or Same
(Same as BCC)
Bit Test
Branch if Less Than
or Equal To
(Signed O pe r an ds )
Branch if Lower
(Same as BCS)
b7
← 0––––––
Branch if (C) = 1––––––REL25 rr3
Branch if (N
Branch if (Z)
Branch if (H) = 0––––––REL28 rr3
Branch if (H) = 1––––––REL29 rr3
Branch if (C) = 0––––––REL24 rr3
(CCR Updated but Operands
Not Changed)
Branch if (Z)
Branch if (C) = 1––––––REL25 rr3
⊕ V) = 0––––––REL90 rr3
| (N ⊕ V) = 0––––––REL92 rr3
(A) & (M)
| (N ⊕ V) = 1––––––REL93 rr3
C
b0
on CCR
VH I NZC
0 ––↕↕–
Address
DIR
INH
INH
IX1
IX
SP1
DIR (b0)
DIR (b1)
DIR (b2)
DIR (b3)
DIR (b4)
DIR (b5)
DIR (b6)
DIR (b7)
IMM
DIR
EXT
IX2
IX1
IX
SP2
SP1
Mode
Opcode
Operand
37
dd
47
57
67
ff
77
9E67
ff
11
dd
13
dd
15
dd
17
dd
19
dd
1B
dd
1D
dd
1F
dd
A5
ii
B5
dd
C5
hh ll
D5
ee ff
E5
ff
F5
9ED5
ee ff
9EE5
ff
Effect
Cycles
4
1
1
4
3
5
4
4
4
4
4
4
4
4
2
3
4
4
3
2
5
4
Reference ManualCPU08 — Rev. 3.0
80Addressing ModesMOTOROLA
Table 4-10. Instruction Set Summary (Sheet 3 of 9)
Addressing Modes
Instruction Set Summary
Source
Form
BLS relBranch if Lower or SameBranch if (C) | (Z) = 1––––––REL23 rr3
BLT rel
BMC rel
BMI relBranch if MinusBranch if (N) = 1––––––REL2B rr3
BMS rel
BNE relBranch if Not EqualBranch if (Z) = 0––––––REL26 rr3
BPL relBranch if PlusBranch if (N) = 0––––––REL2A rr3
BRA relBranch AlwaysNo Test––––––REL20 rr3
BRCLR n,opr8a,rel
BRN relBranch NeverUses 3 Bus Cycles––––––REL21 rr3
Enable Interrupts:
Stop Processing
Refer to MCU
Documentation
Store X (Low 8 B its of
Index R egister)
in Memor y
Subtract A
Transfer Accumulator to
CCR
Transfer Accumulator to
X (Inde x Register Low)
Transfer CCR to
Accumulator
Test for Negative or Zero
Transfer X (Index Reg.
Low) to Accumulator
← 0; Stop Processing––0 –––INH8E1
I bit
← (X)0 ––↕↕–
M
← (A) – (M)↕ ––↕↕↕
← (PC) + $0001
PC
Push (PCL); SP
Push (PCH); SP
Push (X); SP ← (SP) – $0001
Push (A); SP
Push (CCR); SP
← Interrupt Vect or Hi gh Byte
PCH
← Interrupt Vector Low Byte
PCL
← (SP) – $000 1
← (SP) – $0001
← (SP) – $0001
← (SP) – $0001
I ← 1;
← (A)↕↕↕↕↕↕INH842
CCR
← (A)––––––INH971
X
← (CCR)––––––INH851
A
(M) – $00
(A) – $00
(X) – $00
(M) – $00
(M) – $00
(M) – $00
← (SP) + $0001––––––INH952
← (X)––––––INH9F1
A
on CCR
DIR
EXT
IX2
IX1
IX
SP2
SP1
IMM
DIR
EXT
IX2
IX1
IX
SP2
SP1
DIR
INH
INH
IX1
IX
SP1
Mode
Address
Opcode
BF
CF
DF
EF
FF
9EDF
9EEF
A0
B0
C0
D0
E0
F0
9ED0
9EE0
3D
4D
5D
6D
7D
9E6D
Operand
dd
hh ll
ee ff
ff
ee ff
ff
ii
dd
hh ll
ee ff
ff
ee ff
ff
dd
ff
ff
VH I NZC
––1 –––INH839
0 ––↕↕–
Effect
Cycles
3
4
4
3
2
5
4
2
3
4
4
3
2
5
4
3
1
1
3
2
4
Reference ManualCPU08 — Rev. 3.0
86Addressing ModesMOTOROLA
Table 4-10. Instruction Set Summary (Sheet 9 of 9)
Addressing Modes
Opcode Map
Source
Form
TXSTransfer Index Reg. to SPSP ← (H:X) – $0001––––––INH942
WAIT
AAccumulatornAny bit
CCarry/borrow bitopr O pe r an d (one or two byt e s)
CCR Conditio n co de re gi sterPCProgram coun ter
ddDire ct address of op er a ndPCH Progra m co un ter high by te
dd rr Direct address of operand and relative offset of branch instructionPCL Program counter low byte
DDDirect to direct addressing modeREL Relative addressing mode
DIRDirect a ddressing moderelRelative program counter offset byte
DIX+ Direct t o indexed with post increment addressing moderrRelative program counter offset byte
ee ff High and low bytes of offset in indexed, 16-bi t offset addressingSP1 Stack pointer, 8-bit offset addressing mode
EXT Extended addressing modeSP2 Stack pointer 16-bit off s et addressing mode
ffOffset byte in indexed, 8-bit offset addressingSPStack pointer
HHalf-carry bitUUndefined
HIndex regist er high byteVOverflow bit
hh llHigh and low bytes of operand address in extende d addressingXIndex regist er low byte
IInterrupt maskZZero bit
iiImmediate operand byte&Logical AND
IMDImmediate source to direct destination addressing mode|Logical OR
IMMImmediate addressing mode
INHInherent addressing mode( )Contents of
IXIndexed, no offset addressing mode–( ) Negation (two’s complement)
IX+Indexed, no offset, post increment addressing mode#Immediate value
IX+D Indexed with po st increment to direct addressing mode
IX1Indexed, 8-bit offset addressing mode
IX1+ Indexed, 8-bit offset, post increment ad dressing mode?If
IX2Indexed, 16-bit offset addressing mode:Concatenated with
MMemory location↕Set or cleared
NNegative bit—Not affected
This section contains detailed information for all HC08 Family
instructions. Th e instructi ons are arrange d in alphab etical or der with th e
instruction mnemonic set in larger type for easy reference.
This nomenclature is used in the instruction descripti ons throughout this
section.
Operators
( ) =Contents of register or memory location shown inside
parentheses
←=Is loaded with (read: “gets”)
&=Boolean AND
|=Boolean OR
⊕=Boolean exclusive-OR
×=Multiply
÷=Divide
:=Concatenate
+=Add
–=Negate (two’s complement)
«=Sign extend
CPU registers
A=Accumulator
CCR=Condition code register
H=Index register, higher order (most significant) eight bits
X=Index register, lower order (least significant) eight bits
PC=Program counter
PCH=Program counter, higher order (most significant) eight
bits
PCL=Program counter, lower order (least significant) eight
bits
SP=Stack pointer
Reference ManualCPU08 — Rev. 3.0
92Instruction SetMOTOROLA
Instructi on Set
Nomenclature
Memory and addressing
M=A memory location or absolute data, depending on
addressing mode
M:M + $0001=A 16-bit value in two consecutive memory locations.
The higher-order (most significant) eight bits are
located at th e a ddre ss of M, and the l ower -or der (lea st
significant) eight bits are located at the next higher
sequential address.
rel=The relative offset, which is the two’s complement
number stored in the last byte of machine code
corresponding to a branch instruction
Condition code register (CCR) bits
V=Two’s complement overflow indicator, bit 7
H=Half carry, bit 4
I=Interrupt mask, bit 3
N=Negative indicator, bit 2
Z=Zero indicator, bit 1
C=Carry/borrow, bit 0 (carry out of bit 7)
Bit status BEFORE execution of an instruction (n = 7, 6, 5, ... 0)
For 2-byte ope rations such as LDHX, STHX, and CPHX, n = 15 refers
to bit 15 of the 2-byte word or bit 7 of the most significant (first) byte.
Mn=Bit n of memory location used in operation
An=Bit n of accumulator
Hn=Bit n of index register H
Xn=Bit n of index register X
bn=Bit n of the source operand (M, A, or X)
Bit status AFTER execution of an instruction
For 2-byte ope rations such as LDHX, STHX, and CPHX, n = 15 refers
to bit 15 of the 2-byte word or bit 7 of the most significant (first) byte.
Rn=Bit n of the result of an operation (n = 7, 6, 5, … 0)
CPU08 — Rev. 3.0Reference Manual
MOTOROLAInstruction Set 93
Instruction Set
CCR activity figure notation
–=Bit not affected
0=Bit forced to 0
1=Bit forced to 1
↕=Bit set or cleared according to results of operation
U=Undefined after the operation
Machine coding notation
dd=Low-order eight bits of a dire ct address $000 0–$00FF
(high byte assumed to be $00)
ee=Upper eight bits of 16-bit offset
ff=Lower eight bits of 16-bit offset or 8-bit offset
ii=One byte of immediate data
jj=High-order byte of a 16-bit immediate data value
kk=Low-order byte of a 16-bit immediate data value
hh=High-order byte of 16-bit extended address
ll=Low-order byte of 16-bit extended address
rr=Relative offset
Source forms
The instruction detail pages provide only essential information about
assembler source forms. Assemblers generally support a number of
assembler directives, allow definition of program labels, and have
special conventions for comments. For complete information about
writing source files for a particular assembler, r efer to the d ocumentation
provided by the assembler vendor.
Typically, assemblers are flexible about the use of spaces and tabs.
Often, any nu mber of spaces or t abs ca n be used where a single space
is shown on the glossary pages. Spaces and tabs are also normally
allowed before and after commas. Whe n program labels are used, there
must also be a t least one tab or spa ce before all instru ction mnemo nics.
This required space is not apparent in the source forms.
Everything in the sour ce forms columns, except expressions in italic characters, is literal information which must appear in the assembly
source file exactly as shown. The initi al 3- to 5-letter mnemonic is always
Reference ManualCPU08 — Rev. 3.0
94Instruction SetMOTOROLA
Instructi on Set
Nomenclature
a literal ex pression. All comma s, pound signs (#), parentheses, and plus
signs (+) are literal characters.
The definition of a legal label or expression varies from assembler to
assembler. Assemblers also vary in the way CPU registers are specified.
Refer to assembler documentation for detailed information.
Recommended register designators are a, A, h, H, x, X, sp, and SP.
n—Any label or expression that evaluates to a single
integer in the range 0–7
opr8i—Any label or expression that evaluates to an 8-bit
immediate value
opr16i—Any label or expression that evaluates to a 16-bit
immediate value
opr8a—Any label or expression that evaluates to an 8-bit
value. The instruction treats this 8-bit value as the low
order eight bits of an address in the direct page of the
64-Kbyte address space ($00xx).
opr16a—Any label or expression that evaluates to a 16-bit
value. The instruction treats this value as an address
in the 64-Kbyte address space.
oprx8—Any label or expression that evaluates to an unsigned
8-bit value; used for indexed addressing
oprx16—Any label or expression that evaluates to a 16-bit
value. Since the MC68HC08S has a 16-bit address
bus, this can be either a signed or an unsigned value.
rel—Any label or expression that refers to an address that
is within –128 to +127 locations from the next address
after the last byte of object code for the current
instruction. The assembler will calculate the 8-bit
signed offset and include it in the object code for this
instruction.
CPU08 — Rev. 3.0Reference Manual
MOTOROLAInstruction Set 95
Instruction Set
Address modes
INH=Inherent (no operands)
IMM=8-bit or 16-bit immediate
DIR=8-bit direct
EXT=16-bit extended
IX=16-bit index ed no offset
IX+=16-bit indexed no offset, post increment (CBEQ and
MOV only)
IX1=16-bit indexed with 8-bit offset from H:X
IX1+=16-bit indexed with 8-bit offset, post increment
(CBEQ only)
IX2=16-bit indexed with 16-bit offset from H:X
REL=8-bit relative offset
SP1=Stack pointer relative with 8-bit offset
SP2=Stack pointer relative with 16-bit offset
5.4 Convention Definitions
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.
A specific bit is referred to by mnemoni c and bit number . A7 is bit 7 of
accumulator A. A range of bits is referred to by mnemonic and the bit
numbers that define the range. A [7:4] are bits 7 to 4 o f the accu mulator.
Parentheses indicate the contents of a register or memory location,
rather than the register or memory location itself. (A) is the contents of
the accumulator. In Boolean expressions, parentheses have the
traditional mathematical meaning.
5.5 Instruction Set
The following pages summarize each instruction, including operation
and description, condition codes and Boolean formulae , and a tabl e with
source forms, addressing modes, machine code, and cycles.
Reference ManualCPU08 — Rev. 3.0
96Instruction SetMOTOROLA
Instructi on Set
Instructi on Set
ADCAdd with CarryADC
OperationA ← (A) + (M) + (C)
DescriptionAdds the con tents of the C bit to th e sum of the contents of A an d M and
places the result in A. This operation is useful for addition of operands
that are larger than eight bits.
Condition Codes
and Boolean
Formulae
VHINZC
↕11↕—↕↕↕
Source Forms,
Addressing
Modes, Machine
Code, Cycles, and
Access Details
V: A7&M7&R7
| A7&M7&R7
Set if a two’s compement overflow resulted from the operation;
cleared otherwise
H: A3&M3 | M3&R3 | R3&A3
Set if there was a carry from bit 3; cleared otherwise
N: R7
Set if MSB of result is 1; cleared otherwise
Z: R7&R6&R5&R4&R3&R2&R1&R0
Set if result is $00; cleared otherwise
C: A7&M7 | M7&R7
| R7&A7
Set if there w as a carry fr om the m ost sig ni ficant bi t (MSB) of the
result; cleared otherwise
AISAdd Immediate Value (Signed) to Stack PointerAIS
OperationSP ← (SP) + (16 « M)
DescriptionAdds the immediate operand to the stack pointer (SP). The immediate
value is an 8-bit two’s complement signed operand. The 8-bit operand is
sign-extended to 16 bits prior to the addi tion. The A IS instructi on can be
used to create and remove a stack frame buffer that is used to store
temporary variables.
This instruction does not affect any condition code bits so status
information can be passed to or from a subroutine or C function and
allocation or deallocation of space for local variables will not disturb that
status information.
Condition Codes
and Boolean
Formulae
Source Form,
Addressing Mode,
Machine Code,
Cycle, and Access
Detail
None affected
VHINZC
—11—————
Source
Form
AIS#opr8iIMMA7ii2
Address
Mode
Machine CodeHC08
OpcodeOperand(s)
Cycles
CPU08 — Rev. 3.0Reference Manual
MOTOROLAInstruction Set 99
Instruction Set
AIXAdd Immediate Value (Signed) to Index RegisterAIX
OperationH:X ← (H:X) + (16 « M)
DescriptionAdds an immediate operand to the 16-bit index register, formed by the
concatenation of the H and X registers. The immediate operand is an
8-bit two’s complement signed offset. The 8-bit operand is signextended to 16 bits prior to the addition.
This instruction does not aff ect any conditio n code bits so index register
pointer calcul ations do no t di stur b the surro unding code wh ich may rel y
on the state of CCR status bits.
Condition Codes
and Boolean
Formulae
Source Form,
Addressing Mode,
Machine Code,
Cycles, and
Access Detail
None affected
VHINZC
—11—————
Source
Form
AIX#opr8iIMMAFii2
Address
Mode
Machine CodeHC08
OpcodeOperand(s)
Cycles
Reference ManualCPU08 — Rev. 3.0
100Instruction SetMOTOROLA
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.