CPU08RM
CPU08RM
CPU08RM
Reference Manual
M68HC08 Microcontrollers
freescale.com
To provide the most up-to-date information, the revision of our documents on the World Wide Web will be the most current. Your printed copy may be an earlier revision. To verify you have the latest information available, refer to: http://www.freescale.com/ The following revision history table summarizes changes contained in this document. For your convenience, the page number designators have been linked to the appropriate location.
Revision History
Date February, 2006 Revision Level 4 Chapter 5 Instruction Set Corrected description of CLI instruction. 101 Description Updated to meet Freescale identity guidelines. Page Number(s) N/A
Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. This product incorporates SuperFlash technology licensed from SST. Freescale Semiconductor, Inc., 2006. All rights reserved. CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 3
Revision History
List of Chapters
Chapter 1 General Description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Chapter 2 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Chapter 3 Resets and Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Chapter 4 Addressing Modes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33 Chapter 5 Instruction Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59 Chapter 6 Instruction Set Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
List of Chapters
Table of Contents
Chapter 1 General Description
1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Programming Model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Memory Space. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Addressing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arithmetic Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Binary-Coded Decimal (BCD) Arithmetic Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . High-Level Language Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Low-Power Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 13 13 14 14 14 14 14 14
Chapter 2 Architecture
2.1 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.3.3 2.3.4 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . CPU08 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Accumulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Index Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stack Pointer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Program Counter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Condition Code Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . CPU08 Functional Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Internal Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Control Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Execution Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Instruction Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 15 16 16 17 17 18 19 20 20 21 21
23 23 23 24 25 26 27 27 28 28 28
Table of Contents
Reset Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . External Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Active Reset from an Internal Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Interrupt Processing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Interrupt Sources and Priority . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Interrupts in Stop and Wait Modes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Nesting of Multiple Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Allocating Scratch Space on the Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
29 29 29 29 30 31 31 32
Table of Contents
BCS BEQ BGE BGT BHCC BHCS BHI BHS BIH BIL BIT BLE BLO BLS BLT BMC BMI BMS BNE BPL BRA BRA BRCLR n BRN BRSET n BSET n BSR CBEQ CLC CLI CLR CMP COM CPHX CPX DAA DBNZ DEC DIV EOR INC JMP JSR LDA LDHX LDX LSL LSR MOV
Branch if Carry Bit Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Branch if Equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Branch if Greater Than or Equal To . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Branch if Greater Than . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Branch if Half Carry Bit Clear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Branch if Half Carry Bit Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Branch if Higher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Branch if Higher or Same . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Branch if IRQ Pin High . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Branch if IRQ Pin Low . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Bit Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Branch if Less Than or Equal To . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Branch if Lower . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 Branch if Lower or Same . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Branch if Less Than . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Branch if Interrupt Mask Clear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Branch if Minus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Branch if Interrupt Mask Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Branch if Not Equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Branch if Plus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Branch Always . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Branch Always . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Branch if Bit n in Memory Clear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Branch Never . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Branch if Bit n in Memory Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 Set Bit n in Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Branch to Subroutine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Compare and Branch if Equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Clear Carry Bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Clear Interrupt Mask Bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Clear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Compare Accumulator with Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Complement (Ones Complement) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 Compare Index Register with Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Compare X (Index Register Low) with Memory . . . . . . . . . . . . . . . . . . . . . . . . 106 Decimal Adjust Accumulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Decrement and Branch if Not Zero. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Decrement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 Divide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 Exclusive-OR Memory with Accumulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 Increment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Jump. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Jump to Subroutine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Load Accumulator from Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 Load Index Register from Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Load X (Index Register Low) from Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Logical Shift Left. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Logical Shift Right . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 Move. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
CPU08 Central Processor Unit Reference Manual, Rev. 4
Freescale Semiconductor
Table of Contents
MUL NEG NOP NSA ORA PSHA PSHH PSHX PULA PULH PULX ROL ROR RSP RTI RTS SBC SEC SEI STA STHX STOP STX SUB SWI TAP TAX TPA TST TSX TXA TXS WAIT
Unsigned Multiply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Negate (Twos Complement) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . No Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Nibble Swap Accumulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Inclusive-OR Accumulator and Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Push Accumulator onto Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Push H (Index Register High) onto Stack. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Push X (Index Register Low) onto Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pull Accumulator from Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pull H (Index Register High) from Stack. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pull X (Index Register Low) from Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Rotate Left through Carry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Rotate Right through Carry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Reset Stack Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Return from Interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Return from Subroutine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Subtract with Carry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Set Carry Bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Set Interrupt Mask Bit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Store Accumulator in Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Store Index Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Enable IRQ Pin, Stop Oscillator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Store X (Index Register Low) in Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Subtract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Software Interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Transfer Accumulator to Processor Status Byte . . . . . . . . . . . . . . . . . . . . . . . Transfer Accumulator to X (Index Register Low) . . . . . . . . . . . . . . . . . . . . . . Transfer Processor Status Byte to Accumulator . . . . . . . . . . . . . . . . . . . . . . . Test for Negative or Zero . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Transfer Stack Pointer to Index Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . Transfer X (Index Register Low) to Accumulator . . . . . . . . . . . . . . . . . . . . . . . Transfer Index Register to Stack Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Enable Interrupts; Stop Processor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
155 155 155 156 158 159 160 161 162 163 164 165
Table of Contents
CLRH CPHX DAA DBNZ DIV LDHX MOV NSA PSHA PSHH PSHX PULA PULH PULX STHX TAP TPA TSX TXS
Clear H (Index Register High) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Compare Index Register with Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Decimal Adjust Accumulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Decrement and Branch if Not Zero. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Divide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Load Index Register with Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Move. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Nibble Swap Accumulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Push Accumulator onto Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Push H (Index Register High) onto Stack. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Push X (Index Register Low) onto Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pull Accumulator from Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pull H (Index Register High) from Stack. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pull X (Index Register Low) from Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Store Index Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Transfer Accumulator to Condition Code Register . . . . . . . . . . . . . . . . . . . . . . Transfer Condition Code Register to Accumulator . . . . . . . . . . . . . . . . . . . . . . Transfer Stack Pointer to Index Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . Transfer Index Register to Stack Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
166 167 168 169 170 173 174 175 176 177 178 179 180 181 182 183 184 185 186
Glossary
Glossary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Index
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Table of Contents
1.2 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 Memory-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 range beyond 64 Kbytes Flexible internal bus definition to accommodate CPU performance-enhancing peripherals such as a direct memory access (DMA) controller Low-power stop and wait modes
General Description
Chapter 2 Architecture
2.1 Introduction
This section describes the CPU08 registers.
7 A
0 ACCUMULATOR (A)
1 5 H
7 X
1 5
1 5
7 V 1 1 H I N Z
CARRY/BORROW FLAG (C) TWOS COMPLEMENT OVERFLOW FLAG (V) ZERO FLAG (Z) HALF-CARRY FLAG (H) NEGATIVE FLAG (N) INTERRUPT MASK (I)
Architecture
2.2.1 Accumulator
The accumulator (A) shown in Figure 2-2 is a general-purpose 8-bit register. The central processor unit (CPU) uses the accumulator to hold operands and results of arithmetic and non-arithmetic operations.
Bit 7 Read: Write: Reset: X X = Indeterminate X X X X X X X 6 5 4 3 2 1 Bit 0
CPU08 Registers
Figure 2-4. Stack Pointer (SP) NOTE Although preset to $00FF, the location of the stack is arbitrary 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.
Architecture
Figure 2-6. Condition Code Register (CCR) V Overflow Flag 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 these instructions, although its resulting value holds 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 flag when a carry occurs between 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 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 interrupt mask is automatically set after the CPU registers 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 clear), 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. If an interrupt occurs while the interrupt mask is set, the interrupt is latched. Interrupts in order of priority are serviced 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 is set and can only be cleared by a software instruction. See Chapter 3 Resets and Interrupts. N Negative Flag The CPU sets the negative flag when an arithmetic operation, logical 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 carry/borrow flag (as in bit test and branch instructions and shifts and rotates).
CONTROL UNIT
CONTROL SIGNALS
STATUS SIGNALS
Architecture
T1 T2 T3 T4 T1 T2 T3 T4
ADDR. CYCLE N
DATA CYCLE
CPU CLOCK
T1
T2
T3
T4
T1
T2
T3
T4
T1
T2
T3
T4
CYCLE N STATE
CYCLE N STROBE
CYCLE N EU CONTROL
ADDRESS CYCLE N
DATA CYCLE N
Architecture
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 Figure 2-10 are illustrated in Figure 2-11.
ORG FCB ORG 0100 A6 50 0102 97 0103 e6 02 0105 5c 0106 c7 80 00 LDA TAX LDA INCX STA $8000 2, X $50 $12 $100 #$50 ;A = $50 ;A > X ;[X+2] > A ;X = X+1 ;A > $8000 PC=$0103 PC=$0104 PC=$0106 PC = $0107 PC = $010A $34 $56
LDA OPCODE
INCX OPCODE
OPCODE LOOKAHEAD IR/CONTROL UNIT STATE INPUT CONTROL UNIT STROBE CONTROL UNIT OUTPUT TO EXECUTION UNIT
TAX STATE 1
LDA STATE 1
LDA STATE 2
LDA STATE 3
INCX STATE 1
LDA CYCLE 1 STROBE TAX EU CONTROL LDA OPCODE PREFETCH LDA CYCLE 1 EU CONTROL
LDA CYCLE 3 STROBE LDA CYCLE 3 EU CONTROL STA OPCODE PREFETCH $0106
$E6
TAX
LDA
3.2.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. All pending interrupts are recognized by the CPU08 during 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 register in place of what would have been the next instruction. (When using the CPU08 with the direct memory access (DMA) module, the DMA can suspend instruction operation to service the peripheral.)
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 23
Because of the opcode lookahead prefetch mechanism, at instruction boundaries the program counter (PC) always points to the address of the next instruction to be executed plus one. The presence of an interrupt is used to modify the SWI flow such that instead of stacking this PC value, the PC is decremented before being stacked. After 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.
3.2.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 register (CCR) I bit (internal mask) is not set until after the CCR is stacked during cycle 6 of the interrupt stacking procedure. The stack pointer always points to the next available (empty) stack location.
7 0
UNSTACKING ORDER 5 4 3 2 1 1 2 3 4 5 CONDITION CODE REGISTER ACCUMULATOR INDEX REGISTER (LOW BYTE X)(1) PROGRAM COUNTER HIGH PROGRAM COUNTER LOW STACKING ORDER $00FF (DEFAULT ADDRESS ON RESET)
Figure 3-1. Interrupt Stack Frame NOTE To maintain compatibility with the M6805 Family, H (the high byte of the index register) is not stacked during interrupt processing. If the interrupt service routine modifies H or uses the indexed addressing mode, it is the users responsibility to save and restore it prior to returning. See Figure 3-2.
IRQINT PSHH | |Interrupt service routine | | PULH RTI
3.2.3 Arbitration
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 interrupt 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, no other interrupt may take precedence, regardless of priority, until the latched interrupt is serviced (or the I bit is cleared). See Figure 3-3.
BUS CYCLE # 1 LAST CYCLE OF CURRENT INSTRUCTION (A) COMPLETE NEXT INSTRUCTION FETCH (REDUNDANT) BUS CYCLE #
UNSTACK CCR
STACK CCR
YES
NOTE 1
NO
3.2.4 Masking
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 peripheral control registers. The I bit may also be modified by execution of the set interrupt mask bit (SEI), clear interrupt mask bit (CLI), or transfer accumulator to condition code register (TAP) instructions. The I bit is modified in the first cycle of each instruction (these are all 2-cycle instructions). The I bit is also set during interrupt processing (see 3.2.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.2.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 instruction. For example, if an interrupt is recognized during the CLI instruction, the load accumulator from memory (LDA) instruction will not be executed before the interrupt is serviced. See Figure 3-4.
CLI LDA #$FF Background Routine
INT1
Figure 3-4. Interrupt Recognition Example 1 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 opcode is prefetched by both the INT1 and INT2 RTI instructions. However, in the case of the INT1 RTI prefetch, this is a redundant operation. See Figure 3-5.
CLI LDA #$FF Background Routine
INT2
Reset Processing
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
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.
CPU CLOCK
T3 T4 T1 T2 T3 T4 T1 T2 T3 T4 T1 T2 T3 T4 T1 T2 T3 T4 T1 T2 T3 T4
INDETERMINATE
$FFFE
$FFFF
INDETERMINATE
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.
3.3.2 CPU
After reset the CPU08 fetches the reset vector from locations $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 are 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.
Interrupt Processing
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 part to part. Table 3-1. Mode Selection
IRQ1 Pin VDD 2 x VDD Port x X 1 Port y X 0 Mode User Monitor
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 all CPU08 registers onto the stack, except the H register, so that the CPU08 contents can be restored after the interrupt is finished. After stacking the CPU08 registers, the vector for the highest priority pending interrupt source is loaded into the program counter and execution continues with the first instruction of the interrupt service routine. 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 that the interrupted program 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.4.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 to inhibit all interrupts. After minimum system initialization, software may clear the I bit by a TAP or CLI instruction, thus enabling interrupts.
:
FF02 FF00
:
IREQ[124] IREQ[125]
:
127 128
Interrupt Processing
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 interrupt request into a constant that the CPU08 uses to generate 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 interrupt sources in a specific M68HC08 device, refer to the SIM section of the technical data manual written for that device. As an instruction, SWI has the highest priority other than reset; once the SWI opcode is fetched, no other interrupt can be honored until the SWI vector has been fetched.
#-16 3,SP
* 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. . . . LDA 3,SP ;Read the value at a later time . . . AIS #16 ;Clean up stack PULH ;Restore H register RTI ;Return 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.
* Note: * * * * * *
Addressing Modes
4.2.1 Inherent
Inherent instructions have no operand fetch associated with the instruction, such as decimal adjust accumulator (DAA), clear index high (CLRH), and divide (DIV). Some of the inherent instructions act on data in the CPU registers, such as clear accumulator (CLRA), and transfer condition code register to the accumulator (TPA). Inherent instructions require no memory address, and most are one byte long. Table 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 numbers 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.
Machine Code Label Operation Operand Comments
A657 AB45 72
EX_1
#$57 #$45
;A = ;A = ;A = ;bit
A614 8C AE03 52
EX_2
#20 #3
A630 87
EX_3
LDA PSHA
#$30
Addressing Modes
Addressing Modes
4.2.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 effective address of the instruction 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 instructions: one byte for the opcode, two bytes for the immediate data byte. The example code shown here contains two immediate instructions: AIX (add immediate to H:X) and CPHX (compare H:X with immediate value). H:X is first cleared and then incremented by one until it contains $FFFF. Once the condition specified by the CPHX becomes true, the program branches to START, and the process is repeated indefinitely.
Machine Code Label Operation Operand Comments
START TAG
;X = 0 ;H = 0 ;(H:X) = (H:X) + 1 ;Compare (H:X) to ;$FFFF ;Loop until equal ;Start over
Addressing Modes
4.2.3 Direct
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 direct addressing mode is therefore limited to operands 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 memory access, the execution time is reduced 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 are 3-byte instructions that use direct 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). In this example, RAM:(RAM + 1) = TEMP = $50:$51 = $5555.
Machine Code Label Operation Operand Comments
BAD_PART
EQU EQU ORG RMB ORG CLRX CLRH STHX LDHX STHX CPHX BNE
20F1
BRA
START
;RAM equate ;ROM equate ;Beginning of RAM ;Reserve 2 bytes ;Beginning of ROM ;X = 0 ;H = 0 ;H:X=0 > temp ;Load H:X with $5555 ;Temp=$5555 ;RAM=temp ;RAM=temp will be ;same unless something ;is very wrong! ;Do it again
Addressing Modes
Addressing Modes
4.2.4 Extended
Extended instructions can access any address in a 64-Kbyte memory map. All extended instructions are three bytes long. The first byte 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 memory above the direct or zero page ($0000$00FF) is accessed. When using most assemblers, the programmer does not need to specify whether an instruction is direct or extended. The assembler automatically selects the shortest form of the instruction. Table 4-4 lists the instructions that use the extended addressing mode. An example of the extended addressing mode is shown here.
Machine Code Label Operation Operand Comments
5F BE50
5F CE6E00
Addressing Modes
Label
Operation
Operand
Comments
FC
JMP
,X
;No offset ;Jump to address ;pointed to by H:X ;8-bit offset ;Jump to address ;pointed to by H:X + $FF ;16-bit offset ;Jump to address ;pointed to by H:X + $10FF
ECFF
JMP
$FF,X
DC10FF
JMP
$10FF,X
No Offset 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
8-Bit Offset 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
16-Bit Offset 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
LSR NEG ORA ROL ROR SBC STA STX SUB TST
Addressing Modes
#$0100 ;Reset stack pointer ;to $00FF ;A = $20 ;Location $10F = $20 ;8-bit offset ;decrement the ;contents of $10F ;until equal to zero
LP
450100 94 9ED60250
#$0100 ;Reset stack pointer ;to $00FF ;16-bit offset ;Load A with contents ;of $34F
$0250,SP
Addressing Modes
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. Table 4-6. Stack Pointer Addressing Instructions
Instruction Add Memory and Carry to Accumulator Add Memory and Accumulator Logical AND of Memory and Accumulator Arithmetic Shift Left Memory Arithmetic Shift Right Memory Bit Test Memory with Accumulator Compare Direct with Accumulator and Branch if Equal Clear Memory Compare Accumulator with Memory Complement Memory Compare X (Index Register Low) with Memory Decrement Memory and Branch if Not Equal ($00) Decrement Memory Exclusive OR Memory with Accumulator Increment Memory Load Accumulator from Memory Load X (Index Register Low) from Memory Logical Shift Left Memory Logical Shift Right Memory Negate Memory Inclusive OR Accumulator and Memory Rotate Memory Left through Carry Rotate Memory Right through Carry Subtract Memory and Carry from Memory Store Accumulator in Memory Store X (Index Register Low) in Memory Subtract Memory from Accumulator Test Memory for Negative or Zero 1. ASL = LSL Mnemonic ADC ADD AND ASL(1) ASR BIT CBEQ CLR CMP COM CPX DBNZ DEC EOR INC LDA LDX LSL(1) LSR NEG ORA ROL ROR SBC STA STX SUB TST 8-Bit Offset 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 16-Bit Offset 4 4 4 4 4 4 4 4 4 4 4 4 4 4
Addressing Modes
4.2.10 Relative
All conditional branch instructions use relative addressing to evaluate the resultant effective address (EA). The CPU evaluates the conditional branch destination by adding the signed byte following the opcode to the 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 offset is a signed, two's complement 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, BGT, BLE, and BGE and are designed to be used with signed arithmetic operations. When using most assemblers, the programmer does not need to calculate the offset, because the assembler determines 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 (branch always). In this example, the value in the accumulator is compared to the signed value 2. Because #1 is greater than 2, the branch to TAG will not occur.
Machine Code Label Operation Operand Comments
TAG
HERE
Addressing Modes
* Data movement with accumulator B750 A622 B7F0 B650 (2 cycles) (2 cycles) (3 cycles) (2 cycles) 9 cycles PSHA LDA STA PULA #$22 $F0 ;Save current A ; value ;A = $22 ;Store $22 into $F0 ;Restore A value
* Data movement without accumulator 6E22F0 (4 cycles) MOV #$22,$F0 ;Location $F0 ;= $22
Addressing Modes
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, 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 example). This savings can be substantial for a program containing numerous register-to-register data transfers.
Machine Code Label Operation Operand Comments
* Data movement with accumulator B750 B6F0 B7F1 B650 (2 cycles) (3 cycles) (3 cycles) (2 cycles) 10 cycles PSHA LDA STA PULA ;Save A value ;Get contents ;of $F0 ;Location $F1=$F0 ;Restore A value
$F0 $F1
;TX circular ;buffer length ;SCI status ;register 1 ;SCI transmit ;data register
PTR_OUT PTR_IN
55 50 B6 16
7E 18
65 64 23 45 54 35 80
00 03 00 50
TX_B RMB SIZE ;Circular buffer * * SCI transmit data register empty interrupt * service routine * ORG $6E00 TX_INT LDHX PTR_OUT ;Load pointer LDA SCSR1 ;Dummy read of ;SCSR1 as part of ;the TDRE reset MOV X+, SCDR ;Move new byte to ;SCI data reg. ;Clear TDRE. Post ;increment H:X. CPHX #TX_B + ;Gone past end of SIZE ;circular buffer? BLS NOLOOP ;If not, continue LDHX #TX_B ;Else reset to ;start of buffer NOLOOP STHX PTR_OUT ;Save new ;pointer value RTI ;Return
;RX circular ;buffer length ;SCI status reg.1 ;SCI receive data reg.
PTR_OUT PTR_IN
RMB RMB
2 2
55 72 B6 16 5E 18
65 64 23 45 54 35 80
00 03 00 52
RX_B RMB SIZE * * SCI receive data register full interrupt * service routine * ORG $6E00 RX_INT LDHX PTR_IN ;Load pointer LDA SCSR1 ;Dummy read of SCSR1 ;as part of the RDRF reset MOV SCDR ,X+ ;Move new byte from ;SCI data reg. ;Clear RDRF. Post ;increment H:X. CPHX #RX_B + ;Gone past end of SIZE ;circular buffer? BLS NOLOOP ;If not continue LDHX #RX_B ;Else reset to ;start of buffer NOLOOP STHX PTR_IN ;Save new pointer value RTI ;Return
;Circular buffer ;data out pointer ;Circular buffer ;data in pointer ;Circular buffer
* Compare contents of A with contents of location pointed to by * H:X and branch to TAG when equal 7102 20FC 5F LOOP TAG CBEQ BRA CLRX X+,TAG LOOP ;No offset ;Check next location ;Zero X
* Compare contents of A with contents of location pointed to by * H:X + $50 and branch to TG1 when equal 615002 20FB 20FE LOOP2 TG1 CBEQ BRA BRA $50,X+,TG1 LOOP2 TG1 ;8-bit offset ;Check next location ;Finished
Table 4-9. Indexed and Indexed, 8-Bit Offset with Post Increment Instructions
Instruction Compare and Branch if Equal, Indexed (H:X) Compare and Branch if Equal, Indexed (H:X), 8-Bit Offset Move Indexed Operand to Direct Memory Location Move Direct Memory Operand to Indexed Memory Location Mnemonic CBEQ CBEQ MOV MOV
Addressing Modes
Operation
Object Code
A9 B9 C9 D9 E9 F9 9E D9 9E E9 AB BB CB DB EB FB 9E DB 9E EB ii dd hh ll ee ff ff ee ff ff ii dd hh ll ee ff ff ee ff ff
IMM DIR EXT IX2 IX1 IX SP2 SP1 IMM DIR EXT IX2 IX1 IX SP2 SP1 IMM
Cycles
2 3 4 4 3 2 5 4 2 3 4 4 3 2 5 4 2
1 1
1 1
AIS #opr8i
Add Immediate Value (Signed) to Stack Pointer SP (SP) + (M) Add Immediate Value (Signed) to Index Register (H:X) H:X (H:X) + (M)
A7 ii
1 1
AIX #opr8i AND AND AND AND AND AND AND AND #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP
IMM IMM DIR EXT IX2 IX1 IX SP2 SP1 DIR INH INH IX1 IX SP1 DIR INH INH IX1 IX SP1 REL DIR (b0) DIR (b1) DIR (b2) DIR (b3) DIR (b4) DIR (b5) DIR (b6) DIR (b7)
AF ii A4 B4 C4 D4 E4 F4 9E D4 9E E4 ii dd hh ll ee ff ff ee ff ff
2 2 3 4 4 3 2 5 4 4 1 1 4 3 5 4 1 1 4 3 5 3 4 4 4 4 4 4 4 4
pp pp prp pprp pppr ppr pr ppppr pppr prwp p p pprw prw ppprw prwp p p pprw prw ppprw pdp prwp prwp prwp prwp prwp prwp prwp prwp
1 1
0 1 1
ASL opr8a ASLA ASLX ASL oprx8,X ASL ,X ASL oprx8,SP ASR opr8a ASRA ASRX ASR oprx8,X ASR ,X ASR oprx8,SP BCC rel
38 dd 48 58 68 ff 78 9E 68 ff 37 dd 47 57 67 ff 77 9E 67 ff 24 rr 11 13 15 17 19 1B 1D 1F dd dd dd dd dd dd dd dd
1 1
1 1
1 1
BCLR n,opr8a
1 1
Operation
Branch if Carry Bit Set (if C = 1) (Same as BLO) Branch if Equal (if Z = 1) Branch if Greater Than or Equal To (if N V = 0) (Signed) Branch if Greater Than (if Z | (N V) = 0) (Signed) Branch if Half Carry Bit Clear (if H = 0) Branch if Half Carry Bit Set (if H = 1) Branch if Higher (if C | Z = 0) Branch if Higher or Same (if C = 0) (Same as BCC) Branch if IRQ Pin High (if IRQ pin = 1) Branch if IRQ Pin Low (if IRQ pin = 0)
Object Code
REL REL REL REL REL REL REL REL REL REL IMM DIR EXT IX2 IX1 IX SP2 SP1 REL REL REL REL REL REL REL REL REL REL DIR (b0) DIR (b1) DIR (b2) DIR (b3) DIR (b4) DIR (b5) DIR (b6) DIR (b7) REL
Cycles
3 3 3 3 3 3 3 3 3 3 2 3 4 4 3 2 5 4 3 3 3 3 3 3 3 3 3 3
25 rr 27 rr 90 rr 92 rr 28 rr 29 rr 22 rr 24 rr 2F rr 2E rr A5 B5 C5 D5 E5 F5 9E D5 9E E5 ii dd hh ll ee ff ff ee ff ff
Bit Test (A) & (M) (CCR Updated but Operands Not Changed)
0 1 1
BLE rel BLO rel BLS rel BLT rel BMC rel BMI rel BMS rel BNE rel BPL rel BRA rel
Branch if Less Than or Equal To (if Z | (N V) = 1) (Signed) Branch if Lower (if C = 1) (Same as BCS) Branch if Lower or Same (if C | Z = 1) Branch if Less Than (if N V = 1) (Signed) Branch if Interrupt Mask Clear (if I = 0) Branch if Minus (if N = 1) Branch if Interrupt Mask Set (if I = 1) Branch if Not Equal (if Z = 0) Branch if Plus (if N = 0) Branch Always (if I = 1)
93 rr 25 rr 23 rr 91 rr 2C rr 2B rr 2D rr 26 rr 2A rr 20 rr 01 03 05 07 09 0B 0D 0F dd dd dd dd dd dd dd dd rr rr rr rr rr rr rr rr
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
BRCLR n,opr8a,rel
5 5 5 5 5 5 5 5 3
1 1
BRN rel
21 rr
1 1
Addressing Modes
BRSET n,opr8a,rel
DIR (b0) DIR (b1) DIR (b2) DIR (b3) DIR (b4) DIR (b5) DIR (b6) DIR (b7) DIR (b0) DIR (b1) DIR (b2) DIR (b3) DIR (b4) DIR (b5) DIR (b6) DIR (b7)
Cycles
5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4
1 1
BSET n,opr8a
1 1
BSR rel
Branch to Subroutine PC (PC) + $0002 push (PCL); SP (SP) $0001 push (PCH); SP (SP) $0001 PC (PC) + rel Compare and... Branch if (A) = (M) Branch if (A) = (M) Branch if (X) = (M) Branch if (A) = (M) Branch if (A) = (M) Branch if (A) = (M)
REL
AD rr
pssp
1 1
CBEQ opr8a,rel CBEQA #opr8i,rel CBEQX #opr8i,rel CBEQ oprx8,X+,rel CBEQ ,X+,rel CBEQ oprx8,SP,rel CLC CLI CLR opr8a CLRA CLRX CLRH CLR oprx8,X CLR ,X CLR oprx8,SP CMP CMP CMP CMP CMP CMP CMP CMP #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP
DIR IMM IMM IX1+ IX+ SP1 INH INH DIR INH INH INH IX1 IX SP1 IMM DIR EXT IX2 IX1 IX SP2 SP1 DIR INH INH IX1 IX SP1 IMM DIR
31 41 51 61 71 9E 61 98 9A
dd ii ii ff rr ff
rr rr rr rr rr
5 4 4 5 4 6 1 2 3 1 1 1 3 2 4 2 3 4 4 3 2 5 4 4 1 1 4 3 5 3 4
pprdp ppdp ppdp pprdp prdp ppprdp p pd pwp p p p ppw pw pppw pp prp pprp pppr ppr pr ppppr pppr prwp p p pprw prw ppprw ppp prrp
1 1
Clear Carry Bit (C 0) Clear Interrupt Mask Bit (I 0) Clear M $00 A $00 X $00 H $00 M $00 M $00 M $00
1 1 0 1 1 0
3F dd 4F 5F 8C 6F ff 7F 9E 6F ff A1 B1 C1 D1 E1 F1 9E D1 9E E1 ii dd hh ll ee ff ff ee ff ff
0 1 1 0 1
Compare Accumulator with Memory AM (CCR Updated But Operands Not Changed)
1 1
COM opr8a COMA COMX COM oprx8,X COM ,X COM oprx8,SP CPHX #opr CPHX opr
Complement M (M)= $FF (M) (Ones Complement) A (A) = $FF (A) X (X) = $FF (X) M (M) = $FF (M) M (M) = $FF (M) M (M) = $FF (M) Compare Index Register (H:X) with Memory (H:X) (M:M + $0001) (CCR Updated But Operands Not Changed)
33 dd 43 53 63 ff 73 9E 63 ff 65 ii jj 75 dd
0 1 1
1 1
Operation
Object Code
A3 B3 C3 D3 E3 F3 9E D3 9E E3 72 3B 4B 5B 6B 7B 9E 6B dd rr rr rr ff rr rr ff rr ii dd hh ll ee ff ff ee ff ff
IMM DIR EXT Compare X (Index Register Low) with Memory IX2 XM IX1 (CCR Updated But Operands Not Changed) IX SP2 SP1 Decimal Adjust Accumulator After ADD or ADC of BCD Values INH
Cycles
2 3 4 4 3 2 5 4 2 5 3 3 5 4 6 4 1 1 4 3 5 7
1 1
U 1 1
DIR INH Decrement A, X, or M and Branch if Not Zero INH (if (result) 0) IX1 DBNZX Affects X Not H IX SP1 Decrement M (M) $01 A (A) $01 X (X) $01 M (M) $01 M (M) $01 M (M) $01 DIR INH INH IX1 IX SP1 INH IMM DIR EXT IX2 IX1 IX SP2 SP1 DIR INH INH IX1 IX SP1 DIR EXT IX2 IX1 IX DIR EXT IX2 IX1 IX
1 1
3A dd 4A 5A 6A ff 7A 9E 6A ff 52 A8 B8 C8 D8 E8 F8 9E D8 9E E8 ii dd hh ll ee ff ff ee ff ff
1 1
1 1
2 3 4 4 3 2 5 4 4 1 1 4 3 5 2 3 4 3 2 4 5 6 5 4
0 1 1
INC opr8a INCA INCX INC oprx8,X INC ,X INC oprx8,SP JMP JMP JMP JMP JMP JSR JSR JSR JSR JSR opr8a opr16a oprx16,X oprx8,X ,X opr8a opr16a oprx16,X oprx8,X ,X
Increment
M (M) + $01 A (A) + $01 X (X) + $01 M (M) + $01 M (M) + $01 M (M) + $01
3C dd 4C 5C 6C ff 7C 9E 6C ff BC CC DC EC FC BD CD DD ED FD dd hh ll ee ff ff dd hh ll ee ff ff
1 1
1 1
Jump to Subroutine PC (PC) + n (n = 1, 2, or 3) Push (PCL); SP (SP) $0001 Push (PCH); SP (SP) $0001 PC Unconditional Address
1 1
Addressing Modes
Operation
Object Code
A6 B6 C6 D6 E6 F6 9E D6 9E E6 ii dd hh ll ee ff ff ee ff ff
IMM DIR EXT IX2 IX1 IX SP2 SP1 IMM DIR IMM DIR EXT IX2 IX1 IX SP2 SP1 DIR INH INH IX1 IX SP1 DIR INH INH IX1 IX SP1 DIR/DIR DIR/IX+ IMM/DIR IX+/DIR INH DIR INH INH IX1 IX SP1 INH INH IMM DIR EXT IX2 IX1 IX SP2 SP1
Cycles
2 3 4 4 3 2 5 4 3 4 2 3 4 4 3 2 5 4 4 1 1 4 3 5 4 1 1 4 3 5 5 4 4 4 5 4 1 1 4 3 5 1 3
0 1 1
LDHX #opr LDHX opr LDX LDX LDX LDX LDX LDX LDX LDX #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP
45 ii jj 55 dd AE BE CE DE EE FE 9E DE 9E EE ii dd hh ll ee ff ff ee ff ff
0 1 1
0 1 1
LSL opr8a LSLA LSLX LSL oprx8,X LSL ,X LSL oprx8,SP LSR opr8a LSRA LSRX LSR oprx8,X LSR ,X LSR oprx8,SP MOV opr8a,opr8a MOV opr8a,X+ MOV #opr8i,opr8a MOV ,X+,opr8a MUL NEG opr8a NEGA NEGX NEG oprx8,X NEG ,X NEG oprx8,SP NOP NSA ORA ORA ORA ORA ORA ORA ORA ORA #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP
38 dd 48 58 68 ff 78 9E 68 ff 34 dd 44 54 64 ff 74 9E 64 ff 4E 5E 6E 7E 42 30 dd 40 50 60 ff 70 9E 60 ff 9D 62 AA BA CA DA EA FA 9E DA 9E EA ii dd hh ll ee ff ff ee ff ff dd dd dd ii dd dd
1 1
1 1 0
Move (M)destination (M)source In IX+/DIR and DIR/IX+ Modes, H:X (H:X) + $0001 Unsigned multiply X:A (X) (A) Negate M (M) = $00 (M) (Twos Complement) A (A) = $00 (A) X (X) = $00 (X) M (M) = $00 (M) M (M) = $00 (M) M (M) = $00 (M) No Operation Uses 1 Bus Cycle Nibble Swap Accumulator A (A[3:0]:A[7:4])
0 1 1
1 1 0 0
1 1
1 1 1 1
2 3 4 4 3 2 5 4
0 1 1
Operation
Push Accumulator onto Stack Push (A); SP (SP) $0001 Push H (Index Register High) onto Stack Push (H); SP (SP) $0001 Push X (Index Register Low) onto Stack Push (X); SP (SP) $0001 Pull Accumulator from Stack SP (SP + $0001); Pull (A) Pull H (Index Register High) from Stack SP (SP + $0001); Pull (H) Pull X (Index Register Low) from Stack SP (SP + $0001); Pull (X) Rotate Left through Carry
C b7 b0
Object Code
INH INH INH INH INH INH DIR INH INH IX1 IX SP1 DIR INH INH IX1 IX SP1 INH
Cycles
2 2 2 2 2 2 4 1 1 4 3 5 4 1 1 4 3 5 1
87 8B 89 86 8A 88 39 dd 49 59 69 ff 79 9E 69 ff 36 dd 46 56 66 ff 76 9E 66 ff 9C
1 1
1 1
Reset Stack Pointer (Low Byte) SPL $FF (High Byte Not Affected) Return from Interrupt SP (SP) + $0001; SP (SP) + $0001; SP (SP) + $0001; SP (SP) + $0001; SP (SP) + $0001; Pull (CCR) Pull (A) Pull (X) Pull (PCH) Pull (PCL)
1 1
RTI
INH
80
puuuuup
1 1
RTS SBC SBC SBC SBC SBC SBC SBC SBC SEC SEI #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP
INH IMM DIR EXT IX2 IX1 IX SP2 SP1 INH INH
81 A2 B2 C2 D2 E2 F2 9E D2 9E E2 99 9B ii dd hh ll ee ff ff ee ff ff
4 2 3 4 4 3 2 5 4 1 2
1 1
1 1
1 1 1 1 1 1
Addressing Modes
Operation
Object Code
B7 C7 D7 E7 F7 9E D7 9E E7 dd hh ll ee ff ff ee ff ff
Cycles
3 4 4 3 2 5 4 4
0 1 1
STHX opr
Store H:X (Index Reg.) (M:M + $0001) (H:X) Enable Interrupts: Stop Processing Refer to MCU Documentation I bit 0; Stop Processing
35 dd
0 1 1
STOP STX STX STX STX STX STX STX SUB SUB SUB SUB SUB SUB SUB SUB opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP
INH DIR EXT IX2 IX1 IX SP2 SP1 IMM DIR EXT IX2 IX1 IX SP2 SP1
8E BF CF DF EF FF 9E DF 9E EF A0 B0 C0 D0 E0 F0 9E D0 9E E0 dd hh ll ee ff ff ee ff ff ii dd hh ll ee ff ff ee ff ff
1 3 4 4 3 2 5 4 2 3 4 4 3 2 5 4
p pwp ppwp pppw ppw pw ppppw pppw pp prp pprp pppr ppr pr ppppr pppr
1 1 0
0 1 1
1 1
SWI
Software Interrupt PC (PC) + $0001 Push (PCL); SP (SP) $0001 Push (PCH); SP (SP) $0001 Push (X); SP (SP) $0001 Push (A); SP (SP) $0001 Push (CCR); SP (SP) $0001 I 1; PCH Interrupt Vector High Byte PCL Interrupt Vector Low Byte Transfer Accumulator to CCR CCR (A) Transfer Accumulator to X (Index Register Low) X (A) Transfer CCR to Accumulator A (CCR) Test for Negative or Zero (M) $00 (A) $00 (X) $00 (M) $00 (M) $00 (M) $00
INH
83
psssssvvp
1 1 1
TAP
INH
84
pd
1 1
TAX
INH
97
1 1
TPA TST opr8a TSTA TSTX TST oprx8,X TST ,X TST oprx8,SP TSX
85 3D dd 4D 5D 6D ff 7D 9E 6D ff 95
1 3 1 1 3 2 4 2
1 1
0 1 1
1 1
Opcode Map
Operation
Transfer X (Index Reg. Low) to Accumulator A (X) Transfer Index Reg. to SP SP (H:X) $0001 Enable Interrupts; Wait for Interrupt I bit 0; Halt CPU
Object Code
Cycles
1 2 1
9F 94 8F
Object Code: dd Direct address of operand ee ff High and low bytes of offset in indexed, 16-bit offset addressing ff Offset byte in indexed, 8-bit offset addressing hh ll High and low bytes of operand address in extended addressing ii Immediate operand byte ii jj 16-bit immediate operand for H:X rr Relative program counter offset byte Addressing Modes: DIR Direct addressing mode EXT Extended addressing mode IMM Immediate addressing mode INH Inherent addressing mode IX Indexed, no offset addressing mode IX1 Indexed, 8-bit offset addressing mode IX2 Indexed, 16-bit offset addressing mode IX+ Indexed, no offset, post increment addressing mode IX1+ Indexed, 8-bit offset, post increment addressing mode REL Relative addressing mode SP1 Stack pointer, 8-bit offset addressing mode SP2 Stack pointer 16-bit offset addressing mode
Operation Symbols: A Accumulator CCR Condition code register H Index register high byte M Memory location n Any bit opr Operand (one or two bytes) PC Program counter PCH Program counter high byte PCL Program counter low byte rel Relative program counter offset byte SP Stack pointer SPH Most significant byte of stack pointer SPL Least significant byte of stack pointer X Index register low byte & Logical AND | Logical OR Logical EXCLUSIVE OR () Contents of ( ) Negation (twos complement) # Immediate value Sign extend Loaded with ? If : Concatenated with Cycle-by-Cycle Codes: d Dummy duplicate of the previous p, r, or s cycle. d is always a read cycle so sd is a stack write followed by a read of the address pointed to by the updated stack pointer p Program fetch; read from next consecutive location in program memory r Read 8-bit operand s Push (write) eight bits onto stack u Pop (read) eight bits from stack v Read vector from $FFxx (high byte first) w Write 8-bit operand
CCR Bits, Effects: V Overflow bit H Half-carry bit I Interrupt mask N Negative bit Z Zero bit C Carry/borrow bit Set or cleared Not affected U Undefined
58
Addressing Modes
0
LOW 5
1
4
2
3
3
4
4
1
5
1
6
4
9E6
5
7
3
8
7
9
3
A
2
B
3
C
4
D
4
9ED
5
E
3
9EE
4
F
2
0 1 2
BRSET0
3 DIR 5 DIR 5 DIR 5 DIR 5 DIR 5 DIR 5 DIR 5 DIR 5 DIR 5 DIR 5 DIR 5 DIR 5 DIR 5 DIR 5 DIR 5 DIR
BSET0
2 DIR 2 4 DIR 2 4 DIR 2 4 DIR 2 4 DIR 2 4 DIR 2 4 DIR 2 4 DIR 2 4 DIR 2 4 DIR 2 4 DIR 2 4 DIR 2 4 DIR 2 4 DIR 2 4 DIR 2 4 DIR 2
BRA
REL 2 3
NEG
DIR 1 5
NEGA
INH 1 4 IMM 3 5
NEGX
INH 2 4 IMM 3 7
NEG
IX1 3 5
NEG
SP1 1 6
NEG
IX 1 4
RTI
INH 2 4
BGE
REL 2 3
SUB
IMM 2 2
SUB
DIR 3 3
SUB
EXT 3 4
SUB
IX2 4 4
SUB
SP2 2 5
SUB
IX1 3 3
SUB
SP1 1 4
SUB
IX 2
BRCLR0 BCLR0
3 2
BRN
REL 3 3
CBEQ
CBEQA MUL
1
CBEQX DIV
INH 1 1
CBEQ
IX1+ 4 3
CBEQ
SP1 2
CBEQ
IX+ 1 2
RTS
INH 2
BLT
REL 2 3
CMP
IMM 2 2
CMP
DIR 3 3
CMP
EXT 3 4
CMP
IX2 4 4
CMP
SP2 2 5
CMP
IX1 3 3
CMP
SP1 1 4
CMP
IX 2
DIR 3
BRSET1
3
BSET1
2
BHI
REL 3 4
NSA
INH 4 1 5
DAA
INH 3 2 9
BGT
REL 2 3
SBC
IMM 2 2
SBC
DIR 3 3
SBC
EXT 3 4
SBC
IX2 4 4
SBC
SP2 2 5
SBC
IX1 3 3
SBC
SP1 1 4
SBC
IX 2
INH 1 1
3 4 5 6 7 8 9 A B C D E F
BRCLR1 BCLR1
3 2
BLS
REL 2 3
COM
DIR 1 4
COMA
INH 1 1
COMX
INH 2 1
COM
IX1 3 4
COM
SP1 1 5
COM
IX 1 3
SWI
INH 2 2
BLE
REL 2 2
CPX
IMM 2 2
CPX
DIR 3 3
CPX
EXT 3 4
CPX
IX2 4 4
CPX
SP2 2 5
CPX
IX1 3 3
CPX
SP1 1 4
CPX
IX 2
BRSET2
3
BSET2
2
BCC
REL 2 3
LSR
DIR 1 4
LSRA
INH 1 3
LSRX
INH 2 4
LSR
IX1 3 3
LSR
SP1 1
LSR
IX 1 4
TAP
INH 1 1
TXS
INH 2 2
AND
IMM 2 2
AND
DIR 3 3
AND
EXT 3 4
AND
IX2 4 4
AND
SP2 2 5
AND
IX1 3 3
AND
SP1 1 4
AND
IX 2
BRCLR2 BCLR2
3 2
BCS
REL 2 3
STHX
DIR 3 4
LDHX
IMM 2 1
LDHX
DIR 3 1
CPHX
IMM 4 2 5
CPHX
DIR 1 3
TPA
INH 1 2
TSX
INH 2
BIT
IMM 2 2
BIT
DIR 3 3
BIT
EXT 3 4
BIT
IX2 4 4
BIT
SP2 2 5
BIT
IX1 3 3
BIT
SP1 1 4
BIT
IX 2
BRSET3
3
BSET3
2
BNE
REL 2 3
ROR
DIR 1 4
RORA
INH 1 1
RORX
INH 2 1
ROR
IX1 3 4
ROR
SP1 1 5
ROR
IX 1 3
PULA
INH 2 2 1
LDA
IMM 2 2
LDA
DIR 3 3
LDA
EXT 3 4
LDA
IX2 4 4
LDA
SP2 2 5
LDA
IX1 3 3
LDA
SP1 1 4
LDA
IX 2
BRCLR3 BCLR3
3 2
BEQ
REL 2 3
ASR
DIR 1 4
ASRA
INH 1 1
ASRX
INH 2 1
ASR
IX1 3 4
ASR
SP1 1 5
ASR
IX 1 3
PSHA
INH 1 2
TAX
INH 2 1
AIS
IMM 2 2
STA
DIR 3 3
STA
EXT 3 4
STA
IX2 4 4
STA
SP2 2 5
STA
IX1 3 3
STA
SP1 1 4
STA
IX 2
BRSET4
3
BSET4
2
BHCC
REL 2 3
LSL
DIR 1 4
LSLA
INH 1 1
LSLX
INH 2 1
LSL
IX1 3 4
LSL
SP1 1 5
LSL
IX 1 3
PULX
INH 1 2
CLC
INH 2 1
EOR
IMM 2 2
EOR
DIR 3 3
EOR
EXT 3 4
EOR
IX2 4 4
EOR
SP2 2 5
EOR
IX1 3 3
EOR
SP1 1 4
EOR
IX 2
BRCLR4 BCLR4
3 2
BHCS
REL 2 3
ROL
DIR 1 4
ROLA
INH 1 1
ROLX
INH 2 1
ROL
IX1 3 4
ROL
SP1 1 5
ROL
IX 1 3
PSHX
INH 1 2
SEC
INH 2 2
ADC
IMM 2 2
ADC
DIR 3 3
ADC
EXT 3 4
ADC
IX2 4 4
ADC
SP2 2 5
ADC
IX1 3 3
ADC
SP1 1 4
ADC
IX 2
BRSET5
3
BSET5
2
BPL
REL 2 3
DEC
DIR 1 5
DECA
INH 1 3 INH 2 1
DECX
INH 2 3 INH 3 1
DEC
IX1 3 5
DEC
SP1 1 6
DEC
IX 1 4
PULH
INH 1 2
CLI
INH 2 2
ORA
IMM 2 2
ORA
DIR 3 3
ORA
EXT 3 4
ORA
IX2 4 4
ORA
SP2 2 5
ORA
IX1 3 3
ORA
SP1 1 4
ORA
IX 2
BRCLR5 BCLR5
3 2
BMI
REL 3 3
DBNZ INC
DBNZA INCA
DBNZX INCX
INH 2 1
DBNZ
IX1 4 4
DBNZ
SP1 2 5
DBNZ
IX 1 3
PSHH
INH 1 1
SEI
INH 2 1
ADD
IMM 2
ADD
DIR 3 2
ADD
EXT 3 3
ADD
IX2 4 4
ADD
SP2 2
ADD
IX1 3 3
ADD
SP1 1
ADD
IX 2
DIR 2 4 DIR 1 3
BRSET6
3
BSET6
2
BMC
REL 2 3
INC
IX1 3 3
INC
SP1 1 4
INC
IX 1 2
CLRH
INH 1
RSP
INH 1 2 4
JMP
DIR 3 4
JMP
EXT 3 5
JMP
IX2 6 2
JMP
IX1 5 1
JMP
IX 4
INH 1 1
BRCLR6 BCLR6
3 2
BMS
REL 2 3
TST
DIR 1
TSTA
INH 1 5
TSTX
INH 2 4
TST
IX1 3 4
TST
SP1 1
TST
IX 4 1 1
NOP
INH 2
BSR
REL 2 2
JSR
DIR 3 3
JSR
EXT 3 4
JSR
IX2 4 2 5
JSR
IX1 3 1 4
JSR
IX 2
BRSET7
3
BSET7
2
BIL
REL 3 3 3
MOV
DD 2 1
MOV
DIX+ 3 1
MOV
IMD 3 2 4
MOV
IX+D 1 2
STOP
INH 1
*
1
LDX
2 IMM 2 2
LDX
DIR 3 3
LDX
EXT 3 4
LDX
IX2 4 4
LDX
SP2 2 5
LDX
IX1 3 3
LDX
SP1 1 4
LDX
IX 2
BRCLR7 BCLR7
3 2
BIH
REL 2
CLR
DIR 1
CLRA
INH 1 SP1 SP2 IX+ IX1+
CLRX
INH 2
CLR
IX1 3
CLR
SP1 1
CLR
IX 1
WAIT
INH 1
TXA
INH 2
AIX
IMM 2
STX
DIR 3
STX
EXT 3
STX
IX2 4
STX
SP2 2
STX
IX1 3
STX
SP1 1
STX
IX
Inherent REL Relative Immediate IX Indexed, No Offset Direct IX1 Indexed, 8-Bit Offset Extended IX2 Indexed, 16-Bit Offset DIR/DIR IMD IMM/DIR IX+/DIR DIX+ DIR/IX+ *Pre-byte for stack pointer indexed instructions
Stack Pointer, 8-Bit Offset Stack Pointer, 16-Bit Offset Indexed, No Offset with Post Increment Indexed, 1-Byte Offset with Post Increment
F SUB
1 2 HC08 Cycles Opcode Mnemonic IX Number of Bytes / Addressing Mode
5.2 Nomenclature
This nomenclature is used in the instruction descriptions 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 (twos complement) Sign extend
CPU registers
A CCR H X PC PCH PCL SP = = = = = = = = Accumulator Condition code register Index register, higher order (most significant) eight bits Index register, lower order (least significant) eight bits Program counter Program counter, higher order (most significant) eight bits Program counter, lower order (least significant) eight bits Stack pointer
Instruction Set
M =
M:M + $0001 =
rel
A memory location or absolute data, depending on addressing mode A 16-bit value in two consecutive memory locations. The higher-order (most significant) eight bits are located at the address of M, and the lower-order (least significant) eight bits are located at the next higher sequential address. The relative offset, which is the twos complement number stored in the last byte of machine code corresponding to a branch instruction
Nomenclature
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, refer to the documentation provided by the assembler vendor. Typically, assemblers are flexible about the use of spaces and tabs. Often, any number of spaces or tabs can be used where a single space is shown on the glossary pages. Spaces and tabs are also normally allowed before and after commas. When program labels are used, there must also be at least one tab or space before all instruction mnemonics. This required space is not apparent in the source forms. Everything in the source forms columns, except expressions in italic characters, is literal information which must appear in the assembly source file exactly as shown. The initial 3- to 5-letter mnemonic is always a literal expression. All commas, 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 07 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.
Instruction Set
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.
Address modes
INH IMM DIR EXT IX IX+ IX1 IX1+ IX2 REL SP1 SP2 = = = = = = = = = = = = Inherent (no operands) 8-bit or 16-bit immediate 8-bit direct 16-bit extended 16-bit indexed no offset 16-bit indexed no offset, post increment (CBEQ and MOV only) 16-bit indexed with 8-bit offset from H:X 16-bit indexed with 8-bit offset, post increment (CBEQ only) 16-bit indexed with 16-bit offset from H:X 8-bit relative offset Stack pointer relative with 8-bit offset Stack pointer relative with 16-bit offset
Instruction Set
ADC
Operation
A (A) + (M) + (C)
ADC
Description
Adds the contents of the C bit to the sum of the contents of A and M and places the result in A. This operation is useful for addition of operands that are larger than eight bits.
V: A7&M7&R7 | A7&M7&R7 Set if a twos 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 was a carry from the most significant bit (MSB) of the result; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form ADC ADC ADC ADC ADC ADC ADC ADC #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP Address Mode IMM DIR EXT IX2 IX1 IX SP2 SP1 Machine Code Opcode A9 B9 C9 D9 E9 F9 9ED9 9EE9 ee ff ff ii dd hh ee ff ll ff Operand(s) HC08 Cycles 2 3 4 4 3 2 5 4
Instruction Set
ADD
Operation
A (A) + (M)
ADD
Description
Adds the contents of M to the contents of A and places the result in A
V 1 1
V: A7&M7&R7 | A7&M7&R7 Set if a twos complement 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 was a carry from the MSB of the result; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form ADD ADD ADD ADD ADD ADD ADD ADD #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP Address Mode IMM DIR EXT IX2 IX1 IX SP2 SP1 Machine Code Opcode AB BB CB DB EB FB 9EDB 9EEB ee ff ff ii dd hh ee ff ll ff Operand(s) HC08 Cycles 2 3 4 4 3 2 5 4
Instruction Set
AIS
Operation
AIS
SP (SP) + (16 M)
Description
Adds the immediate operand to the stack pointer (SP). The immediate value is an 8-bit twos complement signed operand. The 8-bit operand is sign-extended to 16 bits prior to the addition. The AIS instruction 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.
Source Form, Addressing Mode, Machine Code, Cycle, and Access Detail
Source Form AIS #opr8i Address Mode IMM Machine Code Opcode A7 ii Operand(s) HC08 Cycles 2
Instruction Set
AIX
Operation
AIX
Description
Adds 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 twos complement signed offset. The 8-bit operand is sign- extended to 16 bits prior to the addition. This instruction does not affect any condition code bits so index register pointer calculations do not disturb the surrounding code which may rely on the state of CCR status bits.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form AIX #opr8i Address Mode IMM Machine Code Opcode AF ii Operand(s) HC08 Cycles 2
Instruction Set
AND
Operation
A (A) & (M)
Logical AND
AND
Description
Performs the logical AND between the contents of A and the contents of M and places the result in A. Each bit of A after the operation will be the logical AND of the corresponding bits of M and of A before the operation.
V 0 1 1
V: 0 Cleared 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
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form AND AND AND AND AND AND AND AND #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP Address Mode IMM DIR EXT IX2 IX1 IX SP2 SP1 Machine Code Opcode A4 B4 C4 D4 E4 F4 9ED4 9EE4 ee ff ff ii dd hh ee ff ll ff Operand(s) HC08 Cycles 2 3 4 4 3 2 5 4
Instruction Set
ASL
Operation
C b7
ASL
b0
Description
Shifts all bits of A, X, or M one place to the left. Bit 0 is loaded with a 0. The C bit in the CCR is loaded from the most significant bit of A, X, or M. This is mathematically equivalent to multiplication by two. The V bit indicates whether the sign of the result has changed.
V: R7b7 Set if the exclusive-OR of the resulting N and C flags is 1; 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: b7 Set if, before the shift, the MSB of A, X, or M was set; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form ASL ASLA ASLX ASL ASL ASL oprx8,X ,X oprx8,SP opr8a Addr Mode DIR INH (A) INH (X) IX1 IX SP1 Machine Code Opcode 38 48 58 68 78 9E68 ff ff Operand(s) dd HC08 Cycles 4 1 1 4 3 5
Instruction Set
ASR
Operation
ASR
b7
b0
Description
Shifts all bits of A, X, or M one place to the right. Bit 7 is held constant. Bit 0 is loaded into the C bit of the CCR. This operation effectively divides a twos complement value by 2 without changing its sign. The carry bit can be used to round the result.
V: R7b0 Set if the exclusive-OR of the resulting N and C flags is 1; 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: b0 Set if, before the shift, the LSB of A, X, or M was set; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form ASR ASRA ASRX ASR ASR ASR oprx8,X ,X oprx8,SP opr8a Address Mode DIR INH (A) INH (X) IX1 IX SP1 Machine Code Opcode 37 47 57 67 77 9E67 ff ff Operand(s) dd HC08 Cycles 4 1 1 4 3 5
Instruction Set
BCC
Operation
BCC
Description
Tests state of C bit in CCR and causes a branch if C is clear. BCC can be used after shift or rotate instructions or to check for overflow after operations on unsigned numbers. See the BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BCC Address Mode REL Machine Code Opcode 24 rr Operand(s) HC08 Cycles 3
rel
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BCLR n
Operation
Mn 0
BCLR n
Description
Clear bit n (n = 7, 6, 5, 0) in location M. All other bits in M are unaffected. In other words, M can be any random-access memory (RAM) or input/output (I/O) register address in the $0000 to $00FF area of memory. (Direct addressing mode is used to specify the address of the operand.) This instruction reads the specified 8-bit location, modifies the specified bit, and then writes the modified 8-bit value back to the memory location.
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form BCLR BCLR BCLR BCLR BCLR BCLR BCLR BCLR 0,opr8a 1,opr8a 2,opr8a 3,opr8a 4,opr8a 5,opr8a 6,opr8a 7,opr8a Address Mode DIR (b0) DIR (b1) DIR (b2) DIR (b3) DIR (b4) DIR (b5) DIR (b6) DIR (b7) Machine Code Opcode 11 13 15 17 19 1B 1D 1F Operand(s) dd dd dd dd dd dd dd dd HC08 Cycles 4 4 4 4 4 4 4 4
Instruction Set
BCS
Operation
BCS
Description
Tests the state of the C bit in the CCR and causes a branch if C is set. BCS can be used after shift or rotate instructions or to check for overflow after operations on unsigned numbers. See the BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BCS rel Address Mode REL Machine Code Opcode 25 rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BEQ
Operation
Branch if Equal
BEQ
If (Z) = 1, PC (PC) + $0002 + rel Simple branch; may be used with signed or unsigned operations
Description
Tests the state of the Z bit in the CCR and causes a branch if Z is set. Compare instructions perform a subtraction with two operands and produce an internal result without changing the original operands. If the two operands were equal, the internal result of the subtraction for the compare will be zero so the Z bit will be equal to one and the BEQ will cause a branch. This instruction can also be used after a load or store without having to do a separate test or compare on the loaded value. See the BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BEQ rel Address Mode REL Machine Code Opcode 27 rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BGE
Operation
BGE
If (N V) = 0, PC (PC) + $0002 + rel For signed twos complement values if (Accumulator) (Memory), then branch
Description
If the BGE instruction is executed immediately after execution of a CMP, CPHX, CPX, SBC, or SUB instruction, the branch occurs if and only if the twos complement number in the A, X, or H:X register was greater than or equal to the twos complement number in memory.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BGE rel Address Mode REL Machine Code Opcode 90 rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BGT
Operation
BGT
If (Z) | (N V) = 0, PC (PC) + $0002 + rel For signed twos complement values if (Accumulator) > (Memory), then branch
Description
If the BGT instruction is executed immediately after execution of a CMP, CPHX, CPX, SBC, or SUB instruction, the branch will occur if and only if the twos complement number in the A, X, or H:X register was greater than the twos complement number in memory.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BGT rel Address Mode REL Machine Code Opcode 92 rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BHCC
Operation
BHCC
Description
Tests the state of the H bit in the CCR and causes a branch if H is clear. This instruction is used in algorithms involving BCD numbers that were originally written for the M68HC05 or M68HC08 devices. The DAA instruction in the HC08 simplifies operations on BCD numbers so BHCC and BHCS should not be needed in new programs. See the BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BHCC rel Address Mode REL Machine Code Opcode 28 rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BHCS
Operation
BHCS
Description
Tests the state of the H bit in the CCR and causes a branch if H is set. This instruction is used in algorithms involving BCD numbers that were originally written for the M68HC05 or M68HC08 devices. The DAA instruction in the HC08 simplifies operations on BCD numbers so BHCC and BHCS should not be needed in new programs. See the BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BHCS rel Address Mode REL Machine Code Opcode 29 rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BHI
Operation
Branch if Higher
BHI
If (C) | (Z) = 0, PC (PC) + $0002 + rel For unsigned values, if (Accumulator) > (Memory), then branch
Description
Causes a branch if both C and Z are cleared. If the BHI instruction is executed immediately after execution of a CMP, CPHX, CPX, SBC, or SUB instruction, the branch will occur if the unsigned binary number in the A, X, or H:X register was greater than unsigned binary number in memory. Generally not useful after CLR, COM, DEC, INC, LDA, LDHX, LDX, STA, STHX, STX, or TST because these instructions do not affect the carry bit in the CCR. See the BRA instruction for details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BHI rel Address Mode REL Machine Code Opcode 22 rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BHS
Operation
BHS
If (C) = 0, PC (PC) + $0002 + rel For unsigned values, if (Accumulator) (Memory), then branch
Description
If the BHS instruction is executed immediately after execution of a CMP, CPHX, CPX, SBC, or SUB instruction, the branch will occur if the unsigned binary number in the A, X, or H:X register was greater than or equal to the unsigned binary number in memory. Generally not useful after CLR, COM, DEC, INC, LDA, LDHX, LDX, STA, STHX, STX, or TST because these instructions do not affect the carry bit in the CCR. See the BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BHS rel Address Mode REL Machine Code Opcode 24 rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BIH
Operation
BIH
Description
Tests the state of the external interrupt pin and causes a branch if the pin is high. See the BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BIH rel Address Mode REL Machine Code Opcode 2F rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BIL
Operation
BIL
Description
Tests the state of the external interrupt pin and causes a branch if the pin is low. See the BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BIL rel Address Mode REL Machine Code Opcode 2E rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BIT
Operation
(A) & (M)
Bit Test
BIT
Description
Performs the logical AND comparison of the contents of A and the contents of M and modifies the condition codes accordingly. Neither the contents of A nor M are altered. (Each bit of the result of the AND would be the logical AND of the corresponding bits of A and M.) This instruction is typically used to see if a particular bit, or any of several bits, in a byte are 1s. A mask value is prepared with 1s in any bit positions that are to be checked. This mask may be in accumulator A or memory and the unknown value to be checked will be in memory or the accumulator A, respectively. After the BIT instruction, a BNE instruction will branch if any bits in the tested location that correspond to 1s in the mask were 1s.
V: 0 Cleared 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
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form BIT BIT BIT BIT BIT BIT BIT BIT #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP Address Mode IMM DIR EXT IX2 IX1 IX SP2 SP1 Machine Code Opcode A5 B5 C5 D5 E5 F5 9ED5 9EE5 ee ff ff ii dd hh ee ff ll ff Operand(s) HC08 Cycles 2 3 4 4 3 2 5 4
Instruction Set
BLE
Operation
BLE
If (Z) | (N V) = 1, PC (PC) + $0002 + rel For signed twos complement numbers if (Accumulator) (Memory), then branch
Description
If the BLE instruction is executed immediately after execution of a CMP, CPHX, CPX, SBC, or SUB instruction, the branch will occur if and only if the twos complement in the A, X, or H:X register was less than or equal to the twos complement number in memory.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BLE rel Address Mode REL Machine Code Opcode 93 rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BLO
Operation
Branch if Lower
BLO
If (C) = 1, PC (PC) + $0002 + rel For unsigned values, if (Accumulator) < (Memory), then branch
Description
If the BLO instruction is executed immediately after execution of a CMP, CPHX, CPX, SBC, or SUB instruction, the branch will occur if the unsigned binary number in the A, X, or H:X register was less than the unsigned binary number in memory. Generally not useful after CLR, COM, DEC, INC, LDA, LDHX, LDX, STA, STHX, STX, or TST because these instructions do not affect the carry bit in the CCR. See the BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BLO rel Address Mode REL Machine Code Opcode 25 rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BLS
Operation
BLS
If (C) | (Z) = 1, PC (PC) + $0002 + rel For unsigned values, if (Accumulator) (Memory), then branch
Description
Causes a branch if (C is set) or (Z is set). If the BLS instruction is executed immediately after execution of a CMP, CPHX, CPX, SBC, or SUB instruction, the branch will occur if and only if the unsigned binary number in the A, X, or H:X register was less than or equal to the unsigned binary number in memory. Generally not useful after CLR, COM, DEC, INC, LDA, LDHX, LDX, STA, STHX, STX, or TST because these instructions do not affect the carry bit in the CCR. See the BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycle, and Access Detail
Source Form BLS rel Address Mode REL Machine Code Opcode 23 rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BLT
Operation
BLT
If (N V) = 1, PC (PC) + $0002 + rel For signed twos complement numbers if (Accumulator) < (Memory), then branch
Description
If the BLT instruction is executed immediately after execution of a CMP, CPHX, CPX, SBC, or SUB instruction, the branch will occur if and only if the twos complement number in the A, X, or H:X register was less than the twos complement number in memory. See the BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BLT rel Address Mode REL Machine Code Opcode 91 rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BMC
Operation
BMC
Description
Tests the state of the I bit in the CCR and causes a branch if I is clear (if interrupts are enabled). See the BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BMC rel Address Mode REL Machine Code Opcode 2C rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BMI
Operation
Branch if Minus
BMI
If (N) = 1, PC (PC) + $0002 + rel Simple branch; may be used with signed or unsigned operations
Description
Tests the state of the N bit in the CCR and causes a branch if N is set. Simply loading or storing A, X, or H:X will cause the N condition code bit to be set or cleared to match the most significant bit of the value loaded or stored. The BMI instruction can be used after such a load or store without having to do a separate test or compare instruction before the conditional branch. See the BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BMI rel Address Mode REL Machine Code Opcode 2B rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BMS
Operation
BMS
Description
Tests the state of the I bit in the CCR and causes a branch if I is set (if interrupts are disabled). See BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BMS rel Address Mode REL Machine Code Opcode 2D rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BNE
Operation
BNE
If (Z) = 0, PC (PC) + $0002 + rel Simple branch, may be used with signed or unsigned operations
Description
Tests the state of the Z bit in the CCR and causes a branch if Z is clear Following a compare or subtract instruction, the branch will occur if the arguments were not equal. This instruction can also be used after a load or store without having to do a separate test or compare on the loaded value. See the BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BNE rel Address Mode REL Machine Code Opcode 26 rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BPL
Operation
Branch if Plus
BPL
Description
Tests the state of the N bit in the CCR and causes a branch if N is clear Simply loading or storing A, X, or H:X will cause the N condition code bit to be set or cleared to match the most significant bit of the value loaded or stored. The BPL instruction can be used after such a load or store without having to do a separate test or compare instruction before the conditional branch. See the BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BPL rel Address Mode REL Machine Code Opcode 2A rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BRA
Operation
PC (PC) + $0002 + rel
Branch Always
BRA
Description
Performs an unconditional branch to the address given in the foregoing formula. In this formula, rel is the twos-complement relative offset in the last byte of machine code for the instruction and (PC) is the address of the opcode for the branch instruction. A source program specifies the destination of a branch instruction by its absolute address, either as a numerical value or as a symbol or expression which can be numerically evaluated by the assembler. The assembler calculates the 8-bit relative offset rel from this absolute address and the current value of the location counter.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BRA rel Address Mode REL Machine Code Opcode 20 rr Operand(s) HC08 Cycles 3
Instruction Set
BRA
Branch Instruction Summary
BRA
Table 5-1 is a summary of all branch instructions. Table 5-1. Branch Instruction Summary
Branch Test r>m rm r=m rm r<m r>m rm r=m rm r<m Carry result=0 Negative I mask H-Bit IRQ high Always Boolean (Z) | (NV)=0 (NV)=0 (Z)=1 (Z) | (NV)=1 (NV)=1 (C) | (Z)=0 (C)=0 (Z)=1 (C) | (Z)=1 (C)=1 (C)=1 (Z)=1 (N)=1 (I)=1 (H)=1 Mnemonic Opcode BGT BGE BEQ BLE BLT BHI BHS/BCC BEQ BLS BLO/BCS BCS BEQ BMI BMS BHCS BIH BRA 92 90 27 93 91 22 24 27 23 25 25 27 2B 2D 29 2F 20 Complementary Branch Test rm r<m rm r>m rm rm r<m rm r>m rm No carry result0 Plus I mask=0 H=0 Never Mnemonic Opcode BLE BLT BNE BGT BGE BLS BLO/BCS BNE BHI BHS/BCC BCC BNE BPL BMC BHCC BIL BRN 93 91 26 92 90 23 25 26 22 24 24 26 2A 2C 28 2E 21 Type Signed Signed Signed Signed Signed Unsigned Unsigned Unsigned Unsigned Unsigned Simple Simple Simple Simple Simple Simple Uncond.
m = memory operand
During program execution, if the tested condition is true, the twos complement offset is sign-extended to a 16-bit value which is added to the current program counter. This causes program execution to continue at the address specified as the branch destination. If the tested condition is not true, the program simply continues to the next instruction after the branch.
Instruction Set
BRCLR n
Operation
BRCLR n
Description
Tests bit n (n = 7, 6, 5, 0) of location M and branches if the bit is clear. M can be any RAM or I/O register address in the $0000 to $00FF area of memory because direct addressing mode is used to specify the address of the operand. The C bit is set to the state of the tested bit. When used with an appropriate rotate instruction, BRCLR n provides an easy method for performing serial-to-parallel conversions.
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form BRCLR BRCLR BRCLR BRCLR BRCLR BRCLR BRCLR BRCLR 0,opr8a,rel 1,opr8a,rel 2,opr8a,rel 3,opr8a,rel 4,opr8a,rel 5,opr8a,rel 6,opr8a,rel 7,opr8a,rel Address Mode DIR (b0) DIR (b1) DIR (b2) DIR (b3) DIR (b4) DIR (b5) DIR (b6) DIR (b7) Machine Code Opcode 01 03 05 07 09 0B 0D 0F Operand(s) dd dd dd dd dd dd dd dd rr rr rr rr rr rr rr rr HC08 Cycles 5 5 5 5 5 5 5 5
Instruction Set
BRN
Operation
PC (PC) + $0002
Branch Never
BRN
Description
Never branches. In effect, this instruction can be considered a 2-byte no operation (NOP) requiring three cycles for execution. Its inclusion in the instruction set provides a complement for the BRA instruction. The BRN instruction is useful during program debugging to negate the effect of another branch instruction without disturbing the offset byte. This instruction can be useful in instruction-based timing delays. Instruction-based timing delays are usually discouraged because such code is not portable to systems with different clock speeds.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BRN rel Address Mode REL Machine Code Opcode 21 rr Operand(s) HC08 Cycles 3
See the BRA instruction for a summary of all branches and their complements.
Instruction Set
BRSET n
Operation
BRSET n
Description
Tests bit n (n = 7, 6, 5, 0) of location M and branches if the bit is set. M can be any RAM or I/O register address in the $0000 to $00FF area of memory because direct addressing mode is used to specify the address of the operand. The C bit is set to the state of the tested bit. When used with an appropriate rotate instruction, BRSET n provides an easy method for performing serial-to-parallel conversions.
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form BRSET BRSET BRSET BRSET BRSET BRSET BRSET BRSET 0,opr8a,rel 1,opr8a,rel 2,opr8a,rel 3,opr8a,rel 4,opr8a,rel 5,opr8a,rel 6,opr8a,rel 7,opr8a,rel Address Mode DIR (b0) DIR (b1) DIR (b2) DIR (b3) DIR (b4) DIR (b5) DIR (b6) DIR (b7) Machine Code Opcode 00 02 04 06 08 0A 0C 0E Operand(s) dd dd dd dd dd dd dd dd rr rr rr rr rr rr rr rr HC08 Cycles 5 5 5 5 5 5 5 5
Instruction Set
BSET n
Operation
Mn 1
BSET n
Description
Set bit n (n = 7, 6, 5, 0) in location M. All other bits in M are unaffected. M can be any RAM or I/O register address in the $0000 to $00FF area of memory because direct addressing mode is used to specify the address of the operand. This instruction reads the specified 8-bit location, modifies the specified bit, and then writes the modified 8-bit value back to the memory location.
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form BSET BSET BSET BSET BSET BSET BSET BSET 0,opr8a 1,opr8a 2,opr8a 3,opr8a 4,opr8a 5,opr8a 6,opr8a 7,opr8a Address Mode DIR (b0) DIR (b1) DIR (b2) DIR (b3) DIR (b4) DIR (b5) DIR (b6) DIR (b7) Machine Code Opcode 10 12 14 16 18 1A 1C 1E Operand(s) dd dd dd dd dd dd dd dd HC08 Cycles 4 4 4 4 4 4 4 4
Instruction Set
BSR
Operation
Branch to Subroutine
BSR
PC (PC) + $0002 Advance PC to return address Push (PCL); SP (SP) $0001Push low half of return address Push (PCH); SP (SP) $0001Push high half of return address PC (PC) + rel Load PC with start address of requested subroutine
Description
The program counter is incremented by 2 from the opcode address (so it points to the opcode of the next instruction which will be the return address). The least significant byte of the contents of the program counter (low-order return address) is pushed onto the stack. The stack pointer is then decremented by 1. The most significant byte of the contents of the program counter (high-order return address) is pushed onto the stack. The stack pointer is then decremented by 1. A branch then occurs to the location specified by the branch offset. See the BRA instruction for further details of the execution of the branch.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form BSR rel Address Mode REL Machine Code Opcode AD rr Operand(s) HC08 Cycles 4
Instruction Set
CBEQ
Operation
CBEQ
For DIR or IMM modes:if (A) = (M), PC (PC) + $0003 + rel Or for IX+ mode: if (A) = (M); PC (PC) + $0002 + rel Or for SP1 mode: if (A) = (M); PC (PC) + $0004 + rel Or for CBEQX:if (X) = (M); PC (PC) + $0003 + rel
Description
CBEQ compares the operand with the accumulator (or index register for CBEQX instruction) against the contents of a memory location and causes a branch if the register (A or X) is equal to the memory contents. The CBEQ instruction combines CMP and BEQ for faster table lookup routines and condition codes are not changed. The IX+ variation of the CBEQ instruction compares the operand addressed by H:X to A and causes a branch if the operands are equal. H:X is then incremented regardless of whether a branch is taken. The IX1+ variation of CBEQ operates the same way except that an 8-bit offset is added to H:X to form the effective address of the operand.
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form CBEQ CBEQA CBEQX CBEQ CBEQ CBEQ opr8a,rel #opr8i,rel #opr8i,rel oprx8,X+,rel ,X+,rel oprx8,SP,rel Address Mode DIR IMM IMM IX1+ IX+ SP1 Machine Code Opcode 31 41 51 61 71 9E61 ii ii ff rr ff rr Operand(s) dd rr rr rr rr HC08 Cycles 5 4 4 5 4 6
Instruction Set
CLC
Operation
C bit 0
CLC
Description
Clears the C bit in the CCR. CLC may be used to set up the C bit prior to a shift or rotate instruction that involves the C bit. The C bit can also be used to pass status information between a subroutine and the calling program.
C: 0 Cleared
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form CLC Address Mode INH Machine Code Opcode 98 Operand(s) HC08 Cycles 1
CPU08 Central Processor Unit Reference Manual, Rev. 4 100 Freescale Semiconductor
Instruction Set
CLI
Operation
I bit 0
CLI
Description
Clears the interrupt mask bit in the CCR. When the I bit is clear, interrupts are enabled. The next instruction after a CLI will not be executed if there was an interrupt pending prior to execution of the CLI instruction.
I:
0 Cleared
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form CLI Address Mode INH Machine Code Opcode 9A Operand(s) HC08 Cycles 2
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 101
Instruction Set
CLR
Operation
A $00 Or M $00 Or X $00 Or H $00
Clear
CLR
Description
The contents of memory (M), A, X, or H are replaced with zeros.
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form CLR CLRA CLRX CLRH CLR CLR CLR oprx8,X ,X oprx8,SP opr8a Address Mode DIR INH (A) INH (X) INH (H) IX1 IX SP1 Machine Code Opcode 3F 4F 5F 8C 6F 7F 9E6F ff ff Operand(s) dd HC08 Cycles 3 1 1 1 3 2 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 102 Freescale Semiconductor
Instruction Set
CMP
Operation
(A) (M)
CMP
Description
Compares the contents of A to the contents of M and sets the condition codes, which may then be used for arithmetic (signed or unsigned) and logical conditional branching. The contents of both A and M are unchanged.
V: A7&M7&R7 | A7&M7&R7 Set if a twos complement overflow resulted from the operation; cleared otherwise. Literally read, an overflow condition occurs if a positive number is subtracted from a negative number with a positive result, or, if a negative number is subtracted from a positive number with a negative result. 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 the unsigned value of the contents of memory is larger than the unsigned value of the accumulator; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form CMP CMP CMP CMP CMP CMP CMP CMP #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP Address Mode IMM DIR EXT IX2 IX1 IX SP2 SP1 Machine Code Opcode A1 B1 C1 D1 E1 F1 9ED1 9EE1 ee ff ff ii dd hh ee ff ll ff Operand(s) HC08 Cycles 2 3 4 4 3 2 5 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 103
Instruction Set
COM
Operation
COM
Description
Replaces the contents of A, X, or M with the ones complement. Each bit of A, X, or M is replaced with the complement of that bit.
V: 0 Cleared 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: 1 Set
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form COM COMA COMX COM COM COM oprx8,X ,X oprx8,SP opr8a Address Mode DIR INH (A) INH (X) IX1 IX SP1 Machine Code Opcode 33 43 53 63 73 9E63 ff ff Operand(s) dd HC08 Cycles 4 1 1 4 3 5
CPU08 Central Processor Unit Reference Manual, Rev. 4 104 Freescale Semiconductor
Instruction Set
CPHX
Operation
CPHX
Description
CPHX compares index register (H:X) with the 16-bit value in memory and sets the condition codes, which may then be used for arithmetic (signed or unsigned) and logical conditional branching. The contents of both H:X and M:M + $0001 are unchanged.
V: H7&M15&R15 | H7&M15&R15 Set if a twos complement overflow resulted from the operation; cleared otherwise N: R15 Set if MSB of result is 1; cleared otherwise Z: R15&R14&R13&R12&R11&R10&R9&R8 &R7&R6&R5&R4&R3&R2&R1&R0 Set if the result is $0000; cleared otherwise C: H7&M15 | M15&R15 | R15&H7 Set if the absolute value of the contents of memory is larger than the absolute value of the index register; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form CPHX CPHX #opr opr Address Mode IMM DIR Machine Code Opcode 65 75 jj dd Operand(s) kk+1 HC08 Cycles 3 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 105
Instruction Set
CPX
Operation
(X) (M)
CPX
Description
Compares the contents of X to the contents of M and sets the condition codes, which may then be used for arithmetic (signed or unsigned) and logical conditional branching. The contents of both X and M are unchanged.
V: X7&M7&R7 | X7&M7&R7 Set if a twos complement overflow resulted from the operation; cleared otherwise N: R7 Set if MSB of result of the subtraction is 1; cleared otherwise Z: R7&R6&R5&R4&R3&R2&R1&R0 Set if result is $00; cleared otherwise C: X7&M7 | M7&R7 | R7&X7 Set if the unsigned value of the contents of memory is larger than the unsigned value in the index register; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form CPX CPX CPX CPX CPX CPX CPX CPX #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP Address Mode IMM DIR EXT IX2 IX1 IX SP2 SP1 Machine Code Opcode A3 B3 C3 D3 E3 F3 9ED3 9EE3 ee ff ff ii dd hh ee ff ll ff Operand(s) HC08 Cycles 2 3 4 4 3 2 5 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 106 Freescale Semiconductor
Instruction Set
DAA
Operation
(A)10
DAA
Description
Adjusts the contents of the accumulator and the state of the CCR carry bit after an ADD or ADC operation involving binary-coded decimal (BCD) values, so that there is a correct BCD sum and an accurate carry indication. The state of the CCR half carry bit affects operation. Refer to Table 5-2 for details of operation.
V: U Undefined 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: Set if the decimal adjusted result is greater than 99 (decimal); refer to Table 5-2
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form DAA Address Mode INH Machine Code Opcode 72 Operand(s) HC08 Cycles 2
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 107
Instruction Set
DAA
DAA
Table 5-2 shows DAA operation for all legal combinations of input operands. Columns 14 represent the results of ADC or ADD operations on BCD operands. The correction factor in column 5 is added to the accumulator to restore the result of an operation on two BCD operands to a valid BCD value and to set or clear the C bit. All values in this table are hexadecimal
.
CPU08 Central Processor Unit Reference Manual, Rev. 4 108 Freescale Semiconductor
Instruction Set
DBNZ
Operation
DBNZ
A (A) $01 Or M (M) $01 Or X (X) $01 For DIR or IX1 modes:PC (PC) + $0003 + rel if (result) 0 Or for INH or IX modes:PC (PC) + $0002 + rel if (result) 0 Or for SP1 mode:PC (PC) + $0004 + rel if (result) 0
Description
Subtract 1 from the contents of A, M, or X; then branch using the relative offset if the result of the subtraction is not $00. DBNZX only affects the low order eight bits of the H:X index register pair; the high-order byte (H) is not affected.
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form DBNZ DBNZA DBNZX DBNZ DBNZ DBNZ opr8a,rel rel rel oprx8,X,rel ,X, rel oprx8,SP,rel Address Mode DIR INH INH IX1 IX SP1 Machine Code Opcode 3B 4B 5B 6B 7B 9E6B rr rr ff rr ff rr rr Operand(s) dd rr HC08 Cycles 5 3 3 5 4 6
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 109
Instruction Set
DEC
Operation
A (A) $01 Or X (X) $01 Or M (M) $01
Decrement
DEC
Description
Subtract 1 from the contents of A, X, or M. The V, N, and Z bits in the CCR are set or cleared according to the results of this operation. The C bit in the CCR is not affected; therefore, the BLS, BLO, BHS, and BHI branch instructions are not useful following a DEC instruction. DECX only affects the low-order byte of index register pair (H:X). To decrement the full 16-bit index register pair (H:X), use AIX # 1.
V: R7 & A7 Set if there was a twos complement overflow as a result of the operation; cleared otherwise. Twos complement overflow occurs if and only if (A), (X), or (M) was $80 before the operation. 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
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form DEC DECA DECX DEC DEC DEC oprx8,X ,X oprx8,SP opr8a Address Mode DIR INH (A) INH (X) IX1 IX SP1 Machine Code Opcode 3A 4A 5A 6A 7A 9E6A ff ff Operand(s) dd HC08 Cycles 4 1 1 4 3 5
CPU08 Central Processor Unit Reference Manual, Rev. 4 110 Freescale Semiconductor
Instruction Set
DIV
Operation
A (H:A) (X); H Remainder
Divide
DIV
Description
Divides a 16-bit unsigned dividend contained in the concatenated registers H and A by an 8-bit divisor contained in X. The quotient is placed in A, and the remainder is placed in H. The divisor is left unchanged. An overflow (quotient > $FF) or divide-by-0 sets the C bit, and the quotient and remainder are indeterminate.
Z: R7&R6&R5&R4&R3&R2&R1&R0 Set if result (quotient) is $00; cleared otherwise C: Set if a divide-by-0 was attempted or if an overflow occurred; cleared otherwise
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form DIV Address Mode INH Machine Code Opcode 52 Operand(s) HC08 Cycles 7
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 111
Instruction Set
EOR
Operation
A (A M)
EOR
Description
Performs the logical exclusive-OR between the contents of A and the contents of M and places the result in A. Each bit of A after the operation will be the logical exclusive-OR of the corresponding bits of M and A before the operation.
V: 0 Cleared 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
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form EOR EOR EOR EOR EOR EOR EOR EOR #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP Address Mode IMM DIR EXT IX2 IX1 IX SP2 SP1 Machine Code Opcode A8 B8 C8 D8 E8 F8 9ED8 9EE8 ee ff ff ii dd hh ee ff ll ff Operand(s) HC08 Cycles 2 3 4 4 3 2 5 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 112 Freescale Semiconductor
Instruction Set
INC
Operation
A (A) + $01 Or X (X) + $01 Or M (M) + $01
Increment
INC
Description
Add 1 to the contents of A, X, or M. The V, N, and Z bits in the CCR are set or cleared according to the results of this operation. The C bit in the CCR is not affected; therefore, the BLS, BLO, BHS, and BHI branch instructions are not useful following an INC instruction. INCX only affects the low-order byte of index register pair (H:X). To increment the full 16-bit index register pair (H:X), use AIX #1.
V: A7&R7 Set if there was a twos complement overflow as a result of the operation; cleared otherwise. Twos complement overflow occurs if and only if (A), (X), or (M) was $7F before the operation. 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
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form INC INCA INCX INC INC INC oprx8,X ,X oprx8,SP opr8a Address Mode DIR INH (A) INH (X) IX1 IX SP1 Machine Code Opcode 3C 4C 5C 6C 7C 9E6C ff ff Operand(s) dd HC08 Cycles 4 1 1 4 3 5
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 113
Instruction Set
JMP
Operation
PC effective address
Jump
JMP
Description
A jump occurs to the instruction stored at the effective address. The effective address is obtained according to the rules for extended, direct, or indexed addressing.
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form JMP JMP JMP JMP JMP opr8a opr16a oprx16,X oprx8,X ,X Address Mode DIR EXT IX2 IX1 IX Machine Code Opcode BC CC DC EC FC Operand(s) dd hh ee ff ll ff HC08 Cycles 2 3 4 3 3
CPU08 Central Processor Unit Reference Manual, Rev. 4 114 Freescale Semiconductor
Instruction Set
JSR
Operation
Jump to Subroutine
JSR
PC (PC) + n; n = 1, 2, or 3 depending on address mode Push (PCL); SP (SP) $0001Push low half of return address Push (PCH); SP (SP) $0001Push high half of return address PC effective addressLoad PC with start address of requested subroutine
Description
The program counter is incremented by n so that it points to the opcode of the next instruction that follows the JSR instruction (n = 1, 2, or 3 depending on the addressing mode). The PC is then pushed onto the stack, eight bits at a time, least significant byte first. The stack pointer points to the next empty location on the stack. A jump occurs to the instruction stored at the effective address. The effective address is obtained according to the rules for extended, direct, or indexed addressing.
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form JSR JSR JSR JSR JSR opr8a opr16a oprx16,X oprx8,X ,X Address Mode DIR EXT IX2 IX1 IX Machine Code Opcode BD CD DD ED FD Operand(s) dd hh ee ff ll ff HC08 Cycles 4 5 6 5 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 115
Instruction Set
LDA
Operation
A (M)
LDA
Description
Loads the contents of the specified memory location into A. The N and Z condition codes are set or cleared according to the loaded data; V is cleared. This allows conditional branching after the load without having to perform a separate test or compare.
V: 0 Cleared 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
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form LDA LDA LDA LDA LDA LDA LDA LDA #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP Address Mode IMM DIR EXT IX2 IX1 IX SP2 SP1 Machine Code Opcode A6 B6 C6 D6 E6 F6 9ED6 9EE6 ee ff ff ii dd hh ee ff ll ff Operand(s) HC08 Cycles 2 3 4 4 3 2 5 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 116 Freescale Semiconductor
Instruction Set
LDHX
Operation
LDHX
Description
Loads the contents of the specified memory location into the index register (H:X). The N and Z condition codes are set according to the data; V is cleared. This allows conditional branching after the load without having to perform a separate test or compare.
V: 0 Cleared N: R15 Set if MSB of result is 1; cleared otherwise Z: R15&R14&R13&R12&R11&R10&R9&R8 &R7&R6&R5&R4&R3&R2&R1&R0 Set if the result is $0000; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form LDHX LDHX #opr opr Address Mode IMM DIR Machine Code Opcode 45 55 jj dd Operand(s) kk HC08 Cycles 3 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 117
Instruction Set
LDX
Operation
X (M)
LDX
Description
Loads the contents of the specified memory location into X. The N and Z condition codes are set or cleared according to the loaded data; V is cleared. This allows conditional branching after the load without having to perform a separate test or compare.
V: 0 Cleared 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
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form LDX LDX LDX LDX LDX LDX LDX LDX #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP Address Mode IMM DIR EXT IX2 IX1 IX SP2 SP1 Machine Code Opcode AE BE CE DE EE FE 9EDE 9EEE ee ff ff ii dd hh ee ff ll ff Operand(s) HC08 Cycles 2 3 4 4 3 2 5 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 118 Freescale Semiconductor
Instruction Set
LSL
Operation
C b7
LSL
b0
Description
Shifts all bits of the A, X, or M one place to the left. Bit 0 is loaded with a 0. The C bit in the CCR is loaded from the most significant bit of A, X, or M.
V: R7b7 Set if the exclusive-OR of the resulting N and C flags is 1; 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: b7 Set if, before the shift, the MSB of A, X, or M was set; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form LSL LSLA LSLX LSL LSL LSL oprx8,X ,X oprx8,SP opr8a Address Mode DIR INH (A) INH (X) IX1 IX SP1 Machine Code Opcode 38 48 58 68 78 9E68 ff ff Operand(s) dd HC08 Cycles 4 1 1 4 3 5
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 119
Instruction Set
LSR
Operation
0 b7
LSR
b0 C
Description
Shifts all bits of A, X, or M one place to the right. Bit 7 is loaded with a 0. Bit 0 is shifted into the C bit.
V: 0b0 = b0 Set if the exclusive-OR of the resulting N and C flags is 1; cleared otherwise. Since N = 0, this simplifies to the value of bit 0 before the shift. N: 0 Cleared Z: R7&R6&R5&R4&R3&R2&R1&R0 Set if result is $00; cleared otherwise C: b0 Set if, before the shift, the LSB of A, X, or M, was set; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form LSR LSRA LSRX LSR LSR LSR oprx8,X ,X oprx8,SP opr8a Address Mode DIR INH (A) INH (X) IX1 IX SP1 Machine Code Opcode 34 44 54 64 74 9E64 ff ff Operand(s) dd HC08 Cycles 4 1 1 4 3 5
CPU08 Central Processor Unit Reference Manual, Rev. 4 120 Freescale Semiconductor
Instruction Set
MOV
Operation
(M)Destination (M)Source
Move
MOV
Description
Moves a byte of data from a source address to a destination address. Data is examined as it is moved, and condition codes are set. Source data is not changed. The accumulator is not affected. The four addressing modes for the MOV instruction are: 1. IMM/DIR moves an immediate byte to a direct memory location. 2. DIR/DIR moves a direct location byte to another direct location. 3. IX+/DIR moves a byte from a location addressed by H:X to a direct location. H:X is incremented after the move. 4. DIR/IX+ moves a byte from a direct location to one addressed by H:X. H:X is incremented after the move.
V: 0 Cleared N: R7 Set if MSB of result is set; cleared otherwise Z: R7&R6&R5&R4&R3&R2&R1&R0 Set if result is $00; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form MOV MOV MOV MOV opr8a,opr8a opr8a,X+ #opr8i,opr8a ,X+,opr8a Address Mode DIR/DIR DIR/IX+ IMM/DIR IX+/DIR Machine Code Opcode 4E 5E 6E 7E Operand(s) dd dd ii dd dd dd HC08 Cycles 5 4 4 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 121
Instruction Set
MUL
Operation
X:A (X) (A)
Unsigned Multiply
MUL
Description
Multiplies the 8-bit value in X (index register low) by the 8-bit value in the accumulator to obtain a 16-bit unsigned result in the concatenated index register and accumulator. After the operation, X contains the upper eight bits of the 16-bit result and A contains the lower eight bits of the result.
H: 0 Cleared C: 0 Cleared
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form MUL Address Mode INH Machine Code Opcode 42 Operand(s) HC08 Cycles 5
CPU08 Central Processor Unit Reference Manual, Rev. 4 122 Freescale Semiconductor
Instruction Set
NEG
Operation
NEG
Description
Replaces the contents of A, X, or M with its twos complement. Note that the value $80 is left unchanged.
V: M7&R7 Set if a twos complement overflow resulted from the operation; cleared otherwise. Overflow will occur only if the operand is $80 before the operation. 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: R7|R6|R5|R4|R3|R2|R1|R0 Set if there is a borrow in the implied subtraction from 0; cleared otherwise. The C bit will be set in all cases except when the contents of A, X, or M was $00 prior to the NEG operation.
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form NEG NEGA NEGX NEG NEG NEG oprx8,X ,X oprx8,SP opr8a Address Mode DIR INH (A) INH (X) IX1 IX SP1 Machine Code Opcode 30 40 50 60 70 9E60 ff ff Operand(s) dd HC08 Cycles 4 1 1 4 3 5
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 123
Instruction Set
NOP
Operation
Uses one bus cycle
No Operation
NOP
Description
This is a single-byte instruction that does nothing except to consume one CPU clock cycle while the program counter is advanced to the next instruction. No register or memory contents are affected by this instruction.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form NOP Address Mode INH Machine Code Opcode 9D Operand(s) HC08 Cycles 1
CPU08 Central Processor Unit Reference Manual, Rev. 4 124 Freescale Semiconductor
Instruction Set
NSA
Operation
A (A[3:0]:A[7:4])
NSA
Description
Swaps upper and lower nibbles (4 bits) of the accumulator. The NSA instruction is used for more efficient storage and use of binary-coded decimal operands.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form NSA Address Mode INH Machine Code Opcode 62 Operand(s) HC08 Cycles 3
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 125
Instruction Set
ORA
Operation
A (A) | (M)
ORA
Description
Performs the logical inclusive-OR between the contents of A and the contents of M and places the result in A. Each bit of A after the operation will be the logical inclusive-OR of the corresponding bits of M and A before the operation.
V: 0 Cleared 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
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form ORA ORA ORA ORA ORA ORA ORA ORA #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP Address Mode IMM DIR EXT IX2 IX1 IX SP2 SP1 Machine Code Opcode AA BA CA DA EA FA 9EDA 9EEA ee ff ff ii dd hh ee ff ll ff Operand(s) HC08 Cycles 2 3 4 4 3 2 5 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 126 Freescale Semiconductor
Instruction Set
PSHA
Operation
PSHA
Description
The contents of A are pushed onto the stack at the address contained in the stack pointer. The stack pointer is then decremented to point to the next available location in the stack. The contents of A remain unchanged.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form PSHA Address Mode INH Machine Code Opcode 87 Operand(s) HC08 Cycles 2
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 127
Instruction Set
PSHH
Operation
PSHH
Description
The contents of H are pushed onto the stack at the address contained in the stack pointer. The stack pointer is then decremented to point to the next available location in the stack. The contents of H remain unchanged.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form PSHH Address Mode INH Machine Code Opcode 8B Operand(s) HC08 Cycles 2
CPU08 Central Processor Unit Reference Manual, Rev. 4 128 Freescale Semiconductor
Instruction Set
PSHX
Operation
PSHX
Description
The contents of X are pushed onto the stack at the address contained in the stack pointer (SP). SP is then decremented to point to the next available location in the stack. The contents of X remain unchanged.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form PSHX Address Mode INH Machine Code Opcode 89 Operand(s) HC08 Cycles 2
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 129
Instruction Set
PULA
Operation
PULA
Description
The stack pointer (SP) is incremented to address the last operand on the stack. The accumulator is then loaded with the contents of the address pointed to by SP.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form PULA Address Mode INH Machine Code Opcode 86 Operand(s) HC08 Cycles 2
CPU08 Central Processor Unit Reference Manual, Rev. 4 130 Freescale Semiconductor
Instruction Set
PULH
Operation
PULH
Description
The stack pointer (SP) is incremented to address the last operand on the stack. H is then loaded with the contents of the address pointed to by SP.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form PULH Address Mode INH Machine Code Opcode 8A Operand(s) HC08 Cycles 2
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 131
Instruction Set
PULX
Operation
PULX
Description
The stack pointer (SP) is incremented to address the last operand on the stack. X is then loaded with the contents of the address pointed to by SP.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form PULX Address Mode INH Machine Code Opcode 88 Operand(s) HC08 Cycles 2
CPU08 Central Processor Unit Reference Manual, Rev. 4 132 Freescale Semiconductor
Instruction Set
ROL
Operation
C b7
ROL
b0
Description
Shifts all bits of A, X, or M one place to the left. Bit 0 is loaded from the C bit. The C bit is loaded from the most significant bit of A, X, or M. The rotate instructions include the carry bit to allow extension of the shift and rotate instructions to multiple bytes. For example, to shift a 24-bit value left one bit, the sequence (ASL LOW, ROL MID, ROL HIGH) could be used, where LOW, MID, and HIGH refer to the low-order, middle, and high-order bytes of the 24-bit value, respectively.
V: R7 b7 Set if the exclusive-OR of the resulting N and C flags is 1; 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: b7 Set if, before the rotate, the MSB of A, X, or M was set; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form ROL ROLA ROLX ROL ROL ROL oprx8,X ,X oprx8,SP opr8a Address Mode DIR INH (A) INH (X) IX1 IX SP1 Machine Code Opcode 39 49 59 69 79 9E69 ff ff Operand(s) dd HC08 Cycles 4 1 1 4 3 5
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 133
Instruction Set
ROR
Operation
b7
ROR
C
b0
Description
Shifts all bits of A, X, or M one place to the right. Bit 7 is loaded from the C bit. Bit 0 is shifted into the C bit. The rotate instructions include the carry bit to allow extension of the shift and rotate instructions to multiple bytes. For example, to shift a 24-bit value right one bit, the sequence (LSR HIGH, ROR MID, ROR LOW) could be used, where LOW, MID, and HIGH refer to the low-order, middle, and high-order bytes of the 24-bit value, respectively.
V: R7 b0 Set if the exclusive-OR of the resulting N and C flags is 1; 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: b0 Set if, before the shift, the LSB of A, X, or M was set; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form ROR RORA RORX ROR ROR ROR oprx8,X ,X oprx8,SP opr8a Address Mode DIR INH (A) INH (X) IX1 IX SP1 Machine Code Opcode 36 46 56 66 76 9E66 ff ff Operand(s) dd HC08 Cycles 4 1 1 4 3 5
CPU08 Central Processor Unit Reference Manual, Rev. 4 134 Freescale Semiconductor
Instruction Set
RSP
Operation
RSP
Description
For M68HC05 compatibility, the M68HC08 RSP instruction only sets the least significant byte of SP to $FF. The most significant byte is unaffected. In most M68HC05 MCUs, RAM only goes to $00FF. In most HC08s, however, RAM extends beyond $00FF. Therefore, do not locate the stack in direct address space which is more valuable for commonly accessed variables. In new HC08 programs, it is more appropriate to initialize the stack pointer to the address of the last location (highest address) in the on-chip RAM, shortly after reset. This code segment demonstrates a typical method for initializing SP.
LDHX TXS #ram_end+1 ; Point at next addr past RAM ; SP <-(H:X)-1
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form RSP Address Mode INH Machine Code Opcode 9C Operand(s) HC08 Cycles 1
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 135
Instruction Set
RTI
Operation
RTI
SP SP + $0001; pull (CCR)Restore CCR from stack SP SP + $0001; pull (A)Restore A from stack SP SP + $0001; pull (X)Restore X from stack SP SP + $0001; pull (PCH)Restore PCH from stack SP SP + $0001; pull (PCL)Restore PCL from stack
Description
The condition codes, the accumulator, X (index register low), and the program counter are restored to the state previously saved on the stack. The I bit will be cleared if the corresponding bit stored on the stack is 0, the normal case.
Set or cleared according to the byte pulled from the stack into CCR.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form RTI Address Mode INH Machine Code Opcode 80 Operand(s) HC08 Cycles 7
CPU08 Central Processor Unit Reference Manual, Rev. 4 136 Freescale Semiconductor
Instruction Set
RTS
Operation
RTS
SP SP + $0001; pull (PCH)Restore PCH from stack SP SP + $0001; pull (PCL)Restore PCL from stack
Description
The stack pointer is incremented by 1. The contents of the byte of memory that is pointed to by the stack pointer are loaded into the high-order byte of the program counter. The stack pointer is again incremented by 1. The contents of the byte of memory that are pointed to by the stack pointer are loaded into the low-order eight bits of the program counter. Program execution resumes at the address that was just restored from the stack.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form RTS Address Mode INH Machine Code Opcode 81 Operand(s) HC08 Cycles 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 137
Instruction Set
SBC
Operation
A (A) (M) (C)
SBC
Description
Subtracts the contents of M and the contents of the C bit of the CCR from the contents of A and places the result in A. This is useful for multi-precision subtract algorithms involving operands with more than eight bits.
V: A7&M7&R7 | A7&M7&R7 Set if a twos complement overflow resulted from the operation; cleared otherwise. Literally read, an overflow condition occurs if a positive number is subtracted from a negative number with a positive result, or, if a negative number is subtracted from a positive number with a negative result. 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 the unsigned value of the contents of memory plus the previous carry are larger than the unsigned value of the accumulator; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form SBC SBC SBC SBC SBC SBC SBC SBC #opr8i opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP Address Mode IMM DIR EXT IX2 IX1 IX SP2 SP1 Machine Code Opcode A2 B2 C2 D2 E2 F2 9ED2 9EE2 ee ff ff ii dd hh ee ff ll ff Operand(s) HC08 Cycles 2 3 4 4 3 2 5 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 138 Freescale Semiconductor
Instruction Set
SEC
Operation
C bit 1
SEC
Description
Sets the C bit in the condition code register (CCR). SEC may be used to set up the C bit prior to a shift or rotate instruction that involves the C bit.
C: 1 Set
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form SEC Address Mode INH Machine Code Opcode 99 Operand(s) HC08 Cycles 1
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 139
Instruction Set
SEI
Operation
I bit 1
SEI
Description
Sets the interrupt mask bit in the condition code register (CCR). The microprocessor is inhibited from responding to interrupts while the I bit is set. The I bit actually changes at the end of the cycle where SEI executed. This is too late to stop an interrupt that arrived during execution of the SEI instruction so it is possible that an interrupt request could be serviced after the SEI instruction before the next instruction after SEI is executed. The global I-bit interrupt mask takes effect before the next instruction can be completed.
I:
1 Set
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form SEI Address Mode INH Machine Code Opcode 9B Operand(s) HC08 Cycles 2
CPU08 Central Processor Unit Reference Manual, Rev. 4 140 Freescale Semiconductor
Instruction Set
STA
Operation
M (A)
STA
Description
Stores the contents of A in memory. The contents of A remain unchanged. The N condition code is set if the most significant bit of A is set, the Z bit is set if A was $00, and V is cleared. This allows conditional branching after the store without having to do a separate test or compare.
V: 0 Cleared N: A7 Set if MSB of result is 1; cleared otherwise Z: A7&A6&A5&A4&A3&A2&A1&A0 Set if result is $00; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form STA STA STA STA STA STA STA opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP Address Mode DIR EXT IX2 IX1 IX SP2 SP1 Machine Code Opcode B7 C7 D7 E7 F7 9ED7 9EE7 ee ff ff Operand(s) dd hh ee ff ll ff HC08 Cycles 3 4 4 3 2 5 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 141
Instruction Set
STHX
Operation
(M:M + $0001) (H:X)
STHX
Description
Stores the contents of H in memory location M and then the contents of X into the next memory location (M + $0001). The N condition code bit is set if the most significant bit of H was set, the Z bit is set if the value of H:X was $0000, and V is cleared. This allows conditional branching after the store without having to do a separate test or compare.
V: 0 Cleared N: R15 Set if MSB of result is 1; cleared otherwise Z: R15&R14&R13&R12&R11&R10&R9&R8&R7&R6&R5&R4&R3&R2&R1&R0 Set if the result is $0000; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form STHX opr Address Mode DIR Machine Code Opcode 35 Operand(s) dd HC08 Cycles 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 142 Freescale Semiconductor
Instruction Set
STOP
Operation
STOP
Description
Reduces power consumption by eliminating all dynamic power dissipation. (See module documentation for module reactions to STOP instruction.) The external interrupt pin is enabled and the I bit in the condition code register (CCR) is cleared to enable the external interrupt. Finally, the oscillator is inhibited to put the MCU into the STOP condition. When either the RESET pin or IRQ pin goes low, the oscillator is enabled. A delay of 4095 processor clock cycles is imposed allowing the oscillator to stabilize. The reset vector or interrupt request vector is fetched and the associated service routine is executed. External interrupts are enabled after a STOP command.
I:
0 Cleared
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form STOP Address Mode INH Machine Code Opcode 8E Operand(s) HC08 Cycles 1
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 143
Instruction Set
STX
Operation
M (X)
STX
Description
Stores the contents of X in memory. The contents of X remain unchanged. The N condition code is set if the most significant bit of X was set, the Z bit is set if X was $00, and V is cleared. This allows conditional branching after the store without having to do a separate test or compare.
V: 0 Cleared N: X7 Set if MSB of result is 1; cleared otherwise Z: X7&X6&X5&X4&X3&X2&X1&X0 Set if X is $00; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form STX STX STX STX STX STX STX opr8a opr16a oprx16,X oprx8,X ,X oprx16,SP oprx8,SP Address Mode DIR EXT IX2 IX1 IX SP2 SP1 Machine Code Opcode BF CF DF EF FF 9EDF 9EEF ee ff ff Operand(s) dd hh ee ff ll ff HC08 Cycles 3 4 4 3 2 5 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 144 Freescale Semiconductor
Instruction Set
SUB
Operation
A (A) (M)
Subtract
SUB
Description
Subtracts the contents of M from A and places the result in A
V: A7&M7&R7 | A7&M7&R7 Set if a twos complement overflow resulted from the operation; cleared otherwise. Literally read, an overflow condition occurs if a positive number is subtracted from a negative number with a positive result, or, if a negative number is subtracted from a positive number with a negative result. 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 the unsigned value of the contents of memory is larger than the unsigned value of the accumulator; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form SUB SUB SUB SUB SUB SUB SUB SUB #opr8i opr8a opr16a oprx16,X oprx8,X X oprx16,SP oprx8,SP Address Mode IMM DIR EXT IX2 IX1 IX SP2 SP1 Machine Code Opcode A0 B0 C0 D0 E0 F0 9ED0 9EE0 ee ff ff ii dd hh ee ff ll ff Operand(s) HC08 Cycles 2 3 4 4 3 2 5 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 145
Instruction Set
SWI
Operation
Software Interrupt
SWI
PC (PC) + $0001Increment PC to return address Push (PCL); SP (SP) $0001Push low half of return address Push (PCH); SP (SP) $0001Push high half of return address Push (X); SP (SP) $0001Push index register on stack Push (A); SP (SP) $0001Push A on stack Push (CCR); SP (SP) $0001Push CCR on stack I bit 1Mask further interrupts PCH ($FFFC)Vector fetch (high byte) PCL ($FFFD)Vector fetch (low byte)
Description
The program counter (PC) is incremented by 1 to point at the instruction after the SWI. The PC, index register, and accumulator are pushed onto the stack. The condition code register (CCR) bits are then pushed onto the stack, with bits V, H, I, N, Z, and C going into bit positions 7 and 40. Bit positions 6 and 5 contain 1s. The stack pointer is decremented by 1 after each byte of data is stored on the stack. The interrupt mask bit is then set. The program counter is then loaded with the address stored in the SWI vector located at memory locations $FFFC and $FFFD. This instruction is not maskable by the I bit.
I:
1 Set
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form SWI Address Mode INH Machine Code Opcode 83 Operand(s) HC08 Cycles 9
CPU08 Central Processor Unit Reference Manual, Rev. 4 146 Freescale Semiconductor
Instruction Set
TAP
Operation
CCR (A)
bit 7 6
TAP
bit 0 A
CCR Carry/Borrow Zero Negative I Interrupt Mask Half Carry Overflow (Twos Complement)
Description
Transfers the contents of A to the condition code register (CCR). The contents of A are unchanged. If this instruction causes the I bit to change from 0 to 1, a one bus cycle delay is imposed before interrupts become masked. This assures that the next instruction after a TAP instruction will always be executed even if an interrupt became pending during the TAP instruction.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form TAP Address Mode INH Machine Code Opcode 84 Operand(s) HC08 Cycles 2
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 147
Instruction Set
TAX
Operation
X (A)
TAX
Description
Loads X with the contents of the accumulator (A). The contents of A are unchanged.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form TAX Address Mode INH Machine Code Opcode 97 Operand(s) HC08 Cycles 1
CPU08 Central Processor Unit Reference Manual, Rev. 4 148 Freescale Semiconductor
Instruction Set
TPA
Operation
A (CCR)
bit 7 6
TPA
bit 0 A
CCR Carry/Borrow Zero Negative I Interrupt Mask Half Carry Overflow (Twos Complement)
Description
Transfers the contents of the condition code register (CCR) into the accumulator (A)
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form TPA Address Mode INH Machine Code Opcode 85 Operand(s) HC08 Cycles 1
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 149
Instruction Set
TST
Operation
(A) $00 Or (X) $00 Or (M) $00
TST
Description
Sets the N and Z condition codes according to the contents of A, X, or M. The contents of A, X, and M are not altered.
V: 0 Cleared N: M7 Set if MSB of the tested value is 1; cleared otherwise Z: M7&M6&M5&M4&M3&M2&M1&M0 Set if A, X, or M contains $00; cleared otherwise
Source Forms, Addressing Modes, Machine Code, Cycles, and Access Details
Source Form TST TSTA TSTX TST TST TST oprx8,X ,X oprx8,SP opr8a Address Mode DIR INH (A) INH (X) IX1 IX SP1 Machine Code Opcode 3D 4D 5D 6D 7D 9E6D ff ff Operand(s) dd HC08 Cycles 3 1 1 3 2 4
CPU08 Central Processor Unit Reference Manual, Rev. 4 150 Freescale Semiconductor
Instruction Set
TSX
Operation
TSX
Description
Loads index register (H:X) with 1 plus the contents of the stack pointer (SP). The contents of SP remain unchanged. After a TSX instruction, H:X points to the last value that was stored on the stack.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form TSX Address Mode INH Machine Code Opcode 95 Operand(s) HC08 Cycles 2
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 151
Instruction Set
TXA
Operation
A (X)
TXA
Description
Loads the accumulator (A) with the contents of X. The contents of X are not altered.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form TXA Address Mode INH Machine Code Opcode 9F Operand(s) HC08 Cycles 1
CPU08 Central Processor Unit Reference Manual, Rev. 4 152 Freescale Semiconductor
Instruction Set
TXS
Operation
TXS
SP (H:X) $0001
Description
Loads the stack pointer (SP) with the contents of the index register (H:X) minus 1. The contents of H:X are not altered.
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form TXS Address Mode INH Machine Code Opcode 94 Operand(s) HC08 Cycles 2
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 153
Instruction Set
WAIT
Operation
WAIT
Description
Reduces power consumption by eliminating dynamic power dissipation in some portions of the MCU. The timer, the timer prescaler, and the on-chip peripherals continue to operate (if enabled) because they are potential sources of an interrupt. Wait causes enabling of interrupts by clearing the I bit in the CCR and stops clocking of processor circuits. Interrupts from on-chip peripherals may be enabled or disabled by local control bits prior to execution of the WAIT instruction. When either the RESET or IRQ pin goes low or when any on-chip system requests interrupt service, the processor clocks are enabled, and the reset, IRQ, or other interrupt service request is processed.
I:
0 Cleared
Source Form, Addressing Mode, Machine Code, Cycles, and Access Detail
Source Form WAIT Address Mode INH Machine Code Opcode 8F Operand(s) HC08 Cycles 1
CPU08 Central Processor Unit Reference Manual, Rev. 4 154 Freescale Semiconductor
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 155
AIS
AIS
* * AIS: * 1) Creating local variable space on the stack * * SP --> | | * --------------^ * | | | * | Local | | * | Variable | | * | Space | * | | Decreasing * --------------Address * | PC (MS byte) | * --------------* | PC (LS byte) | * --------------* | | * * NOTE: SP must always point to next unused byte, * therefore do not use this byte (0,SP) for storage * Label Operation Operand Comments SUB1 AIS #-16 ;Create 16 bytes of local space * . * . * . * . AIS #16 ;Clean up stack (Note: AIS ;does not modify CCR) RTS ;Return * *********************************************************** * * 2) Passing parameters through the stack * Label Operation Operand Comments PARAM1 RMB 1 PARAM2 RMB 1 * * LDA PARAM1 PSHA ;Push dividend onto stack LDA PARAM2 PSHA ;Push divisor onto stack JSR DIVIDE ;8/8 divide PULA ;Get result AIS #1 ;Clean up stack ;(CCR not modified) BCS ERROR ;Check result * . ERROR EQU * * . *
CPU08 Central Processor Unit Reference Manual, Rev. 4 156 Freescale Semiconductor
Code Examples
AIS
AIS
********************************** * DIVIDE: 8/8 divide * * SP ---> | | * --------------* | A | * --------------* | X | ^ * --------------| * | H | | * --------------| * | PC (MS byte) | | * --------------| * | PC (LS byte) | | * --------------| * | Divisor | * --------------- Decreasing * | Dividend | Address * --------------* | | * * Entry: Dividend and divisor on stack at * SP,7 and SP,6 respectively * Exit: 8-bit result placed on stack at SP,6 * A, H:X preserved * Label Operation Operand Comments DIVIDE PSHH ;preserve H:X, A PSHX PSHA LDX 6,SP ;Divisor -> X CLRH ;0 -> MS dividend LDA 7,SP ;Dividend -> A DIV OK STA 6,SP ;Save result PULA ;restore H:X, A PULX PULH RTS * ***********************************************************
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 157
AIX
AIX
* AIX: * 1) Find the 8-bit checksum for a 512 byte table * Label Operation Operand Comments ORG $7000 TABLE FDB 512 ORG LDHX CLRA ADD AIX $6E00 #511 TABLE,X #-1 ;ROM/EPROM address space ;Initialize byte count (0..511) ;Clear result
ADDLOOP
;Decrement byte counter * * NOTE: DECX will not carry from X through H. AIX will. * CPHX #0 ;Done? * * NOTE: DECX does affect the CCR. AIX does not (CPHX required). * BPL ADDLOOP ;Loop if not complete. * ********************************************************** * * 2) Round a 16-bit signed fractional number * Radix point is assumed fixed between bits 7 and 8 * * Entry: 16-bit fractional in fract * Exit: Integer result after round operation in A * Label Operation Operand Comments ORG $50 ;RAM address space FRACT RMB 2 * ORG $6E00 ;ROM/EPROM address space LDHX FRACT AIX #1 AIX #$7F ;Round up if X >= $80 (fraction >= 0.5) * * NOTE: AIX operand is a signed 8-bit number. AIX #$80 would * therefore be equivalent to AIX #-128 (signed extended * to 16-bits). Splitting the addition into two positive * operations is required to perform the round correctly. * PSHH PULA *
CPU08 Central Processor Unit Reference Manual, Rev. 4 158 Freescale Semiconductor
Code Examples
BGE
BGE
* 8 x 8 signed multiply * * Entry: Multiplier and multiplicand in VAR1 and VAR2 * Exit : Signed result in X:A * Label Operation Operand Comments ORG $50 ;RAM address space NEG_FLG RMB 1 ;Sign flag byte VAR1 RMB 1 ;Multiplier VAR2 RMB 1 ;Multiplicand * * ORG $6E00 ;ROM/EPROM address space S_MULT CLR NEG_FLG ;Clear negative flag TST VAR1 ;Check VAR1 BGE POS ;Continue is =>0 INC NEG_FLG ;Else set negative flag NEG VAR1 ;Make into positive number * POS TST VAR2 ;Check VAR2 BGE POS2 ;Continue is =>0 INC NEG_FLG ;Else toggle negative flag NEG VAR2 ;Make into positive number * POS2 LDA VAR2 ;Load VAR1 LDX VAR1 ;Load VAR2 MUL ;Unsigned VAR1 x VAR2 -> X:A BRCLR 0,NEG_FLG,EXIT ;Quit if operands both ;positive or both neg. COMA ;Else one's complement A and X COMX ADD #1 ;Add 1 for 2's complement ;(LS byte) PSHA ;Save LS byte of result TXA ;Transfer unsigned MS byte of ;result ADC #0 ;Add carry result to complete ;2's complement TAX ;Return to X PULA ;Restore LS byte of result EXIT RTS ;Return *
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 159
BGT
BGT
* BGT: * Read an 8-bit A/D register, sign it and test for valid range * * Entry: New reading in AD_RES * Exit : Signed result in A. ERR_FLG set if out of range. * * Label Operation Operand Comments ORG $50 ;RAM address space ERR_FLG RMB 1 ;Out of range flag AD_RES RMB 1 ;A/D result register * * ORG $6E00 ;ROM/EPROM address space BCLR 0,ERR_FLG LDA AD_RES ;Get latest reading (0 thru 256) EOR #$80 ;Sign it (-128 thru 128) CMP #$73 ;If greater than upper limit, BGT OUT ; branch to error flag set CMP #$8D ;If greater than lower limit ;($8D = -$73) BGT IN ; branch to exit OUT BSET 0,ERR_FLG ;Set error flag IN RTS ;Return *
CPU08 Central Processor Unit Reference Manual, Rev. 4 160 Freescale Semiconductor
Code Examples
BLE
BLE
* Find the most negative of two 16-bit signed integers * * Entry: Signed 16-bit integers in VAL1 and VAL2 * Exit : Most negative integer in H:X * Label Operation Operand Comments ORG $50 ;RAM address space VAL1 RMB 2 ;16-bit signed integer VAL2 RMB 2 ;16-bit signed integer * * ORG $6E00 ;ROM/EPROM address space LDHX VAL1 CPHX VAL2 BLE EXIT1 ;If VAL1 =< VAL2, exit LDHX VAL2 ; else load VAL2 into H:X EXIT1 EQU * *
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 161
BLT
BLT
* Compare 8-bit signed integers in A and X and place the * most negative in A. * * Entry: Signed 8-bit integers in A and X * Exit : Most negative integer in A. X preserved. * * Label Operation Operand Comments ORG $6E00 ;ROM/EPROM address space PSHX ;Move X onto stack CMP 1,SP ;Compare it with A BLT EXIT2 ;If A =< stacked X, quit TXA ;else move X to A EXIT2 PULX ;Clean up stack *
CPU08 Central Processor Unit Reference Manual, Rev. 4 162 Freescale Semiconductor
Code Examples
CBEQ
CBEQ
* Skip spaces in a string of ASCII characters. String must * contain at least one non-space character. * * Entry: H:X points to start of string * Exit : H:X points to first non-space character in * string * Label Operation Operand Comments LDA #$20 ;Load space character SKIP CBEQ X+,SKIP ;Increment through string until ;non-space character found. * * NOTE: X post increment will occur irrespective of whether * branch is taken. In this example, H:X will point to the * non-space character+1 immediately following the CBEQ * instruction. * Label Operation Operand Comments AIX #-1 ;Adjust pointer to point to 1st ;non-space char. RTS ;Return *
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 163
CBEQA
CBEQA
* Look for an End-of-Transmission (EOT) character from a * serial peripheral. Exit if true, otherwise process data * received. * Label Operation Operand Comments EOT EQU $04 * DATA_RX EQU 1 * LDA DATA_RX ;get receive data CBEQA #EOT,EXIT3 ;check for EOT * * NOTE: CBEQ, CBEQA, CBEQX instructions do NOT modify the * CCR. In this example, Z flag will remain in the state the * LDA instruction left it in. * * | * | Process * | data * | EXIT3 RTS *
CPU08 Central Processor Unit Reference Manual, Rev. 4 164 Freescale Semiconductor
Code Examples
CBEQX
CBEQX
* Keyboard wake-up interrupt service routine. Return to sleep * (WAIT mode) unless "ON" key has been depressed. * Label Operation Operand Comments ON_KEY EQU $02 * SLEEP WAIT BSR DELAY ;Debounce delay routine LDX PORTA ;Read keys CBEQX #ON_KEY,WAKEUP ;Wake up if "ON" pressed, BRA SLEEP ;otherwise return to sleep * WAKEUP EQU * ;Start of main code *
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 165
CLRH
CLRH
* Clear H:X register * Label Operation Operand Comments CLRX CLRH * * NOTE: This sequence takes 2 cycles and uses 2 bytes * LDHX #0 takes 3 cycles and uses 3 bytes. *
CPU08 Central Processor Unit Reference Manual, Rev. 4 166 Freescale Semiconductor
Code Examples
CPHX
CPHX
* Stack pointer overflow test. Branch to a fatal error * handler if overflow detected. * Label Operation Operand Comments STACK EQU $1000 ;Stack start address (empty) SIZE EQU $100 ;Maximum stack size * PSHH ;Save H:X (assuming stack is OK!) PSHX TSX ;Move SP+1 to H:X CPHX #STACK-SIZE ;Compare against stack lowest ;address BLO FATAL ;Branch out if lower * ; otherwise continue executing ;main code PULX ;Restore H:X PULH * * | * | * | * FATAL EQU * ;FATAL ERROR HANDLER *
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 167
DAA
DAA
* Add 2 BCD 8-bit numbers (e.g. 78 + 49 = 127) * Label Operation Operand VALUE1 FCB $78 VALUE2 FCB $49 * LDA VALUE1 ADD VALUE2 DAA *
Comments
;A = $78 ;A = $78+$49 = $C1; C=0, H=1 ;Add $66; A = $27; C=1 {=127 BCD}
CPU08 Central Processor Unit Reference Manual, Rev. 4 168 Freescale Semiconductor
Code Examples
DBNZ
DBNZ
* Delay routine: * Delay = N x (153.6+0.36)uS for 60nS CPU clock * For example, delay=10mS for N=$41 and 60nS CPU clock * * Entry: COUNT = 0 * Exit: COUNT = 0; A = N * Label Operation Operand Comments N EQU $41 ;Loop constant for 10mS delay * ORG $50 ;RAM address space COUNT RMB 1 ;Loop counter * ORG $6E00 ;ROM/EPROM address space DELAY LDA #N ;Set delay constant LOOPY DBNZ COUNT,LOOPY ;Inner loop (5x256 cycles) DBNZA LOOPY ;Outer loop (3 cycles) *
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 169
DIV
Divide
DIV
* 1) 8/8 integer divide > 8-bit integer quotient * Performs an unsigned integer divide of an 8-bit dividend * in A by an 8-bit divisor in X. H must be cleared. The * quotient is placed into A and the remainder in H. * Label Operation Operand Comments ORG $50 ;RAM address space DIVID1 RMB 1 ;storage for dividend DIVISOR1 RMB 1 ;storage for divisor QUOTIENT1 RMB 1 ;storage for quotient * ORG $6E00 ;ROM/EPROM address spcae LDA DIVID1 ;Load dividend CLRH ;Clear MS byte of dividend LDX DIVISOR1 ;Load divisor DIV ;8/8 divide STA QUOTIENT1 ;Store result; remainder in H * * * 2) 8/8 integer divide > 8-bit integer and 8-bit fractional * quotient. Performs an unsigned integer divide of an 8-bit * dividend in A by an 8-bit divisor in X. H must be * cleared. The quotient is placed into A and the remainder * in H. The remainder may be further resolved by executing * additional DIV instructions as shown below. The radix point * of the quotient will be between bits 7 and 8. * Label Operation Operand Comments ORG $50 ;RAM address space DIVID2 RMB 1 ;storage for dividend DIVISOR2 RMB 1 ;storage for divisor QUOTIENT2 RMB 2 ;storage for quotient * ORG $6E00 ;ROM/EPROM address space LDA DIVID2 ;Load dividend CLRH ;Clear MS byte of dividend LDX DIVISOR2 ;Load divisor DIV ;8/8 divide STA QUOTIENT2 ;Store result; remainder in H CLRA DIV ;Resolve remainder STA QUOTIENT2+1 * *
CPU08 Central Processor Unit Reference Manual, Rev. 4 170 Freescale Semiconductor
Code Examples
DIV
Divide (Continued)
DIV
* 3) 8/8 fractional divide > 16-bit fractional quotient * Performs an unsigned fractional divide of an 8-bit dividend * in H by the 8-bit divisor in X. A must be cleared. The * quotient is placed into A and the remainder in H. The * remainder may be further resolved by executing additional * DIV instructions as shown below. * The radix point is assumed to be in the same place for both * the dividend and the divisor. The radix point is to the * left of the MS bit of the quotient. An overflow will occur * when the dividend is greater than or equal to the divisor. * The quotient is an unsigned binary weighted fraction with * a range of $00 to $FF (0.9961). * Label Operation Operand Comments ORG $50 ;RAM address space DIVID3 RMB 1 ;storage for dividend DIVISOR3 RMB 1 ;storage for divisor QUOTIENT3 RMB 2 ;storage for quotient * ORG $6E00 ;ROM/EPROM address space LDHX DIVID3 ;Load dividend into H (and ;divisor into X) CLRA ;Clear LS byte of dividend DIV ;8/8 divide STA QUOTIENT3 ;Store result; remainder in H CLRA DIV ;Resolve remainder STA QUOTIENT3+1 * * * 4) Unbounded 16/8 integer divide * This algorithm performs the equivalent of long division. * The initial divide is an 8/8 (no overflow possible). * Subsequent divide are 16/8 using the remainder from the * previous divide operation (no overflow possible). * The DIV instruction does not corrupt the divisor and leaves * the remainder in H, the optimal position for sucessive * divide operations. The algorithm may be extended to any * precision of dividend by performing additional divides. * This, of course, includes resolving the remainder of a * divide operation into a fractional result as shown below. *
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 171
DIV
Label DIVIDEND4 DIVISOR4 QUOTIENT4 * * Operation ORG RMB RMB RMB ORG LDA CLRH LDX DIV STA * LDA DIV STA CLRA DIV STA
Divide (Concluded)
Operand $50 2 1 3 $6E00 DIVIDEND4 DIVISOR4 QUOTIENT4 Comments ;RAM address ;storage for ;storage for ;storage for space dividend divisor quotient
DIV
DIVIDEND4+1
QUOTIENT4+1
QUOTIENT4+2 * * * 5) Bounded 16/8 integer divide * Although the DIV instruction will perform a 16/8 integer * divide, it can only generate an 8-bit quotient. Quotient * overflows are therefore possible unless the user knows the * bounds of the dividend and divisor in advance. * Label Operation Operand Comments ORG $50 ;RAM address space DIVID5 RMB 2 ;storage for dividend DIVISOR5 RMB 1 ;storage for divisor QUOTIENT5 RMB 1 ;storage for quotient * ORG $6E00 ;ROM/EPROM address space LDHX DIVID5 ;Load dividend into H:X TXA ;Move X to A LDX DIVISOR5 ;Load divisor into X DIV ;16/8 integer divide BCS ERROR5 ;Overflow? STA QUOTIENT5 ;Store result ERROR5 EQU *
;ROM/EPROM address space ;Load MS byte of dividend into ;LS dividend reg. ;Clear H (MS dividend register) ;Load divisor ;8/8 integer divide [A/X -> A; r->H] ;Store result (MS result of ;complete operation) ;Remainder in H (MS dividend ;register) ;Load LS byte of dividend into ;LS dividend reg. ;16/8 integer divide ;[H:A/X -> A; r->H] ;Store result (LS result of ;complete operation) ;Clear LS dividend (prepare for ;fract. divide) ;Resolve remainder ;Store fractional result.
CPU08 Central Processor Unit Reference Manual, Rev. 4 172 Freescale Semiconductor
Code Examples
LDHX
LDHX
* Clear RAM block of memory * Label Operation RAM EQU SIZE1 EQU * LDHX LOOP CLR AIX CPHX BLO
Comments ;Start of RAM ;Length of RAM array ;Load RAM pointer ;Clear byte ;Bump pointer ;Done? ;Loop if not
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 173
MOV
Move
MOV
* 1) Initialize Port A and Port B data registers in page 0. * Label Operation Operand Comments PORTA EQU $0000 ;port a data register PORTB EQU $0001 ;port b data register * MOV #$AA,PORTA ;store $AA to port a MOV #$55,PORTB ;store $55 to port b * * * * 2) Move REG1 to REG2 if REG1 positive; clear REG2* Label Operation Operand Comments REG1 EQU $0010 REG2 EQU $0011 * MOV REG1,REG2 BMI NEG CLR REG2 * NEG EQU * * * * 3) Move data to a page 0 location from a table anywhere in memory * Label Operation Operand Comments SPIOUT EQU $0012 * ORG $50 ;RAM address space TABLE_PTR RMB 2 ;storage for table pointer * ORG $6E00 ;ROM/EPROM address space LDHX TABLE_PTR ;Restore table pointer MOV X+,SPIOUT ;Move data * * NOTE: X+ is a 16-bit increment of the H:X register * NOTE: The increment occurs after the move operation is * completed * STHX TABLE_PTR ;Save modified pointer *
CPU08 Central Processor Unit Reference Manual, Rev. 4 174 Freescale Semiconductor
Code Examples
NSA
NSA
* NSA: * Compress 2 bytes, each containing one BCD nibble, into 1 * byte. Each byte contains the BCD nibble in bits 0-3. Bits * 4-7 are clear. * Label Operation Operand Comments BCD1 RMB 1 BCD2 RMB 1 * LDA BCD1 ;Read first BCD byte NSA ;Swap LS and MS nibbles ADD BCD2 ;Add second BCD byte *
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 175
PSHA
PSHA
* PSHA: * Jump table index calculation. * Jump to a specific code routine based on a number held in A * * Entry : A = jump selection number, 0-3 * Label Operation Operand Comments PSHA ;Save selection number LSLA ;Multiply by 2 ADD 1,SP ;Add stacked number; ;A now = A x 3 TAX ;Move to index reg CLRH ;and clear MS byte PULA ;Clean up stack JMP TABLE1,X ;Jump into table.... TABLE1 JMP PROG_0 JMP PROG_1 JMP PROG_2 JMP PROG_3 * PROG_0 EQU * PROG_1 EQU * PROG_2 EQU * PROG_3 EQU * *
CPU08 Central Processor Unit Reference Manual, Rev. 4 176 Freescale Semiconductor
Code Examples
PSHH
PSHH
* PSHH: * 1) Save contents of H register at the start of an interrupt * service routine * Label Operation Operand Comments SCI_INT PSHH ;Save H (all other registers ;already stacked) * | * | * | * | * | PULH ;Restore H RTI ;Unstack all other registers; ;return to main * * * 2) Effective address calculation * * Entry : H:X=pointer, A=offset * Exit : H:X = A + H:X (A = H) * Label Operation Operand Comments PSHX ;Push X then H onto stack PSHH ADD 2,SP ;Add stacked X to A TAX ;Move result into X PULA ;Pull stacked H into A ADC #0 ;Take care of any carry PSHA ;Push modified H onto stack PULH ;Pull back into H AIS #1 ;Clean up stack *
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 177
PSHX
PSHX
* PSHX: * 1) Implement the transfer of the X register to the H * register * Label Operation Operand Comments PSHX ;Move X onto the stack PULH ;Return back to H * * 2) Implement the exchange of the X register and A * Label Operation Operand Comments PSHX ;Move X onto the stack TAX ;Move A into X PULA ;Restore X into A *
CPU08 Central Processor Unit Reference Manual, Rev. 4 178 Freescale Semiconductor
Code Examples
PULA
PULA
* Implement the transfer of the H register to A * Label Operation Operand Comments PSHH ;Move H onto stack PULA ;Return back to A
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 179
PULH
PULH
* Implement the exchange of the H register and A * Label Operation Operand Comments PSHA ;Move A onto the stack PSHH ;Move H onto the stack PULA ;Pull H into A PULH ;Pull A into H
CPU08 Central Processor Unit Reference Manual, Rev. 4 180 Freescale Semiconductor
Code Examples
PULX
PULX
* Implement the exchange of the X register and A * Label Operation Operand Comments PSHA ;Move A onto the stack TXA ;Move X into A PULX ;Restore A into X
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 181
STHX
STHX
* Effective address calculation * * Entry : H:X=pointer, A=offset * Exit : H:X = A + H:X * Label Operation Operand ORG $50 TEMP RMB 2 * ORG $6E00 STHX TEMP ADD TEMP+1 TAX LDA TEMP ADC #0 PSHA PULH *
Comments ;RAM address space ;ROM/EPROM address space ;Save H:X ;Add saved X to A ;Move result into X ;Load saved X into A ;Take care of any carry ;Push modified H onto stack ;Pull back into H
CPU08 Central Processor Unit Reference Manual, Rev. 4 182 Freescale Semiconductor
Code Examples
TAP
TAP
* * NOTE: The TAP instruction was added to improve testability of * the CPU08, and so few practical applications of the * instruction exist. *
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 183
TPA
TPA
* Implement branch if 2's complement signed overflow bit * (V-bit) is set * Label Operation Operand Comments TPA * * NOTE: Transfering the CCR to A does not modify the CCR. * TSTA BMI V_SET * V_SET EQU * *
CPU08 Central Processor Unit Reference Manual, Rev. 4 184 Freescale Semiconductor
Code Examples
TSX
TSX
* TSX: * Create a stack frame pointer. H:X points to the stack frame * irrespective of stack depth. Useful for handling nested * subroutine calls (e.g. recursive routines) which reference * the stack frame data. * Label Operation Operand Comments LOCAL EQU $20 * AIS #LOCAL ;Create local variable space in ;stack frame TSX ;SP +1 > H:X * * NOTE: TSX transfers SP+1 to allow the H:X register to point * to the first used stack byte (SP always points to the next * available stack byte). The SP itself is not modified. * * | * | * LDA 0,X ;Load the 1st byte in local space * * | * | * | *
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 185
TXS
TXS
* Initialize the SP to a value other than the reset state * Label Operation Operand Comments STACK1 EQU $0FFF * LDHX #STACK1+1 ;$1000 > H:X TXS ;$0FFF > SP * * NOTE: TXS subtracts 1 from the value in H:X before it * transfers to SP.
CPU08 Central Processor Unit Reference Manual, Rev. 4 186 Freescale Semiconductor
Glossary
$xxxx The digits following the $ are in hexadecimal format. #xxxx The digits following the # indicate an immediate operand. A Accumulator. See accumulator. accumulator (A) An 8-bit general-purpose register in the CPU08. The CPU08 uses the accumulator to hold operands and results of arithmetic and non-arithmetic operations. address bus The set of conductors used to select a specific memory location so that the CPU can write information into the memory location or read its contents. addressing mode The way that the CPU obtains (addresses) the information needed to complete an instruction. The M68HC08 CPU has 16 addressing modes. algorithm A set of specific procedures by which a solution is obtained in a finite number of steps, often used in numerical calculation. ALU Arithmetic logic unit. See arithmetic logic unit. arithmetic logic unit (ALU) The portion of the CPU of a computer where mathematical and logical operations take place. Other circuitry decodes each instruction and configures the ALU to perform the necessary arithmetic or logical operations at each step of an instruction. assembly language A method used by programmers for representing machine instructions (binary data) in a more convenient form. Each machine instruction is given a simple, short name, called a mnemonic (or memory aid), which has a one-to-one correspondence with the machine instruction. The mnemonics are translated into an object code program that a microcontroller can use. ASCII American Standard Code for Information Interchange. A widely accepted correlation between alphabetic and numeric characters and specific 7-bit binary numbers. asynchronous Refers to circuitry and operations without common clock signals. BCD Binary-coded decimal. See binary-coded decimal. binary The binary number system using 2 as its base and using only the digits 0 and 1. Binary is the numbering system used by computers because any quantity can be represented by a series of 1s and 0s. Electrically, these 1s and 0s are represented by voltage levels of approximately VDD (input) and VSS (ground), respectively. binary-coded decimal (BCD) A notation that uses binary values to represent decimal quantities. Each BCD digit uses four binary bits. Six of the possible 16 binary combinations are considered illegal. bit A single binary digit. A bit can hold a single value of 0 or 1. Boolean A mathematical system of representing logic through a series of algebraic equations that can only be true or false, using operators such as AND, OR, and NOT.
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 187
Glossary
branch instructions Computer instructions that cause the CPU to continue processing at a memory location other than the next sequential address. Most branch instructions are conditional. That is, the CPU continues to the next sequential address (no branch) if a condition is false, or continue to some other address (branch) if the condition is true. bus A collection of logic lines (conductor paths) used to transfer data. byte A set of exactly eight binary bits. C Abbreviation for carry/borrow in the condition code register of the CPU08. The CPU08 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 C flag (as in bit test and branch instructions and shifts and rotates). CCR Abbreviation for condition code register in the CPU08. See condition code register. central processor unit (CPU) The primary functioning unit of any computer system. The CPU controls the execution of instructions. checksum A value that results from adding a series of binary numbers. When exchanging information between computers, a checksum gives an indication about the integrity of the data transfer. If values were transferred incorrectly, it is unlikely that the checksum would match the value that was expected. clear To establish logic 0 state on a bit or bits; the opposite of set. clock A square wave signal used to sequence events in a computer. condition code register (CCR) An 8-bit register in the CPU08 that contains the interrupt mask bit and five bits (flags) that indicate the results of the instruction just executed. control unit One of two major units of the CPU. The control unit contains logic functions that synchronize the machine and direct various operations. The control unit decodes instructions and generates the internal control signals that perform the requested operations. The outputs of the control unit drive the execution unit, which contains the arithmetic logic unit (ALU), CPU registers, and bus interface. CPU Central processor unit. See central processor unit. CPU08 The central processor unit of the M68HC08 Family. CPU cycles A CPU clock cycle is one period of the internal bus-rate clock, normally derived by dividing a crystal oscillator source by two or more so the high and low times are equal. The length of time required to execute an instruction is measured in CPU clock cycles. CPU registers Memory locations that are wired directly into the CPU logic instead of being part of the addressable memory map. The CPU always has direct access to the information in these registers. The CPU registers in an M68HC08 are: A (8-bit accumulator) H:X (16-bit accumulator) SP (16-bit stack pointer) PC (16-bit program counter) CCR (condition code register containing the V, H, I, N, Z, and C bits)
CPU08 Central Processor Unit Reference Manual, Rev. 4 188 Freescale Semiconductor
Glossary
cycles See CPU cycles. data bus A set of conductors used to convey binary information from a CPU to a memory location or from a memory location to a CPU. decimal Base 10 numbering system that uses the digits zero through nine. direct address Any address within the first 256 addresses of memory ($0000$00FF). The high-order byte of these addresses is always $00. Special instructions allow these addresses to be accessed using only the low-order byte of their address. These instructions automatically fill in the assumed $00 value for the high-order byte of the address. direct addressing mode Direct addressing mode uses a program-supplied value for the low-order byte of the address of an operand. The high-order byte of the operand address is assumed to be $00 and so it does not have to be explicitly specified. Most direct addressing mode instructions can access any of the first 256 memory addresses. direct memory access (DMA) One of a number of modules that handle a variety of control functions in the modular M68HC08 Family. The DMA can perform interrupt-driven and software-initiated data transfers between any two CPU-addressable locations. Each DMA channel can independently transfer data between any addresses in the memory map. DMA transfers reduce CPU overhead required for data movement interrupts. direct page The first 256 bytes of memory ($0000$00FF); also called page 0. DMA Direct memory access. See direct memory access. EA Effective address. See effective address. effective address (EA) The address where an instruction operand is located. The addressing mode of an instruction determines how the CPU calculates the effective address of the operand. EPROM Erasable, programmable, read-only memory. A non-volatile type of memory that can be erased by exposure to an ultraviolet light source. EU Execution unit. See execution unit. execution unit (EU) One of the two major units of the CPU containing the arithmetic logic unit (ALU), CPU registers, and bus interface. The outputs of the control unit drive the execution unit. extended addressing mode In this addressing mode, the high-order byte of the address of the operand is located in the next memory location after the opcode. The low-order byte of the operand address is located in the second memory location after the opcode. Extended addressing mode instructions can access any address in a 64-Kbyte memory map. H Abbreviation for the upper byte of the 16-bit index register (H:X) in the CPU08. H Abbreviation for half-carry in the condition code register of the CPU08. This bit indicates a carry from the low-order four bits of the accumulator value to the high-order four bits. The half-carry bit is required for binary-coded decimal arithmetic operations. The decimal adjust accumulator (DAA) instruction uses the state of the H and C flags to determine the appropriate correction factor.
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 189
Glossary
hexadecimal Base 16 numbering system that uses the digits 0 through 9 and the letters A through F. One hexadecimal digit can exactly represent a 4-bit binary value. Hexadecimal is used by people to represent binary values because a 2-digit number is easier to use than the equivalent 8-digit number. high order The leftmost digit(s) of a number; the opposite of low order. H:X Abbreviation for the 16-bit index register in the CPU08. The upper byte of H:X is called H. The lower byte is called X. In the indexed addressing modes, the CPU uses the contents of H:X to determine the effective address of the operand. H:X can also serve as a temporary data storage location. I Abbreviation for interrupt mask bit in the condition code register of the CPU08. When I is set, all interrupts are disabled. When I is cleared, interrupts are enabled. immediate addressing mode In immediate addressing mode, the operand is located in the next memory location(s) after the opcode. The immediate value is one or two bytes, depending on the size of the register involved in the instruction. index register (H:X) A 16-bit register in the CPU08. The upper byte of H:X is called H. The lower byte is called X. In the indexed addressing modes, the CPU uses the contents of H:X to determine the effective address of the operand. H:X can also serve as a temporary data storage location. indexed addressing mode Indexed addressing mode instructions access data with variable addresses. The effective address of the operand is determined by the current value of the H:X register added to a 0-, 8-, or 16-bit value (offset) in the instruction. There are separate opcodes for 0-, 8-, and 16-bit variations of indexed mode instructions, and so the CPU knows how many additional memory locations to read after the opcode. indexed, post increment addressing mode In this addressing mode, the effective address of the operand is determined by the current value of the index register, added to a 0- or 8-bit value (offset) in the instruction, after which the index register is incremented. Operands with variable addresses can be addressed with the 8-bit offset instruction. inherent addressing mode The inherent addressing mode has no operand because the opcode contains all the information necessary to carry out the instruction. Most inherent instructions are one byte long. input/output (I/O) Input/output interfaces between a computer system and the external world. A CPU reads an input to sense the level of an external signal and writes to an output to change the level on an external signal. instructions Instructions are operations that a CPU can perform. Instructions are expressed by programmers as assembly language mnemonics. A CPU interprets an opcode and its associated operand(s) and instruction(s). instruction set The instruction set of a CPU is the set of all operations that the CPU can perform. An instruction set is often represented with a set of shorthand mnemonics, such as LDA, meaning load accumulator (A). Another representation of an instruction set is with a set of opcodes that are recognized by the CPU.
CPU08 Central Processor Unit Reference Manual, Rev. 4 190 Freescale Semiconductor
Glossary
interrupt Interrupts provide a means to temporarily suspend normal program execution so that the CPU is freed to service sets of instructions in response to requests (interrupts) from peripheral devices. Normal program execution can be resumed later from its original point of departure. The CPU08 can process up to 128 separate interrupt sources, including a software interrupt (SWI). I/O Input/output. See input/output. IRQ Interrupt request. The overline indicates an active-low signal. least significant bit (LSB) The rightmost digit of a binary value; the opposite of most significant bit (MSB). logic 1 A voltage level approximately equal to the input power voltage (VDD). logic 0 A voltage level approximately equal to the ground voltage (VSS). low order The rightmost digit(s) of a number; the opposite of high order. LS Least significant. LSB Least significant bit. See least significant bit. M68HC08 The Motorola Family of 8-bit MCUs. machine codes The binary codes processed by the CPU as instructions. Machine code includes both opcodes and operand data. MCU Microcontroller unit. See microcontroller unit. memory location In the M68HC08, each memory location holds one byte of data and has a unique address. To store information into a memory location, the CPU places the address of the location on the address bus, the data information on the data bus, and asserts the write signal. To read information from a memory location, the CPU places the address of the location on the address bus and asserts the read signal. In response to the read signal, the selected memory location places its data onto the data bus. memory map A pictorial representation of all memory locations in a computer system. memory-to-memory addressing mode In this addressing mode, the accumulator has been eliminated from the data transfer process, thereby reducing execution cycles. This addressing mode, therefore, provides rapid data transfers because it does not use the accumulator and associated load and store instructions. There are four memory-to-memory addressing mode instructions. Depending on the instruction, operands are found in the byte following the opcode, in a direct page location addressed by the byte immediately following the opcode, or in a location addressed by the index register. microcontroller unit (MCU) A complete computer system, including a CPU, memory, a clock oscillator, and input/output (I/O) on a single integrated circuit. mnemonic Three to five letters that represent a computer operation. For example, the mnemonic form of the load accumulator instruction is LDA. most significant bit (MSB) The leftmost digit of a binary value; the opposite of least significant bit (LSB). MS Abbreviation for most significant.
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 191
Glossary
MSB Most significant bit. See most significant bit. N Abbreviation for negative, a bit in the condition code register of the CPU08. The CPU sets the negative flag when an arithmetic operation, logical operation, or data manipulation produces a negative result. nibble Half a byte; four bits. object code The output from an assembler or compiler that is itself executable machine code or is suitable for processing to produce executable machine code. one A logic high level, a voltage level approximately equal to the input power voltage (VDD). ones complement An infrequently used form of signed binary numbers. Negative numbers are simply the complement of their positive counterparts. Ones complement is the result of a bit-by-bit complement of a binary word: All 1s are changed to 0s and all 0s changed to 1s. Ones complement is twos complement without the increment. opcode A binary code that instructs the CPU to do a specific operation in a specific way. operand The fundamental quantity on which a mathematical operation is performed. Usually a statement consists of an operator and an operand. The operator may indicate an add instruction; the operand therefore will indicate what is to be added. oscillator A circuit that produces a constant frequency square wave that is used by the computer as a timing and sequencing reference. page 0 The first 256 bytes of memory ($0000$00FF). Also called direct page. PC Program counter. See program counter. pointer Pointer register. An index register is sometimes called a pointer register because its contents are used in the calculation of the address of an operand, and therefore points to the operand. program A set of computer instructions that cause a computer to perform a desired operation or operations. programming model The registers of a particular CPU. program counter (PC) A 16-bit register in the CPU08. The PC register holds the address of the next instruction or operand that the CPU will use. pull The act of reading a value from the stack. In the M68HC08, a value is pulled by the following sequence of operations. First, the stack pointer register is incremented so that it points to the last value saved on the stack. Next, the value at the address contained in the stack pointer register is read into the CPU. push The act of storing a value at the address contained in the stack pointer register and then decrementing the stack pointer so that it points to the next available stack location. random access memory (RAM) A type of memory that can be read or written by the CPU. The contents of a RAM memory location remain valid until the CPU writes a different value or until power is turned off. RAM Random access memory. See random-access memory. read To transfer the contents of a memory location to the CPU.
CPU08 Central Processor Unit Reference Manual, Rev. 4 192 Freescale Semiconductor
Glossary
read-only memory A type of memory that can be read but cannot be changed (written) by the CPU. The contents of ROM must be specified before manufacturing the MCU. registers Memory locations wired directly into the CPU logic instead of being part of the addressable memory map. The CPU always has direct access to the information in these registers. The CPU registers in an M68HC08 are: A (8-bit accumulator) (H:X) (16-bit index register) SP (16-bit stack pointer) PC (16-bit program counter) CCR (condition code register containing the V, H, I, N, Z, and C bits) Memory locations that hold status and control information for on-chip peripherals are called input/output (I/O) and control registers. relative addressing mode Relative addressing mode is used to calculate the destination address for branch instructions. If the branch condition is true, the signed 8-bit value after the opcode is added to the current value of the program counter to get the address where the CPU will fetch the next instruction. If the branch condition is false, the effective address is the content of the program counter. reset Reset is used to force a computer system to a known starting point and to force on-chip peripherals to known starting conditions. ROM Read-only memory. See read-only memory. set To establish a logic 1 state on a bit or bits; the opposite of clear. signed A form of binary number representation accommodating both positive and negative numbers. The most significant bit is used to indicate whether the number is positive or negative, normally zero for positive and one for negative, and the other seven bits indicate the magnitude. SIM System integration module. See system integration module. SP Stack pointer. See stack pointer. stack A mechanism for temporarily saving CPU register values during interrupts and subroutines. The CPU maintains this structure with the stack pointer (SP) register, which contains the address of the next available (empty) storage location on the stack. When a subroutine is called, the CPU pushes (stores) the low-order and high-order bytes of the return address on the stack before starting the subroutine instructions. When the subroutine is done, a return from subroutine (RTS) instruction causes the CPU to recover the return address from the stack and continue processing where it left off before the subroutine. Interrupts work in the same way except that all CPU registers are saved on the stack instead of just the program counter. stack pointer (SP) A 16-bit register in the CPU08 containing the address of the next available (empty) storage on the stack. stack pointer addressing mode Stack pointer (SP) addressing mode instructions operate like indexed addressing mode instructions except that the offset is added to the stack pointer instead of the index register (H:X). The effective address of the operand is formed by adding the unsigned byte(s) in the stack pointer to the unsigned byte(s) following the opcode.
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 193
Glossary
subroutine A sequence of instructions to be used more than once in the course of a program. The last instruction in a subroutine is a return-from-subroutine (RTS) instruction. At each place in the main program where the subroutine instructions are needed, a jump or branch to subroutine (JSR or BSR) instruction is used to call the subroutine. The CPU leaves the flow of the main program to execute the instructions in the subroutine. When the RTS instruction is executed, the CPU returns to the main program where it left off. synchronous Refers to two or more things made to happen simultaneously in a system by means of a common clock signal. system integration module (SIM) One of a number of modules that handle a variety of control functions in the modular M68HC08 Family. The SIM controls mode of operation, resets and interrupts, and system clock generation. table A collection or ordering of data (such as square root values) laid out in rows and columns and stored in a computer memory as an array. twos complement A means of performing binary subtraction using addition techniques. The most significant bit of a twos complement number indicates the sign of the number (1 indicates negative). The twos complement negative of a number is obtained by inverting each bit in the number and then adding 1 to the result. unsigned Refers to a binary number representation in which all numbers are assumed positive. With signed binary, the most significant bit is used to indicate whether the number is positive or negative, normally 0 for positive and 1 for negative, and the other seven bits are used to indicate the magnitude. variable A value that changes during the course of executing a program. word Two bytes or 16 bits, treated as a unit. write The transfer of a byte of data from the CPU to a memory location. X Abbreviation for the lower byte of the index register (H:X) in the CPU08. Z Abbreviation for zero, a bit in the condition code register of the CPU08. The CPU08 sets the zero flag when an arithmetic operation, logical operation, or data manipulation produces a result of $00. zero A logic low level, a voltage level approximately equal to the ground voltage (VSS).
CPU08 Central Processor Unit Reference Manual, Rev. 4 194 Freescale Semiconductor
Index
A Accumulator (A) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Addressing modes direct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 extended . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 immediate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 indexed with post increment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 indexed, 16-bit offset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 indexed, 8-bit offset. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 indexed, 8-bit offset with post increment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 indexed, no offset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 inherent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 memory to memory direct to direct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 memory to memory direct to indexed with post increment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 memory to memory immediate to direct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 memory to memory indexed to direct with post increment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 relative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 stack pointer, 16-bit offset. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 stack pointer, 8-bit offset. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
C
Carry/borrow flag (C) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Condition code register (CCR) carry/borrow flag (C) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 half-carry flag (H) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 interrupt mask (I) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 negative flag (N) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 overflow flag (V) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 zero flag (Z) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 CPU08 accumulator (A) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 condition code register (CCR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 control unit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 execution unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 index register (HX) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 instruction execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2122 internal timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 low-power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 195
Index
D
Direct addressing mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 DMA (direct memory access module) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
E
Extended addressing mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
H
HX (index register) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
I
Immediate addressing mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Index register (HX) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Indexed with post increment addressing mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Indexed, 16-bit offset addressing mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Indexed, 8-bit offset addressing mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Indexed, 8-bit offset with post increment addressing mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Indexed, no offset addressing mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Inherent addressing mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Instruction execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2122 Instruction set convention definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 nomenclature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Interrupts allocating scratch space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 arbitration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 DMA (direct memory access module) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 flow and timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 H register storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 interrupt processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 interrupt recognition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2627 masking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 nesting of multiple interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30, 31 priority . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 recognition. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 return to calling program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 SIM (system integration module) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 stacking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
CPU08 Central Processor Unit Reference Manual, Rev. 4 196 Freescale Semiconductor
Index
L
Legal label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Literal expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
M
Memory to memory direct to direct addressing mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Memory to memory direct to indexed with post increment addressing mode . . . . . . . . . . . . . . . . . . . . . 47 Memory to memory immediate to direct addressing mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Memory to memory indexed to direct with post increment addressing mode . . . . . . . . . . . . . . . . . . . . . 46 Monitor mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
N
Negative flag (N) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Notation Source forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
O
Opcode map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Overflow flag (V) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
P
Program counter (PC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
R Register designators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Registers accumulator (A) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 condition code (CCR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 index (HX) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 program counter (PC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 stack pointer (SP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Relative addressing mode conditional branch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Resets arbitration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 CPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 DMA (direct memory access module) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 exiting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 external . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 H register storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 I bit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 initial conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 internal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 local enable mask bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 masking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 mode selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 monitor mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 recognition. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
CPU08 Central Processor Unit Reference Manual, Rev. 4 Freescale Semiconductor 197
Index
reseting processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 SIM (system integration module) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25, 29 sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 stacking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 user mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
S
SIM (system integration module) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25, 29 Source form notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Stack pointer (SP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Stack pointer, 16-bit offset addressing mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Stack pointer, 8-bit offset addressing mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 System integration module (SIM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25, 29
T
Timing control unit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 internal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 interrupt processing flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
U User mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 V
V (overflow flag) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Z
Zero flag (Z) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
CPU08 Central Processor Unit Reference Manual, Rev. 4 198 Freescale Semiconductor
Information in this document is provided solely to enable system and software implementers to use Freescale Semiconductor products. There are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits or integrated circuits based on the information in this document. Freescale Semiconductor reserves the right to make changes without further notice to any products herein. Freescale Semiconductor makes no warranty, representation or guarantee regarding the suitability of its products for any particular purpose, nor does Freescale Semiconductor assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation consequential or incidental damages. Typical parameters that may be provided in Freescale Semiconductor 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 customers technical experts. Freescale Semiconductor does not convey any license under its patent rights nor the rights of others. Freescale Semiconductor 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 Freescale Semiconductor product could create a situation where personal injury or death may occur. Should Buyer purchase or use Freescale Semiconductor products for any such unintended or unauthorized application, Buyer shall indemnify and hold Freescale Semiconductor and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims, costs, damages, and expenses, and reasonable attorney fees arising 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 Freescale Semiconductor was negligent regarding the design or manufacture of the part. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2006. All rights reserved.