M68HC11
REFERENCE MANUAL
CENTRAL PROCESSING UNIT
MOTOROLA
6-5
The N bit reflects the state of the most significant bit (MSB) of a result. For two’s com-
plement, a number is negative when the MSB is set and positive when the MSB is ze-
ro. The N bit has uses other than in two’s-complement operations. By assigning an
often tested flag bit to the MSB of a register or memory location, the user can test this
bit by loading an accumulator.
The Z bit is set when all bits of the result are zeros. Compare instructions do an internal
implied subtraction, and the condition codes, including Z, reflect the results of that sub-
traction. A few operations (INX, DEX, INY, and DEY) affect the Z bit and no other con-
dition flags. For these operations, the user can only determine = and
≠
.
The V bit is used to indicate if a two’s-complement overflow has occurred as a result
of the operation.
The C bit is normally used to indicate if a carry from an addition or a borrow has oc-
curred as a result of a subtraction. The C bit also acts as an error flag for multiply and
divide operations. Shift and rotate instructions operate with and through the carry bit
to facilitate multiple-word shift operations.
In the M68HC11 CPU, condition codes are automatically updated by almost all instruc-
tions; thus, it is rare to execute any extra instructions to specifically update the condi-
tion codes. For example, the load accumulator A (LDAA) and store accumulator A
(STAA) instructions automatically set or clear the N, Z, and V condition code flags. (In
some other architectures, very few instructions affect the condition code bits; thus, it
takes two instructions to load and test a variable.) The challenge in a Motorola proces-
sor lies in finding instructions that specifically do not alter the condition codes in rare
cases where that is desirable. The most important instructions that do not alter condi-
tions codes are the pushes, pulls, add B to X (ABX), add B to Y (ABY), and 16-bit trans-
fers and exchanges. It is always a good idea to refer to an instruction set summary
such as the pocket guide (MC68HC11A8RG/AD) to check which condition codes are
affected by a particular instruction.
The STOP disable (S) bit is used to allow or disallow the STOP instruction. Some us-
ers consider the STOP instruction dangerous because it causes the oscillator to stop;
however, the user can set the S bit in the CCR to disallow the STOP instruction. If the
STOP instruction is encountered by the CPU while the S bit is set, it will be treated like
a no-operation (NOP) instruction, and processing continues to the next instruction.
The interrupt request (IRQ) mask (I bit) is a global mask that disables all maskable in-
terrupt sources. While the I bit is set, interrupts can become pending and are remem-
bered, but CPU operation continues uninterrupted until the I bit is cleared. After any
reset, the I bit is set by default and can only be cleared by a software instruction. When
any interrupt occurs, the I bit is automatically set after the registers are stacked but be-
fore the interrupt vector is fetched. After the interrupt has been serviced, an RTI in-
struction is normally executed, restoring the registers to the values that were present
before the interrupt occurred. Normally, the I bit would be zero after an RTI was exe-
cuted. Although interrupts can be re-enabled within an interrupt service routine, to do
so is unusual because nesting of interrupts becomes possible, which requires much
more programming care than single-level interrupts and seldom improves system per-