freescale semiconductor, inc.cpu12rg/d 6 cpu12 reference guide (for hcs12 and original m68hc12)...

32
© Motorola, Inc., 2001 CPU12RG/D Rev. 2, 11/2001 CPU12 Reference Guide (for HCS12 and original M68HC12) Reference Guide Figure 1. Programming Model 7 15 15 15 15 15 D X Y SP PC A B N S X H I Z VC 0 0 0 0 0 0 7 0 CONDITION CODE REGISTER 8-BIT ACCUMULATORS A AND B 16-BIT DOUBLE ACCUMULATOR D INDEX REGISTER X INDEX REGISTER Y STACK POINTER PROGRAM COUNTER OR STOP DISABLE (IGNORE STOP OPCODES) RESET DEFAULT IS 1 CARRY OVERFLOW ZERO NEGATIVE MASK (DISABLE) IRQ INTERRUPTS HALF-CARRY (USED IN BCD ARITHMETIC) MASK (DISABLE) XIRQ INTERRUPTS RESET OR XIRQ SET X, INSTRUCTIONS MAY CLEAR X BUT CANNOT SET X Freescale Semiconductor, I Freescale Semiconductor, Inc. For More Information On This Product, Go to: www.freescale.com nc...

Upload: others

Post on 23-Oct-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

  • CPU12RG/DRev. 2, 11/2001

    CPU12 Reference Guide(for HCS12 and original M68HC12)

    Reference Guide

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    Figure 1. Programming Model

    7

    15

    15

    15

    15

    15

    D

    X

    Y

    SP

    PC

    A B

    NS X H I Z V C

    0

    0

    0

    0

    0

    0

    70

    CONDITION CODE REGISTER

    8-BIT ACCUMULATORS A AND B

    16-BIT DOUBLE ACCUMULATOR D

    INDEX REGISTER X

    INDEX REGISTER Y

    STACK POINTER

    PROGRAM COUNTER

    OR

    STOP DISABLE (IGNORE STOP OPCODES)RESET DEFAULT IS 1

    CARRY

    OVERFLOW

    ZERO

    NEGATIVE

    MASK (DISABLE) IRQ INTERRUPTS

    HALF-CARRY (USED IN BCD ARITHMETIC)

    MASK (DISABLE) XIRQ INTERRUPTSRESET OR XIRQ SET X,INSTRUCTIONS MAY CLEAR X BUT CANNOT SET X

    © Motorola, Inc., 2001

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    Stack and Memory Layout

    Interrupt Vector Locations

    Notation Used in Instruction Set Summary

    SP BEFOREINTERRUPT

    SP AFTERINTERRUPT

    HIGHER ADDRESSES

    LOWER ADDRESSES

    RTNLO

    RTNHI

    YLO

    YHI

    XLO

    XHI

    A

    B

    CCR

    STACK UPON ENTRY TO SERVICE ROUTINEIF SP WAS ODD BEFORE INTERRUPT

    STACK UPON ENTRY TO SERVICE ROUTINEIF SP WAS EVEN BEFORE INTERRUPT

    SP +8 RTNLO SP +9 SP +9 SP +10

    SP +6 YLO RTNHI SP +7 SP +7 RTNHI RTNLO SP +8

    SP +4 XLO YHI SP +5 SP +5 YHI YLO SP +6

    SP +2 A XHI SP +3 SP +4 XHI XLO SP +4

    SP CCR B SP +1 SP +1 B A SP +2

    SP –2 SP –1 SP –1 CCR SP

    $FFFE, $FFFF$FFFC, $FFFD$FFFA, $FFFB$FFF8, $FFF9$FFF6, $FFF7$FFF4, $FFF5$FFF2, $FFF3$FFC0–$FFF1

    Power-On (POR) or External ResetClock Monitor ResetComputer Operating Properly (COP Watchdog ResetUnimplemented Opcode TrapSoftware Interrupt Instruction (SWI)XIRQIRQDevice-Specific Interrupt Sources

    CPU Register NotationAccumulator A — A or a Index Register Y — Y or yAccumulator B — B or b Stack Pointer — SP, sp, or sAccumulator D — D or d Program Counter — PC, pc, or pIndex Register X — X or x Condition Code Register — CCR or c

    2 CPU12 Reference Guide (for HCS12 and original M68HC12) MOTOROLA

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    Explanation of Italic Expressions in Source Form Columnabc — A or B or CCR

    abcdxys — A or B or CCR or D or X or Y or SP. Some assemblers also allow T2 or T3.abd — A or B or D

    abdxys — A or B or D or X or Y or SPdxys — D or X or Y or SP

    msk8 — 8-bit mask, some assemblers require # symbol before valueopr8i — 8-bit immediate value

    opr16i — 16-bit immediate valueopr8a — 8-bit address used with direct address mode

    opr16a — 16-bit address valueoprx0_xysp — Indexed addressing postbyte code:

    oprx3,–xys Predecrement X or Y or SP by 1 . . . 8oprx3,+xys Preincrement X or Y or SP by 1 . . . 8oprx3,xys– Postdecrement X or Y or SP by 1 . . . 8oprx3,xys+ Postincrement X or Y or SP by 1 . . . 8oprx5,xysp 5-bit constant offset from X or Y or SP or PCabd,xysp Accumulator A or B or D offset from X or Y or SP or PC

    oprx3 — Any positive integer 1 . . . 8 for pre/post increment/decrementoprx5 — Any integer in the range –16 . . . +15oprx9 — Any integer in the range –256 . . . +255

    oprx16 — Any integer in the range –32,768 . . . 65,535page — 8-bit value for PPAGE, some assemblers require # symbol before this value

    rel8 — Label of branch destination within –256 to +255 locationsrel9 — Label of branch destination within –512 to +511 locations

    rel16 — Any label within 64K memory spacetrapnum — Any 8-bit integer in the range $30-$39 or $40-$FF

    xys — X or Y or SPxysp — X or Y or SP or PC

    Operators

    + — Addition

    ±

    — Subtraction

    • — Logical AND

    + — Logical OR (inclusive)

    ⊕ — Logical exclusive OR

    × — Multiplication

    ÷ — Division

    M — Negation. One’s complement (invert each bit of M)

    : — ConcatenateExample: A : B means the 16-bit value formed by concatenating 8-bit accumulator A with 8-bit accumulator B.A is in the high-order position.

    Continued on next page

    MOTOROLA CPU12 Reference Guide (for HCS12 and original M68HC12) 3

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    Operators (continued)

    ⇒ — TransferExample: (A) ⇒ M means the content of accumulator A is transferred to memory location M.

    ⇔ — ExchangeExample: D ⇔ X means exchange the contents of D with those of X.

    Address Mode NotationINH — Inherent; no operands in object codeIMM — Immediate; operand in object codeDIR — Direct; operand is the lower byte of an address from $0000 to $00FFEXT — Operand is a 16-bit addressREL — Two’s complement relative offset; for branch instructionsIDX — Indexed (no extension bytes); includes:

    5-bit constant offset from X, Y, SP, or PCPre/post increment/decrement by 1 . . . 8Accumulator A, B, or D offset

    IDX1 — 9-bit signed offset from X, Y, SP, or PC; 1 extension byteIDX2 — 16-bit signed offset from X, Y, SP, or PC; 2 extension bytes

    [IDX2] — Indexed-indirect; 16-bit offset from X, Y, SP, or PC[D, IDX] — Indexed-indirect; accumulator D offset from X, Y, SP, or PC

    Machine Codingdd — 8-bit direct address $0000 to $00FF. (High byte assumed to be $00).ee — High-order byte of a 16-bit constant offset for indexed addressing.eb — Exchange/Transfer post-byte. See Table 3 on page 22.ff — Low-order eight bits of a 9-bit signed constant offset for indexed addressing,

    or low-order byte of a 16-bit constant offset for indexed addressing.hh — High-order byte of a 16-bit extended address.ii — 8-bit immediate data value.jj — High-order byte of a 16-bit immediate data value.kk — Low-order byte of a 16-bit immediate data value.lb — Loop primitive (DBNE) post-byte. See Table 4 on page 23.ll — Low-order byte of a 16-bit extended address.mm — 8-bit immediate mask value for bit manipulation instructions.

    Set bits indicate bits to be affected.pg — Program page (bank) number used in CALL instruction.qq — High-order byte of a 16-bit relative offset for long branches.tn — Trap number $30–$39 or $40–$FF.rr — Signed relative offset $80 (–128) to $7F (+127).

    Offset relative to the byte following the relative offset byte, orlow-order byte of a 16-bit relative offset for long branches.

    xb — Indexed addressing post-byte. See Table 1 on page 20 and Table 2 on page 21.

    4 CPU12 Reference Guide (for HCS12 and original M68HC12) MOTOROLA

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    Access Detail

    Each code letter except (,), and comma equals one CPU cycle. Uppercase = 16-bit operation and lowercase = 8-bit operation. For complex sequences see the CPU12 Reference Manual (CPU12RM/AD) for more detailed information.

    Condition Codes Columns

    f — Free cycle, CPU doesn’t use busg — Read PPAGE internallyI — Read indirect pointer (indexed indirect)i — Read indirect PPAGE value (CALL indirect only)n — Write PPAGE internallyO — Optional program word fetch (P) if instruction is misaligned and has

    an odd number of bytes of object code — otherwise, appears as a free cycle (f); Page 2 prebyte treated as a separate 1-byte instruction

    P — Program word fetch (always an aligned-word read)r — 8-bit data readR — 16-bit data reads — 8-bit stack writeS — 16-bit stack writew — 8-bit data writeW — 16-bit data writeu — 8-bit stack readU — 16-bit stack readV — 16-bit vector fetch (always an aligned-word read)t — 8-bit conditional read (or free cycle)T — 16-bit conditional read (or free cycle)x — 8-bit conditional write (or free cycle)

    () — Indicate a microcode loop, — Indicates where an interrupt could be honored

    Special Cases

    PPP/P — Short branch, PPP if branch taken, P if notOPPP/OPO — Long branch, OPPP if branch taken, OPO if not

    – — Status bit not affected by operation.0 — Status bit cleared by operation.1 — Status bit set by operation.∆ — Status bit affected by operation.? — Status bit may be cleared or remain set, but is not set by operation.⇑ — Status bit may be set or remain cleared, but is not cleared by operation.? — Status bit may be changed by operation but the final state is not defined.! — Status bit used for a special purpose.

    MOTOROLA CPU12 Reference Guide (for HCS12 and original M68HC12) 5

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    Instruction Set Summary (Sheet 1 of 14)

    Source Form Operation Addr.ModeMachine

    Coding (hex)Access Detail

    S X H I N Z V CHCS12 HC12

    ABA (A) + (B) ⇒ AAdd Accumulators A and B

    INH 18 06 OO OO – – ∆ – ∆ ∆ ∆ ∆

    ABX (B) + (X) ⇒ XTranslates to LEAX B,X

    IDX 1A E5 Pf PP1 – – – – – – – –

    ABY (B) + (Y) ⇒ YTranslates to LEAY B,Y

    IDX 19 ED Pf PP1 – – – – – – – –

    ADCA #opr8iADCA opr8aADCA opr16aADCA oprx0_xyspADCA oprx9,xyspADCA oprx16,xyspADCA [D,xysp]ADCA [oprx16,xysp]

    (A) + (M) + C ⇒ AAdd with Carry to A

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    89 ii99 ddB9 hh llA9 xbA9 xb ffA9 xb ee ffA9 xbA9 xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    flPrfPfIPrfP

    – – ∆ – ∆ ∆ ∆ ∆

    ADCB #opr8iADCB opr8aADCB opr16aADCB oprx0_xyspADCB oprx9,xyspADCB oprx16,xyspADCB [D,xysp]ADCB [oprx16,xysp]

    (B) + (M) + C ⇒ BAdd with Carry to B

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    C9 iiD9 ddF9 hh llE9 xbE9 xb ffE9 xb ee ffE9 xbE9 xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – ∆ – ∆ ∆ ∆ ∆

    ADDA #opr8iADDA opr8aADDA opr16aADDA oprx0_xyspADDA oprx9,xyspADDA oprx16,xyspADDA [D,xysp]ADDA [oprx16,xysp]

    (A) + (M) ⇒ AAdd without Carry to A

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    8B ii9B ddBB hh llAB xbAB xb ffAB xb ee ffAB xbAB xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – ∆ – ∆ ∆ ∆ ∆

    ADDB #opr8iADDB opr8aADDB opr16aADDB oprx0_xyspADDB oprx9,xyspADDB oprx16,xyspADDB [D,xysp]ADDB [oprx16,xysp]

    (B) + (M) ⇒ BAdd without Carry to B

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    CB iiDB ddFB hh llEB xbEB xb ffEB xb ee ffEB xbEB xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – ∆ – ∆ ∆ ∆ ∆

    ADDD #opr16iADDD opr8aADDD opr16aADDD oprx0_xyspADDD oprx9,xyspADDD oprx16,xyspADDD [D,xysp]ADDD [oprx16,xysp]

    (A:B) + (M:M+1) ⇒ A:BAdd 16-Bit to D (A:B)

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    C3 jj kkD3 ddF3 hh llE3 xbE3 xb ffE3 xb ee ffE3 xbE3 xb ee ff

    PORPfRPORPfRPOfRPPfIfRPffIPRPf

    OPRfPROPRfPRPOfRPP

    fIfRfPfIPRfP

    – – – – ∆ ∆ ∆ ∆

    ANDA #opr8iANDA opr8aANDA opr16aANDA oprx0_xyspANDA oprx9,xyspANDA oprx16,xyspANDA [D,xysp]ANDA [oprx16,xysp]

    (A) • (M) ⇒ ALogical AND A with Memory

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    84 ii94 ddB4 hh llA4 xbA4 xb ffA4 xb ee ffA4 xbA4 xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – – – ∆ ∆ 0 –

    ANDB #opr8iANDB opr8aANDB opr16aANDB oprx0_xyspANDB oprx9,xyspANDB oprx16,xyspANDB [D,xysp]ANDB [oprx16,xysp]

    (B) • (M) ⇒ BLogical AND B with Memory

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    C4 iiD4 ddF4 hh llE4 xbE4 xb ffE4 xb ee ffE4 xbE4 xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – – – ∆ ∆ 0 –

    ANDCC #opr8i (CCR) • (M) ⇒ CCRLogical AND CCR with Memory

    IMM 10 ii P P ⇓ ⇓ ⇓ ⇓ ⇓ ⇓ ⇓ ⇓

    Note 1. Due to internal CPU requirements, the program word fetch is performed twice to the same address during this instruction.

    6 CPU12 Reference Guide (for HCS12 and original M68HC12) MOTOROLA

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    ASL opr16aASL oprx0_xyspASL oprx9,xyspASL oprx16,xyspASL [D,xysp]ASL [oprx16,xysp]ASLAASLB

    Arithmetic Shift Left

    Arithmetic Shift Left Accumulator AArithmetic Shift Left Accumulator B

    EXTIDX

    IDX1IDX2

    [D,IDX][IDX2]INHINH

    78 hh ll68 xb68 xb ff68 xb ee ff68 xb68 xb ee ff4858

    rPwOrPwrPwOfrPwPfIfrPwfIPrPwOO

    rOPwrPwrPOwfrPPwfIfrPwfIPrPw

    OO

    – – – – ∆ ∆ ∆ ∆

    ASLD

    Arithmetic Shift Left Double

    INH 59 O O – – – – ∆ ∆ ∆ ∆

    ASR opr16aASR oprx0_xyspASR oprx9,xyspASR oprx16,xyspASR [D,xysp]ASR [oprx16,xysp]ASRAASRB

    Arithmetic Shift Right

    Arithmetic Shift Right Accumulator AArithmetic Shift Right Accumulator B

    EXTIDX

    IDX1IDX2

    [D,IDX][IDX2]INHINH

    77 hh ll67 xb67 xb ff67 xb ee ff67 xb67 xb ee ff4757

    rPwOrPwrPwOfrPwPfIfrPwfIPrPwOO

    rOPwrPwrPOwfrPPwfIfrPwfIPrPw

    OO

    – – – – ∆ ∆ ∆ ∆

    BCC rel8 Branch if Carry Clear (if C = 0) REL 24 rr PPP/P1 PPP/P1 – – – – – – – –

    BCLR opr8a, msk8BCLR opr16a, msk8BCLR oprx0_xysp, msk8BCLR oprx9,xysp, msk8BCLR oprx16,xysp, msk8

    (M) • (mm) ⇒ MClear Bit(s) in Memory

    DIREXTIDX

    IDX1IDX2

    4D dd mm1D hh ll mm0D xb mm0D xb ff mm0D xb ee ff mm

    rPwOrPwPrPwOrPwPfrPwPO

    rPOwrPPwrPOwrPwP

    frPwOP

    – – – – ∆ ∆ 0 –

    BCS rel8 Branch if Carry Set (if C = 1) REL 25 rr PPP/P1 PPP/P1 – – – – – – – –

    BEQ rel8 Branch if Equal (if Z = 1) REL 27 rr PPP/P1 PPP/P1 – – – – – – – –

    BGE rel8 Branch if Greater Than or Equal(if N ⊕ V = 0) (signed)

    REL 2C rr PPP/P1 PPP/P1 – – – – – – – –

    BGND Place CPU in Background Modesee CPU12 Reference Manual

    INH 00 VfPPP VfPPP – – – – – – – –

    BGT rel8 Branch if Greater Than(if Z + (N ⊕ V) = 0) (signed)

    REL 2E rr PPP/P1 PPP/P1 – – – – – – – –

    BHI rel8 Branch if Higher(if C + Z = 0) (unsigned)

    REL 22 rr PPP/P1 PPP/P1 – – – – – – – –

    BHS rel8 Branch if Higher or Same (if C = 0) (unsigned) same function as BCC

    REL 24 rr PPP/P1 PPP/P1 – – – – – – – –

    BITA #opr8iBITA opr8aBITA opr16aBITA oprx0_xyspBITA oprx9,xyspBITA oprx16,xyspBITA [D,xysp]BITA [oprx16,xysp]

    (A) • (M)Logical AND A with MemoryDoes not change Accumulator or Memory

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    85 ii95 ddB5 hh llA5 xbA5 xb ffA5 xb ee ffA5 xbA5 xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – – – ∆ ∆ 0 –

    BITB #opr8iBITB opr8aBITB opr16aBITB oprx0_xyspBITB oprx9,xyspBITB oprx16,xyspBITB [D,xysp]BITB [oprx16,xysp]

    (B) • (M)Logical AND B with MemoryDoes not change Accumulator or Memory

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    C5 iiD5 ddF5 hh llE5 xbE5 xb ffE5 xb ee ffE5 xbE5 xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – – – ∆ ∆ 0 –

    BLE rel8 Branch if Less Than or Equal(if Z + (N ⊕ V) = 1) (signed)

    REL 2F rr PPP/P1 PPP/P1 – – – – – – – –

    BLO rel8 Branch if Lower(if C = 1) (unsigned)same function as BCS

    REL 25 rr PPP/P1 PPP/P1 – – – – – – – –

    Note 1. PPP/P indicates this instruction takes three cycles to refill the instruction queue if the branch is taken and one program fetch cycle if the branch is not taken.

    Instruction Set Summary (Sheet 2 of 14)

    Source Form Operation Addr.ModeMachine

    Coding (hex)Access Detail

    S X H I N Z V CHCS12 HC12

    C0

    b7 b0

    C0

    b7 b0A Bb7b0

    Cb7 b0

    MOTOROLA CPU12 Reference Guide (for HCS12 and original M68HC12) 7

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    BLS rel8 Branch if Lower or Same(if C + Z = 1) (unsigned)

    REL 23 rr PPP/P1 PPP/P1 – – – – – – – –

    BLT rel8 Branch if Less Than(if N ⊕ V = 1) (signed)

    REL 2D rr PPP/P1 PPP/P1 – – – – – – – –

    BMI rel8 Branch if Minus (if N = 1) REL 2B rr PPP/P1 PPP/P1 – – – – – – – –

    BNE rel8 Branch if Not Equal (if Z = 0) REL 26 rr PPP/P1 PPP/P1 – – – – – – – –

    BPL rel8 Branch if Plus (if N = 0) REL 2A rr PPP/P1 PPP/P1 – – – – – – – –

    BRA rel8 Branch Always (if 1 = 1) REL 20 rr PPP PPP – – – – – – – –

    BRCLR opr8a, msk8, rel8BRCLR opr16a, msk8, rel8BRCLR oprx0_xysp, msk8, rel8BRCLR oprx9,xysp, msk8, rel8BRCLR oprx16,xysp, msk8, rel8

    Branch if (M) • (mm) = 0(if All Selected Bit(s) Clear)

    DIREXTIDX

    IDX1IDX2

    4F dd mm rr1F hh ll mm rr0F xb mm rr0F xb ff mm rr0F xb ee ff mm rr

    rPPPrfPPPrPPPrfPPPPrfPPP

    rPPPrfPPPrPPP

    rffPPPfrPffPPP

    – – – – – – – –

    BRN rel8 Branch Never (if 1 = 0) REL 21 rr P P – – – – – – – –

    BRSET opr8, msk8, rel8BRSET opr16a, msk8, rel8BRSET oprx0_xysp, msk8, rel8BRSET oprx9,xysp, msk8, rel8BRSET oprx16,xysp, msk8, rel8

    Branch if (M) • (mm) = 0(if All Selected Bit(s) Set)

    DIREXTIDX

    IDX1IDX2

    4E dd mm rr1E hh ll mm rr0E xb mm rr0E xb ff mm rr0E xb ee ff mm rr

    rPPPrfPPPrPPPrfPPPPrfPPP

    rPPPrfPPPrPPP

    rffPPPfrPffPPP

    – – – – – – – –

    BSET opr8, msk8BSET opr16a, msk8BSET oprx0_xysp, msk8BSET oprx9,xysp, msk8BSET oprx16,xysp, msk8

    (M) + (mm) ⇒ MSet Bit(s) in Memory

    DIREXTIDX

    IDX1IDX2

    4C dd mm1C hh ll mm0C xb mm0C xb ff mm0C xb ee ff mm

    rPwOrPwPrPwOrPwPfrPwPO

    rPOwrPPwrPOwrPwP

    frPwOP

    – – – – ∆ ∆ 0 –

    BSR rel8 (SP) – 2 ⇒ SP; RTNH:RTNL ⇒ M(SP):M(SP+1)Subroutine address ⇒ PCBranch to Subroutine

    REL 07 rr SPPP PPPS – – – – – – – –

    BVC rel8 Branch if Overflow Bit Clear (if V = 0) REL 28 rr PPP/P1 PPP/P1 – – – – – – – –

    BVS rel8 Branch if Overflow Bit Set (if V = 1) REL 29 rr PPP/P1 PPP/P1 – – – – – – – –

    CALL opr16a, pageCALL oprx0_xysp, pageCALL oprx9,xysp, pageCALL oprx16,xysp, pageCALL [D,xysp]CALL [oprx16, xysp]

    (SP) – 2 ⇒ SP; RTNH:RTNL ⇒ M(SP):M(SP+1)(SP) – 1 ⇒ SP; (PPG) ⇒ M(SP); pg ⇒ PPAGE register; Program address ⇒ PC

    Call subroutine in extended memory(Program may be located on anotherexpansion memory page.)

    Indirect modes get program addressand new pg value based on pointer.

    EXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    4A hh ll pg4B xb pg4B xb ff pg4B xb ee ff pg4B xb4B xb ee ff

    gnSsPPPgnSsPPPgnSsPPPfgnSsPPPfIignSsPPPfIignSsPPP

    gnfSsPPPgnfSsPPPgnfSsPPPfgnfSsPPPfIignSsPPPfIignSsPPP

    – – – – – – – –

    CBA (A) – (B)Compare 8-Bit Accumulators

    INH 18 17 OO OO – – – – ∆ ∆ ∆ ∆

    CLC 0 ⇒ CTranslates to ANDCC #$FE

    IMM 10 FE P P – – – – – – – 0

    CLI 0 ⇒ ITranslates to ANDCC #$EF(enables I-bit interrupts)

    IMM 10 EF P P – – – 0 – – – –

    CLR opr16aCLR oprx0_xyspCLR oprx9,xyspCLR oprx16,xyspCLR [D,xysp]CLR [oprx16,xysp]CLRACLRB

    0 ⇒ M Clear Memory Location

    0 ⇒ A Clear Accumulator A0 ⇒ B Clear Accumulator B

    EXTIDX

    IDX1IDX2

    [D,IDX][IDX2]INHINH

    79 hh ll69 xb69 xb ff69 xb ee ff69 xb69 xb ee ff87C7

    PwOPwPwOPwPPIfwPIPwOO

    wOPPwPwOPwP

    PIfPwPIPPw

    OO

    – – – – 0 1 0 0

    CLV 0 ⇒ VTranslates to ANDCC #$FD

    IMM 10 FD P P – – – – – – 0 –

    Note 1. PPP/P indicates this instruction takes three cycles to refill the instruction queue if the branch is taken and one program fetch cycle if the branch is not taken.

    Instruction Set Summary (Sheet 3 of 14)

    Source Form Operation Addr.ModeMachine

    Coding (hex)Access Detail

    S X H I N Z V CHCS12 HC12

    8 CPU12 Reference Guide (for HCS12 and original M68HC12) MOTOROLA

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    CMPA #opr8iCMPA opr8aCMPA opr16aCMPA oprx0_xyspCMPA oprx9,xyspCMPA oprx16,xyspCMPA [D,xysp]CMPA [oprx16,xysp]

    (A) – (M)Compare Accumulator A with Memory

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    81 ii91 ddB1 hh llA1 xbA1 xb ffA1 xb ee ffA1 xb A1 xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – – – ∆ ∆ ∆ ∆

    CMPB #opr8iCMPB opr8aCMPB opr16aCMPB oprx0_xyspCMPB oprx9,xyspCMPB oprx16,xyspCMPB [D,xysp]CMPB [oprx16,xysp]

    (B) – (M)Compare Accumulator B with Memory

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    C1 iiD1 ddF1 hh llE1 xbE1 xb ffE1 xb ee ffE1 xbE1 xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – – – ∆ ∆ ∆ ∆

    COM opr16aCOM oprx0_xyspCOM oprx9,xyspCOM oprx16,xyspCOM [D,xysp]COM [oprx16,xysp]COMACOMB

    (M) ⇒ M equivalent to $FF – (M) ⇒ M1’s Complement Memory Location

    (A) ⇒ A Complement Accumulator A(B) ⇒ B Complement Accumulator B

    EXTIDX

    IDX1IDX2

    [D,IDX][IDX2]INHINH

    71 hh ll61 xb61 xb ff61 xb ee ff61 xb61 xb ee ff4151

    rPwOrPwrPwOfrPwPfIfrPwfIPrPwOO

    rOPwrPwrPOwfrPPwfIfrPwfIPrPw

    OO

    – – – – ∆ ∆ 0 1

    CPD #opr16iCPD opr8aCPD opr16aCPD oprx0_xyspCPD oprx9,xyspCPD oprx16,xyspCPD [D,xysp]CPD [oprx16,xysp]

    (A:B) – (M:M+1)Compare D to Memory (16-Bit)

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    8C jj kk9C ddBC hh llAC xbAC xb ffAC xb ee ffAC xbAC xb ee ff

    PORPfRPORPfRPOfRPPfIfRPffIPRPf

    OPRfPROPRfPRPOfRPP

    fIfRfPfIPRfP

    – – – – ∆ ∆ ∆ ∆

    CPS #opr16iCPS opr8aCPS opr16aCPS oprx0_xyspCPS oprx9,xyspCPS oprx16,xyspCPS [D,xysp]CPS [oprx16,xysp]

    (SP) – (M:M+1)Compare SP to Memory (16-Bit)

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    8F jj kk9F ddBF hh llAF xbAF xb ffAF xb ee ffAF xbAF xb ee ff

    PORPfRPORPfRPOfRPPfIfRPffIPRPf

    OPRfPROPRfPRPOfRPP

    fIfRfPfIPRfP

    – – – – ∆ ∆ ∆ ∆

    CPX #opr16iCPX opr8aCPX opr16aCPX oprx0_xyspCPX oprx9,xyspCPX oprx16,xyspCPX [D,xysp]CPX [oprx16,xysp]

    (X) – (M:M+1)Compare X to Memory (16-Bit)

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    8E jj kk9E ddBE hh llAE xbAE xb ffAE xb ee ffAE xbAE xb ee ff

    PORPfRPORPfRPOfRPPfIfRPffIPRPf

    OPRfPROPRfPRPOfRPP

    fIfRfPfIPRfP

    – – – – ∆ ∆ ∆ ∆

    CPY #opr16iCPY opr8aCPY opr16aCPY oprx0_xyspCPY oprx9,xyspCPY oprx16,xyspCPY [D,xysp]CPY [oprx16,xysp]

    (Y) – (M:M+1)Compare Y to Memory (16-Bit)

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    8D jj kk9D ddBD hh llAD xbAD xb ffAD xb ee ffAD xbAD xb ee ff

    PORPfRPORPfRPOfRPPfIfRPffIPRPf

    OPRfPROPRfPRPOfRPP

    fIfRfPfIPRfP

    – – – – ∆ ∆ ∆ ∆

    DAA Adjust Sum to BCDDecimal Adjust Accumulator A

    INH 18 07 OfO OfO – – – – ∆ ∆ ? ∆

    DBEQ abdxys, rel9 (cntr) – 1⇒ cntrif (cntr) = 0, then Branchelse Continue to next instruction

    Decrement Counter and Branch if = 0(cntr = A, B, D, X, Y, or SP)

    REL(9-bit)

    04 lb rr PPP (branch)PPO (no branch)

    PPP – – – – – – – –

    Instruction Set Summary (Sheet 4 of 14)

    Source Form Operation Addr.ModeMachine

    Coding (hex)Access Detail

    S X H I N Z V CHCS12 HC12

    MOTOROLA CPU12 Reference Guide (for HCS12 and original M68HC12) 9

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    DBNE abdxys, rel9 (cntr) – 1 ⇒ cntrIf (cntr) not = 0, then Branch;else Continue to next instruction

    Decrement Counter and Branch if ≠ 0(cntr = A, B, D, X, Y, or SP)

    REL(9-bit)

    04 lb rr PPP (branch)PPO (no branch)

    PPP – – – – – – – –

    DEC opr16aDEC oprx0_xyspDEC oprx9,xyspDEC oprx16,xyspDEC [D,xysp]DEC [oprx16,xysp]DECADECB

    (M) – $01 ⇒ MDecrement Memory Location

    (A) – $01 ⇒ A Decrement A(B) – $01 ⇒ B Decrement B

    EXTIDX

    IDX1IDX2

    [D,IDX][IDX2]INHINH

    73 hh ll63 xb63 xb ff63 xb ee ff63 xb63 xb ee ff4353

    rPwOrPwrPwOfrPwPfIfrPwfIPrPwOO

    rOPwrPwrPOwfrPPwfIfrPwfIPrPw

    OO

    – – – – ∆ ∆ ∆ –

    DES (SP) – $0001 ⇒ SPTranslates to LEAS –1,SP

    IDX 1B 9F Pf PP1 – – – – – – – –

    DEX (X) – $0001 ⇒ XDecrement Index Register X

    INH 09 O O – – – – – ∆ – –

    DEY (Y) – $0001 ⇒ YDecrement Index Register Y

    INH 03 O O – – – – – ∆ – –

    EDIV (Y:D) ÷ (X) ⇒ Y Remainder ⇒ D32 by 16 Bit ⇒ 16 Bit Divide (unsigned)

    INH 11 ffffffffffO ffffffffffO – – – – ∆ ∆ ∆ ∆

    EDIVS (Y:D) ÷ (X) ⇒ Y Remainder ⇒ D32 by 16 Bit ⇒ 16 Bit Divide (signed)

    INH 18 14 OffffffffffO OffffffffffO – – – – ∆ ∆ ∆ ∆

    EMACS opr16a 2 (M(X):M(X+1)) × (M(Y):M(Y+1)) + (M~M+3) ⇒ M~M+3

    16 by 16 Bit ⇒ 32 BitMultiply and Accumulate (signed)

    Special 18 12 hh ll ORROfffRRfWWP ORROfffRRfWWP – – – – ∆ ∆ ∆ ∆

    EMAXD oprx0_xyspEMAXD oprx9,xyspEMAXD oprx16,xyspEMAXD [D,xysp]EMAXD [oprx16,xysp]

    MAX((D), (M:M+1)) ⇒ DMAX of 2 Unsigned 16-Bit Values

    N, Z, V and C status bits reflect result ofinternal compare ((D) – (M:M+1))

    IDXIDX1IDX2

    [D,IDX][IDX2]

    18 1A xb18 1A xb ff18 1A xb ee ff18 1A xb18 1A xb ee ff

    ORPfORPOOfRPPOfIfRPfOfIPRPf

    ORfPORPOOfRPP

    OfIfRfPOfIPRfP

    – – – – ∆ ∆ ∆ ∆

    EMAXM oprx0_xyspEMAXM oprx9,xyspEMAXM oprx16,xyspEMAXM [D,xysp]EMAXM [oprx16,xysp]

    MAX((D), (M:M+1)) ⇒ M:M+1MAX of 2 Unsigned 16-Bit Values

    N, Z, V and C status bits reflect result ofinternal compare ((D) – (M:M+1))

    IDXIDX1IDX2

    [D,IDX][IDX2]

    18 1E xb18 1E xb ff18 1E xb ee ff18 1E xb18 1E xb ee ff

    ORPWORPWOOfRPWPOfIfRPWOfIPRPW

    ORPWORPWOOfRPWPOfIfRPWOfIPRPW

    – – – – ∆ ∆ ∆ ∆

    EMIND oprx0_xyspEMIND oprx9,xyspEMIND oprx16,xyspEMIND [D,xysp]EMIND [oprx16,xysp]

    MIN((D), (M:M+1)) ⇒ DMIN of 2 Unsigned 16-Bit Values

    N, Z, V and C status bits reflect result ofinternal compare ((D) – (M:M+1))

    IDXIDX1IDX2

    [D,IDX][IDX2]

    18 1B xb18 1B xb ff18 1B xb ee ff18 1B xb18 1B xb ee ff

    ORPfORPOOfRPPOfIfRPfOfIPRPf

    ORfPORPOOfRPP

    OfIfRfPOfIPRfP

    – – – – ∆ ∆ ∆ ∆

    EMINM oprx0_xyspEMINM oprx9,xyspEMINM oprx16,xyspEMINM [D,xysp]EMINM [oprx16,xysp]

    MIN((D), (M:M+1)) ⇒ M:M+1MIN of 2 Unsigned 16-Bit Values

    N, Z, V and C status bits reflect result ofinternal compare ((D) – (M:M+1))

    IDXIDX1IDX2

    [D,IDX][IDX2]

    18 1F xb18 1F xb ff18 1F xb ee ff18 1F xb18 1F xb ee ff

    ORPWORPWOOfRPWPOfIfRPWOfIPRPW

    ORPWORPWOOfRPWPOfIfRPWOfIPRPW

    – – – – ∆ ∆ ∆ ∆

    EMUL (D) × (Y) ⇒ Y:D16 by 16 Bit Multiply (unsigned)

    INH 13 ffO ffO – – – – ∆ ∆ – ∆

    EMULS (D) × (Y) ⇒ Y:D16 by 16 Bit Multiply (signed)

    INH 18 13 OfO OfO – – – – ∆ ∆ – ∆(if followed by page 2 instruction)

    OffO OfO

    EORA #opr8iEORA opr8aEORA opr16aEORA oprx0_xyspEORA oprx9,xyspEORA oprx16,xyspEORA [D,xysp]EORA [oprx16,xysp]

    (A) ⊕ (M) ⇒ AExclusive-OR A with Memory

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    88 ii98 ddB8 hh llA8 xbA8 xb ffA8 xb ee ffA8 xbA8 xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – – – ∆ ∆ 0 –

    Notes:1. Due to internal CPU requirements, the program word fetch is performed twice to the same address during this instruction.2. opr16a is an extended address specification. Both X and Y point to source operands.

    Instruction Set Summary (Sheet 5 of 14)

    Source Form Operation Addr.ModeMachine

    Coding (hex)Access Detail

    S X H I N Z V CHCS12 HC12

    10 CPU12 Reference Guide (for HCS12 and original M68HC12) MOTOROLA

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    EORB #opr8iEORB opr8aEORB opr16aEORB oprx0_xyspEORB oprx9,xyspEORB oprx16,xyspEORB [D,xysp]EORB [oprx16,xysp]

    (B) ⊕ (M) ⇒ BExclusive-OR B with Memory

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    C8 iiD8 ddF8 hh llE8 xbE8 xb ffE8 xb ee ffE8 xbE8 xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – – – ∆ ∆ 0 –

    ETBL oprx0_xysp (M:M+1)+ [(B)×((M+2:M+3) – (M:M+1))] ⇒ D16-Bit Table Lookup and Interpolate

    Initialize B, and index before ETBL. points at first table entry (M:M+1)and B is fractional part of lookup value

    (no indirect addr. modes or extensions allowed)

    IDX 18 3F xb ORRffffffP ORRffffffP – – – – ∆ ∆ – ∆?

    C Bit is undefined in HC12

    EXG abcdxys,abcdxys (r1) ⇔ (r2) (if r1 and r2 same size) or$00:(r1) ⇒ r2 (if r1=8-bit; r2=16-bit) or(r1low) ⇔ (r2) (if r1=16-bit; r2=8-bit)

    r1 and r2 may beA, B, CCR, D, X, Y, or SP

    INH B7 eb P P – – – – – – – –

    FDIV (D) ÷ (X) ⇒ X; Remainder ⇒ D16 by 16 Bit Fractional Divide

    INH 18 11 OffffffffffO OffffffffffO – – – – – ∆ ∆ ∆

    IBEQ abdxys, rel9 (cntr) + 1⇒ cntrIf (cntr) = 0, then Branchelse Continue to next instruction

    Increment Counter and Branch if = 0(cntr = A, B, D, X, Y, or SP)

    REL(9-bit)

    04 lb rr PPP (branch)PPO (no branch)

    PPP – – – – – – – –

    IBNE abdxys, rel9 (cntr) + 1⇒ cntrif (cntr) not = 0, then Branch;else Continue to next instruction

    Increment Counter and Branch if ≠ 0(cntr = A, B, D, X, Y, or SP)

    REL(9-bit)

    04 lb rr PPP (branch)PPO (no branch)

    PPP – – – – – – – –

    IDIV (D) ÷ (X) ⇒ X; Remainder ⇒ D16 by 16 Bit Integer Divide (unsigned)

    INH 18 10 OffffffffffO OffffffffffO – – – – – ∆ 0 ∆

    IDIVS (D) ÷ (X) ⇒ X; Remainder ⇒ D16 by 16 Bit Integer Divide (signed)

    INH 18 15 OffffffffffO OffffffffffO – – – – ∆ ∆ ∆ ∆

    INC opr16aINC oprx0_xyspINC oprx9,xyspINC oprx16,xyspINC [D,xysp]INC [oprx16,xysp]INCAINCB

    (M) + $01 ⇒ MIncrement Memory Byte

    (A) + $01 ⇒ A Increment Acc. A(B) + $01 ⇒ B Increment Acc. B

    EXTIDX

    IDX1IDX2

    [D,IDX][IDX2]INHINH

    72 hh ll62 xb62 xb ff62 xb ee ff62 xb62 xb ee ff4252

    rPwOrPwrPwOfrPwPfIfrPwfIPrPwOO

    rOPwrPwrPOwfrPPwfIfrPwfIPrPw

    OO

    – – – – ∆ ∆ ∆ –

    INS (SP) + $0001 ⇒ SPTranslates to LEAS 1,SP

    IDX 1B 81 Pf PP1 – – – – – – – –

    INX (X) + $0001 ⇒ XIncrement Index Register X

    INH 08 O O – – – – – ∆ – –

    INY (Y) + $0001 ⇒ YIncrement Index Register Y

    INH 02 O O – – – – – ∆ – –

    JMP opr16aJMP oprx0_xyspJMP oprx9,xyspJMP oprx16,xyspJMP [D,xysp]JMP [oprx16,xysp]

    Routine address ⇒ PC

    Jump

    EXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    06 hh ll05 xb05 xb ff05 xb ee ff05 xb05 xb ee ff

    PPPPPPPPPfPPPfIfPPPfIfPPP

    PPPPPPPPPfPPP

    fIfPPPfIfPPP

    – – – – – – – –

    Note 1. Due to internal CPU requirements, the program word fetch is performed twice to the same address during this instruction.

    Instruction Set Summary (Sheet 6 of 14)

    Source Form Operation Addr.ModeMachine

    Coding (hex)Access Detail

    S X H I N Z V CHCS12 HC12

    MOTOROLA CPU12 Reference Guide (for HCS12 and original M68HC12) 11

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    JSR opr8aJSR opr16aJSR oprx0_xyspJSR oprx9,xyspJSR oprx16,xyspJSR [D,xysp]JSR [oprx16,xysp]

    (SP) – 2 ⇒ SP;RTNH:RTNL ⇒ M(SP):M(SP+1);Subroutine address ⇒ PC

    Jump to Subroutine

    DIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    17 dd16 hh ll15 xb15 xb ff15 xb ee ff15 xb15 xb ee ff

    SPPPSPPPPPPSPPPSfPPPSfIfPPPSfIfPPPS

    PPPSPPPSPPPSPPPSfPPPS

    fIfPPPSfIfPPPS

    – – – – – – – –

    LBCC rel16 Long Branch if Carry Clear (if C = 0) REL 18 24 qq rr OPPP/OPO1 OPPP/OPO1 – – – – – – – –

    LBCS rel16 Long Branch if Carry Set (if C = 1) REL 18 25 qq rr OPPP/OPO1 OPPP/OPO1 – – – – – – – –

    LBEQ rel16 Long Branch if Equal (if Z = 1) REL 18 27 qq rr OPPP/OPO1 OPPP/OPO1 – – – – – – – –

    LBGE rel16 Long Branch Greater Than or Equal(if N ⊕ V = 0) (signed)

    REL 18 2C qq rr OPPP/OPO1 OPPP/OPO1 – – – – – – – –

    LBGT rel16 Long Branch if Greater Than(if Z + (N ⊕ V) = 0) (signed)

    REL 18 2E qq rr OPPP/OPO1 OPPP/OPO1 – – – – – – – –

    LBHI rel16 Long Branch if Higher(if C + Z = 0) (unsigned)

    REL 18 22 qq rr OPPP/OPO1 OPPP/OPO1 – – – – – – – –

    LBHS rel16 Long Branch if Higher or Same(if C = 0) (unsigned)same function as LBCC

    REL 18 24 qq rr OPPP/OPO1 OPPP/OPO1 – – – – – – – –

    LBLE rel16 Long Branch if Less Than or Equal(if Z + (N ⊕ V) = 1) (signed)

    REL 18 2F qq rr OPPP/OPO1 OPPP/OPO1 – – – – – – – –

    LBLO rel16 Long Branch if Lower(if C = 1) (unsigned)same function as LBCS

    REL 18 25 qq rr OPPP/OPO1 OPPP/OPO1 – – – – – – – –

    LBLS rel16 Long Branch if Lower or Same(if C + Z = 1) (unsigned)

    REL 18 23 qq rr OPPP/OPO1 OPPP/OPO1 – – – – – – – –

    LBLT rel16 Long Branch if Less Than(if N ⊕ V = 1) (signed)

    REL 18 2D qq rr OPPP/OPO1 OPPP/OPO1 – – – – – – – –

    LBMI rel16 Long Branch if Minus (if N = 1) REL 18 2B qq rr OPPP/OPO1 OPPP/OPO1 – – – – – – – –

    LBNE rel16 Long Branch if Not Equal (if Z = 0) REL 18 26 qq rr OPPP/OPO1 OPPP/OPO1 – – – – – – – –

    LBPL rel16 Long Branch if Plus (if N = 0) REL 18 2A qq rr OPPP/OPO1 OPPP/OPO1 – – – – – – – –

    LBRA rel16 Long Branch Always (if 1=1) REL 18 20 qq rr OPPP OPPP – – – – – – – –

    LBRN rel16 Long Branch Never (if 1 = 0) REL 18 21 qq rr OPO OPO – – – – – – – –

    LBVC rel16 Long Branch if Overflow Bit Clear (if V=0) REL 18 28 qq rr OPPP/OPO1 OPPP/OPO1 – – – – – – – –

    LBVS rel16 Long Branch if Overflow Bit Set (if V = 1) REL 18 29 qq rr OPPP/OPO1 OPPP/OPO1 – – – – – – – –

    LDAA #opr8iLDAA opr8aLDAA opr16aLDAA oprx0_xyspLDAA oprx9,xyspLDAA oprx16,xyspLDAA [D,xysp]LDAA [oprx16,xysp]

    (M) ⇒ ALoad Accumulator A

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    86 ii96 ddB6 hh llA6 xbA6 xb ffA6 xb ee ffA6 xbA6 xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – – – ∆ ∆ 0 –

    LDAB #opr8iLDAB opr8aLDAB opr16aLDAB oprx0_xyspLDAB oprx9,xyspLDAB oprx16,xyspLDAB [D,xysp]LDAB [oprx16,xysp]

    (M) ⇒ BLoad Accumulator B

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    C6 iiD6 ddF6 hh llE6 xbE6 xb ffE6 xb ee ffE6 xbE6 xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – – – ∆ ∆ 0 –

    LDD #opr16iLDD opr8aLDD opr16aLDD oprx0_xyspLDD oprx9,xyspLDD oprx16,xyspLDD [D,xysp]LDD [oprx16,xysp]

    (M:M+1) ⇒ A:BLoad Double Accumulator D (A:B)

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    CC jj kkDC ddFC hh llEC xbEC xb ffEC xb ee ffEC xbEC xb ee ff

    PORPfRPORPfRPOfRPPfIfRPffIPRPf

    OPRfPROPRfPRPOfRPP

    fIfRfPfIPRfP

    – – – – ∆ ∆ 0 –

    Note 1. OPPP/OPO indicates this instruction takes four cycles to refill the instruction queue if the branch is taken and three cycles if the branch is not taken.

    Instruction Set Summary (Sheet 7 of 14)

    Source Form Operation Addr.ModeMachine

    Coding (hex)Access Detail

    S X H I N Z V CHCS12 HC12

    12 CPU12 Reference Guide (for HCS12 and original M68HC12) MOTOROLA

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    LDS #opr16iLDS opr8aLDS opr16aLDS oprx0_xyspLDS oprx9,xyspLDS oprx16,xyspLDS [D,xysp]LDS [oprx16,xysp]

    (M:M+1) ⇒ SPLoad Stack Pointer

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    CF jj kkDF ddFF hh llEF xbEF xb ffEF xb ee ffEF xbEF xb ee ff

    PORPfRPORPfRPOfRPPfIfRPffIPRPf

    OPRfPROPRfPRPOfRPP

    fIfRfPfIPRfP

    – – – – ∆ ∆ 0 –

    LDX #opr16iLDX opr8aLDX opr16aLDX oprx0_xyspLDX oprx9,xyspLDX oprx16,xyspLDX [D,xysp]LDX [oprx16,xysp]

    (M:M+1) ⇒ XLoad Index Register X

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    CE jj kkDE ddFE hh llEE xbEE xb ffEE xb ee ffEE xbEE xb ee ff

    PORPfRPORPfRPOfRPPfIfRPffIPRPf

    OPRfPROPRfPRPOfRPP

    fIfRfPfIPRfP

    – – – – ∆ ∆ 0 –

    LDY #opr16iLDY opr8aLDY opr16aLDY oprx0_xyspLDY oprx9,xyspLDY oprx16,xyspLDY [D,xysp]LDY [oprx16,xysp]

    (M:M+1) ⇒ YLoad Index Register Y

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    CD jj kkDD ddFD hh llED xbED xb ffED xb ee ffED xbED xb ee ff

    PORPfRPORPfRPOfRPPfIfRPffIPRPf

    OPRfPROPRfPRPOfRPP

    fIfRfPfIPRfP

    – – – – ∆ ∆ 0 –

    LEAS oprx0_xyspLEAS oprx9,xyspLEAS oprx16,xysp

    Effective Address ⇒ SPLoad Effective Address into SP

    IDXIDX1IDX2

    1B xb1B xb ff1B xb ee ff

    PfPOPP

    PP1

    POPP

    – – – – – – – –

    LEAX oprx0_xyspLEAX oprx9,xyspLEAX oprx16,xysp

    Effective Address ⇒ XLoad Effective Address into X

    IDXIDX1IDX2

    1A xb1A xb ff1A xb ee ff

    PfPOPP

    PP1

    POPP

    – – – – – – – –

    LEAY oprx0_xyspLEAY oprx9,xyspLEAY oprx16,xysp

    Effective Address ⇒ YLoad Effective Address into Y

    IDXIDX1IDX2

    19 xb19 xb ff19 xb ee ff

    PfPOPP

    PP1

    POPP

    – – – – – – – –

    LSL opr16aLSL oprx0_xyspLSL oprx9,xyspLSL oprx16,xyspLSL [D,xysp]LSL [oprx16,xysp]LSLALSLB

    Logical Shift Leftsame function as ASL

    Logical Shift Accumulator A to LeftLogical Shift Accumulator B to Left

    EXTIDX

    IDX1IDX2

    [D,IDX][IDX2]INHINH

    78 hh ll68 xb68 xb ff68 xb ee ff68 xb68 xb ee ff4858

    rPwOrPwrPwOfrPPwfIfrPwfIPrPwOO

    rOPwrPwrPOwfrPPwfIfrPwfIPrPw

    OO

    – – – – ∆ ∆ ∆ ∆

    LSLD

    Logical Shift Left D Accumulatorsame function as ASLD

    INH 59 O O – – – – ∆ ∆ ∆ ∆

    LSR opr16aLSR oprx0_xyspLSR oprx9,xyspLSR oprx16,xyspLSR [D,xysp]LSR [oprx16,xysp]LSRALSRB

    Logical Shift Right

    Logical Shift Accumulator A to RightLogical Shift Accumulator B to Right

    EXTIDX

    IDX1IDX2

    [D,IDX][IDX2]INHINH

    74 hh ll64 xb64 xb ff64 xb ee ff64 xb64 xb ee ff4454

    rPwOrPwrPwOfrPwPfIfrPwfIPrPwOO

    rOPwrPwrPOwfrPPwfIfrPwfIPrPw

    OO

    – – – – 0 ∆ ∆ ∆

    LSRD

    Logical Shift Right D Accumulator

    INH 49 O O – – – – 0 ∆ ∆ ∆

    MAXA oprx0_xyspMAXA oprx9,xyspMAXA oprx16,xyspMAXA [D,xysp]MAXA [oprx16,xysp]

    MAX((A), (M)) ⇒ AMAX of 2 Unsigned 8-Bit Values

    N, Z, V and C status bits reflect result ofinternal compare ((A) – (M)).

    IDXIDX1IDX2

    [D,IDX][IDX2]

    18 18 xb18 18 xb ff18 18 xb ee ff18 18 xb18 18 xb ee ff

    OrPfOrPOOfrPPOfIfrPfOfIPrPf

    OrfPOrPOOfrPP

    OfIfrfPOfIPrfP

    – – – – ∆ ∆ ∆ ∆

    Note 1. Due to internal CPU requirements, the program word fetch is performed twice to the same address during this instruction.

    Instruction Set Summary (Sheet 8 of 14)

    Source Form Operation Addr.ModeMachine

    Coding (hex)Access Detail

    S X H I N Z V CHCS12 HC12

    C0

    b7 b0

    C0

    b7 b0A Bb7b0

    C0

    b7 b0

    C0

    b7 b0A Bb7b0

    MOTOROLA CPU12 Reference Guide (for HCS12 and original M68HC12) 13

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    MAXM oprx0_xyspMAXM oprx9,xyspMAXM oprx16,xyspMAXM [D,xysp]MAXM [oprx16,xysp]

    MAX((A), (M)) ⇒ MMAX of 2 Unsigned 8-Bit Values

    N, Z, V and C status bits reflect result ofinternal compare ((A) – (M)).

    IDXIDX1IDX2

    [D,IDX][IDX2]

    18 1C xb18 1C xb ff18 1C xb ee ff18 1C xb18 1C xb ee ff

    OrPwOrPwOOfrPwPOfIfrPwOfIPrPw

    OrPwOrPwOOfrPwPOfIfrPwOfIPrPw

    – – – – ∆ ∆ ∆ ∆

    MEM µ (grade) ⇒ M(Y);(X) + 4 ⇒ X; (Y) + 1 ⇒ Y; A unchanged

    if (A) < P1 or (A) > P2 then µ = 0, elseµ = MIN[((A) – P1)×S1, (P2 – (A))×S2, $FF]where:A = current crisp input value;X points at 4-byte data structure that describes a trapezoidal membership function (P1, P2, S1, S2);Y points at fuzzy input (RAM location).See CPU12 Reference Manual for special cases.

    Special 01 RRfOw RRfOw – – ? – ? ? ? ?

    MINA oprx0_xyspMINA oprx9,xyspMINA oprx16,xyspMINA [D,xysp]MINA [oprx16,xysp]

    MIN((A), (M)) ⇒ AMIN of 2 Unsigned 8-Bit Values

    N, Z, V and C status bits reflect result ofinternal compare ((A) – (M)).

    IDXIDX1IDX2

    [D,IDX][IDX2]

    18 19 xb18 19 xb ff18 19 xb ee ff18 19 xb18 19 xb ee ff

    OrPfOrPOOfrPPOfIfrPfOfIPrPf

    OrfPOrPOOfrPP

    OfIfrfPOfIPrfP

    – – – – ∆ ∆ ∆ ∆

    MINM oprx0_xyspMINM oprx9,xyspMINM oprx16,xyspMINM [D,xysp]MINM [oprx16,xysp]

    MIN((A), (M)) ⇒ MMIN of 2 Unsigned 8-Bit Values

    N, Z, V and C status bits reflect result ofinternal compare ((A) – (M)).

    IDXIDX1IDX2

    [D,IDX][IDX2]

    18 1D xb18 1D xb ff18 1D xb ee ff18 1D xb18 1D xb ee ff

    OrPwOrPwOOfrPwPOfIfrPwOfIPrPw

    OrPwOrPwOOfrPwPOfIfrPwOfIPrPw

    – – – – ∆ ∆ ∆ ∆

    MOVB #opr8, opr16a1

    MOVB #opr8i, oprx0_xysp1

    MOVB opr16a, opr16a1

    MOVB opr16a, oprx0_xysp1

    MOVB oprx0_xysp, opr16a1

    MOVB oprx0_xysp, oprx0_xysp1

    (M1) ⇒ M2Memory to Memory Byte-Move (8-Bit)

    IMM-EXTIMM-IDXEXT-EXTEXT-IDXIDX-EXTIDX-IDX

    18 0B ii hh ll18 08 xb ii18 0C hh ll hh ll18 09 xb hh ll18 0D xb hh ll18 0A xb xb

    OPwPOPwOOrPwPOOPrPwOrPwPOrPwO

    OPwPOPwO

    OrPwPOOPrPwOrPwPOrPwO

    – – – – – – – –

    MOVW #oprx16, opr16a1

    MOVW #opr16i, oprx0_xysp1

    MOVW opr16a, opr16a1

    MOVW opr16a, oprx0_xysp1

    MOVW oprx0_xysp, opr16a1

    MOVW oprx0_xysp, oprx0_xysp1

    (M:M+11) ⇒ M:M+12Memory to Memory Word-Move (16-Bit)

    IMM-EXTIMM-IDXEXT-EXTEXT-IDXIDX-EXTIDX-IDX

    18 03 jj kk hh ll18 00 xb jj kk18 04 hh ll hh ll18 01 xb hh ll18 05 xb hh ll18 02 xb xb

    OPWPOOPPWORPWPOOPRPWORPWPORPWO

    OPWPOOPPW

    ORPWPOOPRPWORPWPORPWO

    – – – – – – – –

    MUL (A) × (B) ⇒ A:B8 by 8 Unsigned Multiply

    INH 12 O ffO – – – – – – – ∆

    NEG opr16aNEG oprx0_xyspNEG oprx9,xyspNEG oprx16,xyspNEG [D,xysp]NEG [oprx16,xysp]NEGA

    NEGB

    0 – (M) ⇒ M equivalent to (M) + 1 ⇒ MTwo’s Complement Negate

    0 – (A) ⇒ A equivalent to (A) + 1 ⇒ ANegate Accumulator A0 – (B) ⇒ B equivalent to (B) + 1 ⇒ BNegate Accumulator B

    EXTIDX

    IDX1IDX2

    [D,IDX][IDX2]INH

    INH

    70 hh ll60 xb60 xb ff60 xb ee ff60 xb60 xb ee ff40

    50

    rPwOrPwrPwOfrPwPfIfrPwfIPrPwO

    O

    rOPwrPwrPOwfrPPwfIfrPwfIPrPw

    O

    O

    – – – – ∆ ∆ ∆ ∆

    NOP No Operation INH A7 O O – – – – – – – –

    ORAA #opr8iORAA opr8aORAA opr16aORAA oprx0_xyspORAA oprx9,xyspORAA oprx16,xyspORAA [D,xysp]ORAA [oprx16,xysp]

    (A) + (M) ⇒ ALogical OR A with Memory

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    8A ii9A ddBA hh llAA xbAA xb ffAA xb ee ffAA xbAA xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – – – ∆ ∆ 0 –

    Note 1. The first operand in the source code statement specifies the source for the move.

    Instruction Set Summary (Sheet 9 of 14)

    Source Form Operation Addr.ModeMachine

    Coding (hex)Access Detail

    S X H I N Z V CHCS12 HC12

    14 CPU12 Reference Guide (for HCS12 and original M68HC12) MOTOROLA

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    ORAB #opr8iORAB opr8aORAB opr16aORAB oprx0_xyspORAB oprx9,xyspORAB oprx16,xyspORAB [D,xysp]ORAB [oprx16,xysp]

    (B) + (M) ⇒ BLogical OR B with Memory

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    CA iiDA ddFA hh llEA xbEA xb ffEA xb ee ffEA xbEA xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – – – ∆ ∆ 0 –

    ORCC #opr8i (CCR) + M ⇒ CCRLogical OR CCR with Memory

    IMM 14 ii P P ⇑ – ⇑ ⇑ ⇑ ⇑ ⇑ ⇑

    PSHA (SP) – 1 ⇒ SP; (A) ⇒ M(SP)Push Accumulator A onto Stack

    INH 36 Os Os – – – – – – – –

    PSHB (SP) – 1 ⇒ SP; (B) ⇒ M(SP)Push Accumulator B onto Stack

    INH 37 Os Os – – – – – – – –

    PSHC (SP) – 1 ⇒ SP; (CCR) ⇒ M(SP)Push CCR onto Stack

    INH 39 Os Os – – – – – – – –

    PSHD (SP) – 2 ⇒ SP; (A:B) ⇒ M(SP):M(SP+1)Push D Accumulator onto Stack

    INH 3B OS OS – – – – – – – –

    PSHX (SP) – 2 ⇒ SP; (XH:XL) ⇒ M(SP):M(SP+1)Push Index Register X onto Stack

    INH 34 OS OS – – – – – – – –

    PSHY (SP) – 2 ⇒ SP; (YH:YL) ⇒ M(SP):M(SP+1)Push Index Register Y onto Stack

    INH 35 OS OS – – – – – – – –

    PULA (M(SP)) ⇒ A; (SP) + 1 ⇒ SPPull Accumulator A from Stack

    INH 32 ufO ufO – – – – – – – –

    PULB (M(SP)) ⇒ B; (SP) + 1 ⇒ SPPull Accumulator B from Stack

    INH 33 ufO ufO – – – – – – – –

    PULC (M(SP)) ⇒ CCR; (SP) + 1 ⇒ SPPull CCR from Stack

    INH 38 ufO ufO ∆ ⇓ ∆ ∆ ∆ ∆ ∆ ∆

    PULD (M(SP):M(SP+1)) ⇒ A:B; (SP) + 2 ⇒ SPPull D from Stack

    INH 3A UfO UfO – – – – – – – –

    PULX (M(SP):M(SP+1)) ⇒ XH:XL; (SP) + 2 ⇒ SPPull Index Register X from Stack

    INH 30 UfO UfO – – – – – – – –

    PULY (M(SP):M(SP+1)) ⇒ YH:YL; (SP) + 2 ⇒ SPPull Index Register Y from Stack

    INH 31 UfO UfO – – – – – – – –

    REV MIN-MAX rule evaluationFind smallest rule input (MIN).Store to rule outputs unless fuzzy output is already larger (MAX).

    For rule weights see REVW.

    Each rule input is an 8-bit offset from the base address in Y. Each rule output is an 8-bit offset from the base address in Y. $FE separates rule inputs from rule outputs. $FF terminates the rule list.

    REV may be interrupted.

    Special 18 3A Orf(t,tx)O Orf(t,tx)O – – ? – ? ? ∆ ?(exit + re-entry replaces comma

    above if interrupted)

    ff + Orf(t, ff + Orf(t,

    REVW MIN-MAX rule evaluationFind smallest rule input (MIN),Store to rule outputs unless fuzzy output is already larger (MAX).

    Rule weights supported, optional.

    Each rule input is the 16-bit address of a fuzzy input. Each rule output is the 16-bit address of a fuzzy output. The value $FFFE separates rule inputs from rule outputs. $FFFF terminates the rule list.

    REVW may be interrupted.

    Special 18 3B ORf(t,Tx)O ORf(t,Tx)O – – ? – ? ? ∆ !(loop to read weight if enabled)

    (r,RfRf) (r,RfRf)

    (exit + re-entry replaces comma above if interrupted)

    ffff + ORf(t, fff + ORf(t,

    Instruction Set Summary (Sheet 10 of 14)

    Source Form Operation Addr.ModeMachine

    Coding (hex)Access Detail

    S X H I N Z V CHCS12 HC12

    MOTOROLA CPU12 Reference Guide (for HCS12 and original M68HC12) 15

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    ROL opr16aROL oprx0_xyspROL oprx9,xyspROL oprx16,xyspROL [D,xysp]ROL [oprx16,xysp]ROLAROLB

    Rotate Memory Left through Carry

    Rotate A Left through CarryRotate B Left through Carry

    EXTIDX

    IDX1IDX2

    [D,IDX][IDX2]INHINH

    75 hh ll65 xb65 xb ff65 xb ee ff65 xb65 xb ee ff4555

    rPwOrPwrPwOfrPwPfIfrPwfIPrPwOO

    rOPwrPwrPOwfrPPwfIfrPwfIPrPw

    OO

    – – – – ∆ ∆ ∆ ∆

    ROR opr16aROR oprx0_xyspROR oprx9,xyspROR oprx16,xyspROR [D,xysp]ROR [oprx16,xysp]RORARORB

    Rotate Memory Right through Carry

    Rotate A Right through CarryRotate B Right through Carry

    EXTIDX

    IDX1IDX2

    [D,IDX][IDX2]INHINH

    76 hh ll66 xb66 xb ff66 xb ee ff66 xb66 xb ee ff4656

    rPwOrPwrPwOfrPwPfIfrPwfIPrPwOO

    rOPwrPwrPOwfrPPwfIfrPwfIPrPw

    OO

    – – – – ∆ ∆ ∆ ∆

    RTC (M(SP)) ⇒ PPAGE; (SP) + 1 ⇒ SP;(M(SP):M(SP+1)) ⇒ PCH:PCL;(SP) + 2 ⇒ SPReturn from Call

    INH 0A uUnfPPP uUnPPP – – – – – – – –

    RTI (M(SP)) ⇒ CCR; (SP) + 1 ⇒ SP (M(SP):M(SP+1)) ⇒ B:A; (SP) + 2 ⇒ SP (M(SP):M(SP+1)) ⇒ XH:XL; (SP) + 4 ⇒ SP(M(SP):M(SP+1)) ⇒ PCH:PCL; (SP) – 2 ⇒ SP(M(SP):M(SP+1)) ⇒ YH:YL; (SP) + 4 ⇒ SPReturn from Interrupt

    INH 0B uUUUUPPP uUUUUPPP ∆ ⇓ ∆ ∆ ∆ ∆ ∆ ∆(with interrupt pending)

    uUUUUVfPPP uUUUUfVfPPP

    RTS (M(SP):M(SP+1)) ⇒ PCH:PCL;(SP) + 2 ⇒ SPReturn from Subroutine

    INH 3D UfPPP UfPPP – – – – – – – –

    SBA (A) – (B) ⇒ ASubtract B from A

    INH 18 16 OO OO – – – – ∆ ∆ ∆ ∆

    SBCA #opr8iSBCA opr8aSBCA opr16aSBCA oprx0_xyspSBCA oprx9,xyspSBCA oprx16,xyspSBCA [D,xysp]SBCA [oprx16,xysp]

    (A) – (M) – C ⇒ ASubtract with Borrow from A

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    82 ii92 ddB2 hh llA2 xbA2 xb ffA2 xb ee ffA2 xbA2 xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – – – ∆ ∆ ∆ ∆

    SBCB #opr8iSBCB opr8aSBCB opr16aSBCB oprx0_xyspSBCB oprx9,xyspSBCB oprx16,xyspSBCB [D,xysp]SBCB [oprx16,xysp]

    (B) – (M) – C ⇒ BSubtract with Borrow from B

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    C2 iiD2 ddF2 hh llE2 xbE2 xb ffE2 xb ee ffE2 xbE2 xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – – – ∆ ∆ ∆ ∆

    SEC 1 ⇒ CTranslates to ORCC #$01

    IMM 14 01 P P – – – – – – – 1

    SEI 1 ⇒ I; (inhibit I interrupts)Translates to ORCC #$10

    IMM 14 10 P P – – – 1 – – – –

    SEV 1 ⇒ VTranslates to ORCC #$02

    IMM 14 02 P P – – – – – – 1 –

    SEX abc,dxys $00:(r1) ⇒ r2 if r1, bit 7 is 0 or$FF:(r1) ⇒ r2 if r1, bit 7 is 1

    Sign Extend 8-bit r1 to 16-bit r2r1 may be A, B, or CCRr2 may be D, X, Y, or SP

    Alternate mnemonic for TFR r1, r2

    INH B7 eb P P – – – – – – – –

    Instruction Set Summary (Sheet 11 of 14)

    Source Form Operation Addr.ModeMachine

    Coding (hex)Access Detail

    S X H I N Z V CHCS12 HC12

    C b7 b0

    Cb7 b0

    16 CPU12 Reference Guide (for HCS12 and original M68HC12) MOTOROLA

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    STAA opr8aSTAA opr16aSTAA oprx0_xyspSTAA oprx9,xyspSTAA oprx16,xyspSTAA [D,xysp]STAA [oprx16,xysp]

    (A) ⇒ MStore Accumulator A to Memory

    DIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    5A dd7A hh ll6A xb6A xb ff6A xb ee ff6A xb6A xb ee ff

    PwPwOPwPwOPwPPIfwPIPw

    PwwOPPwPwOPwP

    PIfPwPIPPw

    – – – – ∆ ∆ 0 –

    STAB opr8aSTAB opr16aSTAB oprx0_xyspSTAB oprx9,xyspSTAB oprx16,xyspSTAB [D,xysp]STAB [oprx16,xysp]

    (B) ⇒ MStore Accumulator B to Memory

    DIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    5B dd7B hh ll6B xb6B xb ff6B xb ee ff6B xb6B xb ee ff

    PwPwOPwPwOPwPPIfwPIPw

    PwwOPPwPwOPwP

    PIfPwPIPPw

    – – – – ∆ ∆ 0 –

    STD opr8aSTD opr16aSTD oprx0_xyspSTD oprx9,xyspSTD oprx16,xyspSTD [D,xysp]STD [oprx16,xysp]

    (A) ⇒ M, (B) ⇒ M+1Store Double Accumulator

    DIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    5C dd7C hh ll6C xb6C xb ff6C xb ee ff6C xb6C xb ee ff

    PWPWOPWPWOPWPPIfWPIPW

    PWWOPPWPWOPWP

    PIfPWPIPPW

    – – – – ∆ ∆ 0 –

    STOP (SP) – 2 ⇒ SP;RTNH:RTNL ⇒ M(SP):M(SP+1);(SP) – 2 ⇒ SP; (YH:YL) ⇒ M(SP):M(SP+1);(SP) – 2 ⇒ SP; (XH:XL) ⇒ M(SP):M(SP+1);(SP) – 2 ⇒ SP; (B:A) ⇒ M(SP):M(SP+1);(SP) – 1 ⇒ SP; (CCR) ⇒ M(SP);STOP All Clocks

    Registers stacked to allow quicker recovery by interrupt.

    If S control bit = 1, the STOP instruction is disabled and acts like a two-cycle NOP.

    INH 18 3E (entering STOP) – – – – – – – –

    OOSSSSsf OOSSSfSs

    (exiting STOP)

    fVfPPP fVfPPP

    (continue)

    ff fO

    (if STOP disabled)

    OO OO

    STS opr8aSTS opr16aSTS oprx0_xyspSTS oprx9,xyspSTS oprx16,xyspSTS [D,xysp]STS [oprx16,xysp]

    (SPH:SPL) ⇒ M:M+1Store Stack Pointer

    DIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    5F dd7F hh ll6F xb6F xb ff6F xb ee ff6F xb6F xb ee ff

    PWPWOPWPWOPWPPIfWPIPW

    PWWOPPWPWOPWP

    PIfPWPIPPW

    – – – – ∆ ∆ 0 –

    STX opr8aSTX opr16aSTX oprx0_xyspSTX oprx9,xyspSTX oprx16,xyspSTX [D,xysp]STX [oprx16,xysp]

    (XH:XL) ⇒ M:M+1Store Index Register X

    DIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    5E dd7E hh ll6E xb6E xb ff6E xb ee ff6E xb6E xb ee ff

    PWPWOPWPWOPWPPIfWPIPW

    PWWOPPWPWOPWP

    PIfPWPIPPW

    – – – – ∆ ∆ 0 –

    STY opr8aSTY opr16aSTY oprx0_xyspSTY oprx9,xyspSTY oprx16,xyspSTY [D,xysp]STY [oprx16,xysp]

    (YH:YL) ⇒ M:M+1Store Index Register Y

    DIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    5D dd7D hh ll6D xb6D xb ff6D xb ee ff6D xb6D xb ee ff

    PWPWOPWPWOPWPPIfWPIPW

    PWWOPPWPWOPWP

    PIfPWPIPPW

    – – – – ∆ ∆ 0 –

    SUBA #opr8iSUBA opr8aSUBA opr16aSUBA oprx0_xyspSUBA oprx9,xyspSUBA oprx16,xyspSUBA [D,xysp]SUBA [oprx16,xysp]

    (A) – (M) ⇒ ASubtract Memory from Accumulator A

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    80 ii90 ddB0 hh llA0 xbA0 xb ffA0 xb ee ffA0 xbA0 xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – – – ∆ ∆ ∆ ∆

    Instruction Set Summary (Sheet 12 of 14)

    Source Form Operation Addr.ModeMachine

    Coding (hex)Access Detail

    S X H I N Z V CHCS12 HC12

    MOTOROLA CPU12 Reference Guide (for HCS12 and original M68HC12) 17

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    SUBB #opr8iSUBB opr8aSUBB opr16aSUBB oprx0_xyspSUBB oprx9,xyspSUBB oprx16,xyspSUBB [D,xysp]SUBB [oprx16,xysp]

    (B) – (M) ⇒ BSubtract Memory from Accumulator B

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    C0 iiD0 ddF0 hh llE0 xbE0 xb ffE0 xb ee ffE0 xbE0 xb ee ff

    PrPfrPOrPfrPOfrPPfIfrPffIPrPf

    PrfPrOPrfPrPOfrPP

    fIfrfPfIPrfP

    – – – – ∆ ∆ ∆ ∆

    SUBD #opr16iSUBD opr8aSUBD opr16aSUBD oprx0_xyspSUBD oprx9,xyspSUBD oprx16,xyspSUBD [D,xysp]SUBD [oprx16,xysp]

    (D) – (M:M+1) ⇒ DSubtract Memory from D (A:B)

    IMMDIREXTIDX

    IDX1IDX2

    [D,IDX][IDX2]

    83 jj kk93 ddB3 hh llA3 xbA3 xb ffA3 xb ee ffA3 xbA3 xb ee ff

    PORPfRPORPfRPOfRPPfIfRPffIPRPf

    OPRfPROPRfPRPOfRPP

    fIfRfPfIPRfP

    – – – – ∆ ∆ ∆ ∆

    SWI (SP) – 2 ⇒ SP;RTNH:RTNL ⇒ M(SP):M(SP+1);(SP) – 2 ⇒ SP; (YH:YL) ⇒ M(SP):M(SP+1);(SP) – 2 ⇒ SP; (XH:XL) ⇒ M(SP):M(SP+1);(SP) – 2 ⇒ SP; (B:A) ⇒ M(SP):M(SP+1);(SP) – 1 ⇒ SP; (CCR) ⇒ M(SP)1 ⇒ I; (SWI Vector) ⇒ PCSoftware Interrupt

    INH 3F VSPSSPSsP* VSPSSPSsP* – – – 1 – – – –

    (for Reset)

    1 1 – 1 – – – –VfPPP VfPPP

    *The CPU also uses the SWI microcode sequence for hardware interrupts and unimplemented opcode traps. Reset uses the VfPPP variation of this sequence.

    TAB (A) ⇒ BTransfer A to B

    INH 18 0E OO OO – – – – ∆ ∆ 0 –

    TAP (A) ⇒ CCRTranslates to TFR A , CCR

    INH B7 02 P P ∆ ⇓ ∆ ∆ ∆ ∆ ∆ ∆

    TBA (B) ⇒ ATransfer B to A

    INH 18 0F OO OO – – – – ∆ ∆ 0 –

    TBEQ abdxys,rel9 If (cntr) = 0, then Branch;else Continue to next instruction

    Test Counter and Branch if Zero(cntr = A, B, D, X,Y, or SP)

    REL(9-bit)

    04 lb rr PPP (branch)PPO (no branch)

    PPP – – – – – – – –

    TBL oprx0_xysp (M) + [(B) × ((M+1) – (M))] ⇒ A8-Bit Table Lookup and Interpolate

    Initialize B, and index before TBL. points at first 8-bit table entry (M) and B is fractional part of lookup value.

    (no indirect addressing modes or extensions allowed)

    IDX 18 3D xb ORfffP OrrffffP – – – – ∆ ∆ – ∆?

    C Bit is undefinedin HC12

    TBNE abdxys,rel9 If (cntr) not = 0, then Branch;else Continue to next instruction

    Test Counter and Branch if Not Zero(cntr = A, B, D, X,Y, or SP)

    REL(9-bit)

    04 lb rr PPP (branch)PPO (no branch)

    PPP – – – – – – – –

    TFR abcdxys,abcdxys (r1) ⇒ r2 or $00:(r1) ⇒ r2 or (r1[7:0]) ⇒ r2

    Transfer Register to Registerr1 and r2 may be A, B, CCR, D, X, Y, or SP

    INH B7 eb P P – – – – – – – –

    or

    ∆ ⇓ ∆ ∆ ∆ ∆ ∆ ∆

    TPA (CCR) ⇒ ATranslates to TFR CCR ,A

    INH B7 20 P P – – – – – – – –

    Instruction Set Summary (Sheet 13 of 14)

    Source Form Operation Addr.ModeMachine

    Coding (hex)Access Detail

    S X H I N Z V CHCS12 HC12

    18 CPU12 Reference Guide (for HCS12 and original M68HC12) MOTOROLA

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    TRAP trapnum (SP) – 2 ⇒ SP;RTNH:RTNL ⇒ M(SP):M(SP+1);(SP) – 2 ⇒ SP; (YH:YL) ⇒ M(SP):M(SP+1);(SP) – 2 ⇒ SP; (XH:XL) ⇒ M(SP):M(SP+1);(SP) – 2 ⇒ SP; (B:A) ⇒ M(SP):M(SP+1);(SP) – 1 ⇒ SP; (CCR) ⇒ M(SP)1 ⇒ I; (TRAP Vector) ⇒ PC

    Unimplemented opcode trap

    INH 18 tntn = $30–$39or $40–$FF

    OVSPSSPSsP OfVSPSSPSsP – – – 1 – – – –

    TST opr16aTST oprx0_xyspTST oprx9,xyspTST oprx16,xyspTST [D,xysp]TST [oprx16,xysp]TSTATSTB

    (M) – 0Test Memory for Zero or Minus

    (A) – 0 Test A for Zero or Minus(B) – 0 Test B for Zero or Minus

    EXTIDX

    IDX1IDX2

    [D,IDX][IDX2]INHINH

    F7 hh llE7 xbE7 xb ffE7 xb ee ffE7 xbE7 xb ee ff97D7

    rPOrPfrPOfrPPfIfrPffIPrPfOO

    rOPrfPrPOfrPP

    fIfrfPfIPrfP

    OO

    – – – – ∆ ∆ 0 0

    TSX (SP) ⇒ XTranslates to TFR SP,X

    INH B7 75 P P – – – – – – – –

    TSY (SP) ⇒ YTranslates to TFR SP,Y

    INH B7 76 P P – – – – – – – –

    TXS (X) ⇒ SPTranslates to TFR X,SP

    INH B7 57 P P – – – – – – – –

    TYS (Y) ⇒ SPTranslates to TFR Y,SP

    INH B7 67 P P – – – – – – – –

    WAI (SP) – 2 ⇒ SP;RTNH:RTNL ⇒ M(SP):M(SP+1);(SP) – 2 ⇒ SP; (YH:YL) ⇒ M(SP):M(SP+1);(SP) – 2 ⇒ SP; (XH:XL) ⇒ M(SP):M(SP+1);(SP) – 2 ⇒ SP; (B:A) ⇒ M(SP):M(SP+1);(SP) – 1 ⇒ SP; (CCR) ⇒ M(SP);WAIT for interrupt

    INH 3E OSSSSsf OSSSfSsf – – – – – – – –

    (after interrupt) or

    fVfPPP VfPPP – – – 1 – – – –

    or

    – 1 – 1 – – – –

    WAV

    Calculate Sum of Products and Sum of Weights for Weighted Average Calculation

    Initialize B, X, and Y before WAV. B specifies number of ele-ments. X points at first element in Si list. Y points at first ele-ment in Fi list.

    All Si and Fi elements are 8-bits.

    If interrupted, six extra bytes of stack used for intermediate values

    Special 18 3C Of(frr,ffff)OOff(frr,fffff)O

    – – ? – ? ∆ ? ?

    (add if interrupt)

    SSS + UUUrr, SSSf + UUUrr

    wavr

    pseudo-instruction

    see WAV

    Resume executing an interrupted WAV instruction (recover in-termediate results from stack rather than initializing them to zero)

    Special 3C UUUrr,ffff(frr,ffff)O

    UUUrrfffff(frr,fffff)O

    – – ? – ? ∆ ? ?

    (exit + re-entry replaces commaabove if interrupted)

    SSS + UUUrr, SSSf + UUUrr

    XGDX (D) ⇔ (X)Translates to EXG D, X

    INH B7 C5 P P – – – – – – – –

    XGDY (D) ⇔ (Y)Translates to EXG D, Y

    INH B7 C6 P P – – – – – – – –

    Instruction Set Summary (Sheet 14 of 14)

    Source Form Operation Addr.ModeMachine

    Coding (hex)Access Detail

    S X H I N Z V CHCS12 HC12

    Fi

    i 1=

    B

    ∑ X⇒SiFii 1=

    B

    ∑ Y:D⇒ and

    MOTOROLA CPU12 Reference Guide (for HCS12 and original M68HC12) 19

    For More Information On This Product, Go to: www.freescale.com

  • CPU12R

    G/D

    20 Table 1. Indexed Addressing Mode Postbyte Encoding (xb)00 10 20 30 40 50 60 70 80 90 A0 B0 C0

    ,PConst

    D0–16,PC

    5b const

    E0n,X

    9b const

    F0n,SP

    9b const

    ,PConst

    D1–15,PC

    5b const

    E1–n,X

    9b const

    F1–n,SP

    9b const

    ,PConst

    D2–14,PC

    5b const

    E2n,X

    16b const

    F2n,SP

    16b const

    ,PConst

    D3–13,PC

    5b const

    E3[n,X]

    16b indr

    F3[n,SP]

    16b indr

    ,PConst

    D4–12,PC

    5b const

    E4A,X

    A offset

    F4A,SP

    A offset

    ,PConst

    D5–11,PC

    5b const

    E5B,X

    B offset

    F5B,SP

    B offset

    ,PConst

    D6–10,PC

    5b const

    E6D,X

    D offset

    F6D,SP

    D offset

    ,PConst

    D7–9,PC

    5b const

    E7[D,X]

    D indirect

    F7[D,SP]

    D indirect

    ,PConst

    D8–8,PC

    5b const

    E8n,Y

    9b const

    F8n,PC

    9b const

    ,PConst

    D9–7,PC

    5b const

    E9–n,Y

    9b const

    F9–n,PC

    9b const

    0,PConst

    DA–6,PC

    5b const

    EAn,Y

    16b const

    FAn,PC

    16b const

    1,PConst

    DB–5,PC

    5b const

    EB[n,Y]

    16b indr

    FB[n,PC]

    16b indr

    2,PConst

    DC–4,PC

    5b const

    ECA,Y

    A offset

    FCA,PC

    A offset

    3,PConst

    DD–3,PC

    5b const

    EDB,Y

    B offset

    FDB,PC

    B offset

    4,PConst

    DE–2,PC

    5b const

    EED,Y

    D offset

    FED,PC

    D offset

    5,PConst

    DF–1,PC

    5b const

    EF[D,Y]

    D indirect

    FF[D,PC]

    D indirect

    Freescale Semiconductor, Inc.

    CP

    U12 R

    eference Guide

    (for HC

    S12 and original M

    68H

    C12)

    MO

    TO

    RO

    LA

    0,X5b const

    –16,X5b const

    1,+Xpre-inc

    1,X+post-inc

    0,Y5b const

    –16,Y5b const

    1,+Ypre-inc

    1,Y+post-inc

    0,SP5b const

    –16,SP5b const

    1,+SPpre-inc

    1,SP+post-inc

    05b c

    011,X

    5b const

    11–15,X

    5b const

    212,+X

    pre-inc

    312,X+

    post-inc

    411,Y

    5b const

    51–15,Y

    5b const

    612,+Y

    pre-inc

    712,Y+

    post-inc

    811,SP

    5b const

    91–15,SP

    5b const

    A12,+SP

    pre-inc

    B12,SP+

    post-inc

    C11

    5b c02

    2,X5b const

    12–14,X

    5b const

    223,+X

    pre-inc

    323,X+

    post-inc

    422,Y

    5b const

    52–14,Y

    5b const

    623,+Y

    pre-inc

    723,Y+

    post-inc

    822,SP

    5b const

    92–14,SP

    5b const

    A23,+SP

    pre-inc

    B23,SP+

    post-inc

    C22

    5b c03

    3,X5b const

    13–13,X

    5b const

    234,+X

    pre-inc

    334,X+

    post-inc

    433,Y

    5b const

    53–13,Y

    5b const

    634,+Y

    pre-inc

    734,Y+

    post-inc

    833,SP

    5b const

    93–13,SP

    5b const

    A34,+SP

    pre-inc

    B34,SP+

    post-inc

    C33

    5b c04

    4,X5b const

    14–12,X

    5b const

    245,+X

    pre-inc

    345,X+

    post-inc

    444,Y

    5b const

    54–12,Y

    5b const

    645,+Y

    pre-inc

    745,Y+

    post-inc

    844,SP

    5b const

    94–12,SP

    5b const

    A45,+SP

    pre-inc

    B45,SP+

    post-inc

    C44

    5b c05

    5,X5b const

    15–11,X

    5b const

    256,+X

    pre-inc

    356,X+

    post-inc

    455,Y

    5b const

    55–11,Y

    5b const

    656,+Y

    pre-inc

    756,Y+

    post-inc

    855,SP

    5b const

    95–11,SP

    5b const

    A56,+SP

    pre-inc

    B56,SP+

    post-inc

    C55

    5b c06

    6,X5b const

    16–10,X

    5b const

    267,+X

    pre-inc

    367,X+

    post-inc

    466,Y

    5b const

    56–10,Y

    5b const

    667,+Y

    pre-inc

    767,Y+

    post-inc

    866,SP

    5b const

    96–10,SP

    5b const

    A67,+SP

    pre-inc

    B67,SP+

    post-inc

    C66

    5b c07

    7,X5b const

    17–9,X

    5b const

    278,+X

    pre-inc

    378,X+

    post-inc

    477,Y

    5b const

    57–9,Y

    5b const

    678,+Y

    pre-inc

    778,Y+

    post-inc

    877,SP

    5b const

    97–9,SP

    5b const

    A78,+SP

    pre-inc

    B78,SP+

    post-inc

    C77

    5b c08

    8,X5b const

    18–8,X

    5b const

    288,–X

    pre-dec

    388,X–

    post-dec

    488,Y

    5b const

    58–8,Y

    5b const

    688,–Y

    pre-dec

    788,Y–

    post-dec

    888,SP

    5b const

    98–8,SP

    5b const

    A88,–SP

    pre-dec

    B88,SP–

    post-dec

    C88

    5b c09

    9,X5b const

    19–7,X

    5b const

    297,–X

    pre-dec

    397,X–

    post-dec

    499,Y

    5b const

    59–7,Y

    5b const

    697,–Y

    pre-dec

    797,Y–

    post-dec

    899,SP

    5b const

    99–7,SP

    5b const

    A97,–SP

    pre-dec

    B97,SP–

    post-dec

    C99

    5b c0A

    10,X5b const

    1A–6,X

    5b const

    2A6,–X

    pre-dec

    3A6,X–

    post-dec

    4A10,Y

    5b const

    5A–6,Y

    5b const

    6A6,–Y

    pre-dec

    7A6,Y–

    post-dec

    8A10,SP

    5b const

    9A–6,SP

    5b const

    AA6,–SP

    pre-dec

    BA6,SP–

    post-dec

    CA1

    5b c0B

    11,X5b const

    1B–5,X

    5b const

    2B5,–X

    pre-dec

    3B5,X–

    post-dec

    4B11,Y

    5b const

    5B–5,Y

    5b const

    6B5,–Y

    pre-dec

    7B5,Y–

    post-dec

    8B11,SP

    5b const

    9B–5,SP

    5b const

    AB5,–SP

    pre-dec

    BB5,SP–

    post-dec

    CB1

    5b c0C

    12,X5b const

    1C–4,X

    5b const

    2C4,–X

    pre-dec

    3C4,X–

    post-dec

    4C12,Y

    5b const

    5C–4,Y

    5b const

    6C4,–Y

    pre-dec

    7C4,Y–

    post-dec

    8C12,SP

    5b const

    9C–4,SP

    5b const

    AC4,–SP

    pre-dec

    BC4,SP–

    post-dec

    CC1

    5b c0D

    13,X5b const

    1D–3,X

    5b const

    2D3,–X

    pre-dec

    3D3,X–

    post-dec

    4D13,Y

    5b const

    5D–3,Y

    5b const

    6D3,–Y

    pre-dec

    7D3,Y–

    post-dec

    8D13,SP

    5b const

    9D–3,SP

    5b const

    AD3,–SP

    pre-dec

    BD3,SP–

    post-dec

    CD1

    5b c0E

    14,X5b const

    1E–2,X

    5b const

    2E2,–X

    pre-dec

    3E2,X–

    post-dec

    4E14,Y

    5b const

    5E–2,Y

    5b const

    6E2,–Y

    pre-dec

    7E2,Y–

    post-dec

    8E14,SP

    5b const

    9E–2,SP

    5b const

    AE2,–SP

    pre-dec

    BE2,SP–

    post-dec

    CE1

    5b c0F

    15,X5b const

    1F–1,X

    5b const

    2F1,–X

    pre-dec

    3F1,X–

    post-dec

    4F15,Y

    5b const

    5F–1,Y

    5b const

    6F1,–Y

    pre-dec

    7F1,Y–

    post-dec

    8F15,SP

    5b const

    9F–1,SP

    5b const

    AF1,–SP

    pre-dec

    BF1,SP–

    post-dec

    CF1

    5b c

    postbyte (hex)B0#,REG

    type

    type offset used

    source code syntax

    Key to Table 1

    Fre

    esc

    ale

    Se

    mic

    on

    du

    cto

    r, I

    For More Information On This Product, Go to: www.freescale.com

    nc

    ...

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    Table 2. Indexed Addressing Mode Summary

    PostbyteCode (xb)

    OperandSyntax Comments

    rr0nnnnn ,rn,r–n,r

    5-bit constant offset n = –16 to +15rr can specify X, Y, SP, or PC

    111rr0zs n,r–n,r

    Constant offset (9- or 16-bit signed)z- 0 = 9-bit with sign in LSB of postbyte (s)

    1 = 16-bitif z = s = 1, 16-bit offset indexed-indirect (see below)rr can specify X, Y, SP, or PC

    rr1pnnnn n,–rn,+rn,r– n,r+

    Auto predecrement, preincrement, postdecrement, or postincrement; p = pre-(0) or post-(1), n = –8 to –1, +1 to +8rr can specify X, Y, or SP (PC not a valid choice)

    111rr1aa A,rB,rD,r

    Accumulator offset (unsigned 8-bit or 16-bit)aa - 00 = A

    01 = B10 = D (16-bit)11 = see accumulator D offset indexed-indirect

    rr can specify X, Y, SP, or PC

    111rr011 [n,r] 16-bit offset indexed-indirectrr can specify X, Y, SP, or PC

    111rr111 [D,r] Accumulator D offset indexed-indirectrr can specify X, Y, SP, or PC

    MOTOROLA CPU12 Reference Guide (for HCS12 and original M68HC12) 21

    For More Information On This Product, Go to: www.freescale.com

  • CPU12R

    G/D

    22

    Table 3. Transfer and Exchange Postbyte Encoding

    6 7

    YL ⇒ A SPL ⇒ A

    YL ⇒ B SPL ⇒ B

    YL ⇒ CCR SPL ⇒ CCR

    2 Y ⇒ TMP2 SP ⇒ TMP2

    Y ⇒ D SP ⇒ D

    Y ⇒ X SP ⇒ X

    Y ⇒ Y SP ⇒ Y

    Y ⇒ SP SP ⇒ SP

    E F

    YL ⇒ A$00:A ⇒ Y

    SPL ⇒ A$00:A ⇒ SP

    YL ⇒ B$FF:B ⇒ Y

    SPL ⇒ B$FF:B ⇒ SP

    XYL ⇒ CCR

    $FF:CCR ⇒ YSPL ⇒ CCR

    $FF:CCR ⇒ SP

    2 Y ⇔ TMP2 SP ⇔ TMP2

    Y ⇔ D SP ⇔ D

    Y ⇔ X SP ⇔ X

    Y ⇔ Y SP ⇔ Y

    Y ⇔ SP SP ⇔ SP

    Freescale Semiconductor, Inc.

    CP

    U12 R

    eference Guide

    (for HC

    S12 and original M

    68H

    C12)

    MO

    TO

    RO

    LA

    TRANSFERS

    ⇓ LS MS⇒ 0 1 2 3 4 5

    0 A ⇒ A B ⇒ A CCR ⇒ A TMP3L ⇒ A B ⇒ A XL ⇒ A

    1 A ⇒ B B ⇒ B CCR ⇒ B TMP3L ⇒ B B ⇒ B XL ⇒ B

    2 A ⇒ CCR B ⇒ CCR CCR ⇒ CCR TMP3L ⇒ CCR B ⇒ CCR XL ⇒ CCR

    3 sex:A ⇒ TMP2 sex:B ⇒ TMP2 sex:CCR ⇒ TMP2 TMP3 ⇒ TMP2 D ⇒ TMP2 X ⇒ TMP

    4sex:A ⇒ DSEX A,D

    sex:B ⇒ DSEX B,D

    sex:CCR ⇒ DSEX CCR,D

    TMP3 ⇒ D D ⇒ D X ⇒ D

    5sex:A ⇒ XSEX A,X

    sex:B ⇒ XSEX B,X

    sex:CCR ⇒ XSEX CCR,X

    TMP3 ⇒ X D ⇒ X X ⇒ X

    6sex:A ⇒ YSEX A,Y

    sex:B ⇒ YSEX B,Y

    sex:CCR ⇒ YSEX CCR,Y

    TMP3 ⇒ Y D ⇒ Y X ⇒ Y

    7sex:A ⇒ SPSEX A,SP

    sex:B ⇒ SPSEX B,SP

    sex:CCR ⇒ SPSEX CCR,SP

    TMP3 ⇒ SP D ⇒ SP X ⇒ SP

    EXCHANGES

    ⇓ LS MS⇒ 8 9 A B C D

    0 A ⇔ A B ⇔ A CCR ⇔ ATMP3L ⇒ A

    $00:A ⇒ TMP3B ⇒ AA ⇒ B

    XL ⇒ A$00:A ⇒ X

    1 A ⇔ B B ⇔ B CCR ⇔ BTMP3L ⇒ B

    $FF:B ⇒ TMP3B ⇒ B

    $FF ⇒ AXL ⇒ B

    $FF:B ⇒ X

    2 A ⇔ CCR B ⇔ CCR CCR ⇔ CCRTMP3L ⇒ CCR

    $FF:CCR ⇒ TMP3B ⇒ CCR

    $FF:CCR ⇒ DXL ⇒ CCR

    $FF:CCR ⇒

    3$00:A ⇒ TMP2

    TMP2L ⇒ A$00:B ⇒ TMP2

    TMP2L ⇒ B$00:CCR ⇒ TMP2

    TMP2L ⇒ CCRTMP3 ⇔ TMP2 D ⇔ TMP2 X ⇔ TMP

    4 $00:A ⇒ D $00:B ⇒ D$00:CCR ⇒ D

    B ⇒ CCRTMP3 ⇔ D D ⇔ D X ⇔ D

    5$00:A ⇒ X

    XL ⇒ A$00:B ⇒ X

    XL ⇒ B$00:CCR ⇒ X

    XL ⇒ CCRTMP3 ⇔ X D ⇔ X X ⇔ X

    6 $00:A ⇒ Y

    YL ⇒ A$00:B ⇒ Y

    YL ⇒ B$00:CCR ⇒ Y

    YL ⇒ CCRTMP3 ⇔ Y D ⇔ Y X ⇔ Y

    7$00:A ⇒ SP

    SPL ⇒ A$00:B ⇒ SP

    SPL ⇒ B$00:CCR ⇒ SP

    SPL ⇒ CCRTMP3 ⇔ SP D ⇔ SP X ⇔ SP

    TMP2 and TMP3 registers are for factory use only.

    Fre

    esc

    ale

    Se

    mic

    on

    du

    cto

    r, I

    For More Information On This Product, Go to: www.freescale.com

    nc

    ...

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    Table 4. Loop Primitive Postbyte Encoding (lb)00 A

    DBEQ(+)

    10 ADBEQ

    (–)

    20 ADBNE

    (+)

    30 ADBNE

    (–)

    40 ATBEQ

    (+)

    50 ATBEQ

    (–)

    60 ATBNE

    (+)

    70 ATBNE

    (–)

    80 AIBEQ

    (+)

    90 AIBEQ

    (–)

    A0 AIBNE

    (+)

    B0 AIBNE

    (–)01 B

    DBEQ(+)

    11 BDBEQ

    (–)

    21 BDBNE

    (+)

    31 BDBNE

    (–)

    41 BTBEQ

    (+)

    51 BTBEQ

    (–)

    61 BTBNE

    (+)

    71 BTBNE

    (–)

    81 BIBEQ

    (+)

    91 BIBEQ

    (–)

    A1 BIBNE

    (+)

    B1 BIBNE

    (–)02

    —12

    —22

    —32

    —42

    —52

    —62

    —72

    —82

    —92

    —A2

    —B2

    03—

    13—

    23—

    33—

    43—

    53—

    63—

    73—

    83—

    93—

    A3—

    B3—

    04 DDBEQ

    (+)

    14 DDBEQ

    (–)

    24 DDBNE

    (+)

    34 DDBNE

    (–)

    44 DTBEQ

    (+)

    54 DTBEQ

    (–)

    64 DTBNE

    (+)

    74 DTBNE

    (–)

    84 DIBEQ

    (+)

    94 DIBEQ

    (–)

    A4 DIBNE

    (+)

    B4 DIBNE

    (–)05 X

    DBEQ(+)

    15 XDBEQ

    (–)

    25 XDBNE

    (+)

    35 XDBNE

    (–)

    45 XTBEQ

    (+)

    55 XTBEQ

    (–)

    65 XTBNE

    (+)

    75 XTBNE

    (–)

    85 XIBEQ

    (+)

    95 XIBEQ

    (–)

    A5 XIBNE

    (+)

    B5 XIBNE

    (–)06 Y

    DBEQ(+)

    16 YDBEQ

    (–)

    26 YDBNE

    (+)

    36 YDBNE

    (–)

    46 YTBEQ

    (+)

    56 YTBEQ

    (–)

    66 YTBNE

    (+)

    76 YTBNE

    (–)

    86 YIBEQ

    (+)

    96 YIBEQ

    (–)

    A6 YIBNE

    (+)

    B6 YIBNE

    (–)07 SP

    DBEQ(+)

    17 SPDBEQ

    (–)

    27 SPDBNE

    (+)

    37 SPDBNE

    (–)

    47 SPTBEQ

    (+)

    57 SPTBEQ

    (–)

    67 SPTBNE

    (+)

    77 SPTBNE

    (–)

    87 SPIBEQ

    (+)

    97 SPIBEQ

    (–)

    A7 SPIBNE

    (+)

    B7 SPIBNE

    (–)

    postbyte (hex)B0 A_BEQ

    (–)

    counter used

    sign of 9-bit relative branch offset(lower eight bits are an extension byte following postbyte)

    branch condition

    Key to Table 4

    (bit 3 is don’t care)

    Table 5. Branch/Complementary Branch

    Branch Complementary BranchTest Mnemonic Opcode Boolean Test Mnemonic Opcode Comment r>m BGT 2E Z + (N ⊕ V) = 0 r≤m BLE 2F Signed r≥m BGE 2C N ⊕ V = 0 rm BGT 2E Signed rm BHI 22 C + Z = 0 r≤m BLS 23 Unsigned r≥m BHS/BCC 24 C = 0 rm BHI 22 Unsigned r

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    Memory Expansion

    There are three basic memory expansion configurations in the M68HC12 and HCS12 MCU Families.

    1. Basic 64 Kbyte memory map with no additional expanded memory support

    2. >5 megabyte expanded memory support with 8-bit PPAGE, DPAGE, and EPAGE registers (MC68HC812A4 only)

    3. >1 megabyte expanded memory support with 6-bit PPAGE register only — This configuration applies to all currently available HC12 and HCS12 devices with >60 Kbytes of on-chip FLASH memory.

    Memory precedence— Highest —On-chip registers (usually $0000 or $1000)BDM ROM (only when BDM active)On-chip RAMOn-chip EEPROMOn-chip program memory (FLASH or ROM)Expansion windows (on MCUs with expanded memory)Other external memory— Lowest —

    CPU sees 64 Kbytes of address space (CPU_ADDR [15:0])PPAGE 8-bit register to select 1 of 256 —16 Kbyte program pages

    or 6-bit register to select 1 of 64 — 16 Kbyte program pagesDPAGE 8-bit register to select 1 of 256 — 4 Kbyte data pagesEPAGE 8-bit register to select 1 of 256 — 1 Kbyte extra pages

    Extended address is up to 22 bits (EXT_ADDR [21:0])Program expansion window works with CALL and RTC instructions to simplify program access to extended memory space. Data and extra expansion windows (when present) use traditional banked expansion memory techniques.

    24 CPU12 Reference Guide (for HCS12 and original M68HC12) MOTOROLA

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    Program windowIf CPU_ADDR [15:0] = $8000–BFFF and PWEN = 1

    Then EXT_ADDR [21:0] = PPAGE [7:0]:CPU_ADDR [13:0]or EXT_ADDR [19:0] = PPAGE [5:0]:CPU_ADDR [13:0]

    Program window works with CALL/RTC to automate bank switching. 256 pages (banks) of 16 Kbytes each = 4 megabytes or 64 pages (banks) of 16 Kbytes each = 1 megabyte

    Data window (when present)If CPU_ADDR [15:0] = $7000–7FFF and DWEN = 1

    Then EXT_ADDR [21:0] = 1:1:DPAGE [7:0]:CPU_ADDR [11:0]User program controls DPAGE value

    Extra window (when present)If CPU_ADDR [15:0] = $0000–03FF and EWDIR = 1

    and EWEN = 1or CPU_ADDR [15:0] = $0400–07FF and EWDIR = 0

    and EWEN = 1Then EXT_ADDR [21:0] = 1:1:1:1:EPAGE [7:0]:CPU_ADDR

    [9:0]User program controls EPAGE value

    CPU address not in any enabled windowEXT_ADDR [21:0] = 1:1:1:1:1:1:CPU_ADDR [15:0] (4 megabyte map)

    or (for 1 megabyte map)If CPU_ADDR [15:0] = $0000–3FFF

    Then EXT_ADDR [19:0] = 1:1:1:1:0:1:CPU_ADDR [13:0]This causes the FLASH at PPAGE $3D to also appearas unpaged memory at CPU addresses $0000–3FFF.

    If CPU_ADDR [15:0] = $4000–7FFFThen EXT_ADDR [19:0] = 1:1:1:1:1:0:CPU_ADDR [13:0]

    This causes the FLASH at PPAGE $3E to also appearas unpaged memory at CPU addresses $4000–7FFF.

    If CPU_ADDR [15:0] = $C000–FFFFThen EXT_ADDR [19:0] = 1:1:1:1:1:1:CPU_ADDR [13:0]

    This causes the FLASH at PPAGE $3F to also appear as unpaged memory at CPU addresses $C000–FFFF.

    MOTOROLA CPU12 Reference Guide (for HCS12 and original M68HC12) 25

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    Figure 2. Memory Mapping in 1-Megabyte Map

    64 PAGES OF 16 KBYTES EACH VIEWED THROUGH P-WINDOW0 0000

    3 0000

    C 0000

    E FFFFF 0000

    F 8000

    F BFFF

    F FFFFFFFF

    0000

    1FFF

    3FFF

    5FFF

    6FFF

    7FFF

    DFFF

    BFFF

    9FFFP WINDOW

    PPAGE($3F)

    63

    PPAGE($3E)

    62

    PPAGE($3D)

    61

    PPAGE($3C)

    60

    CPU_ADDR EXT_ADR

    2000

    4000

    040007FF

    6000

    7000

    8000 F 0000

    A000

    C000 F C000

    E000

    “PPAGE($3D)

    “image”

    “PPAGE($3E)

    “image”

    “PPAGE($3F)

    “image”

    26 CPU12 Reference Guide (for HCS12 and original M68HC12) MOTOROLA

    For More Information On This Product, Go to: www.freescale.com

  • CPU12RG/D

    F

    ree

    sca

    le S

    em

    ico

    nd

    uc

    tor,

    I

    Freescale Semiconductor, Inc.n

    c..

    .

    Figure 3. Memory Mapping in 4-Megabyte Map

    224

    225

    226

    227

    228

    229

    230

    231

    232

    233

    234

    235

    236

    237

    238

    239

    240

    241

    242

    243

    244

    245

    246

    247

    248

    249

    250

    251

    252

    253

    254

    255

    DPAGE($F1)241

    DPAGE($F2)242

    DPAGE($F3)243

    DPAGE($F4)244

    DPAGE($F5)245

    DPAGE($F6)246

    DPAGE($F7)247

    DPAGE($F0)240

    DPAGE($F8)248

    DPAGE($F9)249

    DPAGE($FA)250

    DPAGE($FB)251

    DPAGE($FC)252

    DPAGE($FD)253

    DPAGE($FE)254

    DPAGE($FF)255

    PPAGE($FC)252

    PPAGE($FD)253

    PPAGE($FE)254

    PPAGE($FF)255

    .

    .

    ....

    .

    .

    .

    256 pages of 1 Kbyte each viewed

    256 pages of 4 Kbytes each viewed through D-window (1 M)

    256 pages of 16 Kbytes each viewed through P-window (4 M)00 0000

    30 0000

    3C 0000

    3E FFFF3F 0000

    3F 7FFF3F 8000

    3F BFFF3F C000

    3F FFFFFFFF

    0000

    040007FF

    1FFF2000

    3FFF4000

    5FFF6000

    6FFF7000

    7FFF8000

    DFFFE000

    BFFFC000

    9FFFA000

    D window

    P window

    E window(EWDIR = 1)

    E window(EWDIR = 0)

    CPU_ADDR EXT_ADDR

    through E-window (256 K)

    MOTOROLA CPU12 Reference Guide (for HCS12 and original M68HC12) 27

    For More Information On This Product, Go to: www.freescale.com

  • CPU12R

    G/D

    28 Table 6. CPU12 Opcode Map (Sheet 1 of 2)1

    BB2

    D0 3SUBB

    DI 2

    E0 3-6SUBB

    ID 2-4

    F0 3SUBB

    EX 31

    PB2

    D1 3CMPB

    DI 2

    E1 3-6CMPB

    ID 2-4

    F1 3CMPB

    EX 31

    CB2

    D2 3SBCB

    DI 2

    E2 3-6SBCB

    ID 2-4

    F2 3SBCB

    EX 32

    DD3

    D3 3ADDD

    DI 2

    E3 3-6ADDD

    ID 2-4

    F3 3ADDD

    EX 31

    DB2

    D4 3ANDB

    DI 2

    E4 3-6ANDB

    ID 2-4

    F4 3ANDB

    EX 31

    B2

    D5 3BITB

    DI 2

    E5 3-6BITB

    ID 2-4

    F5 3BITB

    EX 31

    AB2

    D6 3LDAB

    DI 2

    E6 3-6LDAB

    ID 2-4

    F6 3LDAB

    EX 31

    RB1

    D7 1TSTB

    IH 1

    E7 3-6TST

    ID 2-4

    F7 3TST

    EX 31

    RB2

    D8 3EORB

    DI 2

    E8 3-6EORB

    ID 2-4

    F8 3EORB

    EX 31

    CB2

    D9 3ADCB

    DI 2

    E9 3-6ADCB

    ID 2-4

    F9 3ADCB

    EX 31

    AB2

    DA 3ORAB

    DI 2

    EA 3-6ORAB

    ID 2-4

    FA 3ORAB

    EX 31

    DB2

    DB 3ADDB

    DI 2

    EB 3-6ADDB

    ID 2-4

    FB 3ADDB

    EX 32

    D3

    DC 3LDD

    DI 2

    EC 3-6LDD

    ID 2-4

    FC 3LDD

    EX 32

    Y3

    DD 3LDY

    DI 2

    ED 3-6LDY

    ID 2-4

    FD 3LDY

    EX 32

    X3

    DE 3LDX

    DI 2

    EE 3-6LDX

    ID 2-4

    FE 3LDX

    EX 32

    S3

    DF 3LDS

    DI 2

    EF 3-6LDS

    ID 2-4

    FF 3LDS

    EX 3

    different)

    Freescale Semiconductor, Inc.

    CP

    U12 R

    eference Guide

    (for HC

    S12 and original M

    68H

    C12)

    MO

    TO

    RO

    LA

    00 †5BGND

    IH 1

    10 1ANDCCIM 2

    20 3BRA

    RL 2

    30 3PULX

    IH 1

    40 1NEGA

    IH 1

    50 1NEGB

    IH 1

    60 3-6NEG

    ID 2-4

    70 4NEG

    EX 3

    80 1SUBA

    IM 2

    90 3SUBA

    DI 2

    A0 3-6SUBA

    ID 2-4

    B0 3SUBA

    EX 3

    C0SU

    IM01 5

    MEMIH 1

    11 11EDIV

    IH 1

    21 1BRN

    RL 2

    31 3PULY

    IH 1

    41 1COMA

    IH 1

    51 1COMB

    IH 1

    61 3-6COM

    ID 2-4

    71 4COM

    EX 3

    81 1CMPA

    IM 2

    91 3CMPA

    DI 2

    A1 3-6CMPA

    ID 2-4

    B1 3CMPA

    EX 3

    C1CM

    IM02 1

    INYIH 1

    12 ‡1MUL

    IH 1

    22 3/1BHI

    RL 2

    32 3PULA

    IH 1

    42 1INCA

    IH 1

    52 1INCB

    IH 1

    62 3-6INC

    ID 2-4

    72 4INC

    EX 3

    82 1SBCA

    IM 2

    92 3SBCA

    DI 2

    A2 3-6SBCA

    ID 2-4

    B2 3SBCA

    EX 3

    C2SB

    IM03 1

    DEYIH 1

    13 3EMUL

    IH 1

    23 3/1BLS

    RL 2

    33 3PULB

    IH 1

    43 1DECA

    IH 1

    53 1DECB

    IH 1

    63 3-6DEC

    ID 2-4

    73 4DEC

    EX 3

    83 2SUBD

    IM 3

    93 3SUBD

    DI 2

    A3 3-6SUBD

    ID 2-4

    B3 3SUBD

    EX 3

    C3AD

    IM04 3

    loop*

    RL 3

    14 1ORCC

    IM 2

    24 3/1BCC

    RL 2

    34 2PSHX

    IH 1