PageItemDescription
P27Figure 1-12 Instruction FormatsFigure (4) amended
P33Table 1-6 Effective Address Calculation (8)Table amended
P512.2.6 BANDNotes added
P582.2.11 BIOROperand Format and Number of Register direct 1st byte
States Required for Executionamended
P672.2.18 BSRNotes description added
P742.2.22 (3) CMP (L)Operand Format and Number ofOperands amended
States Required for Execution
P862.2.26 (3) DIVXSDescription amended
P87DIVXS Example 2Example 2 added
P1062.2.33 JSR CautionsDescription added
P1082.2.34 (1) LDC (B)Description amended
/added
P1102.2.34 (2) LDC (W)Operand Format and Number ofMnemonic amended
States Required for Execution
P1142.2.35 (4) MOV (B)DescriptionDescription amended
P1172.2.35 (5) MOV (W)Operand Format and Number ofTable contents amended
States Required for Execution
P1192.2.35 (6) MOV (L)Operand Format and Number ofTable contents amended
States Required for Execution
P1232.2.35 (8) MOV (W)Operand Format and Number ofTable contents amended
States Required for Execution
P1252.2.35 (9) MOV (L)Operand Format and Number ofTable contents amended
States Required for Execution
P1292.2.38 (2) MULXS (W)Figure amended
P1442.2.45 (2) POP (L)Number of execution states
2.2.58 (2) STC (W)Assembler FormatAssembler format amended
P1762.2.58 (2) STC (W)Operand Format and Number ofMnemonic amended
States Required for Execution
P1802.2.60 SUBSOperationOperation amended
P189(1) Data Transfer Instructions MOV.W @ERs+,RdOperation amended
(1) Data Transfer Instructions MOV.W Rs,@ERdOperation amended
(1) Data Transfer Instructions MOV.W Rs,@(d:24,ERd)Number of execution states
amended
(1) Data Transfer Instructions MOV.L #xx:32,ERdOperation and number of
execution states amended
P190(1) Data Transfer Instructions MOV.L @ERs+,ERdOperation amended
(1) Data Transfer Instructions POP.L ERnNumber of execution states
amended
(1) Data Transfer Instructions PUSH.L ERnNumber of execution states
amended
P191(2) Arithmetic Operation Instructions DAA RdCondition code amended
P192(2) Arithmetic Operation Instructions CMP.L #xx:32,ERdNumber of execution states
amended
P196(5) Bit Manipulation InstructionsTable amended
P197,(6) Branch InstructionsAdded
P198
P198(7) System Control Instructions LDC @ERs,CCROperation amended
(7) System Control Instructions LDC @(d:16,ERs),CCROperation amended
(7) System Control Instructions LDC @(d:24,ERs),CCROperation amended
(7) System Control Instructions LDC @ERs+,CCROperation amended
P204Table 2-3 Instruction Codes (4) MOV.B@aa:16,RdInstruction format amended
P231Table 2-8 Bus States BSR d:16Execution order nos.2 to
5 amended
P234, Table 2-8 Bus States POP.W Rn to PUSH.L ERnInstruction added
P235
4.4External Data Bus ........................................................................................................... 248
Page 9
Section 1 CPU
1.1 Overview
The H8/300H CPU is a high-speed central processing unit with an internal 32-bit architecture that
is upward-compatible with the H8/300 CPU. The H8/300H CPU has sixteen 16-bit general
registers, can address a 16-Mbyte linear address space, and is ideal for realtime control.
1.1.1 Features
The H8/300H CPU has the following features.
•Upward-compatible with H8/300 CPU
— Can execute H8/300 object programs
•General-register architecture
— Sixteen 16-bit general registers (also usable as sixteen 8-bit registers or eight 32-bit
registers)
•Sixty-two basic instructions
— 8/16/32-bit arithmetic and logic instructions
— Multiply and divide instructions
— Powerful bit-manipulation instructions
•Eight addressing modes
— Register direct [Rn]
— Register indirect [@ERn]
— Register indirect with displacement [@(d:16,ERn) or @(d:24,ERn)]
— Register indirect with post-increment or pre-decrement [@ERn+ or @–ERn]
— Absolute address [@aa:8, @aa:16, or @aa:24]
— Immediate [#xx:8, #xx:16, or #xx:32]
— Program-counter relative [@(d:8,PC) or @(d:16,PC)]
— Memory indirect [@@aa:8]
•16-Mbyte address space
•High-speed operation
— All frequently-used instructions execute in two to four states
— Maximum clock frequency: 16 MHz
— Transition to power-down state by SLEEP instruction
1.1.2 Differences from H8/300 CPU
In comparison to the H8/300 CPU, the H8/300H CPU has the following enhancements.
•More general registers
Eight 16-bit registers have been added.
•Expanded address space
Normal mode supports the same 64-kbyte address space as the H8/300 CPU.
Advanced mode supports a maximum 16-Mbyte address space.
•Enhanced addressing
The addressing modes have been enhanced to make effective use of the 16-Mbyte address
space.
•Enhanced instructions
Signed multiply/divide instructions and other instructions have been added.
2
Page 11
1.2 CPU Operating Modes
The H8/300H CPU has two operating modes: normal and advanced. Normal mode supports a
maximum 64-kbyte address space. Advanced mode supports up to 16 Mbytes. The mode is
selected at the mode pins of the microcontroller. For further information, refer to the relevant
hardware manual.
Normal mode
CPU operating modes
Advanced mode
Maximum 64 kbytes, program
and data areas combined
Maximum 16 Mbytes, program
and data areas combined
Figure 1-1 CPU Operating Modes
(1) Normal Mode: The exception vector table and stack have the same structure as in the H8/300
CPU.
Address Space: A maximum address space of 64 kbytes can be accessed, as in the H8/300 CPU.
Extended Registers (En): The extended registers (E0 to E7) can be used as 16-bit data registers,
or they can be combined with the general registers (R0 to R7) for use as 32-bit data registers.
When En is used as a 16-bit register it can contain any value, even when the corresponding
general register (R0 to R7) is used as an address register. If the general register is referenced in the
register indirect addressing mode with pre-decrement (@–Rn) or post-increment (@Rn+) and a
carry or borrow occurs, however, the value in the corresponding extended register will be affected.
Instruction Set: All additional instructions and addressing modes of the H8/300 CPU can be
used. If a 24-bit effective address (EA) is specified, only the lower 16 bits are used.
Exception Vector Table and Memory Indirect Branch Addresses: In normal mode the top area
starting at H'0000 is allocated to the exception vector table. One branch address is stored per 16
bits (figure 1-2). The exception vector table differs depending on the microcontroller, so see the
microcontroller hardware manual for further information.
The memory indirect addressing mode (@@aa:8) employed in the JMP and JSR instructions uses
an 8-bit absolute address to specify a memory operand that contains a branch address. In normal
mode the operand is a 16-bit word operand, providing a 16-bit branch address. Branch addresses
can be stored in the top area from H'0000 to H'00FF. Note that this area is also used for the
exception vector table.
Stack Structure: When the program counter (PC) is pushed on the stack in a subroutine call, and
the PC and condition-code register (CCR) are pushed on the stack in exception handling, they are
stored in the same way as in the H8/300 CPU. See figure 1-3.
(a) Subroutine branch(b) Exception handling
SP
Note: * Ignored at return.
PC
(16 bits)
SP
CCR
CCR*
(16 bits)
Figure 1-3 Stack Structure (normal mode)
4
PC
Page 13
(2) Advanced Mode: In advanced mode the exception vector table and stack structure differ from
the H8/300 CPU.
Address Space: Up to 16 Mbytes can be accessed linearly.
Extended Registers (En): The extended registers (E0 to E7) can be used as 16-bit data registers,
or they can be combined with the general registers (R0 to R7) for use as 32-bit data registers.
When a 32-bit register is used as an address register, the upper 8 bits are ignored.
Instruction Set: All additional instructions and addressing modes of the H8/300H can be used.
Exception Vector Table and Memory Indirect Branch Addresses: In advanced mode the top
area starting at H'000000 is allocated to the exception vector table in units of 32 bits. In each 32
bits, the upper 8 bits are ignored and a branch address is stored in the lower 24 bits (figure 1-4).
The exception vector table differs depending on the microcontroller, so see the relevant hardware
manual for further information.
H'000000
H'000003
H'000004
H'00000B
H'00000C
Don’t care
Reset exception vector
Exception vector table
Reserved for system use
Don’t care
Exception vector
Figure 1-4 Exception Vector Table (advanced mode)
5
Page 14
The memory indirect addressing mode (@@aa:8) employed in the JMP and JSR instructions uses
an 8-bit absolute address to specify a memory operand that contains a branch address. In advanced
mode the operand is a 32-bit longword operand, of which the lower 24 bits are the branch address.
Branch addresses can be stored in the top area from H'000000 to H'0000FF. Note that this area is
also used for the exception vector table.
Stack Structure:When the program counter (PC) is pushed on the stack in a subroutine call, and
the PC and condition-code register (CCR) are pushed on the stack in exception handling, they are
stored as shown in figure 1-5.
(a) Subroutine branch(b) Exception handling
SP
Reserved
PC
(24 bits)
SP
Figure 1-5 Stack Structure (advanced mode)
CCR
PC
(24 bits)
6
Page 15
1.3 Address Space
Figure 1-6 shows a memory map of the H8/300H CPU.
(a) Normal mode(b) Advanced mode
H'0000
H'FFFF
H'000000
H'FFFFFF
Figure 1-6 Memory Map
7
Page 16
1.4 Register Configuration
1.4.1 Overview
The H8/300H CPU has the internal registers shown in figure 1-7. There are two types of registers:
general and extended registers, and control registers.
General registers (Rn) and extended registers (En)
1507070
E0
E1
E2
E3
E4
E5
E6
SP
Control registers (CR)
E7
R0H
R1H
R2H
R3H
R4H
R5H
R6H
R7H
230
PC
R0L
R1L
R2L
R3L
R4L
R5L
R6L
R7L
Legend
Stack pointer
SP:
Program counter
PC:
Condition code register
CCR:
Interrupt mask bit
I:
User bit or interrupt mask bit
U:
Half-carry flag
H:
Negative flag
N:
Zero flag
Z:
Overflow flag
V:
Carry flag
C:
76543210
I UHUNZVCCCR
Figure 1-7 CPU Registers
8
Page 17
1.4.2 General Registers
The H8/300H CPU has eight 32-bit general registers. These general registers are all functionally
alike and can be used without distinction between data registers and address registers. When a
general register is used as a data register, it can be accessed as a 32-bit, 16-bit, or 8-bit register.
When the general registers are used as 32-bit registers or as address registers, they are designated
by the letters ER (ER0 to ER7).
The ER registers divide into 16-bit general registers designated by the letters E (E0 to E7) and R
(R0 to R7). These registers are functionally equivalent, providing a maximum sixteen 16-bit
registers. The E registers (E0 to E7) are also referred to as extended registers.
The R registers divide into 8-bit general registers designated by the letters RH (R0H to R7H) and
RL (R0L to R7L). These registers are functionally equivalent, providing a maximum sixteen 8-bit
registers.
Figure 1-8 illustrates the usage of the general registers. The usage of each register can be selected
independently.
General register ER7 has the function of stack pointer (SP) in addition to its general-register
function, and is used implicitly in exception handling and subroutine calls. Figure 1-9 shows the
stack.
Free area
SP (ER7)
Stack area
Figure 1-9 Stack
1.4.3 Control Registers
The control registers are the 24-bit program counter (PC) and the 8-bit condition-code register
(CCR).
(1) Program Counter (PC): This 24-bit counter indicates the address of the next instruction the
CPU will execute. The length of all CPU instructions is 16 bits (one word) or a multiple of 16 bits,
so the least significant PC bit is ignored. When an instruction is fetched, the least significant PC
bit is regarded as 0.
(2) Condition Code Register (CCR): This 8-bit register contains internal CPU status
information, including the interrupt mask bit (I) and half-carry (H), negative (N), zero (Z),
overflow (V), and carry (C) flags.
Bit 7—Interrupt Mask Bit (I): Masks interrupts other than NMI when set to 1. (NMI is accepted
regardless of the I bit setting.) The I bit is set to 1 by hardware at the start of an exceptionhandling sequence.
Bit 6—User Bit (U): Can be written and read by software using the LDC, STC, ANDC, ORC,
and XORC instructions. This bit can also be used as an interrupt mask bit. For details see the
relevant microcontroller hardware manual.
10
Page 19
Bit 5—Half-Carry Flag (H): When the ADD.B, ADDX.B, SUB.B, SUBX.B, CMP.B, or NEG.B
instruction is executed, this flag is set to 1 if there is a carry or borrow at bit 3, and cleared to 0
otherwise. When the ADD.W, SUB.W, CMP.W, or NEG.W instruction is executed, the H flag is
set to 1 if there is a carry or borrow at bit 11, and cleared to 0 otherwise. When the ADD.L,
SUB.L, CMP.L, or NEG.L instruction is executed, the H flag is set to 1 if there is a carry or
borrow at bit 27, and cleared to 0 otherwise.
Bit 4—User Bit (U): Can be written and read by software using the LDC, STC, ANDC, ORC,
and XORC instructions.
Bit 3—Negative Flag (N): Indicates the most significant bit (sign bit) of the result of an
instruction.
Bit 2—Zero Flag (Z): Set to 1 to indicate a zero result, and cleared to 0 to indicate a non-zero
result.
Bit 1—Overflow Flag (V): Set to 1 when an arithmetic overflow occurs, and cleared to 0 at other
times.
Bit 0—Carry Flag (C): Set to 1 when a carry occurs, and cleared to 0 otherwise. Used by:
•Add instructions, to indicate a carry
•Subtract instructions, to indicate a borrow
•Shift and rotate instructions, to store the value shifted out of the end bit
The carry flag is also used as a bit accumulator by bit manipulation instructions. Some
instructions leave some or all of the flag bits unchanged. For the action of each instruction on the
flag bits, refer to the detailed descriptions of the instructions starting in section 2.2.1.
Operations can be performed on the CCR bits by the LDC, STC, ANDC, ORC, and XORC
instructions. The N, Z, V, and C flags are used as branching conditions for conditional branch
(Bcc) instructions.
1.4.4 Initial Register Values
When the CPU is reset, the program counter (PC) is loaded from the vector table and the I bit in
the condition-code register (CCR) is set to 1. The other CCR bits and the general registers and
extended registers are not initialized. In particular, the stack pointer (extended register E7 and
general register R7) is not initialized. The stack pointer must therefore be initialized by an MOV.L
instruction executed immediately after a reset.
11
Page 20
1.5 Data Formats
The H8/300H CPU can process 1-bit, 4-bit, 8-bit (byte), 16-bit (word), and 32-bit (longword)
data. Bit-manipulation instructions operate on 1-bit data by accessing bit n (n = 0, 1, 2, …, 7) of
byte operand data. The DAA and DAS decimal-adjust instructions treat byte data as two digits of
4-bit BCD data.
1.5.1 General Register Data Formats
Figure 1-10 shows the data formats in general registers.
Data typeRegister numberData format
1-bit data
1-bit data
4-bit BCD data
4-bit BCD data
Byte data
Byte data
RnH
RnL
RnH
RnL
RnH
RnL
70
76543210Don’t care
70
Don’t care76543210
70
70
MSBLSB
43
70
Don’t care
70
Don’t care
MSB
Figure 1-10 General Register Data Formats
Don’t careUpperLower
Upper
Don’t care
43
Lower
LSB
12
Page 21
Word data
Word data
15
MSBLSB
Rn
En
0
15
MSBLSB
0
Longword data
31
MSB
Legend
ERn:
General register ER
En:
General register E
Rn:
General register R
RnH:
General register RH
RnL:
General register RL
MSB:
Most significant bit
LSB:
Least significant bit
ERn
15
16
EnRn
0
LSB
Figure 1-10 General Register Data Formats (cont)
1.5.2 Memory Data Formats
Figure 1-11 shows the data formats on memory. The H8/300H CPU can access word data and
longword data on memory, but word or longword data must begin at an even address. If an
attempt is made to access word or longword data at an odd address, no address error occurs but
the least significant bit of the address is regarded as 0, so the access starts at the preceding
address. This also applies to instruction fetches.
13
Page 22
Data typeData format
Address
70
1-bit data
Address L
76543210
Byte data
Word data
Longword data
Address L
Address 2M
Address 2M + 1
Address 2N
Address 2N + 1
Address 2N + 2
Address 2N + 3
MSBLSB
MSB
LSB
MSB
LSB
Figure 1-11 Memory Data Formats
When ER7 is used as an address register to access the stack, the operand size should be word size
or longword size.
14
Page 23
1.6 Instruction Set
1.6.1 Overview
The H8/300H CPU has 62 types of instructions, which are classified by function in table 1-1. For
a detailed description of each instruction see section 2.2, Instruction Descriptions.
ROTXR
Bit manipulationBSET, BCLR, BNOT, BTST, BAND, BIAND, BOR, BIOR, 14
BXOR, BIXOR, BLD, BILD, BST, BIST
2
*
BranchBcc
, JMP, BSR, JSR, RTS5
System controlTRAPA, RTE, SLEEP, LDC, STC, ANDC, ORC, XORC, NOP9
Block data transferEEPMOV1
Notes: The shaded instructions are not present in the H8/300 instruction set.
1. POP.W Rn and PUSH.W Rn are identical to MOV.W @SP+, Rn and MOV.W Rn, @–SP.
POP.L ERn and PUSH.L ERn are identical to MOV.L @SP+, ERn and MOV.L ERn,
@–SP.
2. Bcc is the generic designation of a conditional branch instruction.
, POP
2
*
, MOVTPE, MOVFPE3
Total 62 types
15
Page 24
1.6.2 Instructions and Addressing Modes
Table 1-2 indicates the instructions available in the H8/300H CPU.
Table 1-2 Instruction Set Overview
Function Instruction
Data
transfer
Arithmetic
operations
Logic
operations
Shift
Bit manipulation
MOV
POP, PUSH
MOVFPE,
MOVTPE
ADD, CMP
SUB
ADDX,
SUBX
ADDS,
SUBS
INC, DEC
DAA, DAS
MULXU,
DIVXU
MULXS,
DIVXS
NEG
EXTU, EXTS
AND, OR,
XOR
NOT
Notes: 1. The operand size of the ADDS and SUBS instructions of the H8/300H CPU has been changed to longword size. (In the
H8/300 CPU it was word size.)
2. Because of its larger address space, the H8/300H CPU uses a 24-bit absolute address for the JMP and JSR instructions.
(The H8/300 CPU used 16 bits.)
1.6.3 Tables of Instructions Classified by Function
Table 1-3 summarizes the instructions in each functional category. The notation used in table 1-3
is defined next.
Operation Notation
RdGeneral register (destination)*
RsGeneral register (source)*
RnGeneral register*
ERnGeneral register (32-bit register)
(EAd)Destination operand
(EAs)Source operand
CCRCondition code register
NN (negative) bit of CCR
ZZ (zero) bit of CCR
VV (overflow) bit of CCR
CC (carry) bit of CCR
PCProgram counter
SPStack pointer
#IMMImmediate data
dispDisplacement
+Addition
–Subtraction
×Multiplication
÷Division
∧AND logical
∨OR logical
⊕Exclusive OR logical
→Move
¬Not
:3/:8/:16/:243-, 8-, 16-, or 24-bit length
Note: * General registers include 8-bit registers (R0H/R0L to R7H/R7L), 16-bit registers (R0 to
R7, E0 to E7), and 32-bit registers (ER0 to ER7).
18
Page 27
Table 1-3 Instructions Classified by Function
TypeInstructionSize*Function
Data transferMOVB/W/L(EAs) → Rd, Rs → (EAd)
Moves data between two general registers or between
a general register and memory, or moves immediate
data to a general register.
MOVFPEB(EAs) → Rd
Moves external memory contents (addressed by
@aa:16) to a general register in synchronization with
an E clock.
MOVTPEBRs → (EAd)
Moves general register contents to an external memory
location (addressed by @aa:16) in synchronization with
an E clock.
POPW/L@SP+ → Rn
Pops a register from the stack. POP.W Rn is identical to
MOV.W @SP+, Rn. POP.L ERn is identical to MOV.L
@SP+, ERn.
PUSHW/LRn → @–SP
Pushes a register onto the stack. PUSH.W Rn is
identical to MOV.W Rn, @–SP. PUSH.L ERn is
identical to MOV.L ERn, @–SP.
Note: * Size refers to the operand size.
B: Byte
W: Word
L: Longword
19
Page 28
Table 1-3 Instructions Classified by Function (cont)
TypeInstructionSize*Function
Arithmetic
operations
Note: * Size refers to the operand size.
B: Byte
W: Word
L: Longword
ADD
SUB
ADDX
SUBX
INC
DEC
ADDS
SUBS
DAA
DAS
MULXSB/WRd × Rs → Rd
MULXUB/WRd × Rs → Rd
DIVXSB/WRd ÷ Rs → Rd
B/W/LRd ±Rs → Rd, Rd ± #IMM → Rd
Performs addition or subtraction on data in two general
registers, or on immediate data and data in a general
register. (Immediate byte data cannot be subtracted
from data in a general register. Use the SUBX or ADD
instruction.)
BRd ± Rs ±C → Rd, Rd ± #IMM ± C → Rd
Performs addition or subtraction with carry or borrow
on byte data in two general registers, or on immediate
data and data in a general register.
B/W/LRd ±1 → Rd, Rd ± 2 → Rd
Increments or decrements a general register by 1 or 2.
(Byte operands can be incremented or decremented by
1 only.)
LRd ± 1 → Rd, Rd ± 2 → Rd, Rd ±4 → Rd
Adds or subtracts the value 1, 2, or 4 to or from data in
a 32-bit register.
BRd decimal adjust → Rd
Decimal-adjusts an addition or subtraction result in a
general register by referring to the CCR to produce
4-bit BCD data.
Performs signed multiplication on data in two general
registers: either 8 bits × 8 bits → 16 bits or 16 bits × 16
bits → 32 bits.
Performs unsigned multiplication on data in two general
registers: either 8 bits × 8 bits → 16 bits or 16 bits × 16
bits → 32 bits.
Performs signed division on data in two general
registers: either 16 bits ÷ 8 bits → 8-bit quotient and
8-bit remainder or 32 bits ÷ 16 bits →16-bit quotient
and 16-bit remainder.
20
Page 29
Table 1-3 Instructions Classified by Function (cont)
Performs unsigned division on data in two general
registers: either 16 bits ÷ 8 bits → 8-bit quotient and 8bit remainder or 32 bits ÷ 16 bits → 16-bit quotient and
16-bit remainder.
CMPB/W/LRd – Rs, Rd – #IMM
Compares data in a general register with data in
another general register or with immediate data, and
sets the CCR according to the result.
NEGB/W/L0 – Rd → Rd
Takes the two’s complement (arithmetic complement) of
data in a general register.
EXTSW/LRd (sign extension) → Rd
Extends byte data in the lower 8 bits of a 16-bit register
to word data, or extends word data in the lower 16 bits
of a 32-bit register to longword data, by extending the
sign bit.
EXTUW/LRd (zero extension) → Rd
Extends byte data in the lower 8 bits of a 16-bit register
to word data, or extends word data in the lower 16 bits
of a 32-bit register to longword data, by padding with
zeros.
Performs a logical AND operation on a general register
and another general register or immediate data.
ORB/W/LRd ∨ Rs → Rd, Rd ∨ #IMM → Rd
Performs a logical OR operation on a general register
and another general register or immediate data.
XORB/W/LRd ⊕ Rs → Rd, Rd ⊕ #IMM → Rd
Performs a logical exclusive OR operation on a general
register and another general register or immediate
data.
NOTB/W/L¬ (Rd) → (Rd)
Takes the one’s complement of general register
contents.
21
Page 30
Table 1-3 Instructions Classified by Function (cont)
TypeInstructionSize*Function
Shift operationsB/W/LRd (shift) → Rd
Bit-manipulation
instructions
Note: * Size refers to the operand size.
B: Byte
W: Word
L: Longword
SHAL
SHAR
SHLL
SHLR
ROTL
ROTR
ROTXL
ROTXR
BSETB1 → (<bit-No.> of <EAd>)
BCLRB0 → (<bit-No.> of <EAd>)
BNOTB¬ (<bit-No.> of <EAd>) → (<bit-No.> of <EAd>)
BTSTB¬ (<bit-No.> of <EAd>) → Z
BANDBC ∧ (<bit-No.> of <EAd>) → C
BIANDBC ∧ ¬ (<bit-No.> of <EAd>) → C
B/W/LRd (shift) → Rd
B/W/LRd (rotate) → Rd
B/W/LRd (rotate) → Rd
Performs an arithmetic shift on general register
contents.
Performs a logical shift on general register contents.
Rotates general register contents.
Rotates general register contents through the carry bit.
Sets a specified bit in a general register or memory
operand to 1. The bit number is specified by 3-bit
immediate data or the lower three bits of a general
register.
Clears a specified bit in a general register or memory
operand to 0. The bit number is specified by 3-bit
immediate data or the lower three bits of a general
register.
Inverts a specified bit in a general register or memory
operand. The bit number is specified by 3-bit
immediate data or the lower three bits of a general
register.
Tests a specified bit in a general register or memory
operand and sets or clears the Z flag accordingly. The
bit number is specified by 3-bit immediate data or the
lower three bits of a general register.
ANDs the carry flag with a specified bit in a general
register or memory operand and stores the result in the
carry flag.
ANDs the carry flag with the inverse of a specified bit in
a general register or memory operand and stores the
result in the carry flag.
The bit number is specified by 3-bit immediate data.
22
Page 31
Table 1-3 Instructions Classified by Function (cont)
TypeInstructionSize*Function
Bit-manipulation
instructions
Note: * Size refers to the operand size.
B: Byte
BORBC ∨ (<bit-No.> of <EAd>) → C
ORs the carry flag with a specified bit in a general
register or memory operand and stores the result in the
carry flag.
BIORBC ∨ [¬ (<bit-No.> of <EAd>)] → C
ORs the carry flag with the inverse of a specified bit in a
general register or memory operand and stores the
result in the carry flag.
The bit number is specified by 3-bit immediate data.
BXORBC ⊕ (<bit-No.> of <EAd>) → C
Exclusive-ORs the carry flag with a specified bit in a
general register or memory operand and stores the
result in the carry flag.
BIXORBC ⊕ [¬ (<bit-No.> of <EAd>)] → C
Exclusive-ORs the carry flag with the inverse of a
specified bit in a general register or memory operand
and stores the result in the carry flag.
The bit number is specified by 3-bit immediate data.
BLDB(<bit-No.> of <EAd>) → C
Transfers a specified bit in a general register or
memory operand to the carry flag.
BILDB¬ (<bit-No.> of <EAd>) → C
Transfers the inverse of a specified bit in a general
register or memory operand to the carry flag.
The bit number is specified by 3-bit immediate data.
BSTBC → (<bit-No.> of <EAd>)
Transfers the carry flag value to a specified bit in a
general register or memory operand.
BISTB¬ C → (<bit-No.> of <EAd>)
Transfers the inverse of the carry flag value to a
specified bit in a general register or memory operand.
The bit number is specified by 3-bit immediate data.
23
Page 32
Table 1-3 Instructions Classified by Function (cont)
TypeInstructionSize*Function
Branching Bcc—Branches to a specified address if a specified condition
instructionsis true. The branching conditions are listed below.
MnemonicDescriptionCondition
BRA(BT)Always (true)Always
BRN(BF)Never (false)Never
BHIHighC ∨ Z = 0
BLSLow or sameC ∨ Z = 1
Bcc(BHS)Carry clear C = 0
(high or same)
BCS(BLO)Carry set (low)C = 1
BNENot equalZ = 0
BEQEqualZ = 1
BVCOverflow clearV = 0
BVSOverflow setV = 1
BPLPlusN = 0
BMIMinusN = 1
BGEGreater or equalN ⊕ V = 0
BLTLess thanN ⊕ V = 1
BGTGreater thanZ ∨ (N ⊕ V) = 0
BLELess or equalZ ∨ (N ⊕ V) = 1
JMP—Branches unconditionally to a specified address.
BSR—Branches to a subroutine at a specified address.
JSR—Branches to a subroutine at a specified address.
RTS—Returns from a subroutine.
Note: * Size refers to the operand size.
24
Page 33
Table 1-3 Instructions Classified by Function (cont)
TypeInstructionSize*Function
System control
instructions
Note: * Size refers to the operand size.
B: Byte
W: Word
TRAPA—Starts trap-instruction exception handling.
RTE—Returns from an exception-handling routine.
SLEEP—Causes a transition to the power-down state.
LDCB/W(EAs) → CCR
Moves the source operand contents to the condition
code register. Byte transfer is performed in the #xx:8,
Rs addressing mode and word transfer in other
addressing modes.
STCB/WCCR → (EAd)
Transfers the CCR contents to a destination location.
Byte transfer is performed in the Rd addressing mode
and word transfer in other addressing modes.
ANDCBCCR ∧ #IMM → CCR
Logically ANDs the condition code register with
immediate data.
ORCBCCR ∨ #IMM → CCR
Logically ORs the condition code register with
immediate data.
XORCBCCR ⊕ #IMM → CCR
Logically exclusive-ORs the condition code register
with immediate data.
NOP—PC + 2 → PC
Only increments the program counter.
25
Page 34
Table 1-3 Instructions Classified by Function (cont)
TypeInstructionSize*Function
Block data
transfer
instruction
Note: * Size refers to the operand size.
EEPMOV.B—if R4L ≠ 0 then
Repeat @ER5 +→ @ER6 +
R4L – 1→R4L
Until R4L = 0
else next;
EEPMOV.W—if R4 ≠ 0 then
Repeat @ER5 +→ @ER6 +
R4 – 1→R4L
Until R4 = 0
else next;
Transfers a data block according to parameters set in
general registers R4L or R4, ER5, and R6.
R4L or R4: size of block (bytes)
Execution of the next instruction begins as soon as the
transfer is completed.
26
Page 35
1.6.4 Basic Instruction Formats
The H8/300H instructions consist of 2-byte (1-word) units. An instruction consists of an operation
field (OP field), a register field (r field), an effective address extension (EA field), and a condition
field (cc).
Operation Field: Indicates the function of the instruction, the effective address, and the operation
to be carried out on the operand. The operation field always includes the first four bits of the
instruction. Some instructions have two operation fields.
Register Field: Specifies a general register. Address registers are specified by 3 bits, data
registers by 3 bits or 4 bits. Some instructions have two register fields. Some have no register
field.
Effective Address Extension: Eight, 16, or 32 bits specifying immediate data, an absolute
address, or a displacement. A 24-bit address or a displacement is treated as 32-bit data in which
the first 8 bits are 0.
Condition Field: Specifies the branching condition of Bcc instructions.
Figure 1-12 shows examples of instruction formats.
(1) Operation field only
op
(2) Operation field and register fields
op
(3) Operation field, register fields, and effective address extension
op
EA (disp)
(4) Operation field, effective address extension, and condition field
opccEA (disp)
rn
rnrm
rm
NOP, RTS, etc.
ADD. Rn, Rm, etc.
MOV @(d:16, Rn), Rm
BRA @(d:8, PC)
Figure 1-12 Instruction Formats
27
Page 36
1.6.5 Addressing Modes and Effective Address Calculation
(1) Addressing Modes: The H8/300H CPU supports the eight addressing modes listed in table 1-
4. Each instruction uses a subset of these addressing modes. Arithmetic and logic instructions can
use the register direct and immediate modes. Data transfer instructions can use all addressing
modes except program-counter relative and memory indirect. Bit manipulation instructions use
register direct, register indirect, or absolute (8-bit) addressing mode to specify an operand, and
register direct (BSET, BCLR, BNOT, and BTST instructions) or immediate (3-bit) addressing
mode to specify a bit number in the operand.
Table 1-4 Addressing Modes
No.Addressing ModeSymbol
1Register directRn
2Register indirect@ERn
3Register indirect with displacement@(d:16,ERn)/@(d:24,ERn)
4Register indirect with post-increment@ERn+
1 Register Direct—Rn: The register field of the instruction specifies an 8-, 16-, or 32-bit general
register containing the operand. R0H to R7H and R0L to R7L can be specified as 8-bit registers.
R0 to R7 and E0 to E7 can be specified as 16-bit registers. ER0 to ER7 can be specified as 32-bit
registers.
2 Register Indirect—@ERn: The register field of the instruction code specifies an address
register (ERn), the lower 24 bits of which contain the address of a memory operand.
3 Register Indirect with Displacement—@(d:16, ERn) or @(d:24, ERn): A 16-bit or 24-bit
displacement contained in the instruction is added to an address register (an extended register
paired with a general register) specified by the register field of the instruction, and the lower 24
bits of the sum specify the address of a memory operand. A 16-bit displacement is sign-extended
when added.
28
Page 37
4 Register Indirect with Post-Increment or Pre-Decrement—@ERn+ or @–ERn:
•Register indirect with post-increment—@ERn+
The register field of the instruction code specifies an address register (ERn), the lower 24 bits
of which contain the address of a memory operand. After the operand is accessed, 1, 2, or 4 is
added to the address register contents (32 bits) and the sum is stored in the address register.
The value added is 1 for byte access, 2 for word access, or 4 for longword access. For word or
longword access, the register value should be even.
•Register indirect with pre-decrement—@–ERn
The value 1, 2, or 4 is subtracted from an address register (ERn) specified by the register field
in the instruction code, and the lower 24 bits of the result becomes the address of a memory
operand. The result is also stored in the address register. The value subtracted is 1 for byte
access, 2 for word access, or 4 for longword access. For word or longword access, the
resulting register value should be even.
5 Absolute Address—@aa:8, @aa:16, or @aa:24: The instruction code contains the absolute
address of a memory operand. The absolute address may be 8 bits long (@aa:8), 16 bits long
(@aa:16), or 24 bits long (@aa:24). For an 8-bit absolute address, the upper 16 bits are all
assumed to be 1 (H'FFFF). For a 16-bit absolute address the upper 8 bits are a sign extension.
A 24-bit absolute address can access the entire address space. Table 1-5 indicates the accessible
address ranges.
Table 1-5 Absolute Address Access Ranges
Normal ModeAdvanced Mode
8 bits H'FF00 to H'FFFFH'FFFF00 to H'FFFFF
(@aa:8)(65,280 to 65,535)(16,776,960 to 16,777,215)
16 bits H'0000 to H'FFFFH'000000 to H'007FFF, H'FF8000 to H'FFFFFF
(@aa:16)(0 to 65,535)(0 to 32,767, 16,744,448 to 16,777,215)
24 bits H'0000 to H'FFFFH'00000 to H'FFFFF
(@aa:24)(0 to 65,535)(0 to 16,777,215)
For further details on the accessible range, see the relevant microcontroller hardware manual.
6 Immediate—#xx:8, #xx:16, or #xx:32: The instruction contains 8-bit (#xx:8), 16-bit (#xx:16),
or 32-bit (#xx:32) immediate data as an operand.
The ADDS, SUBS, INC, and DEC instructions contain immediate data implicitly. Some bit
manipulation instructions contain 3-bit immediate data in the second or fourth byte of the
instruction, specifying a bit number. The TRAPA instruction contains 2-bit immediate data in the
second byte of the instruction, specifying a vector address.
29
Page 38
7 Program-Counter Relative—@(d:8, PC) or @(d:16, PC): This mode is used in the Bcc and
BSR instructions. An 8-bit or 16-bit displacement contained in the instruction is sign-extended
and added to the 24-bit program counter (PC) contents to generate a branch address. The PC value
to which the displacement is added is the address of the first byte of the next instruction, so the
possible branching range is –126 to +128 bytes (–63 to +64 words) or –32766 to +32768 bytes
(–16383 to +16384 words) from the branch instruction. The resulting value should be an even
number.
8 Memory Indirect—@@aa:8: This mode can be used by the JMP and JSR instructions. The
second byte of the instruction specifies a memory operand by an 8-bit absolute address. This
memory operand contains a branch address. The upper 8 bits of the absolute address are assumed
to be 0 (H'00), so the address range is 0 to 255 (H’0000 to H’00FF in normal mode, H'000000 to
H'0000FF in advanced mode). In normal mode the memory operand is a word operand and the
branch address is 16 bits long. In advanced mode the memory operand is a longword operand. The
first byte is ignored and the branch address is 24 bits long. Note that the first part of the address
range is also the exception vector area. For further details see the relevant microcontroller
hardware manual.
Specified
by @aa:8
Branch address
(a) Normal mode(b) Advanced mode
Specified
by @aa:8
Reserved
Branch address
Figure 1-13 Branch Address Specification in Memory Indirect Mode
If an odd address is specified in word or longword memory access, or as a branch address, the
least significant bit is regarded as 0, causing access to be performed at the address preceding the
specified address. [See (2) Memory Data Formats in section 1.5.2 for further information.]
(2) Effective Address Calculation: Table 1-6 indicates how effective addresses are calculated in
each addressing mode. In normal mode the upper 8 bits of the effective address are ignored in
order to generate a 16-bit address.
30
Page 39
Table 1-6 Effective Address Calculation
No.Addressing Mode and Instruction FormatEffective Address CalculationEffective Address (EA)
(1)Register direct Rn
opRegm Regn
Operands are contents of regm and regn
Register indirect @ERn(2)
opreg
Register indirect with displacement
(3)
@(d:16, ERn)
opreg
Register indirect with post-increment or pre-decrement
(4)
• Register indirect with post-increment
@ERn+
op
reg
• Register indirect with pre-decrement
@–ERn
opreg
disp
310230
Register contents
310
Register contents
230
310
Sign extension
310
Register contents
310
Register contents
Operand Size Added Value
Byte
Word
Longword
1
2
4
disp
230
1, 2, or 4
230
1, 2, or 4
31
Page 40
Table 1-6 Effective Address Calculation (cont)
No.Addressing Mode and Instruction FormatEffective Address Calculation
Absolute address
(5)
@aa:8
opabs
@aa:16
@aa:24
Immediate #xx:8/#xx:16/#xx:32
(6)
op
op
op
abs
abs
IMM
Effective Address (EA)
2308 7
H'FFFF
23016 15
Sign
extension
230
Operand is immediate data.
32
Page 41
Table 1-6 Effective Address Calculation (cont)
(7)
Program-counter relative
@(d:8, PC)/@(d:16, PC)
dispop
(8)
Memory indirect @@aa:8
Normal mode
absop
Effective Address CalculationEffective Address (EA)No.Addressing Mode and Instruction Format
23
23
Sign
extension
0
PC contents
230
0
disp
Advanced mode
23
H'0000abs
absop
H'0000abs
310
Memory contents
8 7
15
Memory contents
8 7
0
0
023
23016 15
H'00
230
33
Page 42
Legend
reg, regm, regn: General registers
op:Operation field
disp: Displacement
abs: Absolute address
IMM: Immediate data
34
Page 43
Section 2 Instruction Descriptions
2.1 Tables and Symbols
This section explains how to read the tables describing each instruction. Note that the descriptions
of some instructions extend over two pages or more.
Mnemonic (full name): Gives the full and mnemonic names of the instruction.
Type: Indicates the type of instruction.
Operation: Describes the instruction in symbolic notation. (See section 2.1.2, Operation.)
Assembly-Language Format: Indicates the assembly-language format of the instruction. (See
section 2.1.1, Assembler Format.)
Operand Size: Indicates the available operand sizes.
Condition Code: Indicates the effect of instruction execution on the flag bits in the CCR. (See
section 2.1.3, Condition Code.)
Description: Describes the operation of the instruction in detail.
Available Registers: Indicates which registers can be specified in the register field of the
instruction.
Operand Format and Number of States Required for Execution: Shows the addressing modes
and instruction format together with the number of states required for execution.
Notes: Gives notes concerning execution of the instruction.
35
Page 44
2.1.1 Assembler Format
Example: ADD. B <EAs>, Rd
Destination operand
Source operand
Size
Mnemonic
The operand size is byte (B), word (W), or longword (L). Some instructions are restricted to a
limited set of operand sizes.
The symbol <EA> indicates that two or more addressing modes can be used. The H8/300H CPU
supports the eight addressing modes listed next. Effective address calculation is described in
section 1.7, Effective Address Calculation.
SymbolAddressing Mode
RnRegister direct
@ERnRegister indirect
@(d:16, ERn)/@(d:24, ERn)Register indirect with displacement (16-bit or 24-bit)
@ERn+, @–ERnRegister indirect with post-increment or pre-decrement
@aa:8/16/24Absolute address (8-bit, 16-bit, or 24-bit)
#xx:8/16/32Immediate (8-bit, 16-bit, or 32-bit)
@(d:8, PC)/@(d:16, PC)Program-counter relative (8-bit or 16-bit)
@@aa:8Memory indirect
36
Page 45
2.1.2 Operation
The symbols used in the operation descriptions are defined as follows.
SymbolMeaning
RdGeneral destination register*
RsGeneral source register*
RnGeneral register*
ERdGeneral destination register (address register or 32-bit register)
ERsGeneral source register (address register or 32-bit register)
ERnGeneral register (32-bit register)
(EAd)Destination operand
(EAs)Source operand
PCProgram counter
SPStack pointer
CCRCondition-code register
NN (negative) flag in CCR
ZZ (zero) flag in CCR
VV (overflow) flag in CCR
CC (carry) flag in CCR
dispDisplacement
→Transfer from the operand on the left to the operand on the right, or transition
from the state on the left to the state on the right
+Addition of the operands on both sides
–Subtraction of the operand on the right from the operand on the left
×Multiplication of the operands on both sides
÷Division of the operand on the left by the operand on the right
∧Logical AND of the operands on both sides
∨Logical OR of the operands on both sides
⊕Logical exclusive OR of the operands on both sides
¬Logical NOT (logical complement)
( ) < >Contents of effective address of the operand
Note: * General registers include 8-bit registers (R0H to R7H and R0L to R7L), 16-bit registers
(R0 to R7 ad E0 to E7) and 32-bit registers.
37
Page 46
2.1.3 Condition Code
The symbols used in the condition-code description are defined as follows.
SymbolMeaning
↕Changes according to the result of the instruction
*Undetermined (no guaranteed value)
0Always cleared to 0
–Not affected by execution of the instruction
∆Varies depending on conditions; see the notes.
2.1.4 Instruction Format
The symbols used in the instruction format descriptions are listed below.
SymbolMeaning
IMMImmediate data (2, 3, 8, 16, or 32 bits)
absAbsolute address (8, 16, or 24 bits)
dispDisplacement (8, 16, or 24 bits)
rs, rd, rnRegister number (4 bits. The symbol rs corresponds to operand symbols such
as Rs. The symbol rd corresponds to operand symbols such as Rd. The symbol
rn corresponds to the operand symbol Rn.)
ers, erd, ernRegister number (3 bits. The symbol ers corresponds to operand symbols such
as ERs. The symbol erd corresponds to operand symbols such as ERd and
@ERd. The symbol ern corresponds to the operand symbol ERn.)
38
Page 47
2.1.5 Register Specification
Address Register Specification: When a general register is used as an address register [@ERn,
@(d:16, ERn), @(d:24, ERn), @ERn+, or @–ERn], the register is specified by a 3-bit register
field (ers or erd). The lower 24 bits of the register are valid.
Data Register Specification: A general register can be used as a 32-bit, 16-bit, or 8-bit data
register, which is specified by a 3-bit register number. When a 32-bit register (ERn) is used as a
longword data register, it is specified by a 3-bit register field (ers, erd, or ern). When a 16-bit
register is used as a word data register, it is specified by a 4-bit register field (rs, rd, or rn). The
lower 3 bits specify the register number. The upper bit is set to 1 to specify an extended register
(En) or cleared to 0 to specify a general register (Rn). When an 8-bit register is used as a byte data
register, it is specified by a 4-bit register field (rs, rd, or rn). The lower 3 bits specify the register
number. The upper bit is set to 1 to specify a low register (RnL) or cleared to 0 to specify a high
register (RnH). This is shown next.
Register General Register General Register General
FieldRegisterFieldRegisterFieldRegister
000ER00000R00000R0H
001ER10001R10001R1H
111ER70111R70111R7H
1000E01000E0L
1001E11001E1L
1111E71111E7L
39
Page 48
2.1.6 Bit Data Access in Bit Manipulation Instructions
Bit data is accessed as the n-th bit (n = 0, 1, 2, 3, …, 7) of a byte operand in a general register or
memory. The bit number is given by 3-bit immediate data, or by the lower 3 bits of a general
register value.
Example 1: To set bit 3 in R2H to 1
BSET R1L, R2H
R1L
R2H
Don’t care
011
Bit number
001
10110
Set to 1
Example 2: To load bit 5 at address H'FFFF02 into the bit accumulator
BLD #5, @FFFF02
#5
H'FF02
Load
00101
110
C
The operand size and addressing mode are as indicated for register or memory operand data.
40
Page 49
2.2 Instruction Descriptions
The instructions are described starting in section 2.2.1.
41
Page 50
2.2.1 (1) ADD (B)
ADD (ADD binary)Add Binary
Operation
Rd + (EAs) → Rd
Assembly-Language Format
ADD.B <EAs>, Rd
Operand Size
Condition Code
IUIHUNZVC
—— ↕ — ↕↕↕↕
H: Set to 1 if there is a carry at bit 3;
otherwise cleared to 0.
N: Set to 1 if the result is negative; otherwise
Byte
cleared to 0.
Z: Set to 1 if the result is zero; otherwise
cleared to 0.
V: Set to 1 if an overflow occurs; otherwise
cleared to 0.
C: Set to 1 if there is a carry at bit 7;
otherwise cleared to 0.
Description
This instruction adds the source operand to the contents of an 8-bit register Rd (destination
operand) and stores the result in the 8-bit register Rd.
Available Registers
Rd:R0L to R7L, R0H to R7H
Rs:R0L to R7L, R0H to R7H
Operand Format and Number of States Required for Execution
This instruction adds the source operand to the contents of a 16-bit register Rd (destination
operand) and stores the result in the 16-bit register Rd.
Available Registers
Rd:R0 to R7, E0 to E7
Rs:R0 to R7, E0 to E7
Operand Format and Number of States Required for Execution
This instruction adds the source operand to the contents of a 32-bit register ERd (destination
operand) and stores the result in the 32-bit register ERd.
Available Registers
ERd: ER0 to ER7
ERs: ER0 to ER7
Operand Format and Number of States Required for Execution
ADDS (ADD with Sign extension)Add Binary Address Data
Operation
Rd + 1 → ERd
Rd + 2 → ERd
Rd + 4 → ERd
Assembly-Language Format
ADDS #1, ERd
ADDS #2, ERd
ADDS #4, ERd
Condition Code
IUIHUNZVC
————————
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Z: Previous value remains unchanged.
V: Previous value remains unchanged.
C: Previous value remains unchanged.
Operand Size
Longword
Description
This instruction adds the immediate value 1, 2, or 4 to the contents of a 32-bit register ERd.
Differing from the ADD instruction, it does not affect the condition code flags.
Available Registers
ERd: ER0 to ER7
Operand Format and Number of States Required for Execution
This instruction adds the source operand and carry flag to the contents of an 8-bit register Rd
(destination register) and stores the result in the 8-bit register Rd.
Available Registers
Rd:R0L to R7L, R0H to R7H
Rs:R0L to R7L, R0H to R7H
Operand Format and Number of States Required for Execution
H: Previous value remains unchanged.
N: Set to 1 if the result is negative; otherwise
cleared to 0.
Byte
Z: Set to 1 if the result is zero; otherwise
cleared to 0.
V: Always cleared to 0.
C: Previous value remains unchanged.
Description
This instruction ANDs the source operand with the contents of an 8-bit register Rd (destination
register) and stores the result in the 8-bit register Rd.
Available Registers
Rd:R0L to R7L, R0H to R7H
Rs:R0L to R7L, R0H to R7H
Operand Format and Number of States Required for Execution
H: Previous value remains unchanged.
N: Set to 1 if the result is negative; otherwise
cleared to 0.
Word
Z: Set to 1 if the result is zero; otherwise
cleared to 0.
V: Always cleared to 0.
C: Previous value remains unchanged.
Description
This instruction ANDs the source operand with the contents of a 16-bit register Rd (destination
register) and stores the result in the 16-bit register Rd.
Available Registers
Rd:R0 to R7, E0 to E7
Rs:R0 to R7, E0 to E7
Operand Format and Number of States Required for Execution
H: Previous value remains unchanged.
N: Set to 1 if the result is negative; otherwise
cleared to 0.
Longword
Z: Set to 1 if the result is zero; otherwise
cleared to 0.
V: Always cleared to 0.
C: Previous value remains unchanged.
Description
This instruction ANDs the source operand with the contents of a 32-bit register ERd (destination
register) and stores the result in the 32-bit register ERd.
Available Registers
ERd: ER0 to ER7
ERs: ER0 to ER7
Operand Format and Number of States Required for Execution
I:Stores the corresponding bit of the result.
UI: Stores the corresponding bit of the result
H: Stores the corresponding bit of the result.
Byte
U: Stores the corresponding bit of the result
N: Stores the corresponding bit of the result.
Z: Stores the corresponding bit of the result.
V: Stores the corresponding bit of the result.
C: Stores the corresponding bit of the result.
Description
This instruction ANDs the contents of the condition-code register (CCR) with immediate data and
stores the result in the condition-code register. No interrupt requests, including NMI, are accepted
immediately after execution of this instruction.
Operand Format and Number of States Required for Execution
Addressing
Mode
ImmediateANDC#xx:8, CCR06IMM2
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
Notes
50
No. of
States
Page 59
2.2.6 BAND
BAND (Bit AND)Bit Logical AND
Operation
C ∧ (<bit No.> of <EAd>) →C
Assembly-Language Format
BAND #xx:3, <EAd>
Operand Size
Condition Code
IUIHUNZVC
——————— ↕
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Z: Previous value remains unchanged.
Byte
V: Previous value remains unchanged.
C: Stores the result of the operation.
Description
This instruction ANDs a specified bit in the destination operand with the carry bit and stores the
result in the carry bit. The bit number is specified by 3-bit immediate data. The destination
operand contents remain unchanged.
Specified by #xx:3
Bit No.
<EAd>
70
C
∧
C
Available Registers
Rd:R0L to R7L, R0H to R7H
ERd: ER0 to ER7
Operand Format and Number of States Required for Execution
Note: * The addressing mode is the addressing mode of the destination operand <EAd>.
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
IMM
rd2
IMM
IMM
Notes
See the corresponding LSI hardware manual for details on the access range for @aa : 8.
51
No. of
States
06
06
Page 60
2.2.7 Bcc
Bcc (Branch conditionally)Conditional Branch
Operation
If condition is true, then
PC + disp → PC
else next;
Assembly-Language Format
Bcc disp
→ Condition field
Operand Size
Condition Code
IUIHUNZVC
————————
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Z: Previous value remains unchanged.
V: Previous value remains unchanged.
C: Previous value remains unchanged.
—
Description
If the condition specified in the condition field (cc) is true, a displacement is added to the program
counter (PC) and execution branches to the resulting address. The PC value used in the address
calculation is the starting address of the instruction immediately following the Bcc instruction.
The displacement is a signed 8-bit or 16-bit value. The branch destination address can be located
in the range from –126 to +128 bytes or –32766 to +32768 bytes from the Bcc instruction.
MnemonicMeaningccConditionSigned/Unsigned*
BRA (BT)Always (true)0000True
BRn (BF)Never (false)0001False
BHIHIgh0010C∨Z = 0X > Y (unsigned)
BLSLow or Same0011C∨Z = 1X ≤ Y (unsigned)
BCC (BHS)Carry Clear (High or Same)0100C = 0X ≥ Y (unsigned)
BCS (BLO)Carry Set (LOw)0101C = 1X < Y (unsigned)
BNENot Equal0110Z = 0X ≠ Y (unsigned or signed)
BEQEQual0111Z = 1X > Y (unsigned or signed)
BVCoVerflow Clear1000V = 0
BVSoVerflow Set1001V = 1
BPLPLus1010N = 0
BMIMinus1011N = 1
BGEGreater or Equal1100N⊕V = 0X ≥ Y (signed)
BLTLess Than1101N⊕V = 1X < Y (signed)
BGTGreater Than1110Z∨(N⊕V) = 0X > Y (signed)
BLELess or Equal1111Z∨(N⊕V) = 1X ≤ Y (signed)
Note: * If the immediately preceding instruction is a CMP instruction, X is the destination operand
and Y is the source operand.
52
Page 61
Bcc (Branch conditionally)Conditional Branch
Operand Format and Number of States Required for Execution
2.In machine language BRA, BRN, BCC, and BCS are identical to BT, BF, BHS, and BLO,
respectively. The number of execution states for BRn (BF) is the same as for two NOP
instructions.
53
Page 62
2.2.8 BCLR
BCLR (Bit CLeaR)Bit Clear
Operation
0 → (<bit No.> of <EAd>)
Assembly-Language Format
BCLR #xx:3, <EAd>
BCLR Rn, <EAd>
Operand Size
Condition Code
IUIHUNZVC
————————
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Z: Previous value remains unchanged.
V: Previous value remains unchanged.
Byte
C: Previous value remains unchanged.
Description
This instruction clears a specified bit in the destination operand to 0. The bit number can be
specified by 3-bit immediate data, or by the lower three bits of a general register (Rn). The
specified bit is not tested. The condition-code flags are not altered.
Specified by #xx:3 or Rn
Bit No.
<EAd>
70
0
Available Registers
Rd:R0L to R7L, R0H to R7H
Rn:R0L to R7L, R0H to R7H
ERd: ER0 to ER7
54
Page 63
BCLR (Bit CLeaR)Bit Clear
Operand Format and Number of States Required for Execution
Note: * The addressing mode is the addressing mode of the destination operand <EAd>.
Notes
For the @aa:8 access range, refer to the relevant microcontroller hardware manual.
55
Page 64
2.2.9 BIAND
BIAND (Bit Invert AND)Bit Logical AND
Operation
C ∧ [¬ (<bit No.> of <EAd>)] → C
Assembly-Language Format
BIAND #xx:3, <EAd>
Operand Size
Condition Code
IUIHUNZVC
——————— ↕
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Z: Previous value remains unchanged.
Byte
V: Previous value remains unchanged.
C: Stores the result of the operation.
Description
This instruction ANDs the inverse of a specified bit in the destination operand with the carry bit
and stores the result in the carry bit. The bit number is specified by 3-bit immediate data. The
destination operand contents remain unchanged.
Specified by #xx:3
Bit No.
<EAd>
70
Invert
C
∧
C
Available Registers
Rd:R0L to R7L, R0H to R7H
ERd: ER0 to ER7
Operand Format and Number of States Required for Execution
Note: * The addressing mode is the addressing mode of the destination operand <EAd>.
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
No. of
States
Notes
For the @aa:8 access range, refer to the relevant microcontroller hardware manual.
56
Page 65
2.2.10 BILD
BILD (Bit Invert LoaD)Bit Load
Operation
¬ (<bit No.> of <EAd>) →C
Assembly-Language Format
BILD #xx:3, <EAd>
Operand Size
Condition Code
IUIHUNZVC
——————— ↕
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Z: Previous value remains unchanged.
Byte
V: Previous value remains unchanged.
C: Loaded with the inverse of the specified bit.
Description
This instruction loads the inverse of a specified bit from the destination operand into the carry bit.
The bit number is specified by 3-bit immediate data. The destination operand contents remain
unchanged.
Specified by #xx:3
Bit No.
<EAd>
70
Invert
C
Available Registers
Rd:R0L to R7L, R0H to R7H
ERd: ER0 to ER7
Operand Format and Number of States Required for Execution
Note: * The addressing mode is the addressing mode of the destination operand <EAd>.
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
No. of
States
Notes
For the @aa:8 access range, refer to the relevant microcontroller hardware manual.
57
Page 66
2.2.11 BIOR
BIOR (Bit Invert inclusive OR)Bit Logical OR
Operation
C ∨ [¬ (<bit No.> of <EAd>)] →C
Assembly-Language Format
BIOR #xx:3, <EAd>
Operand Size
Condition Code
IUIHUNZVC
——————— ↕
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Z: Previous value remains unchanged.
Byte
V: Previous value remains unchanged.
C: Stores the result of the operation.
Description
This instruction ORs the inverse of a specified bit in the destination operand with the carry bit and
stores the result in the carry bit. The bit number is specified by 3-bit immediate data. The
destination operand contents remain unchanged.
Specified by #xx:3
Bit No.
<EAd>
70
Invert
C
∨
C
Available Registers
Rd:R0L to R7L, R0H to R7H
ERd: ER0 to ER7
Operand Format and Number of States Required for Execution
Note: * The addressing mode is the addressing mode of the destination operand <EAd>.
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
No. of
States
Notes
For the @aa:8 access range, refer to the relevant microcontroller hardware manual.
58
Page 67
2.2.12 BIST
BIST (Bit Invert STore)Bit Store
Operation
¬C→(<bit No.> of <EAd>)
Assembly-Language Format
BIST #xx:3, <EAd>
Operand Size
Condition Code
IUIHUNZVC
————————
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Z: Previous value remains unchanged.
Byte
V: Previous value remains unchanged.
C: Previous value remains unchanged.
Description
This instruction stores the inverse of the carry bit in a specified bit location in the destination
operand. The bit number is specified by 3-bit immediate data. Other bits in the destination
operand remain unchanged.
Specified by #xx:3
Bit No.
<EAd>
70
C
Invert
Available Registers
Rd:R0L to R7L, R0H to R7H
ERd: ER0 to ER7
Operand Format and Number of States Required for Execution
Note: * The addressing mode is the addressing mode of the destination operand <EAd>.
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
No. of
States
Notes
For the @aa:8 access range, refer to the relevant microcontroller hardware manual.
59
Page 68
2.2.13 BIXOR
BIXOR (Bit Invert eXclusive OR)Bit Exclusive Logical OR
Operation
C ⊕ [¬ (<bit No.> of <EAd>)] →C
Assembly-Language Format
BIXOR #xx:3, <EAd>
Operand Size
Condition Code
IUIHUNZVC
——————— ↕
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Z: Previous value remains unchanged.
Byte
V: Previous value remains unchanged.
C: Stores the result of the operation.
Description
This instruction exclusively ORs the inverse of a specified bit in the destination operand with the
carry bit and stores the result in the carry bit. The bit number is specified by 3-bit immediate data.
The destination operand contents remain unchanged.
Specified by #xx:3
Bit No.
<EAd>
Invert
C
⊕
07
C
Available Registers
Rd:R0L to R7L, R0H to R7H
ERd: ER0 to ER7
Operand Format and Number of States Required for Execution
Note: * The addressing mode is the addressing mode of the destination operand <EAd>.
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
No. of
States
Notes
For the @aa:8 access range, refer to the relevant microcontroller hardware manual.
60
Page 69
2.2.14 BLD
BLD (Bit LoaD)Bit Load
Operation
(<Bit No.> of <EAd>) → C
Assembly-Language Format
BLD #xx:3, <EAd>
Operand Size
Condition Code
IUIHUNZVC
——————— ↕
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Z: Previous value remains unchanged.
Byte
V: Previous value remains unchanged.
C: Loaded from the specified bit.
Description
This instruction loads a specified bit from the destination operand into the carry bit. The bit
number is specified by 3-bit immediate data. The destination operand contents remain unchanged.
Specified by #xx:3
07Bit No.
<EAd>
C
Available Registers
Rd:R0L to R7L, R0H to R7H
ERd: ER0 to ER7
Operand Format and Number of States Required for Execution
Note: * The addressing mode is the addressing mode of the destination operand <EAd>.
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
No. of
States
Notes
For the @aa:8 access range, refer to the relevant microcontroller hardware manual.
61
Page 70
2.2.15 BNOT
BNOT (Bit NOT)Bit NOT
Operation
¬ (<bit No.> of <EAd>)→ (<bit No.> of
<EAd>)
Condition Code
IUIHUNZVC
————————
Assembly-Language Format
BNOT #xx:3, <EAd>
BNOT Rn, <EAd>
Operand Size
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Z: Previous value remains unchanged.
V: Previous value remains unchanged.
C: Previous value remains unchanged.
Byte
Description
This instruction inverts a specified bit in the destination operand. The bit number is specified by
3-bit immediate data or by the lower 3 bits of a general register. The specified bit is not tested.
The condition code remains unchanged.
Specified by #xx:3 or Rn
70Bit No.
<EAd>
Invert
Available Registers
Rd:R0L to R7L, R0H to R7H
Rn:R0L to R7L, R0H to R7H
ERd: ER0 to ER7
62
Page 71
BNOT (Bit NOT)Bit NOT
Operand Format and Number of States Required for Execution
Note: * The addressing mode is the addressing mode of the destination operand <EAd>.
Notes
For the @aa:8 access range, refer to the relevant microcontroller hardware manual.
63
Page 72
2.2.16 BOR
BOR (bit inclusive OR)Bit Logical OR
Operation
C ∨ [(<bit No.> of <EAd>)] → C
Assembly-Language Format
BOR #xx:3, <EAd>
Operand Size
Condition Code
IUIHUNZVC
——————— ↕
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Z: Previous value remains unchanged.
Byte
V: Previous value remains unchanged.
C: Stores the result of the operation.
Description
This instruction ORs a specified bit in the destination operand with the carry bit and stores the
result in the carry bit. The bit number is specified by 3-bit immediate data. The destination
operand contents remain unchanged.
Specified by #xx:3
Bit No.
<EAd>
70
CC
∨
Available Registers
Rd:R0L to R7L, R0H to R7H
ERd: ER0 to ER7
Operand Format and Number of States Required for Execution
Note: * The addressing mode is the addressing mode of the destination operand <EAd>.
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
No. of
States
Notes
For the @aa:8 access range, refer to the relevant microcontroller hardware manual.
64
Page 73
2.2.17 BSET
BSET (Bit SET)Bit Set
Operation
1 → (<bit No.> of <EAd>)
Assembly-Language Format
BSET #xx:3, <EAd>
BSET Rn, <EAd>
Operand Size
Condition Code
IUIHUNZVC
————————
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Z: Previous value remains unchanged.
V: Previous value remains unchanged.
Byte
C: Previous value remains unchanged.
Description
This instruction sets a specified bit in the destination operand to 1. The bit number can be
specified by 3-bit immediate data, or by the lower three bits of a general register. The specified bit
is not tested. The condition code flags are not altered.
Specified by #xx:3 or Rn
70Bit No.
<EAd>
1
Available Registers
Rd:R0L to R7L, R0H to R7H
Rn:R0L to R7L, R0H to R7H
ERd: ER0 to ER7
65
Page 74
BSET (Bit SET)Bit Set
Operand Format and Number of States Required for Execution
Note: * The addressing mode is the addressing mode of the destination operand <EAd>.
Notes
For the @aa:8 access range, refer to the relevant microcontroller hardware manual.
<EAd> is byte data in a register or on memory.
No. of
66
Page 75
2.2.18 BSR
BSR (Branch to SubRoutine)Branch to Subroutine
Operation
PC → @–SP
PC + disp → PC
Condition Code
IUIHUNZVC
————————
Assembly-Language Format
BSR disp
Operand Size
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Z: Previous value remains unchanged.
V: Previous value remains unchanged.
—
C: Previous value remains unchanged.
Description
This instruction branches to a subroutine at a specified address. It pushes the program counter
(PC) value onto the stack as a restart address, then adds a specified displacement to the PC value
and branches to the resulting address. The PC value pushed onto the stack is the address of the
instruction following the BSR instruction. The displacement is a signed 8-bit or 16-bit value, so
the possible branching range is –126 to +128 bytes or –32766 to +32768 bytes from the address of
the BSR instruction.
Operand Format and Number of States Required for Execution
Addressing
Mode
Program-counter
relative
Mnemonic Operands
BSR
d:855disp68
d:165C00disp810
1st byte 2nd byte 3rd byte 4th byte Normal Advanced
Instruction FormatNo. of States
Notes
The stack structure differs between normal mode and advanced mode. In normal mode only the
lower 16 bits of the program counter are pushed on the stack.
Reserved
PC
2316 158 70
Normal mode
PC
2316 158 70
Advanced mode
The branch address must be even.
67
Page 76
2.2.19 BST
BST (Bit STore)Bit Store
Operation
C → (<bit No.> of <EAd>)
Assembly-Language Format
BST #xx:3, <EAd>
Operand Size
Condition Code
IUIHUNZVC
————————
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Z: Previous value remains unchanged.
Byte
V: Previous value remains unchanged.
C: Previous value remains unchanged.
Description
This instruction stores the carry bit in a specified bit location in the destination operand. The bit
number is specified by 3-bit immediate data. Other bits in the destination operand remain
unchanged.
Specified by #xx:3
Bit No.
<EAd>
70
C
Available Registers
Rd:R0L to R7L, R0H to R7H
ERd: ER0 to ER7
Operand Format and Number of States Required for Execution
Note: * The addressing mode is the addressing mode of the destination operand <EAd>.
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
No. of
States
Notes
For the @aa:8 access range, refer to the relevant microcontroller hardware manual.
68
Page 77
2.2.20 BTST
BTST (Bit TeST)Bit Test
Operation
¬ (<Bit No.> of <EAd>) →Z
Assembly-Language Format
Condition Code
IUIHUNZVC
————— ↕ ——
BTST #xx:3, <EAd>
BTST Rn, <EAd>
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Operand Size
Byte
Z: Set to 1 if the specified bit is zero;
otherwise cleared to 0.
V: Previous value remains unchanged.
C: Previous value remains unchanged.
Description
This instruction tests a specified bit in the destination operand and sets or clears the Z flag
according to the result. The bit number can be specified by 3-bit immediate data, or by the lower
three bits of a general register. The destination operand remains unchanged.
Specified by #xx:3 or Rn
70Bit No.
<EAd>
Test
Available Registers
Rd:R0L to R7L, R0H to R7H
Rn:R0L to R7L, R0H to R7H
ERd: ER0 to ER7
69
Page 78
BTST (Bit TeST)Bit Test
Operand Format and Number of States Required for Execution
Note: * The addressing mode is the addressing mode of the destination operand <EAd>.
Notes
For the @aa:8 access range, refer to the relevant microcontroller hardware manual.
No. of
70
Page 79
2.2.21 BXOR
BXOR (Bit eXclusive OR)Bit Exclusive Logical OR
Operation
C ⊕ (<bit No.> of <EAd>) → C
Assembly-Language Format
BXOR #xx:3, <EAd>
Operand Size
Condition Code
IUIHUNZVC
——————— ↕
H: Previous value remains unchanged.
N: Previous value remains unchanged.
Z: Previous value remains unchanged.
Byte
V: Previous value remains unchanged.
C: Stores the result of the operation.
Description
This instruction exclusively ORs a specified bit in the destination operand with the carry bit and
stores the result in the carry bit. The bit number is specified by 3-bit immediate data. The
destination operand contents remain unchanged.
Specified by #xx:3
Bit No.
<EAd>
70
CC
⊕
Available Registers
Rd:R0L to R7L, R0H to R7H
ERd: ER0 to ER7
Operand Format and Number of States Required for Execution
Note: * The addressing mode is the addressing mode of the destination operand <EAd>.
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
No. of
States
Notes
For the @aa:8 access range, refer to the relevant microcontroller hardware manual.
71
Page 80
2.2.22 (1) CMP (B)
CMP (CoMPare)Compare
Operation
Rd – (EAs), set or clear CCR
Assembly-Language Format
CMP.B <EAs>, Rd
Operand Size
Condition Code
IUIHUNZVC
—— ↕ — ↕↕↕↕
H: Set to 1 if there is a borrow at bit 3;
otherwise cleared to 0.
N: Set to 1 if the result is negative; otherwise
Byte
cleared to 0.
Z: Set to 1 if the result is zero; otherwise
cleared to 0.
V: Set to 1 if an overflow occurs; otherwise
cleared to 0.
C: Set to 1 if there is a borrow at bit 7;
otherwise cleared to 0.
Description
This instruction subtracts the source operand from the contents of an 8-bit register Rd (destination
register) and sets or clears the CCR bits according to the result. The destination register contents
remain unchanged.
Available Registers
Rd:R0L to R7L, R0H to R7H
Rs:R0L to R7L, R0H to R7H
Operand Format and Number of States Required for Execution
otherwise cleared to 0.
N: Set to 1 if the result is negative; otherwise
Word
cleared to 0.
Z: Set to 1 if the result is zero; otherwise
cleared to 0.
V: Set to 1 if an overflow occurs; otherwise
cleared to 0.
C: Set to 1 if there is a borrow at bit 15;
otherwise cleared to 0.
Description
This instruction subtracts the source operand from the contents of a 16-bit register Rd (destination
register) and sets or clears the CCR bits according to the result. The contents of the 16-bit register
Rd remain unchanged.
Available Registers
Rd:R0 to R7, E0 to E7
Rs:R0 to R7, E0 to E7
Operand Format and Number of States Required for Execution
I:Previous value remains unchanged.
H: Set to 1 if there is a borrow at bit 27;
otherwise cleared to 0.
Longword
N: Set to 1 if the result is negative; otherwise
cleared to 0.
Z: Set to 1 if the result is zero; otherwise
cleared to 0.
V: Set to 1 if an overflow occurs; otherwise
cleared to 0.
C: Set to 1 if there is a borrow at bit 31;
otherwise cleared to 0.
Description
This instruction subtracts the source operand from the contents of a 32-bit register ERd
(destination register) and sets or clears the CCR bits according to the result. The contents of the
32-bit register ERd remain unchanged.
Available Registers
ERd: ER0 to ER7
ERs: ER0 to ER7
Operand Format and Number of States Required for Execution
Addressing
Mode
ImmediateCMP.L#xx:32, ERd7A20 erdIMM6
Register directCMP.LERs, ERd1F 1 ers 0 erd2
Mnemonic Operands
1st byte2nd byte3rd byte4th byte5th byte6th byte
Instruction Format
Notes
74
No. of
States
Page 83
2.2.23 DAA
DAA (Decimal Adjust Add)Decimal Adjust
Operation
Rd (decimal adjust) → Rd
Assembly-Language Format
Condition Code
IUIHUNZVC
——*—↕↕*↕
DAA Rd
H: Undetermined (no guaranteed value).
Operand Size
Byte
N: Set to 1 if the adjusted result is negative;
otherwise cleared to 0.
Z: Set to 1 if the adjusted result is zero;
otherwise cleared to 0.
V: Undetermined (no guaranteed value).
C: Set to 1 if there is a carry at bit 7;
otherwise left unchanged.
Description
Given that the result of an addition operation performed by an ADD.B or ADDX instruction on
4-bit BCD data is contained in an 8-bit register Rd (destination register) and the carry and halfcarry flags, the DAA instruction adjusts the general register contents by adding H'00, H'06, H'60,
or H'66 according to the table below.
C FlagUpper 4 BitsH Flag Lower 4 BitsC Flag
beforebeforebeforebeforeafter
00 to 900 to 9000
00 to 80A to F060
00 to 910 to 3060
0A to F00 to 9601
09 to F0A to F661
0A to F10 to 3661
11 to 20 0 to 9601
11 to 20A to F661
11 to 310 to 3661
75
Value Added
(hexadecimal)
Page 84
DAA (Decimal Adjust Add)Decimal Adjust
Available Registers
Rd: R0L to R7L, R0H to R7H
Operand Format and Number of States Required for Execution
Addressing
Mode
Register directDAARd0F0rd2
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
Notes
Valid results (8-bit register Rd contents and C, V, Z, N, and H flags) are not assured if this
instruction is executed under conditions other than those described above.
No. of
States
76
Page 85
2.2.24 DAS
DAS (Decimal Adjust Subtract)Decimal Adjust
Operation
Rd (decimal adjust) → Rd
Assembly-Language Format
DAS Rd
Operand Size
Condition Code
IUIHUNZVC
——*—↕↕*—
H: Undetermined (no guaranteed value).
N: Set to 1 if the adjusted result is negative;
otherwise cleared to 0.
Byte
Z: Set to 1 if the adjusted result is zero;
otherwise cleared to 0.
V: Undetermined (no guaranteed value).
C: Previous value remains unchanged.
Description
Given that the result of a subtraction operation performed by a SUB.B, SUBX.B, or NEG.B
instruction on 4-bit BCD data is contained in an 8-bit register Rd (destination register) and the
carry and half-carry flags, the DAS instruction adjusts the general register contents by adding
H'00, H'FA, H'A0, or H'9A according to the table below.
C FlagUpper 4 BitsH Flag Lower 4 BitsC Flag
beforebeforebeforebeforeafter
00 to 900 to 9000
00 to 816 to FFA0
17 to F00 to 9A01
16 to F16 to F9A1
Value Added
(hexadecimal)
Available Registers
Rd: R0L to R7L, R0H to R7H
77
Page 86
DAS (Decimal Adjust Subtract)Decimal Adjust
Operand Format and Number of States Required for Execution
Addressing
Mode
Register directDASRd1F0rd2
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
Notes
Valid results (8-bit register Rd contents and C, V, Z, N, and H flags) are not assured if this
instruction is executed under conditions other than those described above.
No. of
States
78
Page 87
2.2.25 (1) DEC (B)
DEC (DECrement)Decrement
Operation
Rd – 1 → Rd
Assembly-Language Format
DEC.B Rd
Operand Size
Condition Code
IUIHUNZVC
———— ↕↕↕—
H: Previous value remains unchanged.
N: Set to 1 if the result is negative; otherwise
cleared to 0.
Byte
Z: Set to 1 if the result is zero; otherwise
cleared to 0.
V: Set to 1 if an overflow occurs (the
previous value in Rd was H'80);
otherwise cleared to 0.
C: Previous value remains unchanged.
Description
This instruction decrements an 8-bit register Rd (destination register) and stores the result in the
8-bit register Rd.
Available Registers
Rd: R0L to R7L, R0H to R7H
Operand Format and Number of States Required for Execution
Addressing
Mode
Register directDEC.BRd1A0rd2
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
Notes
An overflow is caused by the operation H'80 – 1 → H'7F.
79
No. of
States
Page 88
2.2.25 (2) DEC (W)
DEC (DECrement)Decrement
Operation
Rd – 1 → Rd
Rd – 2 → Rd
Condition Code
IUIHUNZVC
———— ↕↕↕—
Assembly-Language Format
DEC.W #1, Rd
DEC.W #2, Rd
H: Previous value remains unchanged.
N: Set to 1 if the result is negative; otherwise
cleared to 0.
Operand Size
Word
Z: Set to 1 if the result is zero; otherwise
cleared to 0.
V: Set to 1 if an overflow occurs (the
previous value in Rd was H'8000);
otherwise cleared to 0.
C: Previous value remains unchanged.
Description
This instruction subtracts the immediate value 1 or 2 from the contents of a 16-bit register Rd
(destination register) and stores the result in the 16-bit register Rd.
Available Registers
Rd: R0 to R7, E0 to E7
Operand Format and Number of States Required for Execution
An overflow is caused by the operations H'8000 – 1 → H'7FFF, H'8000 – 2 → H'7FFE, and
H'8001 – 2 → H'7FFF.
80
No. of
States
Page 89
2.2.25 (3) DEC (L)
DEC (DECrement)Decrement
Operation
ERd – 1 → ERd
ERd – 2 → ERd
Condition Code
IUIHUNZVC
———— ↕↕↕—
Assembly-Language Format
DEC.L #1, ERd
DEC.L #2, ERd
H: Previous value remains unchanged.
N: Set to 1 if the result is negative; otherwise
cleared to 0.
Operand Size
Longword
Z: Set to 1 if the result is zero; otherwise
cleared to 0.
V: Set to 1 if an overflow occurs; otherwise
cleared to 0.
C: Previous value remains unchanged.
Description
This instruction subtracts the immediate value 1 or 2 from the contents of a 32-bit register ERd
(destination register) and stores the result in the 32-bit register ERd.
Available Registers
ERd: ER0 to ER7
Operand Format and Number of States Required for Execution
An overflow is caused by the operations H'80000000 – 1 → H'7FFFFFFF, H'80000000 – 2 →
H'7FFFFFFE, and H'80000001 – 2 → H'7FFFFFFF.
81
Page 90
2.2.26 (1) DIVXS (B)
DIVXS (DIVide eXtend as Signed)Divide Signed
Operation
Rd ÷ Rs → Rd
Assembly-Language Format
DIVXS.B Rs, Rd
Operand Size
Condition Code
IUIHUNZVC
———— ↕↕——
H: Previous value remains unchanged.
N: Set to 1 if the quotient is negative;
otherwise cleared to 0.
Byte
Z: Set to 1 if the divisor is zero; otherwise
cleared to 0.
V: Previous value remains unchanged.
C: Previous value remains unchanged.
Description
This instruction divides the contents of a 16-bit register Rd (destination register) by the contents
of an 8-bit register Rs (source register) and stores the result in the 16-bit register Rd. The division
is signed. The operation performed is 16 bits ÷ 8 bits →8-bit quotient and 8-bit remainder. The
quotient is placed in the lower 8 bits of Rd. The remainder is placed in the upper 8 bits of Rd.
RdRsRd
Dividend÷Divisor→Remainder Quotient
16 bits8 bits8 bits8 bits
Valid results are not assured if division by zero is attempted or an overflow occurs. For
information on avoiding overflow, see DIVXS Instruction, Zero Divide, and Overflow.
Available Registers
Rd: R0 to R7, E0 to E7
Rs: R0L to R7L, R0H to R7H
82
Page 91
DIVXS (B)
DIVXS (DIVide eXtend as Signed)Divide Signed
Operand Format and Number of States Required for Execution
Addressing
Mode
Register directDIVXS.BRs, Rd01D051rsrd16
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
No. of
States
Notes
The N flag is set to 1 if the dividend and divisor have different signs, and cleared to 0 if they have
the same sign. The N flag may therefore be set to 1 when the quotient is zero.
83
Page 92
2.2.26 (2) DIVXS (W)
DIVXS (DIVide eXtend as Signed)Divide Signed
Operation
ERd ÷ Rs →ERd
Assembly-Language Format
DIVXS.W Rs, ERd
Operand Size
Condition Code
IUIHUNZVC
———— ↕↕——
H: Previous value remains unchanged.
N: Set to 1 if the quotient is negative;
otherwise cleared to 0.
Word
Z: Set to 1 if the divisor is zero; otherwise
cleared to 0.
V: Previous value remains unchanged.
C: Previous value remains unchanged.
Description
This instruction divides the contents of a 32-bit register ERd (destination register) by the contents
of a 16-bit register Rs (source register) and stores the result in the 32-bit register ERd. The
division is signed. The operation performed is 32 bits ÷ 16 bits →16-bit quotient and 16-bit
remainder. The quotient is placed in the lower 16 bits (Rd) of the 32-bit register ERd. The
remainder is placed in the upper 16 bits (Ed).
ERdRsERd
Dividend÷Divisor→Remainder Quotient
32 bits16 bits16 bits16 bits
Valid results are not assured if division by zero is attempted or an overflow occurs. For
information on avoiding overflow, see DIVXS Instruction, Zero Divide, and Overflow.
Available Registers
ERd: ER0 to ER7
Rs:R0 to R7, E0 to E7
84
Page 93
DIVXS (W)
DIVXS (DIVide eXtend as Signed)Divide Signed
Operand Format and Number of States Required for Execution
Addressing
Mode
Register directDIVXS.WRs, ERd01D053rs0 erd24
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
No. of
States
Notes
The N flag is set to 1 if the dividend and divisor have different signs, and cleared to 0 if they have
the same sign. The N flag may therefore be set to 1 when the quotient is zero.
85
Page 94
2.2.26 (3) DIVXS
DIVXS (DIVide eXtend as Signed)Divide Signed
DIVXS instruction, Division by Zero, and Overflow
Since the DIVXS instruction does not detect division by zero or overflow, applications should
detect and handle division by zero and overflow using techniques similar to those used in the
following program.
1. Programming solution for DIVXS.B R0L, R1
Example 1: Convert dividend and divisor to non-negative numbers, then use DIVXU
programming solution for zero divide and overflow
MOV.BR0L, R0L; Test divisor
BEQZERODIV; Branch to ZERODIV if R0L = 0
ANDC#AF, CCR; Clear CCR user bits (bits 6 and 4) to 0
BPLL1; Branch to L1 if N flag = 0 (positive divisor)
NEG.BR0L; Take 2’s complement of R0L to make sign positive
ORC#10, CCR; Set CCR bit 4 to 1
L1: MOV.WR1.R1; Test dividend
BPLL2; Branch to L2 if N flag = 0 (positive dividend)
NEG.WR1; Take 2’s complement of R1 to make sign positive
XORC#50, CCR; Invert CCR bits 6 and 4
L2: MOV.BR1H, R2L;
EXTU.WR2;
DIVXU.BR0L, R2;Use DIVXU.B instruction to divide non-negative dividend
MOV.BR2H, R1H;by positive divisor
DIVXU.BR0L, R1;16 bits ÷ 8 bits → quotient (16 bits) and remainder (8 bits)
MOV.BR2L, R2H;(See DIVXU Instruction, Zero Divide, and Overflow)
MOV.BR1L, R2L;
STCCCR, R1L; Copy CCR contents to R1L
BTST#6, R1L; Test CCR bit 6
BEQL3; Branch to L3 if bit 6 = 1
NEG.BR1H; Take 2’s complement of R1H to make sign of remainder negative
L3: BTST#4, R1L; Test CCR bit 4
BEQL4; Branch to L4 if bit 4 = 1
NEG.WR2; Take 2’s complement of R2 to make sign of quotient negative
L4: RTS
ZERODIV:
; Zero-divide handling routine
This program leaves a 16-bit quotient in R2 and an 8-bit remainder in R1H.
R1
R1H
R2
R0L
Dividend
Remainder
Quotient
Divisor
86
Page 95
DIVXS
DIVXS (DIVide eXtend as Signed)Divide Signed
Example 2: Sign extend the 8-bit divisor to 16 bits, sign extend the 16-bit dividend to 32 bits, and
This program leaves the 16-bit quotient in R1 and the 8-bit remainder in E1 (in a 16-bit sign
extended format).
ER1
ER1
R1
ROL
R0L
Dividend
Sign extension
DividendSign extension
QuotientRemainder
Divisor
Divisor
87
Page 96
DIVXS
DIVXS (DIVide eXtend as Signed)Divide Signed
2. Programming solution for DIVXS.W R0, ER1
Example: Convert dividend and divisor to non-negative numbers, then use DIVXU programming
solution for zero divide and overflow
MOV.WR0, R0; Test divisor
BEQZERODIV; Branch to ZERODIV if R0 = 0
ANDC#AF, CCR; Clear CCR user bits (bits 6 and 4) to 0
BPLL1; Branch to L1 if N flag = 0 (positive divisor)
NEG.WR0; Take 2’s complement of R0 to make sign positive
ORC#10, CCR; Set CCR bit 4 to 1
L1: MOV.LER1,ER1; Test dividend
BPLL2; Branch to L2 if N flag = 0 (positive dividend)
NEG.LER1; Take 2’s complement of ER1 to make sign positive
XORC#50,CCR; Invert CCR bits 6 and 4
L2: MOV.WE1, R2;
EXTU.LER2;
DIVXU.WR0, E2;Use DIVXU.W instruction to divide non-negative dividend
MOV.WE2, R1;by positive divisor
DIVXU.WR0, ER1;32 bits ÷ 16 bits → quotient (32 bits) and remainder
MOV.WR2, E2(16 bits)
MOV.WR1, R2(See DIVXU Instruction, Zero Divide, and Overflow)
STCCCR, R1L; Copy CCR contents to R1L
BTST#6, R1L; Test CCR bit 6
BEQL3; Branch to L3 if bit 6 = 1
NEG.WE1; Take 2’s complement of E1 to make sign of remainder negative
L3: BTST#4, R1L; Test CCR bit 4
BEQL4; Branch to L4 if bit 4 = 1
NEG.LER2; Take 2’s complement of ER2 to make sign of quotient negative
L4: RTS
ZERODIV:
; Zero-divide handling routine
This program leaves a 32-bit quotient in ER2 and a 16-bit remainder in E1.
ER1
E1
ER2
R0
Dividend
Remainder
Quotient
Divisor
88
Page 97
DIVXS (W)
DIVXS (DIVide eXtend as Signed)Divide Signed
The preceding two examples flag the status of the divisor and dividend in the UI and U bits in the
CCR, and modify the sign of the quotient and remainder in the unsigned division result of the
DIVXU instruction as shown next.
00PositivePositivePositivePositiveNo sign modification
01NegativePositivePositiveNegativeSign of quotient is reversed
10NegativeNegativeNegativePositiveSign of remainder is reversed
11PositiveNegativeNegativeNegativeSigns of quotient and remainder
are both reversed
89
Page 98
2.2.27 (1) DIVXU (B)
DIVXU (DIVide eXtend as Unsigned)Divide
Operation
Rd ÷ Rs → Rd
Assembly-Language Format
Condition Code
IUIHUNZVC
———— ↕↕——
DIVXU.B Rs, Rd
H: Previous value remains unchanged.
Operand Size
Byte
N: Set to 1 if the divisor is negative;
otherwise cleared to 0.
Z: Set to 1 if the divisor is zero; otherwise
cleared to 0.
V: Previous value remains unchanged.
C: Previous value remains unchanged.
Description
This instruction divides the contents of a 16-bit register Rd (destination register) by the contents
of an 8-bit register Rs (source register) and stores the result in the 16-bit register Rd. The division
is unsigned. The operation performed is 16 bits ÷ 8 bits →8-bit quotient and 8-bit remainder. The
quotient is placed in the lower 8 bits of Rd. The remainder is placed in the upper 8 bits of Rd.
RdRsRd
Dividend÷Divisor→Remainder Quotient
16 bits8 bits8 bits8 bits
Valid results are not assured if division by zero is attempted or an overflow occurs. For
information on avoiding overflow, see DIVXU Instruction, Zero Divide, and Overflow.
Available Registers
Rd:R0 to R7, E0 to E7
Rs:R0L to R7L, R0H to R7H
Operand Format and Number of States Required for Execution
Addressing
Mode
Register directDIVXU.BRs, Rd51rsrd14
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
Notes
90
No. of
States
Page 99
2.2.27 (2) DIVXU (W)
DIVXU (DIVide eXtend as Unsigned)Divide
Operation
ERd ÷ Rs → ERd
Assembly-Language Format
DIVXU.W Rs, ERd
Operand Size
Condition Code
IUIHUNZVC
———— ↕↕——
H: Previous value remains unchanged.
N: Set to 1 if the divisor is negative;
otherwise cleared to 0.
Word
Z: Set to 1 if the divisor is zero; otherwise
cleared to 0.
V: Previous value remains unchanged.
C: Previous value remains unchanged.
Description
This instruction divides the contents of a 32-bit register ERd (destination register) by the contents
of a 16-bit register Rs (source register) and stores the result in the 32-bit register ERd. The
division is unsigned. The operation performed is 32 bits ÷ 16 bits →16-bit quotient and 16-bit
remainder. The quotient is placed in the lower 16 bits (Rd) of the 32-bit register ERd. The
remainder is placed in the upper 8 bits of (Ed).
ERdRsERd
Dividend÷Divisor→Remainder Quotient
32 bits16 bits16 bits16 bits
Valid results are not assured if division by zero is attempted or an overflow occurs. For
information on avoiding overflow, see DIVXU Instruction, Zero Divide, and Overflow.
Available Registers
ERd: ER0 to ER7
Rs:R0 to R7, E0 to E7
Operand Format and Number of States Required for Execution
Addressing
Mode
Register directDIVXU.WRs, ERd53rs0 ERd22
Mnemonic Operands
1st byte2nd byte3rd byte4th byte
Instruction Format
No. of
States
Notes
91
Page 100
DIVXU
DIVXU (DIVide eXtend as Unsigned)Divide
DIVXU Instruction, Zero Divide, and Overflow
Zero divide and overflow are not detected in the DIVXU instruction. A program like the following
can detect zero divisors and avoid overflow.
1. Programming solutions for DIVXU.B R0L, R1
Example 1: Divide upper 8 bits and lower 8 bits of 16-bit dividend separately and obtain 16-bit
quotient
CMP.B#0, R0L; R0L = 0? (Zero divisor?)
BEQZERODIV; Branch to ZERODIV if R0L = 0
MOV.BR1H,R2L;Copy upper 8 bits of dividend to R2L and
EXTU.WR2 (*1).;zero-extend to 16 bits
DIVXU.BR0L, R2 (*2); Divide upper 8 bits of dividend
MOV.BR2H, R1H (*3); R2H → R1H (store partial remainder in R1H)
DIVXU.BR0L, R1 (*4); Divide lower 8 bits of dividend (including repeated division of
MOV.BR2L, R2H; Store upper part of quotient in R2H
upper 8 bits)
MOV.BR1L, R2L (*5); Store lower part of quotient in R2L
RTS
ZERODIV:; Zero-divide handling routine
The resulting operation is 16 bits ÷ 8 bits →quotient (16 bits) and remainder (8 bits), and no
overflow occurs. The 16-bit quotient is stored in R2, the 8-bit remainder in R1H.
R0L
R1
R2
Sign extensionDividend (high)
R2
Remainder (part) Quotient (high)
R1
Remainder (part) Dividend (low)
R1
R1
R2
RemainderQuotient (low)
Remainder
Dividend
Quotient (low)
Quotient
Divisor
( 1)*
( 2)*
( 3)*
( 4)*
( 5)*
92
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.