6809 Microcomputer Programming and Interfacing With Experiments (Andrew C. Staugaard JR.)
6809 Microcomputer Programming and Interfacing With Experiments (Andrew C. Staugaard JR.)
6809 Microcomputer Programming and Interfacing With Experiments (Andrew C. Staugaard JR.)
21798
6809
MICROCOMPUTER
PROGRAMMING
&
INTERFACING
WITH EXPERIMENTS
BY ANDREW C. STAUGAARD JR.
L
The Blacksburg Continuing Education™ Series
The Blacksburg Continuing Education Series™ of books provide a Laboratory-or experiment-
oriented approach to electronic topics. Present and forthcoming titles in this series include:
In most cases, these books provide both text material and experiments, which permit one to
demonstrate and explore the concepts that are covered in the book. These books remain among
the very few that provide step-by-step instructions concerning how to learn basic electronic con-
cepts, wire actual circuits, test microcomputer interfaces, and program computers based on popu-
lar microprocessor chips. We have found that the books are very useful to the electronic novice
who desires to join the "electronics revolution," with minimum time and effort.
Additional information about the "Blacksburg Group" is presented inside the rear cover.
by
Andrew C. Staugaard, Jr.
FIRST EDITION
FIRST PRINTING-1981
CHAPTER 1
FUNDAMENTAL 6809 CONCEPTS AND CHIP STRUCTURE 7
Introduction-Objectives-6809' Evolution and Design Philosophy-
6809 Improvements - 6809 Chip Structure - Review Questions-
Answers
CHAPTER 2
6809 ADDRESSING MODES . 23
Introduction-Objectives-Inherent, Immediate, and Extended Ad-
dressing-Direct Addressing and the Direct Page Register Relative
Addressing-Indexed Addressing-Post Byte-Indirect Addressing-
Register Addressing-Review Questions-Answers
CHAPTER 3
6809 REGISTERS AND DATA MOVEMENT INSTRUCTIONS 51
Introduction - Objectives - 6809 Internal Register Format - Data
Movement Instructions-Review Questions-Answers
CHAPTER 4
ARITHMETIC, LOGIC, AND TEST INSTRUCTIONS 73
Introduction-Objectives-Arithmetic Instructions-Logic Instructions
-Test Instructions-Review Questions-Answers
CHAPTER 5
BRANCH AND MISCELLANEOUS INSTRUCTIONS 93
Introduction - Objectives - Branch Instructions - Miscellaneous In-
structions-Review Questions-Answers
CHAPTER 6
6809/6809E INPUT AND OUTPUT SIGNALS 115
Introduction-Objectives-6809 Pin-Outs-6809E Pin-Outs-Review
Questions-Answers
CHAPTER 7
6809/6809E INTERFACING AND ApPLICATIONS 140
Introduction-Objectives-A Minimum 6809 System-An Expanded
6809 System-Multiprocessor Systems-Remote Data Acquisition-
The MEK6809D4 Microcomputer Evaluation System
APPENDIX A
6809/6809E INSTRUCTION SET . 163
Operation Notation-Register Notation-Definitions of Executable
Instructions
APPENDIX B
THE 6820/6821 PERIPHERAL INTERFACE ADAPTER (PIA) 192
6821 Functional Description-6820/6821 Pin Assignments-PIA In-
terfacing and Addressing-PIA Initialization and Servicing-Review
Questions-Answers
APPENDIX C
SPECIFICATION SHEETS. 211
MC6809/MC68A09/MC68B09-MC6809E/MC68A09E/MC68B09E
-MC6829 - MC6839 - MC6842 - MEK6809AC - MEK6809D4/
MEK68KPD
APPENDIX D
MC6809 INSTRUCTION SET SUMMARY. . 256
INDEX . 268
CHAPTER 1
Fundamental 6 809
Concepts and iC'hip Structure
INTRODUCTION
As you will discover in this and subsequent chapters, the 6809 is
one of the most powerful 8-bit processors to come on the market to
date. In conceiving the 6809 the Motorola design engineers wanted
to maintain compatibility with the popular 6800 at some level, yet
"soup up" the 6800 architecture and instruction set to approach the
performance of a 16-bit processor, such as the 68000 or Z-8000. From
user surveys Motorola concluded that many customers desired such
performance from an 8-bit, 40-pin device. It was found that many
users did not want to pay the price for conversion to a 16-bit device
with up to 64 pins if a high-performance 8-bit device were available.
Therefore, the 6809 was designed to approach 16-bit performance at
minimum cost to the user.
In this chapter we begin by discussing the 6809 evolution and
design philosophy. You will see that the 6809 has been designed
primarily for the systems market, where high-level language imple-
mentation is common. Throughout the discussion, comparisons will
be made between the 6809, 6800, and other competitive processors.
In addition, as an introduction to subsequent chapters, this chapter
will summarize the 6809's architecture, software, and hardware. It
is important that you understand what improvements have been
made in the 6809 over the 6800 since this will enable you to better
understand the material to follow.
OBJECTIVES
At the end of this chapter you will be able to do the following:
7
• Explain the evolution of the 6800 family.
• Understand the design philosophy that created the 6809.
• State the differences between the 6809, 68A09, 68B09, and
6809E.
• List the additional registers present in the 6809 that do not exist
in the 6800.
• Describe the two additional condition code Rags available in the
6809.
• Define indirect addressing.
• Compare 6809 branching to 6800 branching.
• Explain what is meant by "memory paging" and how this is
accomplished with the 6809.
• Describe the fundamental hardware differences between the
6809 and 6800.
• Explain the difference between a standard interrupt request and
a fast interrupt request.
8
were also prime design considerations. These terms have the follow-
ing meanings:
• program position independence-that quality of a program to
execute properly when placed anywhere within the memory
address map. Thus the program is independent of its position
within the memory map.
• program re-entrancy-that quality of a program which allows a
subroutine to be shared by several tasks concurrently, without
destroying the return addresses by nesting routines.
\Vith position independence, programs can be loaded from a mass
storage disc and located anywhere within R/vV memory without
requiring the use of a relocating loader routine. In addition, position
independence will allow ROM programs to be written for general
distribution. The user can assign any arbitrary set of addresses to
the RO~1 since the program execution is "independent" of its posi-
tion within the memory map. This wiII eliminate the necessity for
full ROJ'.1 address decoding and will also allow the user to locate
the ROM such that it will not interfere with other software. As you
will see shortly, the advanced 6809 architecture also facilitates the
use of modular programming. Such programming will allow the sys-
tem software designer to divide a project up into modular programs
which can be designed and tested independently before being in-
corporated into the final system design. This same architecture al-
lows programs to be structured and interrupted in any part of the
address map and still execute properly on return, thus satisfying the
program re-entrancy design goaL In addition, high-level block-
structured languages, such as Pascal, BASIC, FORTRAN, and
COBOL, can be compiled into more efficient and faster-running
machine code than was possible \vith earlier processors.
The 6800 family evolution scheme is shown in Fig. 1-1. Note the
position of the 6809. As far as central processing unit (CPU) per-
formance is concerned the 6809 is the most advanced processor in
the :Motorola 8-bit family. However, the 6809, by itself, is a micro-
processor and not a microcomputer. It requires external Rl'iV mem-
ory and ROM to function as a microcomputer. Therefore a minimum
6809 system would consist of three chips. Recall from our discussion
in the Preface that microprocessor/microcomputer applications take
two directions: small, dedicated applications and systems applica-
tions. In the 8-bit Motorola family the 6809 satisfies the needs of the
latter, while the 6801, 6802, 6803, and 6805 were designed for the
dedicated applications. These four devices all contain various
amounts of R/W memory, ROM, and parallel/serial i/o capabilities.
They are therefore more advanced as far as chip integration is con-
cerned since some or all of these capabilities are integrated into the
9
1-CHIP MIN SYS -
en
w
U
z 2-CHIP
« MIN SYS-
>
c
«
z
o
i=
«
a:
C)
w
I-
Z
5-CHIP t
MUCH MORE
MIN SYS-
CAPABLE
1.0-J.l.s
STANDARD t t t INST
PERFORMANCE 2.0-J.l.s 1.3-J.l.s 1.0-J.l.s
INST INST INST
PERFORMANCE ADVANCES
same chip, along with the CPU. For example, the 6801 contains an
enhanced 6800 CPU, R/W memory, ROM, timer, parallel interfacing
ports, and a serial port, all on one 40-pin chip. Hence, we say that
the 6801 is a "single-chip" microcomputer. o The 6809, however, is a
far more advanced processor, approaching 16-bit performance.
As you will see in Chapter 6, the standard 6809 does contain an
on-chip clock/ oscillator and therefore only requires an external crys-
tal to provide the clock signal. The standard 6809 operates at 1 MHz.
However, it is also available in 1.5-MHz and 2.0-MHz versions: the
68A09 and 68B09, respectively. In addition, there is an off-chip clock
version of the 6809 available, the 6809E.
Now let's compare the performance of the 6809 to the 6800 and
some other well-known processors. Compared to the 6800, the 6809
boasts the following performance:
• 72 percent decrease in the number of instructions required for a
program compared to similar 6800 programs.
• 58 percent decrease in the required program memory compared
to 6800 programs.
• 167 percent increase in 6809 processor throughput compared to
6800 throughput.
10
Motorola claims that these statistics allow the user to achieve 2.5 to
5 times the performance from a 6809 system compared with a similar
6800-based system. Of course, the exact amount of increased per-
formance depends on how efficiently the increased capabilities of the
6809 are utilized and on the specific application.
Comparisons of the 6809 to the 6800 and other processors are
summarized in Fig. 1-2 and in Tables 1-1 through 1-3. Note, espe-
cially from Fig. 1-2, that the 6809 approaches 16-bit performance.
The comparison values in these tables and Fig. 1-2 were supplied
by Motorola and thus tend to illustrate the better aspects of the 6809
over the other processors.
6809 IMPROVEMENTS
The increased performance of the 6809 over other 8-bit processors
is made possible by specific improvements in architecture, software,
and hardware. Each of the following improvements over the 6800
is discussed in detail in subsequent chapters; however, we will sum-
marize them here.
Architectural Improvements
Compared with the 6800 architecture the 6809 adds an 8-bit regis-
ter and three 16-bit registers as shown in Fig. 1-3. The additional
8-bit register is the direct page register, which will allow you to use
the direct addressing mode anywhere within the 6809 memory map.
(Recall that direct addressing is limited to the first 256 bytes of
memory with the 6800.) The three additional 16-bit registers include
a 16-bit accumulator, index register, and stack pointer. The addi-
tional accumulator is referred to as accumulator D and is simply the
concatenation of the two 8-bit accumulators, A and B. The additional
index register is called the Y index register (Y) and the additional
stack pointer is referred to as the user stack pointer (U). The two
index registers, X and Y, will also function as pointers and the two
stack pointers (S and U) can be used for indexing.
In addition, you will note from Fig. 1-3 that all 8 bits of the con-
dition code register (CC) are being used in the 6809. Recall that
only the first 6 bits are utilized in the 6800. The functions of the first
6 CC bits (C, V, Z, N, I, H) in the 6809 are identical with those of
the 6800. The two additional bits (F and E) are used in conjunction
with the 6809's interrupts. The use of these two additional bits will
be discussed in detail in subsequent chapters.
These architectural improvements along with the 6809's powerful
addressing modes speed processor throughput, since less data move-
ment is required between the internal registers and memory, and
11
..
N
Table 1·1. Relative Processor Execution·Time Comparisons for Eight Software Operations
Double Vector Vector
Shift Addition Addition Average
I/O Character Computed Right 16·Blt 8·Blt 16 x 16·Blt Move Block Execution
Handler Search GoTo 5 Bits Elements Elements Multiplication (64 Bytes) Time
6809 2.0 MHz 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.5 MHz 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.3
1.0 MHz 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0
Z-80 4.0 MHz 1.4 0.8 2.1 2.7 1.6 1.8 3.3 1.0 1.8
2.5 MHz 2.2 1.2 3.4 4.4 2.6 2.9 5.2 1.6 2.9
9900 3.0 MHz 2.6 2.3 2.8 1.5 1.7 3.0 0.5 1.6 2.0
6800 2.0 MHz 0.9 1.4 1.9 1.3 3.1 2.8 5.0 3.3 2.4
1.5 MHz 1.2 1.9 2.5 1.7 4.1 3.7 6.7 4.3 3.3
1.0 MHz 1.8 2.8 3.7 2.5 6.1 5.5 10 6.5 4.9
8080 3.0 MHz 1.9 1.8 2.8 6.1 2.3 2.7 9.6 2.4 3.7
8085 2.0 MHz 2.8 2.6 4.2 9.1 3.4 4.1 14.3 3.7 5.5
Table 1-2. Actual Processor Execution-Time Comparisons for Eight Software Operations
Double Vector Vector
Shift Addition Addition
I/O Character Computed Right 16-Bit 8·Bit 16 x 16-Blt Move Block
Handler Search Go To 5 Bits Elements Elements Multiplication (64 Bytes)
6809 2.0 MHz 28 287.5 34.5 15 325 180 82 344.5
1.5 MHz 37.3 383 46 20 433 240 109.3 459.3
1.0 MHz 56 575 69 30 650 360 164 689
Z·80 4.0 MHz 38.3 220.5 73.3 41 518 323 267 342
2.5 MHz 61.3 352.8 117.2 65.6 828.8 516.8 427.2 547.6
9900 3.0 MHz 72 661 98 22 537 537 42 537
6800 2.0 MHz 24.5 404 64.5 19 993.5 498.5 409.5 1123.5
1.5 MHz 32.7 539 86 25.3 1325 665 546 1498
1.0 MHz 49 808 129 38 1987 997 819 2247
8080 3.0 MHz 52.7 506.7 96.7 91.3 732 492 784 841
8085 2.0 MHz 79 760 145 137 1098 738 1176 1262
...w
Table 1·3. Summarized Processor Performance Comparisons
Performance Criteria MC6809 Z·80A MC6800 8085
Number of Instructions 1.0* 1.56 1.72 2.30
Number of Bytes 1.0 1.31 1.58 1.80
Number of Microseconds 1.0 1.80 2.40 2.20
(2 MHz) (4 MHz) (2 MHz) (5 MHz)
'Normalized to 1.00 for the MC6809 - poorer performance has higher numbers.
they also aid software development since many of the internal regis-
ters can be made to perform different functions at different times.
Software Improvements
Improvements in the 6809's architecture have allowed the Moto-
rola designers to make many significant software improvements over
3
2.7 Z·80A (4 MHz; 8 BITS)
2.45 9900 (3 MHz; 16 BITS) 8085 (5 MHz; 8 BITS)
14
B O a - B I T ACCUMULATOR A AND 8-BIT
~ _ _-':"':'-_ _--L______ ACCUMULATOR B OR 16-BIT
'-.,;..... 0 DOUBLE ACCUMULATOR D
FHINZVC
the 6800. In fact, the 6809 has been termed «the programmer's dream
machine." Prior to firm definition of the 6809 instruction set Motorola
conducted a survey of 6800 users to determine: (1) if a 16-bit archi-
tecture was more desirable than an 8-bit architecture and (2) should
6809 compatibility with the 6800 occur at the object code level or
source code level? The survey results indicated that most of the
6800 users felt that an 8-bit architecture was adequate for their future
applications. They did not want to pay the price for a new 16-bit
device if an 8-bit device could be designed to perform common 16-
bit operations, such as load, store, add, subtract, compare, and multi-
ply. As you will discover in Chapter 3, the inclusion of the 16-bit
accumulator and associated instructions will allow such 16-bit opera-
tions to be performed internally. In answer to the second survey
question, almost all of the responses indicated that source code com-
patibility would be adequate, mainly because they did not foresee
using 6800 ROMs in future 6809 systems. Source code compatibility
meant that users could take full advantage of their familiarity with
the 6800 mnemonic code for assembly language programming and
it also allowed the 6809 designers to completely remap or reassign
the 6800 op codes to produce more efficient and faster running 6809
programs. Also, source code compatibility would allow any 6800
programs to be processed through a 6809 assembler to produce 6809
code. Therefore, you will see a familiar mnemonic code in Chapters
3,4, and 5; however, most of the corresponding op codes are differ-
ent from those of the 6800.
15
As mentioned earlier, the 6809 adds many new and powerful ad-
dressing modes. For example, the indexed mode of addressing can
use the four 16-bit indexible registers (X, Y, U, and S) to point to
the address of an operand or to the address of the address of an
operand. The latter is referred to as iruIirect addressing. These regis-
ters can also be incremented and decremented automatically or
under program control. The 6809 can even use the program counter
to access operands or operand addresses. Furthermore, with the use
of the direct page register, you can access any part of the 6809 mem-
ory map using direct addressing. You can also branch to any part of
the program using relative addressing. Recall that with the 6800, you
were limited to a plus 127 10 and minus 128 10 branch range within the
program, since the relative address offset is only 1 byte. However,
the 6809 allows for a 2-byte relative address offset and thus permits
branching anywhere within the 64K memory map (long branch).
This allows position-independent programs to be written for the
6809. We will discuss the idea of position independence in more
detail when discussing relative addressing.
Other software features of the 6809 include:
Hardware Improvements
Besides the architectural and software improvements of the 6809
over the 6800, many hardware improvements were also made. Most
of these improvements involve the 6809's interrupts, control signals,
and associated control lines. We will summarize these new hardware
features here; however, a complete discussion of the 6809 pin-outs
and associated chip operation is provided in Chapter 6.
Like the 6800, the 6809 is a 40-pin device available in both a plas-
tic (P-suffix) and ceramic (L-suffix) package. A bus and control
signal diagram for the 6809 is shown in Fig. 1-4. The most obvious
change to the chip hardware is the inclusion of an on-chip clock/
oscillator for the standard 6809 package. (Recall that the 6809E is
an off-chip clock version of the 6809.) The 6809 on-chip clock re-
16
+5V GND
BUS AVAILABLE
DATA BUS
BUS STATUS
FIRO
16 ADDRESS BUS
NON-MASKABLE INT
MC6809
RESET
DMA REO
MEMORY READY
XTAL out
EXTAL E
°out 1
CONTROL
BUS
IRO READ/WRITE
17
The new bus status (BS) line is used in conjunction with the bus
available (BA) line to indicate bus status and provide an interrupt
acknowledge. The quadrature clock (Q) is a clock signal which
leads the enable clock signal (E) by one-quarter cycle (90°). En-
able (E) is the same as the 6800's ep2 clock signal. Valid addresses
are available from the 6809 on the leading edge of Q, with data
being latched on the trailing edge of E. These two external clock
signals provide four effective system timing edges for interfacing
purposes. The memory ready line (MRDY) is for interfacing with
slow memories. This input control signal. effectively stretches the E
pulse to extend data-access time. Finally, the direct memory access
request line (DMA REQ) is an input control line which provides a
method for suspending processor execution and freeing the external
buses for other purposes, such as direct memory access by a periphe-
ral device or dynamic memory refresh.
A bus and control signal diagram for the 6809E is shown in Fig.
1-5. Since the 6809E does not require an external crystal connection,
two additional control signals are added. They are: Busy, and Last
Instruction Cycle (LIC). Since these two control signals are avail-
DMA/BREO
Rm
HALT
BA
BS
XTAL
EXTAL
MRDY
E
Q
18
+5V GND
BUS AVAILABLE
DATA BUS
HALT
BUS STATUS
16 ADDRESS BUS
NON-MASKABLE INT
MC6809E
TSC VMA
L1C
CONTROL
BUS
BUSY
READ/WRITE
19
6809 CHIP STRUCTURE
The 6809 chip structure is shown in Fig. 1-6 in summary to the
discussion just completed. You should now have a basic understand-
ing of each functional region and the associated control features of
the 6809 and 6809E. In addition, you should now be aware of the
architectural, software, and hardware improvements of the 6809 and
6809E over the 6800. In the chapters that follow we will discuss each
of these new features in detail, beginning with the 6809's addressing
modes and its instruction set.
REVIEW QUESTIONS
1. Compatibility between the 6800 and 6809 instruction set exists at what
level?
2. How many basic instructions are contained in the 6809 instruction set?
5. Two prime design considerations for the 6809 are: ~_~_ and _
9. List the additional registers present in the 6809 architecture which do not
exist in the 6800.
10. The two new condition code Hags and their bit positions in the CC
n. Which of the internal 6809 registers are indexible and can therefore be
used with the index mode of addressing?
12. When an instruction points to an address of the address of an operand,
20
this is called ____ addressing.
13. What is the branching range of the 6809 and how does this compare to
the 6800?
14. What is the difference in the direct addressing mode for the 6809 versus
the 6800?
16. With the 6809's fast interrupt request (FIRQ) only the ,_ _~~_ and
19. The 6809 replaces the 6800 three-state control line (TSC) with >-- _
20. The two extra control lines available on the 6809E which are not available
ANSWERS
1. Source code (mnemonic)
2.59
3. 19
4. Systems
5. Position-independent code and 6800 compatibility
6. 6809
7. 6801
8. The 6809E is an off-chip clock version of the 6809.
9. Accumulator D (D)
Direct page register (DP)
Y index register (Y)
User stack pointer (U)
10. F (bit 6)
E (bit 7)
11. All the index registers and stack pointers (X, Y, 5, and U)
12. Indirect
13. The 6809 can branch anywhere within the 64K memory map using long
relative addressing where the 6800 is limited to a plus 12710 and minus 12&0
byte branching range.
21
14. With the direct addressing mode the 6809 can access any part of the 64K
memory map using the direct page register ( DP), where the 6800 is
limited to the first 256 bytes of memory (page 0).
15. 0.8 MHz
16. Program counter (PC) and condition code (CC)
17. One-quarter cycle (90 0
)
18. The 6809 address is FFFF 16 during any clock signal when it is not using
the bus structure.
19. Direct memory access request (DMA REQ)
20. Busy and last instruction cycle (LIC)
22
CHAPTER 2
INTRODUCTION
You are about to see what makes the 6809 a super microprocessor.
As was mentioned earlier, it is not the mere number of instructions
in an instruction set that makes one processor more powerful than
another but a more important consideration: how many different
ways the processor can utilize the fundamental instructions available
to it. Instructions can access and operate on data in different ways
by using different addressing modes. The 6809 has 59 instructions
which utilize ten fundamental addressing modes, bringing the total
number of unique operations to 1464. The ten fundamental address-
ing modes available to the 6809 are: inherent (implied), immediate,
direct, extended, branch relative, indexed, extended indirect, pro-
gram counter relative, indexed indirect, and register.
In addition, variations of these ten fundamental modes actually
bring the total number of unique addressing modes to 19. For exam-
ple, one of the most powerful addressing modes, indexed addressing,
has five options: zero offset, constant offset (5-,8-, or 16-bit), accu-
mulator offset (A, B, or D) and auto-increment or auto-decrement
(by 1 or 2). All of these options can access data indirectly using in-
dexed indirect addressing. Indirect addressing means to address a
memory location that contains the address of the operand rather than
the operand itself. Thus, the instruction accesses the address of the
operand, which in turn accesses the operand. Indirect operations are
also available with the extended and program counter relative ad-
dressing modes.
As with the 6800, relative addressing is used with branch opera-
tions. With the 6809, however, relative addressing can also be used
23
to access and operate on memory data. It is also available in two
versions: short relative (8-bit oHset) and long relative (16-bit oH-
set). Thus 6809 programs can be written with complete position
independence.
Finally, register addressing will allow you to transfer to, or ex-
change, data between any two like-size registers within the 6809's
architecture.
You might be wondering how an 8-bit machine can perform so
many unique operations and, given an instruction, how do you
specify which addressing mode is to be used? The answer is found
in a post byte. A post byte is used with indexed, indexed indirect,
extended indirect, program counter relative, and register addressing.
The post byte follows the instruction op code in the instruction state-
ment. It is used to specify the addressing mode and which internal
register is to be used in the operation. With register addressing it is
used to specify which two like-size registers are to be used in the
transfer or exchange of data.
It is very important that you understand how to use the post byte
and, for that matter, all the concepts presented in this chapter such
that you can take full advantage of all of the 6809's capabilities.
Once a full understanding of the addressing modes is achieved, you
will be ready to apply these modes to the 6809 instruction set pre-
sented in Chapters 3, 4, and 5.
OBJECTIVES
At the end of this chapter you will be able to do the following:
24
INHERENT, IMMEDIATE, AND EXTENDED ADDRESSING
Inherent Addressing
I nherent addressing, also referred to as implied addressing, is the
simplest type of addressing since it only involves I-byte instructions.
Instructions involving the accumulators, such as increment, decre-
ment, clear, shift (left or right), complement, etc., fall into this cate-
gory. This type of addressing is also sometimes referred to as accu-
mulator addressing when the instruction involves an operation on
one of the accumulators. The format for inherent addressing is the
same as that for the 6800 and most of the same instructions are in-
volved.
25
map, and therefore the address is 2 bytes in length: a HI address
byte followed by a LO address byte. The instruction op code will be
1 or 2 bytes, depending on the particular instruction involved. There-
fore 6809 instructions using extended addressing will be a total of
3 or 4 bytes in length. The instruction format for extended address-
ing is shown in Fig. 2-1B. Another form of extended addressing, ex-
tended indirect, will be discussed later in this chapter.
1. LOA $ 2. LOA $$
C7 00
C7
LOA $
C7
26
would be used. If, however, the DPR contained 01, the same instruc-
tion would access address 01C7. This eliminates the need to use ex-
tended addressing when you are accessing addresses above OOFF.
Some terminology is useful here. When the DPR contains 00, we
say it is accessing page zero; when the DPR contains 01, it is access-
ing page 1, and so on, up to page 255 (FF). Note that the DPR can
be used to access 256 pages (including page zero). Each page con-
tains 256 address bytes. In other words, the DPR can be used to
"page" through the entire 6809 address map, since 256 pages with
256 address bytes per page equals 64K address bytes, or the total
6809 map. A common application of the DPR is in high-level lan-
guages where global variables are accessed frequently. A global
variable is a variable whose value is accessible throughout an entire
program, in contrast to a local variable, whose value is accessible
only in the program block (or subroutine) in which it is defined. In
a subroutine the DPR can be used to "point" to a page containing
the global variables, with the stack containing local variables. No
problems arise as long as the language compiler keeps track of the
DPR value. The DPR can also be used for multitasking operations.
Multitasking is when several separate but interrelated tasks operate
within a single program. In this application each task will be allo-
cated a different page by the main program and accessed via the
DPR. When writing programs you must be very careful in using the
DPR since it is very easy to lose track of its value. But, when the
DPR is used properly, you can generate very efficient, byte-saving
programs.
After the 6809 is reset, the DPR contains all zeros (page zero) and
the 6809 direct addressing mode will perform just as it would in the
6800. As you will see in Chapter 3 the DPR contents can then be
easily modified to point to any page within the 6809's memory map.
RELATIVE ADDRESSING
There are two types of relative addressing available to the 6809.
They are branch relative and program counter relative. By using
these relative addressing modes you will be able to write complete
position-independent programs for the 6809. A discussion of branch
relative addressing will be provided first since it is very similar to
the branching operation used in the 6800. Then a complete discus-
sion of program counter relative addressing will be provided.
27
branch the offset is added to the program counter's contents to form
the branch destination address.
Example 2-1: Determining Forward Branch Destinations
Given a branch instruction located at address 002B with a relative
address offset of 6F, determine the branch destination.
Since the branch instruction is 2 bytes (op code followed by the
relative address offset), the program counter contains 002B+2 =
002D. The destination equals the program counter contents plus the
offset, or 002D+006F = 009C.
28
Table 2-1.6809 Short-Branch Calculator Table
MSH·B F E 0 C B A 9 8
LSH·B LSH·F
16 32 48 64 80 96 112 0
F 1 17 33 49 65 81 97 113 1
E 2 18 34 50 66 82 98 114 2
0 3 19 35 51 67 83 99 115 3
C 4 20 36 52 68 84 100 116 4
B 5 21 37 53 69 85 101 117 5
A 6 22 38 54 70 86 102 118 6
9 7 23 39 55 71 87 103 119 7
8 8 24 40 56 72 88 104 120 8
7 9 25 41 57 73 89 105 121 9
6 10 26 42 58 74 90 106 122 A
5 11 27 43 59 75 91 107 123 B
4 12 28 44 60 76 92 108 124 C
3 13 29 45 61 77 93 109 125 0
2 14 30 46 62 78 94 110 126 E
1 15 31 47 63 79 95 111 127 F
0 16 32 48 64 80 96 112
0 1 2 3 4 5 6 7 MSH·F
1. Count the number of bytes (in decimal) from the instruction following the branch to the branch target instruction.
2. Find this number inside the table.
3. Read this hexadecimal equivalent.
a. Top and left for branching backward.
b. Bottom and right for branching forward.
Examples: Back 15 10 bytes F116' Forward 77 10 bytes =4016' BacK 107 10 bytes =9516'
4. Key:
MSH·B = Most significant hex-backward
LSH-B = Least significant hex-backward
MSH-F = Most significant hex-forward
LSH·F = Least significant hex-forward
Courtesy Mr. Ray Boaz, 1516 Jarvis PI., San Jose, Calif. 95118
29
Example 2-3: Determining Long-Branch Destinations
Given a branch instruction located at address 5000 with a relative
address offset of 02FO, determine the branch destination.
Since the long branch instruction is 4 bytes (a 2-byte op code
followed by a 2-byte signed offset), the program counter contains
5000+4 = 5004. The destination equals the program counter's con-
tents plus the offset, or 5004+02FO = 52F4.
Now, suppose the offset were F2FO. Then, since the most signifi-
cant bit of the offset is a logic 1, the 6809 will branch backward. As
with short branches, to obtain the destination, add the twos comple-
ment offset to the program counter's contents. Therefore the destina-
tion address is 5004+F2FO = 42F4.
Program Counter Relative (PC Relative) Addressing
To allow complete position-independent programs to be written
without a lot of software overhead, the 6809 includes program
counter relative addressing. With this type of addressing the address
of an operand located in memory can be determined relative to the
program counter's contents. With PC relative addressing an 8- or
16-bit signed offset is added to the program counter's contents to
create the effective address of the operand, or the effective address
of the address of the operand. (The latter case is referred to as indi-
rect addressing, and will be discussed later.) Therefore data can be
accessed anywhere within the 6809's memory map, relative to the
program counter contents, thus allowing for complete position-inde-
pendent programs.
The instruction format required for program counter relative ad-
dressing is shown in Fig. 2-3. Note that the instruction can be 3 or 4
bytes in length, depending on the offset desired. Both 8- and 16-bit
offsets are allowed. In either case a post byte follows the instruction
op code. The offset byte( s) then follows the post byte. When this
type of addressing is used, the program counter is used as a pointer
register with an 8- or 16-bit offset; thus program counter relative
INSTRUCTION OP CODE
--------------------------
(1 OR 2 BYTES)
INSTRUCTION OP CODE
-------------------------- POST BYTE
(1 OR 2 BYTES)
± OFFSET
POST BYTE (HI BYTE)
OFFSET
± OFFSET
(LO BYTE)
30
addressing can be thought of as a type of indexed addressing. As you
will see in Chapter 3 any instructions which use indexed addressing
can also use program counter relative addressing. Since program
counter addressing is considered a type of indexed addressing, a
post byte is required to designate that the program counter register
is being used as the pointer register rather than one of the indexible
registers (X,Y,S,U). The use of the post byte will be discussed in
more detail in the next section, on indexed addressing.
The following examples illustrate program counter relative ad-
dressing.
Example 2-4: Using Program Counter Relative Addressing
With an 8-Bit Signed Offset
Consider the following instruction mnemonic sequence:
OOFF
0100 LOA (instruction op code)
0101 post byte
0102 10 (8-bit offset)
0103
OOFF
0100 LOB (instruction op code)
0101 post byte
0102 01 (offset HI byte)
31
0103 FF (offset LO byte)
0104
INDEXED ADDRESSING
You can probably recall that indexed addressing is the most
powerful form of addressing available to the 6800. It became ex-
tremely valuable when operating on data located in consecutive
memory locations. In the 6800 the indexed addressing instruction is
a 2-byte instruction consisting of the instruction command followed
by a signed indexed offset. To form the effective operand address the
6800 adds the offset to the contents of the 16-bit index register. Sev-
eral 6800 instructions are associated with the index register. Recall
also that you can increment, decrement, load, store and transfer the
index register contents to and from the stack pointer. A substantial
amount of programming power was gained by including the index
register within the 68oo's architecture.
Now, with the 6809, the indexed addressing mode has been en-
hanced by the inclusion of four 16-bit registers which may be used
as pointer registers in the indexed mode of addressing. As mentioned
in Chapter 1 these registers are the X, Y, S, and U registers (refer to
Fig. 1-3). With the 6809 there are four basic forms of indexed ad-
dressing that can be used with these registers. They are: zero-offset
indexed, constant-offset indexed, accumulator-offset indexed, and
auto-increment/ decrement indexed.
The instruction format for indexed addressing is shown in Fig. 2-4.
You see that the instruction op code is always followed by a post
byte, which in turn mayor may not be followed by an offset. The
post byte of an indexed instruction specifies the basic form of in-
INSTRUCTION OP CODE
~--------------------------
(1 OR 2 BYTES)
POST BYTE
I OFFSET I
r-------(10R-2BYTES)-------j
L J
32
dexed addressing to be used as well as the specific pointer register
that will be used in determining the effective operand address. In-
dexed addressing can be used with 31 of the 59 instructions of the
6809.
Now let us discuss each basic type of indexed addressing; then,
we will learn how to use the post byte. Examples of each indexed
mode are provided at the end of this chapter.
Zero-Offset Indexed Addressing
This type of indexed addressing allows the pointer register to
point directly to the effective operand address, since the offset is
zero. In other words, the specified pointer register contains the ad-
dress of the operand to be used in the operation. These instructions
will be 2 or 3 bytes: the instruction op-code byte ( s ) ~ followed by
the post byte. The post byte will specify the zero-offset mode and the
pointer register to be used. This mode of indexed addressing is the
fastest since a minimum number of bytes is required and no offset
calculation is required.
Constant-Offset Indexed Addressing
This form of indexed addressing is very similar to the 6800's in-
dexed addressing. However, any of the pointer registers (X, Y, U,
or S) can be used and the signed offset can be 5, 8, or 16 bits. The
post byte will follow the instruction op code and will specify the
pointer register and the offset size. When a 5-bit signed offset is used,
the offset is included as part of the post byte and therefore the 5-bit
offset is most efficient in the use of bytes and MPU cycles as com-
pared with the other constant-offset versions. Also, the offset is a
twos complement (signed) value with the most significant bit
(msb) of the offset used to determine its sign. If the most significant
bit is a logic 0, the offset will be positive, and if the most significant
bit is a logic 1, the offset will be negative. Therefore, the 5-bit offset
reduces to a ±4-bit offset with a corresponding offset range of from
-16 10 to + 15] o.
If an 8-bit offset is desired, the instruction will be 3 or 4 bytes in
length. Here the instruction op-code byte ( s ) ~ is followed by the post
byte, which in turn is followed by the 8-bit offset byte. The post byte
will specify constant-offset indexed addressing and the pointer reg-
ister to be used. The offset byte is then added to the pointer register
contents to determine the effective address. Again, the offset is a
twos complement (signed) value with the msb used to determine
the sign. Therefore the 8-bit offset reduces to a ±7-bit offset with a
corresponding range of from -128 10 to +127]0'
33
If a 16-bit offset is desired, the post byte will be followed· by 2
offset bytes. The most significant offset byte will be first, then the
least significant byte. To determine the effective address, the 16-bit
signed offset will be added to the pointer register specified by the
post byte. Since the offset is signed, it reduces to ±15 bits with a
corresponding range of from -32,76810 to +32,767 10 ,
34
POST BYTE
From the previous discussion it is obvious that the post byte plays
an important role in the indexed addressing mode. In addition, you
saw that a post byte was also required when using program counter
relative (PC relative) addressing. In summary, you should have dis-
covered from previous discussions that:
1. The post byte is used to specify one of the following modes of
addressing:
program counter relative
zero-offset indexed
constant-offset indexed
accumulator-offset indexed
auto-increment/ decrement indexed
2. The post byte specifies either the program counter, X, Y, S, or U
register to be used as the pointer register.
3. The post byte specifies the offset size to be used in program
counter relative and constant-offset indexed addressing.
4. The post byte specifies the accumulator (A, B, or D) to be used
during accumulator-offset indexed addressing.
5. When using a 5-bit signed constant-offset, the offset value is in-
cluded as part of the post byte.
How is all of this accomplished with 1 byte of information? The an-
swer is found in the post-byte format shown in Fig. 2-5. You see that
the post byte is divided into the following bit fields:
addressing mode field (bits 0-3)
indirect field (bit 4)
pointer register field (bits 5 and 6 )
5-bit offset field (bit 7)
Each of the above post-byte fields will now be discussed.
Addressing Mode Field (Bits 0-3)
This 4-bit field is used to select the type of addressing mode that
is to be used. The addressing modes and their respective bit pattern
POINTER ADDRESSING
REGISTER MODE SELECT
SELECT
5-81T INDIRECT
OFFSET SELECT
SELECT
Fig. 2-5. Indexed addressing post-byte format.
35
....
Table 2-2. Bit Pattern Definitions of Addressing Mode Fields
Post-Byte
Addressing Mode Field
Bit 3 Bit 2 Bit 1 Bit 0 Addressing Mode Symbol
0 0 0 0 Auto Increment (+1) R+
0 0 0 1 Auto Increment (+2) R++
0 0 1 0 Auto Decrement (-1) -R
0 0 1 1 Auto Decrement (-2) --R
0 1 0 0 Zero Offset R ±O
0 1 0 1 ACCB Offset R ±ACCB
0 1 1 0 ACCA Offset R ±ACCA
1 0 0 0 a·Bit Signed Offset R ±7 Bit
1 0 0 1 16-Bit Signed Offset R ±15 Bit
1 0 1 1 ACCD Offset R ±ACCD
1 1 0 0 PC Relative - a·Bit Signed PC ±7 Bit
1 1 0 1 PC Relative -16-Bit Signed PC ±15 Bit
1 1 1 1 Extended Indirect [n]
36
Table 2·3. Bit Pattern Definitions of Pointer Register Fields
Post·Byte
Pointer Register Field
Bit 6 Bit 5 Pointer Register
o 0 R =X
o 1 R=Y
1 0 R= U
1 1 R= S
post byte. Bit 4 becomes the sign bit, with bits 0 through 3 repre-
senting the offset weight.
All of the post-byte register bit assignments are summarized in
Table 2-4. Now, let us look at some examples of instructions which
use the post byte. Before you can write mnemonic code for these in-
structions, however, you need a code which can be used to represent
the various post-byte designations. Such a code is shown in Table
2-5. In this table, n denotes offset value, R the specified pointer reg-
ister, and PC the program counter. You will follow the instruction
mnemonic with the respective post-byte designation shown in Table
2-5. For example, LDA 23,X means to load accumulator A with the
contents of the memory location specified by adding the constant
offset 23 16 to pointer register X; LDX D, Y means to load index
register X with the contents of the memory location specified by
adding the contents of accumulator D to pointer register Y.
37
Table 2·4. Indexed Addressing Post·Byte Bit Assignments
Post-Byte Register Bit Indexed
Addressing
7 6 5 4 3 2 1 0 Mode
0 R R X X X X X EA = ,R ± 4 bit offset
1 R R 0 0 0 0 0 ,R+
1 R R I 0 0 0 1 ,R++
1 R R 0 0 0 1 0 ,-R
1 R R I 0 0 1 1 ,--R
1 R R I 0 1 0 0 EA = ,R ±O offset
1 R R I 0 1 0 1 EA = ,R ± ACCB offset
1 R R I 0 1 1 0 EA = ,R ± ACCA offset
1 R R I 1 0 0 0 EA = ,R ± 7·bit offset
1 R R I 1 0 0 1 EA = ,R ± 15-bit offset
1 R R I 1 0 1 1 EA = ,R ± D offset
1 X X I 1 1 0 0 EA = ,PC ± 7·bit offset
1 X X I 1 1 0 1 EA = ,PC ± 15·bit offset
1 R R 1 1 1 1 1 EA = ,Address
L
I
"
T r Addressing Mode Field
Indirect Field (I)
Sign Bit When B7 = 0
Register Field
OO:R = X
01:R = Y
10:R = U
11:R = S
X = Don't Care
38
J
Table 2·5. Post·Byte Assembler Code
Addressing Mode Assembler
Symbol Code
R ±O ,R
R ±4 Bit n,R
R ±7 Bit n,R
R ±15 Bit n,R
R ±ACCA A,R
R ±ACCB B,R
R ±ACCD D,R
PC ±7 Bit n,PCR
PC ±15 Bit n,PCR
R+ ,R+
R++ ,R++
-R ,-R
--R ,--R
register. After the operation has been executed, the Y index register
contents would be automatically incremented by 1.
39
proper assembler code to represent this operation and what post
byte would be required?
From Table 2-5, the proper assembler code would be: LDX D, X.
Since accumulator D offset is required, the addressing mode field of
the post byte must be 1011 (refer to Table 2-4). Also, since the X
register must be the specified pointer register, the pointer register
field must be 00. The indirect addressing field (bit 5) must be
cleared and the 5-bit constant offset field (bit 7) must be set. There-
fore the required post byte would be 10001011 2 or 8B 1G •
INDIRECT ADDRESSING
As mentioned in previous discussions the 6809 is capable of a very
powerful mode of addressing known as indirect addressing. With
indirect addressing the operand's address (effective address) is con-
tained at the location specified by the operation. Therefore you ob-
tain the operand "indirectly" via an intermediate address. For exam-
ple, suppose that an indirect addressing operation is to locate an
operand at address 02FO. The operation would first point to an inter-
mediate address, say 01FO, which would contain the actual address
of the operand, 02FO. Actually, address 01FO would contain 02 and
address OlFl would contain FO. This operation is summarized in
Fig. 2-6.
I
C::::::02FO Operand
40
Example 2-10: Indirect Addressing (Indexed)
The following program segment is given:
OOFF
0100 LOA [10,X]
0101 post byte
0102 10
020E FO
020F 95
0210 05
0211 00
0212 87
04FE C6
04FF E9
0500 AA
0501 F5
If, prior to executing the LDA instruction, the X index register con-
tains 0200, what will be loaded into accumulator A? The operand's
address will be found at the memory location formed by adding the
constant offset 0010 to the contents of the index register. Therefore
the memory location which contains the address of the operand is
0010 + 0200, or 0210. From the program listing you find 05 at this
address, which is the high byte of the operand's address. The low
byte is found in the next conseclitive memory location. Therefore the
operand's address is 0500. Thus the operand is located at address
0500. At this address you find the value AA, which will be loaded
into accumulator A.
\Vhat post byte would be required for this operation? Since an
8-bit signed offset is required, the addressing mode field of the post
byte must be 1000 (refer to Table 2-4). Since the pointer register is
the X index register, the pointer register field must be 00. The indi-
rect addressing field (bit 5) must be set to indicate indirect address-
ing and the 5-bit offset field (bit 7) must be set. Therefore the
proper post byte would be 100110002 or 98 16 • This value must appear
at address 0101 in the above program listing. The constant offset,
10](), follows the post byte at address 0102.
Example 2-11: Indirect Addressing (PC Relative)
Consider the following program segment:
41
0100 post byte
0101 OE
0102 next instruction
010F 70
0110 F1
0111 50
0112 AS
F14F AF
F150 C5
42
F151 50
F152 9C
Where will the contents of the X index register be stored? The as-
sembly language code for extended indirect addressing is [nl, where
n is the address of the address of the operand (or where the operand
is to be stored). Therefore the above instruction specifies extended
indirect addressing. Note that this instruction consists of 4 bytes: the
instruction op code followed by the post byte, which is in turn fol-
lowed by the address at which the effective address will be found.
Thus the high byte of the effective address is located at F150 and
the low byte is located at F1.51. Address F150 contains C5 and F151
contains 50. Therefore, the address where the X index register con-
tents will be stored is C550. Since the X index register is a 16-bit
register, the high byte will be stored at address C550 and the low
byte at address C551.
What post byte would be required for this operation? Since ex-
tended indirect addressing is required, the addressing mode field of
the post byte must be 1111. Neither of the pointer registers is used
to determine the effective address and the pointer register field must
be cleared (refer to Table 2-6). The indirect addressing field (bit 5)
must be set to indicate indirect addressing and the 5-bit offset field
(bit 7) must be set. Therefore, the proper post byte would be
1001111!:! or 9F 16. This value must appear at address 0501 in the
above program.
Obviously, many more possibilities exist than those provided in
these few examples. The reader is encouraged to work the problems
given in the review questions at the end of this chapter, and then to
make up examples such that a full understanding of the various ad-
dressing modes is obtained. Finally, Table 2-6 summarizes the vari-
ous indexed addressing modes, along with their respective assembly
language codes and post-byte formats.
REGISTER ADDRESSING
There is one more major mode of addressing available to the 6809
that should be discussed. Within the 6809, any user register may be
transferred to, or exchanged with, any other register of like size. In-
herent instructions are used to accomplish this task; however, a post
byte is required to define the registers involved. Therefore any in-
structions which involve the transfer or exchange of data between
internal registers will be referred to as register addressing instruc-
tions. As you will see in Chapter 3, these instructions will be 2 bytes
in length: the instruction op code followed by a post byte. The in-
43
t
Table 2-6. Indexed Addressing Modes Summary
Nonindirect Indirect
Assembler Post· Byte x + Assembler Post·Byte + +
Type Forms Form Op Code rv # Form Op Code rv #
Constant Offset From R No offset ,R 1RR00100 0 0 [,R] 1RR10100 3 0
(Signed Offsets) 5·Bit offset n, R ORRnnnnn 1 0 Defau Its to a·bit
a·Bit offset n, R 1RR01000 1 1 [n, R] 1RR11000 4 1
16·Bit offset n, R 1RR01001 4 2 [n, R] 1RR11001 7 2
Accumulator Offset From R A - Register offset A, R 1RR00110 1 0 [A, R] 1RR10110 4 0
(Signed Offsets) B - Register offset B, R 1RR00101 1 0 [B, R] 1RR10101 4 0
0- Register offset 0, R 1RR01011 4 0 [0, R] 1RR11011 7 0
Auto·1 ncrementlDecrement R Increment by 1 ,R+ 1RROOOOO 2 0 Not allowed
Increment by 2 jR++ 1RROOO01 3 0 [,R++] 1RR10001 6 0
Decrement by 1 ,-R 1RROO010 2 0 Not allowed
Decrement by 2 ,--R 1RROO011 3 0 [,--R] 1RR10011 6 0
Constant Offset From PC a·bit offset n, PCR 1XX01100 1 1 [n, PCR] 1XX11100 4 1
16·bit offset n, PCR 1XX01101 5 2 [n, PCR] 1XX11101 a 2
Extended Indirect 16·bit address - - - - [n] 10011111 5 2
R =x, Y, U orS x=oo Y=01
X = Don't care U = 10 s= 11
+ and + Indicate the number of additional cycles and bytes for the particular variation.
rv #
TRANSFER OR EXCHANGE
INSTRUCTION OP CODE
(A) Instruction format.
POST BYTE
INTERNAL
4·BIT FIELD REGISTER
0000 ACCD
0001 X
0010 Y
0011 U
(C) Bit field designations. 0100 S
0101 PC
1000 ACCA
1001 ACCB
1010 CCR
1011 DP
struction and post-byte formats are shown in Fig. 2-7. The post byte
is divided into two fields: the source register field and destination
register field. With the instructions provided in Chapter 3, data can
be moved from the source register to the destination register or ex-
changed between the source and destination registers. The bit-pat-
tern definitions for each internal register are also given in Fig. 2-7.
The only requirement is that both registers defined by the post byte
must be of like size; that is, 8-bit to 8-bit, or 16-bit to 16-bit.
REVIEW QUESTIONS
45
4. The DPR forms the ~_______ byte of the direct address and the
~ and · 0
10. List the registers available for use with indexed addressing.
______, and ,
13. The three constant offsets available with constant-offset indexed addressing
are: -) :, and _
14. Why is the 5-bit signed offset mode the most efficient constant-offset in-
dexed addressing mode?
46
-J
16. State an advantage of accumulator-oHset over constant-oHset indexed
addressing.
20. When a 5-bit signed oHset is not included in the post byte, the 5-bit offset
22. What post byte would be required to perform the operation in Question 21?
23. Given an indexed addressing post byte of 83I6, interpret its meaning and
determine the proper assembler code.
25. Which of the 6809 addressing modes can use indirect addressing?
47
26. The assembly language symbol used to represent indirect addressing is:
04FB LDA#
04FC 10
04FD LDU#
04FE FC
04FF 50
0500 LDX [A, U]
0501 post byte
06FE C7
06FF F5
0700 IB
0701 AA
FC5E D5
FC5F C7
FC60 06
FC61 FF
FC62 00
29. How many bytes are required for an instmction using extended indirect
addressing?
30. As you will discover in Chapter 3, the EXG instmction exchanges the
contents of two like-size registers. Which two registers would be exchanged
using the following instmction?
EXG
8B
48
ANSWERS
1. Implied or accumulator if the operation involves one of the accumulators
2. Register
3. With the 6800, direct addressing is limited to the first 256 bytes of memory.
With the 6809, direct addressing can be used with the entire 64K memory
map by using the direct page register (DPR).
4. Most significant
Least significant
5. Branch relative and program counter relative
6. Short and long branches
7. A 2-byte instruction op code followed by a 2-byte relative address offset
(except for LBRA and LBSR, where the op code is only 1 byte; see Chap. 5)
8. Since the offset is 2 bytes (F150), a long branch instruction is required.
Long branches use 4 bytes; therefore the program counter contains 2000 +
4 = 2004. Now, the most significant bit of the offset is a logic 1; therefore
the 6809 will branch backward. To obtain the destination, you add the
twos complement offset to the program counter contents. Thus the destina-
tion address is 2004 + F150 =1154.
9. Program counter relative with an 8-bit signed offset and program counter
relative with a 16-bit signed offset
10. X, Y, S, and U
11. Zero-offset, constant-offset, accumulator-offset, and auto-increment/decre-
ment indexed
12. A post byte
13. 5-, 8-, and 16-bit signed offsets
14. Since the 5-bit signed offset is included as part of the post byte
15. -32,768 to +32,767 (±15 bits)
16. With accumulator-offset, the offset can be calculated just prior to the
indexed operation.
17. Post-increment/pre-decrement
18. 1 or 2
19. Addressing mode field (bits 0-3)
Indirect field (bit 4 )
Pointer register field (bits 5 and 6)
5-Bit offset field (bit 7)
20. Set (logic 1)
21. LDA 10, Y (reference, Table 2-5)
22. 101010002 = A816 (reference, Table 2-6)
23. This post byte specifies auto decrement by two on the X index register.
49
The X index register will be decremented by two after each execution of an
instruction using this post byte. The assembler code will be: ,--X.
24. With indirect addressing the addressed memory location contains the
address of the operand rather than the operand itself.
25. Extended addressing, program counter relative addressing, and all of the
indexed addressing modes except auto-increment/decrement by 1
26. The bracket, [ ]
27. Prior to the LDX instruction, accumulator A is loaded with 10 and the
U pointer register is loaded with FCSO. The LDX instruction is using
indirect accumulator A offset addressing on the U pointer register. There-
fore the memory location which contains the address of the operand is
+
0010 FC50 = FC60. From the program listing you find 06 at this
address, which is the high byte of the operand's address. The low byte is
found at address FC6!. Thus the operand is located at address 06FF. At
this address you find the value F5. But, the X index register is a 16-bit
register. Therefore F5 forms the high byte to be loaded and the contents
of the next consecutive memory location will form the low byte to be
loaded. Thus the value F51B will be loaded into the index register.
28. 1l0l01lCh = D616 (reference, Table 2-6)
29. 4 or 5: the instruction op-code byte ( s ), followed by a post byte, followed
by a 2-byte address
30. Accumulator A and the direct page register (reference Fig. 2-7)
50
CHAPTER 3
INTRODUCTION
As stated previously, the main design goal for the 6809 was to
make it a super 8-bit processor, approaching 16-bit performance,
without sacrificing compatibility with the 6800. Therefore, the
6800's architecture was expanded and the instruction set "cleaned
up" to provide more efficient processing. The 72 fundamental 6800
instructions have been reduced to 59 for the 6809. Combined with
the various addressing modes discussed in the previous chapter,
these 59 fundamental instructions, however, allow for 1464 unique
operations within the 6809, as compared with 197 for the 6800.
Prior to defining the 6809's instruction set, Motorola conducted a
survey of 6800 users to determine which 6800 instructions were used
most frequently and which were not so well used. The most fre-
quently used instructions were the loads and stores, followed by
subroutine calls, branches, compares, increments/ decrements, clears,
and adds/ subtracts, in that order. Therefore, the major 6809 instruc-
tion set improvements have been made in the data movement in-
struction category: loads, stores, transfers, exchanges, etc. For ex-
ample, data transfers and exchanges may be made between any two
like-size registers (R1, R2) using the TFR R1, R2 and EXG R1, R2
instructions. There are 42 valid combinations of the TFR instruc-
tion and 21 valid combinations of the EXG instruction. You there-
fore have just learned 63 6809 instructions with two mnemonics
rather than 63 unique mnemonics of the form: transfer A to B
(TAB), transfer A to CCR ( TAP), transfer X to S (TXS), etc.,
51
as was the case with the 6800. This frees a number of op codes for
more efficient use elsewhere. To maintain compatibility with the
6800 the 6809 source code (mnemonic code) has not changed, ex-
cept for the new instructions. Changes have been made, however,
at the object code (op code) level to allow for more efficient instruc-
tion coding.
You have already been familiarized with the 6809's internal reg-
ister format (architecture). We will begin this chapter by discuss-
ing each internal register in detail. Then a discussion of the 6809
instruction set will begin and continue through the next two chap-
ters. For convenience, we have broken the 59 fundamental 6809
instructions down into six functional categories. They are: data
movement, arithmetic, logic, test, branch, and miscellaneous in-
structions. The data movement instructions will be discussed in this
chapter, with the remaining instructions being covered in Chap-
ters 4 and 5.
If you are familiar with the 6800, you will find many of the 6809
instructions are familiar. The difference is in how they are used
with the various addressing modes which were presented in Chap-
ter 2. Therefore, a basic understanding of the 6800's instruction set
will be assumed in this and subsequent chapters. If you are not
familiar with the 6800 instruction set or need some "brushing up,"
consult a textbook on the 6800, such as How to Program and I nter-
face the 6800, published by Howard W. Sams & Co., Inc.
OBJECTIVES
At the end of this chapter you will be able to do the following:
52
J
• Explain how to push/pull any or all of the internal 6809 reg-
isters on the S or U stacks.
• List the order of stacking with the PSHS and PSHU instruc-
tions.
• Define a "stack processor."
PROGRAM COUNTER
ters to the 6800 architecture. The new 8-bit register is the direct
page register (DPR) whose function was discussed in Chapter 2.
The three new 16-bit registers are accumulator D, the Y index reg-
ister, and the U stack pointer. The remaining registers are identical
with those in the 6800 and they perform similar functions. The fol-
lowing is a brief review of each register, as shown in Fig. 3-1.
Accumulators A, B, and 0 (A, B, D)
Accumulators A and Bare 8-bit storage registers that are used to
hold operands before they are used in an operation, and also to hold
the results of various operations. As with the 6800, data may be
53
loaded into, stored from, transferred to and from, exchanged with,
added to, subtracted from, shifted, ANDed with, oRed with, xORed
with, and compared to, the contents of either accumulator. Accum-
ulator D is a 16-bit register which combines accumulators A and B.
Accumulator A forms the high byte, with accumulator B forming
the low byte, of accumulator D. Accumulator D is used in the same
way as accumulators A and B, but it is used for 16-bit arithmetic
operations. As you will see presently, there are several instructions
associated with this accumulator. These instructions allow 16 bits
of data to be loaded into, stored from, transferred to and from, ex-
changed with, added to, subtracted from, and compared with the
contents of accumulator D.
X Register
The X register is a 16-bit register that can be used as a pointer
register to store data or 16-bit addresses in conjunction with the in-
dexed mode of memory addressing, as discussed in Chapter 2. As you
discovered in Chapter 2, this register can be automatically incre-
mented or decremented by either one or two counts. The 6809's
instruction set will allow the X register to be loaded from and
copied into memory. In addition, you can add to, subtract from,
and compare its contents, as well as push and pull its contents
from a memory stack. As you will soon see, this register may also
be used as a software controlled stack pointer using auto-increment/
decrement.
Y Register
The Y register functions are identical to those of the X register.
Instructions are provided to manipulate this register in the same
ways as the X register.
U Register
This 16-bit register has the same capabilities and can function
in the same way as the X and Y registers, or it can be used to de-
fine a user or software memory stack, which is not used automati-
cally by the 6809's interrupts as in the case of the hardware stack.
As you will see, the same instructions which operate on the X and
Y registers are also available to the U register. Moreover, push and
pull instructions are provided such that you may stack any or all
of the internal 6809 registers' contents in an R/W memory stack de-
fined by the U register. We will refer to such a stack as the U stack.
.s Register
The S register corresponds to the 68oo's stack pointer. It is a
hardware stack pointer and thus provides for automatic stacking
54
of the internal 6809 register information during subroutine calls
and interrupts. However, it may also be used as a pointer register
for any of the indexed modes of addressing, and it has associated
instructions which allow it to be loaded, stored, added to, sub-
tracted from, and compared. In addition, it can be used to define
a software stack since push and pull instructions are provided so
that you can stack any or all of the 6809 internal register contents
in the S stack.
Direct Page Register (DP)
This is an 8-bit register which is used to define the high-memory
address byte (page) for the direct mode of memory addressing (see
Chapter 2).
Program Counter {PC}
The program counter is a 16-bit binary counter that provides in-
struction sequencing. In addition, it is used in the calculation of
branch destinations for branch relative addressing and effective ad-
dresses for the program counter relative mode of memory address-
ing (see Chapter 2).
55
correct sign, even if the result sign is wrong. Loads, stores, and
logical operations will clear V.
Zero Flag (Z-Bit 2)-The Z flag is set (=1) whenever the result
of an operation or data transfer is identically equal to zero. It can
also be used to reflect the equal or unequal condition between 2
data bytes that are being compared. If the bytes are identical, the
Z flag will set.
Negative Flag (N-Bit 3)-The N flag is the twos complement
sign bit and can be thought of as being connected directly to the
msb (bit 7) of the result. A 1 indicates a negative result, with a
o indicating a positive result. If a twos complement overflow oc-
curs, the sign of the result (N flag) will be incorrect. Therefore
signed branches will always test the condition N "if V to obtain a
valid sign result.
Interrupt Flag (I-Bit 4)-This flag is used in conjunction with
external if 0 device interfacing and it will be discussed in detail
later. Briefly, when this flag is set, it will not allow the 6809 to be
interrupted by the interrupt request (IRQ) line. As you will dis-
cover later, the 6809 interrupts are: NMI, FIRQ, IRQ, RESET,
SWIl, SWI2, and SWI3. All of the above, except SWI2 and SWI3,
will automatically set the I flag during their respective interrupt
sequences.
Half-Carry Flag (H-Bit 5)-The half-carry flag is used to indi-
cate a carry from bit 3 to bit 4 in the arithmetic logic unit (alu).
It will be set if a carry from bit 3's column to bit 4's column took
place during an addition operation only (ADD or ADC). The 6809
uses this flag to implement the decimal-adjust instruction that al-
lows it to operate on binary-coded decimal, or bcd, values.
Fast Interrupt Mask (F-Bit 6) and Entire State Saved (E-
Bit 7) Flags-The two new 6809 flags which were mentioned in
Chapter 1 are the fast interrupt mask (F) and entire state saved
( E) flags, bits 6 and 7 of the CCR, respectively. Recall that these
2 bits are not used and are permanently set (logic 1) in the 6800.
Associated with these flags is a hardware interrupt line called the
fast interrupt request (FIRQ) line. Like the 6800, the 6809 auto-
matically. stacks all the internal register data when an interrupt re-
quest (IRQ) is acknowledged. There is, however, no need for the
computer to waste its time stacking all of the internal register data
if it is known ahead of time that the interrupt service routine will
either use the existing internal register contents or it is not necessary
to save these contents. For this reason the 6809 includes a fast inter-
rupt request (FIRQ) in addition to the standard interrupt request
(IRQ). When an FIRQ is acknowledged, the 6809 will finish exe-
cuting its current instruction and then it automatically "stacks" only
the contents of the program counter and the condition code register.
56
Program control is then passed to the FIRQ interrupt service rou-
tine via the FIRQ interrupt vector. (Interrupt vectors are discussed
in Chapters 5 and 6.) The F flag of the condition code register is
a mask bit for all FIRQ interrupts. When it is cleared (logic 0),
fast interrupts are allowed; however, when it is set (logic 1), fast
interrupts are masked out or disallowed. The E flag of the condition
code register is used in conjunction with the fast interrupt request
(FIRQ) and all other 6809 interrupts. When an FIRQ is acknowl-
edged, the E flag is automatically cleared (logic 0), indicating that
only the program counter and condition code register have been
stacked. However, the E flag is set (logic 1) when an IRQ, NMI,
or SWI is acknowledged, indicating that all the internal working
registers have been stacked. The E flag of the stacked condition
code register is then used by the 6809 during a return from inter-
rupt (RTI) to determine the extent of "unstacking" that is required.
All the 6809 interrupts, except FIRQ will cause the E flag to set.
We will discuss the 6809's interrupt structure in detail later. At this
time it is only necessary that you understand the basic functions
of the E and F flags.
Now that you are familiar with the 6809 addressing modes and
internal register structure, you are ready to study the 59 fundamen-
tal instructions that make up the 6809 instruction set.
57
Table 3·1. Data Movement Instructions
Mnemonic Operation Operation Symbol
LD LDA Load A immediate, or from memory M-A
LDB Load B immediate, or from memory M-B
LDD Load D immediate, or from memory M:M + 1-D
LDS Load S immediate, or from memory M:M + 1-S
LDU Load U immediate, or from memory M:M + 1-U
LDX Load X immediate, or from memory M:M + 1-X
LDY Load Y immediate, or from memory M:M + 1-Y
ST STA Store A to memory A-M
STB Store B to memory B-M
STD Store D to memory D-M:M + 1
STS Store S to memory S-M:M + 1
STU Store U to memory U-M:M + 1
STX Store X to memory X-M:M + 1
STY Store Y to memory Y-M:M + 1
TFR R1, R2 Transfer R1 to R2 R1-R2
EXG R1, R2 Exchange R1 with R2 R1-R2
LEA LEAS Load effective address into S EA-S
LEAU Load effective address into U EA-U
LEAX Load effective address into X EA-X
LEAY Load effective address into Y EA-Y
PSH PSHS Push onto hardware stack (S) None
PSHU Push onto user stack (U) None
PUL PULS Pull from hardware stack (S) None
PULU Pull from user stack (U) None
LDX $$
F1
C5
58
means to load the X register with the contents of memory locations
FIC5 and FIC6. Here, M equals FIC5, whose contents will be
loaded into the high byte of the X register. The value to be loaded
into the low X register byte is found at memory location M + 1, or
FIC6 in this example. In contrast, the instruction
LOX #
F1
C5
59
lator A to the S register; and LEAY 10, U will add 10 to the U reg-
ister and transfer the sum to the Y register. To increment the X
register, you could use LEAX 1, X; while LEAY -1, Y would dec-
rement the Y register. Obviously there are many more possibilities
than the examples presented here. The LEA instructions used in
conjunction with the various modes of indexed addressing will find
many applications in your assembly-language programs.
The 6809 PSH and PUL instructions will allow you to push or
pull one or any number of internal registers to and from the user
(U) or hardware (S) memory stack. Before we discuss these in-
structions, let's notice something about the 6809 stacking. First, the
user stack pointer (U) defines the beginning of a software stack
which is not affected by the use of subroutine calls or interrupts.
Therefore the U stack is controlled completely by the programmer.
In contrast, the hardware stack pointer (S) defines the beginning
of a hardware stack that is used automatically by the 6809 to stack
internal register data during subroutine calls and interrupt servic-
ing. During a subroutine call the program counter is automatically
saved on the S stack, and during an interrupt all the internal reg-
isters are automatically saved on the S stack. The fast interrupt re-
quest (FIRQ) is an exception, since only the condition code reg-
ister and program counter are "stacked." More will be said later
about the use of the S stack with subroutines and interrupts. Recall
that both the U and S stack pointers can be used as index registers
in the indexed mode of addressing, but in addition they support the
push and pull instructions. This dual function allows the 6809 to be
used as a stack processor, and thus it can readily support such high-
level languages as Pascal, FORTRAN, and so on.
• stack processor-a processor which allows unlimited memory
stacking for easy processing of multiple-level interrupts and
subroutine nesting.
In the 6800 the stack pointer "points" to the next available loca-
tion on an R/W memory stack. However, with the 6809 the stack
pointer actually points to the last value pushed onto the stack, some-
times referred to as the top of the stack. This change was made to
allow the 6809's X and Y registers to function also as software stack
pointers in the auto-increment/ decrement mode of indexed address-
ing. For example, an STA, -Xis equivalent to a pull-accumulator-A-
from-the-stack instruction, using a stack defined by the address in
the X register. The instruction LDA, X+ would pull the top byte of
a stack defined by the X register into accumulator A. Before-and-
after illustrations of the operation of these instructions are shown in
Figs.3-2 and 3-3. .
The same types of instructions can be used to push and pull ac-
60
ACCA ACCA
89 89
MEMORY MEMORY
r--- ---
·
OOFE
··
XX OOFE
·
XX
ooFF XX OOFF XX
0100 XX 0100 89
0101 XX 0101 XX
0102 XX 0102 XX
-·
·
(A) 6809 chip and X stack before
··-
(8) 6809 chip and X stack after
STA, -X. STA, -X.
Fig. 3-2. Before and after STA, - X.
MEMORY MEMORY
--- --·
OOFE
··
XX OOFE
·
XX
OOFF XX OOFF XX
0100 89 0100 89
0101 XX 0101 XX
0102 XX 0102 XX
··- ·
- ·-
(A) 6809 chip and X stack before (8) 6809 chip and X stack after
LOA, X+. LOA, X+.
Fig. 3-3. Before and after LOA, X +.
61
:
ACCD Y REGISTER ACCD
__ ~_:::_ ~ ~_:::o_l _
FC50
MEMORY
--·-
L
MEMORY
--
OOFE
·
XX OOFE XX
··
OOFF XX OOFF FC
0100 XX 0100 50
0101 XX 0101 XX
0102 XX 0102 XX
ACCD ACCD
I xxxx I FC50
MEMORY MEMORY
- ·--- --
· ··
OOFE XX OOFE XX
OOFF FC OOFF FC
0100 50 0100 50
0101 XX 0101 XX
0102 XX 0102 XX
- ·-
....
·
- ·-
·
(A) 6809 chip and Y stack before (B) 6809 chip and Y stack after
LDD, Y++. LDD, Y++.
Fig. 3-5. Before and after LOO, Y + +.
by 2 since the data will require 2 bytes in the stack. For example,
STD, - - Y would push the contents of accumulator D onto a stack
defined by the Y register, while LDD, Y++ would pull the top 2
bytes of a stack defined by the Y register into accumulator D. Before
and after illustrations of these instructions are shown in Figs. 3-4
and 3-5.
So, you might be wondering why we need the PSH and PUL
instructions listed in Table 3-1. The advantage is that, with these
62
IBIT 7\ BIT 6\ BIT 51 BIT 41 BIT 31 BIT 2\ BIT 1 I I
BIT 0 PU LL ORDER
I •
I C CR
:}O INCREASING
OPR MEMORY
X
~
Y
S/U
PC
•
PUSH ORDER
Fig. 3-6. Push/pull post-byte format.
instructions, you can push or pull any or all of the internal 6809
registers onto a stack denned by the S or U registers with one 2-byte
instruction. The PSH and PUL instructions require 2 bytes: the in-
struction op code followed by a post byte. The post byte dennes
which registers are to be pushed or pulled. The push/pull post-byte
format is shown in Fig. 3-6. A logic 1 in a bit position will cause that
respective register to be pushed/pulled. The order in which the
registers are pushed or pulled is also shown in Fig. 3-6. For exam-
ple, if you wanted to push accumulators A, B, and the program
counter (PC) onto the U stack, the proper assembly code would
be: PSHU A, B, PC. The required post byte would then be 1000
01102 or 86 16 -
When using PSHU or PULU, bit 6 of the post byte will corre-
spond to the S register being pushed or pulled. When using PSHS
or PULS, bit 6 corresponds to the U register. Not all the registers
need to be stacked, but the order given in Fig. 3-6 is the same even
if only a subset is stacked. You will see shortly that this order of
stacking is the same when the 6809 services interrupts. When a 16-
bit register is pushed, the low byte is pushed nrst, followed by the
high byte. And when a 16-bit register is pulled from the stack, the
high byte is pulled nrst, then the low byte. Note from Fig. 3-6 that
stacking all of the internal 6809 registers would require 12 bytes
of stack memory. Also, accumulator D is not specincally stacked
since it is simply the concatenation of accumulators A and B.
The data handling instruction op codes are listed alphabetically
in Table 3-2. Note that, besides providing the instruction op codes,
this table also provides the number of bytes and MPU cycles re-
quired for a given instruction. In addition, the effect that an instruc-
tion has on the condition code register flags is also provided. The
notes and legend provided with this table will also apply to all sub-
sequent op-code tables.
63
M OD Cod
.
en Instructlonl
Forms
I
I
I OP
Inherent
'V # OP
Direct
'V #
6809 Addressing Modes
Extended
OP 'V #
Immediate
OP 'V # OP
Indexed'
'V # OP
Relative
'V 5
I
I
#1 Description
5
H
3
N
2
Z
1
V
0
C
EXG R1,R2 1E 7 2
A6
R1-R2'
M....A ·· · · · ··
t t
··
LO LOA 4 2 B6 5 86 2 2 0
··
96 3 4+ 2+
LOB 06 4 2 F6 5 3 C6 2 2 E6 4+ 2+ M.... B t t 0
EC M:M+1 ....0 t t
·
LOO DC 2 FC 6 CC 3 3 2+ 0
·
5 3 5+
LOS 10 6 3 10 7 4 10 4 4 10 6+ 3+ M:M+1 ....S t t 0
··
DE FE CE EE
LOU DE 5 2 FE 6 3 CE 3 3 EE 5+ 2+ M:M+1 ....U
M:M+1 ....X
t
t
t
t
0
··
·
9E 2 BE 8E 3 3 AE 0
·
LOX 5 6 3 5+ 2+
LOY 10 6 3 10 7 4 10 4 4 10 6+ 3+ M:M+1 ....Y t t 0
AE
·· ·· ·· ·· ··
9E BE 8E
LEA LEAS 32 4+ 2+ EA'....S
EA'....U
·· ·· ·· ··
LEAU 33 4+ 2+
LEAX 30 4+ 2+ EA'....X t
EA'....Y t
·····
LEAY 31 4+ 2+
PSH PSHS 34 5+< 2 Push registers
on S stack
PSHU 36 5+< 2 Push registers
·····
·····
on U stack
PUL PULS 35 5+< 2 Pull registers
from S stack
PULU 37 5+< 2
~~~I~e8i:::~~ ·····
ST STA 97 4 2 B7 5 A7 A....M t
· t
·
···
3 4+ 2+ 0
···
STB 07 4 2 F7 5 3 E7 4+ 2+ B....M t t 0
STD DO 5 2 FO 6 3 ED 5+ 2+ 0....M:M+1 t t 0
STS 10 6 3 10 7 4 10 6+ 3+ S....M:M+1 t t 0
···
OF FF EF
STU OF 5 2 FF 6 3 EF 5+ 2+ U....M:M+1 t
t
t
t
0
··
· · · · ··
STX 9F 5 2 BF 6 3 AF 5+ 2+ X....M:M+1 0
STY 10 6 3 10 7 4 10 Y....M:M+1 t t 0
9F BF AF 6+ 3+
TFR R1,R2 1F 7 2 R1 ....R2'
..
Notes.
1. Given in the table are the base cycles and byte counts. To determine the total 4. The PSH and PUL instructions require 5 cycles plus 1 cycle for each byte
cycles and byte counts add the values from the 6809 indexing modes table. pushed or pulled.
2. R1 and R2 may be any pair of 8-bit or any pair of 16-bit registers. 5. 5(6) means: 5 cycles if branch not taken, 6 cycles if taken.
6. SW1 sets I&F bits. SW12 and SW13 do not affect I&F.
The 8-bit registers are: A, B, CC, OP 7. Conditions codes set as a direct result of the instruction.
The 16-bit registers are: X, Y, U, S, 0, PC 8. Value of half-carry flag is undefined.
3. EA is the effective address. 9. Special Case-carry set if b7 is SET.
Legend
OP Operation code (hexadecimal); Z Zero lbyte)
'V Number of MPU cycles; V Overf ow, twos complement
#
+
Number of program bytes;
Arithmetic plus;
Arithmetic minus;
Multiply
.
C
t
CC
Carry from bit 7
Test and set if true, cleared otherwise
Not affected
Condition code register
M Complement of M; Concatenation
.... Transfer Into; V Logical OR
I H ~~~:~~r:y,!f~!!1 ...~l~ 3; II ~og!ca~ ANI?
This completes the discussion of the data handling instructions.
The following examples illustrate the use of these instructions.
Study the examples carefully. Then, if you have a Motorola MEK-
6809D4 trainer, or an equivalent 6809-based system available to
you, implement the following examples to verify their proper exe-
cution. (A discussion of the Motorola ~1EK6809D4 evaluation sys-
tem is provided in Chapter 7.)
Example 3-1: Loading and Storing the Direct
Page Register
Write an instruction sequence to load the direct page register with
a new value and to store the old value.
Even though there is no LDDP or STDP, the exchange instruc-
tion (EXG) makes this a rather simple process. Suppose the new
value to be loaded into the direct page register (DP) is E5, and
the old DP contents are to be stored in memory location E510.
Then, the following instructions should accomplish this task:
LDA #
E5
EXG A, DP
STA $
10
The above instruction sequence loads accumulator A with immedi-
ate data byte E5. The contents of accumulator A and the direct page
register are then exchanged. Thus the new value (E5) is now in the
DP register and the DP contents are in accumulator A. Since it is
desired to store the old DP contents in memory location E510 and
the DP register now contains E5, you can use direct addressing for
the store operation. The store accumulator A direct operation will
cause the contents of accumulator A (old DP register contents) to
be stored at memory location E510 since the DP register contains
E5 and forms the high memory location byte and the instruction
contains 10, which forms the low memory location byte.
What post byte would be required for the EXG instruction in the
above program?
To exchange accumulator A and the DP register, the required
post byte would be 1000 lOll:! or 8B 16 (see Fig. 2-7).
Determine the number of bytes and MPU cycles required to exe-
cute this program.
Adding the number of bytes and MPU cycles required for each
instruction from Table 3-2, you should find that this program re-
quires 6 bytes of memory and 13 MPU cycles for execution.
Example 3-2: Adding to a Pointer Register
Write an instruction sequence to add the contents of accumulator
A to the Y register, then transfer that result to the S register.
65
There are no 6809 ADD instructions which allow you to add to
any of the pointer registers. However, the load effective address
(LEA) instruction can be used for this purpose. The following sin-
gle instruction will accomplish the above task:
LEAS A, Y
LEAY A, Y
TFR Y, S
How many bytes and MPU cycles are required for each of the
above programs?
From Table 3-2 the LEAS A, Y instruction requires 2+ bytes and
4+ MPU cycles. This means that to determine the exact number of
bytes and MPU cycles, you must add the values from the 6809 in-
dexed addressing modes table (Table 2-6) for the given operation.
Referring to Table 2-6, you find that this operation requires no addi-
tional bytes and one additional MPU cycle. Therefore the LEAS A,
Y instruction requires 2 bytes and 5 MPU cycles for execution. In
the same way you find from Tables 3-2 and 2-6 that the second pro-
gram requires 4 memory bytes and 12 MPU cycles for execution.
Note the difference in the number of bytes and MPU cycles for the
two different programs, both of which accomplish the same task.
Example 3-3: Stack Operations
Write an instruction sequence that will stack accumulator A, the
DP register and the U stack pointer on a stack defined by the Y
register.
To use the Y register as a stack pointer, you must use auto-incre-
ment/ decrement by 1, or 2, depending upon the size of the register
to be stacked or unstacked. The following instructions will accom-
plish the given task:
TFR OP, B
STO , - - Y
STU , - - Y
66
since you must store both accumulators A and B, you can use an
STD instruction, since accumulator D is simply the combination of
A and B. The STD, - - Y instruction will push accumulator B onto
the Y stack first, followed by accumulator A. The STU, - - Y instruc-
tion will then push the U register onto the Y stack. The low U reg-
ister byte (U L) will be pushed first, followed by the high U register
byte (UII)' After the instructions have been executed, the Y register
will point to the top of the stack or the memory location which con-
tains Un. Accumulator B will be at the bottom of the stack.
Determine the proper post byte for each of the above instruc-
tions.
The transfer (TFR) instruction post byte will be 1011 100b or
B9 16 since the source register is the direct page register and the
destination register is accumulator B '( see Fig. 2-7). The proper
post byte for the STD, - - Y instruction is 1010 00lb or A3 16 • The
post byte for the STU, - - Y instruction will be the same since both
instructions use the same mode of indexed addressing and operate
on the same pointer register (see Table 2-6).
Write an instruction sequence to unstack the above registers.
The correct instruction sequence would be:
LOU, Y++
LOO, Y++
TFR B, OP
Note that you will unstack the register data in the reversed order
to that in which they were originally stacked, since the last-in, first-
out (LIFO) principle applies. The proper post bytes for the above
instructions would be: A1 16 , A1 16 , and 9B 16, respectively (see Ta-
ble 2-6 and Fig. 2-7).
Example 3-4: Stack Operations
Write an instruction sequence that will stack accumulator A, the
CCR, DPR, PC, and X register on the user stack.
This task only requires one 2-byte instruction:
PSHU A, CC, OP, PC, X
67
Chart 3-1. Performing Additional Data Transfer Operations
With 6809 Instructions
Transfer A to X PSHS X
(A:XL-X) STA O,S
PULS X
Transfer B to X PSHS X
(XH:B-X) STB 1,S
PULS X
REVIEW QUESTIONS
1. List the 8·bit registers of the 6809.
68
4. Which register is used automatically by the 6809 for stacking data during
subroutines and interrupts?
8. For the 6809 to acknowledge a fast interrupt request, the F Hag must be
11. Which of the internal 6809 registers can be loaded and stored?
69
13. EA~ Y is the operation symbol for the instruction.
14. Write an instruction that will subtract 7 from the contents of the S
register.
15. Write an instruction that will add the contents of accumulator B to the
Y register.
16. Write an instruction that will add the contents of accumulator A to the
U register, then transfer the result to the X register.
20. Write an instruction sequence which will stack the Y register, accumulator
A, and the condition code register, in that order on the X stack.
21. Why wouldn't the following be a correct answer to the preceding question?
STY, --X
TFR ee, B
STD, --X
70
22. Write an instruction sequence that will unstack the stack created in
Question 20.
23. What is the order of stacking when using the PSH instructions?
24. Write an instruction which will stack both accumulators (A and B), the
X register, and the program counter on the U stack.
25. Write the correct op-code listing for the preceding instruction.
ANSWERS
1. Accumulator A (A)
Accumulator B (B)
Direct page register (DPR)
Condition code register (CCR)
2. Accumulator D (D)
Program counter (PC)
X register (X)
Y register (Y)
U register (U)
S register (S)
3. The X, Y, S, or U register
4. The S register
5. None. They can be used in exactly the same manner and are operated on
by the same set of instructions.
6. When the result of an operation is zero
7. The V flag
8. Cleared (logic 0)
9. Only the program counter and condition code register
10. The E flag is used in conjunction with the F flag. The E flag is automatically
cleared when a fast interrupt request is acknowledged and set for all other
71
interrupts. This flag is used by the 6809 for unstacking purposes to de-
termine the amount of unstacking required.
11. Accumulators A, B, and D and the X, Y, S, and U registers.
12. LDX # loads the X register immediately with FC50, while LDX $$ loads
the high X register byte (X H ) with the contents of FC50 and the low
register byte (XL) with the contents of FC5l.
13. Load effective address into Y (LEAY)
14. LEAS -7, S
15. LEAY B, Y
16. LEAX A, U
17. The X, Y, S, and U registers
18. To the "top" of the stack or last value pushed onto the stack
19. By using auto-increment/decrement indexed addressing on the X and Y
registers in conjunction with the various load and store instructions
20. STY, --X
STA, -X
TFR CC, B
STB, -X
21. This instruction sequence will stack the Y register, the CCR, then accumu-
lator A which is not the specified order of stacking in Question 20.
22. LDB, X+
TFR B, CC
LDA, X+
LDY, X++
Note that the data must be unstacked in the reverse order of stacking.
23. CC
A Increasing
B memory
DP
X
Y
U/S
PC
24. PSHU A, B, X, PC
25. From Table 3-2 and Fig. 3-6 the correct op-code listing would be:
PSHU op code: 3616
Post byte: 96t6
72
CHAPTER 4
INTRODUCTION
Most of the arithmetic, logic, and test instructions of the 6809 are
very similar to those of the 6800, except in the way they can be used
with the various addressing modes. There are, however, a few sur-
prises. You will see arithmetic and test instructions which allow you
to operate on accumulator D. One of the most significant of these is
the multiply (MUL) instruction that allows you to multiply the con-
tents of accumulators A and B, with a 16-bit product being gener-
ated in accumulator D. In addition, you will find an instruction that
will allow you to extend the sign bit of accumulator B into accumu-
lator D such that 8-bit signed (twos complement) values can be ex-
tended into 16-bit signed (twos complement) values.
The logic instructions of the 6809 allow you to perform the stan-
dard logic operations of AND, OR, XOR or EOR, complement, shift, etc.,
on the contents of accumulators A, B, and memory. However, rather
than have separate, inherent instructions to set and clear the condi-
tion code register flags, the 6809 uses two logic instructions, ANDCC
and ORCC. These two 6809 instructions replace six 6800 instructions
and therefore release valuable op codes for more efficient use else-
where.
The discussions and examples in this chapter will concentrate on
how to apply the arithmetic, logic, and test instructions using the
addressing modes presented in Chapter 2. Only the new instructions
will be defined and discussed separately. Again, a basic understand-
ing of the 6800 instruction set is assumed.
73
OBJECTIVES
At the end of this chapter you will be able to do the following:
• Write a program to multiply two values and store the result in-
directly.
• Understand why the 6809 multiply (MUL) instruction is an
unsigned multiply.
• Write an instruction sequence to compute the U stack pointer.
• Determine the correct op-code listing, given an assembly-lan-
guage program listing.
• Determine the MPU cycles required to execute a given instruc-
tion sequence.
• Explain how to set and clear the condition code register flags.
• Describe the three main categories of test instructions.
• Understand which CCR flags are affected by the various test
instructions.
• Determine CCR flag status after execution of a given test in-
struction.
ARITHMETIC INSTRUCTIONS
The 6809 arithmetic instructions can be used to perform the fol-
lowing operations:
• Add and subtract memory into A, Band D.
• Add and subtract memory with carry into A and B.
• Increment and decrement A, B, D, and memory.
• Clear A, B, and memory.
• Negate A, B, and memory.
• Operate on bcd numbers.
• Multiply A times B.
• Sign extend B into D.
The 6809 arithmetic instructions are listed in Table 4-1. If you are
familiar with the 6800, you will recognize many of the instruction
mnemonics. The difference between these and the similar 6800 in-
structions is simply in how they can be applied using the numerous
6809 addressing modes. Therefore a detailed description of each in-
struction will not be given here, but examples will be given pres-
ently, showing various ways in which many of these instructions may
be used. However, three new instructions do justify explanation.
They are: ABX (add B to X), MUL (multiply), and SEX (sign ex-
tend B into A).
The ABX instruction adds the unsigned (8-bit straight binary)
contents of accumulator B to the X register contents, with the result
74
Table 4-1. 6809 Arithmetic Instructions
Mnemonic Operation Operation Symbol
ABX Add B to X (unsigned) B+X-X
ADC ADCA Add memory to A with carry A + M +C-A
ADCB Add memory to B with carry B + M + C-B
ADD ADDA Add memory to A A+M-A
ADDB Add memory to B B+M-B
ADDD Add memory to 0 0+ M:M + 1-0
CLR CLRA Clear A O-A
CLRB Clear B O-B
CLR Clear memory O-M
DAA Decimal adjust A None
DEC DECA Decrement A A -1-A
DECB Decrement B B -1-B
DEC Decrement memory M -1-M
INC INCA Increment A A+1-A
INCB Increment B B + 1-B
INC Increment memory M +1-M
MUL Multiply A times B (unsigned) AxB-D
NEG NEGA Negate A (twos complement) A+1-A
NEGB Negate B (twos complement) B +1-B
NEG Negate memory (twos complement) t1 + 1-M
SBC SBCA Subtract memory from A with borrow A - M -C-A
SBCB Subtract memory from B with borrow B - M - C-B
SEX Sign extend B into A None
SUB SUBA Subtract memory from A A-M-A
SUBB Subtract memory from B B-M-B
SUBD Subtract memory from 0 0- M:M + 1-0
75
"MUL"
8 ALU 8
8 8
16
ACCA ACCB
RESULT
ACCD
Fig. 4·1. Execution of the multiply (MUL) instruction.
76
Table 4-2. Arithmetic Instruction Op Codes
6809 Addressing Modes
·...·
Forms OP '" # OP '" # OP '" # OP '" # OP '" # OP '" # Description H N Z V C
ABX 3A 3 1 B+X-X
(Unsigned)
ADC ADCA 99 4 2 B9 5 3 89 2 2 A9 4+ 2+ A+ M +C-A t t t t t
ADCB 09 4 2 F9 5 3 C9 2 2 E9 4+ 2+ B + M +C-B t t t t t
ADD ADDA 9B 4 2 BB 5 3 8B 2 2 AB 4+ 2+ A+M-A t t t t t
ADDB DB 4 2 FB 5 3 CB 2 2 EB 4+ 2+ B+M-B t t t t t
ADDD D3 6 2 F3 7 3 C3 4 3 E3 6+ 2+ D + M:M + 1-0 t t t t t
CLR CLRA
CLRB
4F
5F
2
2
1
1
O-A
O-B ··
0
0
1
1
0
0
0
0
CLR OF 6 2 7F 7 3 6F 6+ 2+ O-M 0
· 1 0 0
···
DAA 19 2 1 Decimal adjust A t t 0 t
DEC DECA
DECB
4A
5A
2
2
1
1
A -1-A
B -1-B
t
t
t
t
t
t··
··· ···
DEC OA 6 2 7A 7 3 6A 6+ 2+ M -1-M t t t
INC INCA 4C 2 1 A +1-A t t t
INCB 5C 2 1 B + 1-B t t t
MUL
INC
3D 11 1
OC 6 2 7C 7 3 6C 6+ 2+ M +1-M
AxB-D
.;unsigned)
t
·· . . ·
t
t
t
9
SBC SBCA
1D 2 1
92 4 2 B2 5 3 82 2 2 A2 4+ 2+
Sign extend B
into A
A - M -C-A
·
8
t
t
t
t
0
t
·
t
SBCB D2 4 2 F2 5 3 C2 2 2 E2 4+ 2+ B -M -C-B 8 t t t t
SUB SUBA 90 4 2 BO 5 3 80 2 2 AO 4+ 2+ A-M-A 8 t t t t
SUBB DO 4 2 FO 5 3 CO 2 2 EO 4+ 2+ B-M-B 8 t t t t
SUBD 93 6 2 B3 7 3 83 4 3 A3 6+ 2+ 0- M:M + 1-D
· t t t t
::I
Example 4-1: Using the Multiply (MUL) Instruction
Describe the task of the following instruction sequence:
LOA #
20
LOB #
OA
MUL
STO [, Xl
The instruction sequence first loads accumulator A with 20, then
loads accumulator B with OA. The MUL instruction then multiplies
these values and places the 16-bit result, 0140, in accumulator D.
Note, since accumulator D is the combined contents of accumulators
A and B, accumulator A should now contain 01 and accumulator B
will contain 40. The previous accumulator contents are lost. Finally,
the result is stored by the STD instruction using indirect addressing,
with the X pointer register (no offset). Therefore, the contents of
the X register specify the address where you will find the high ad-
dress byte of the high result byte storage location. The low address
byte of the high result byte storage location will be found at the ad-
dress specified by the index register contents plus 1, or X+ 1. For
example, suppose the index register contains 0100. Then, X=OI00
and X+1=0101. Also, suppose that memory location 0100 contains
FC and memory location 0101 contains 50. Then the high result byte
is stored in memory location FC50 and the low result byte is stored
in memory location FC51.
Write the correct op-code listing for the above instruction mne-
monic sequence.
From Tables 2-6,3-2, and 4-2 the proper op-code listing would be:
LOA # 86
20 20
LOB # C6
OA OA
MUL 30
STO [, Xl EO
94
78
..
are specified by the Y register. Once the offset is computed, add it to
the X register to create an X stack pointer. Then, save the Sand U
registers on the X stack.
The following instruction sequence will perform the above task:
LOB ,Y
ADDB 1, Y
ABX
STS ,--X
STU ,--X
LOB, Y E6
A4
ADDB 1, Y EB
21
ABX 3A
STS ,--X 10
EF
83
STU ,--X EF
83
You should verify the proper instruction op codes and post bytes
such that a complete understanding of the 6809 instruction set is
achieved. A few comments are in order:
1. The constant offset of 1 in the ADDB instruction is included as
part of the post byte (see Chapter 2).
2. The STS instruction requires a 2-byte op code (see Table 3-2).
79
LOGIC INSTRUCTIONS
The logic instructions of the 6809 can be used to perform the fol-
lowing operations:
• AND, OR, and EOR memory into A or B.
• Shift and rotate memory, A, or B.
• Complement memory, A, or B.
• AND or OR immediate data into the CCR.
The 6809 logic instructions are listed in Table 4-3. As with the
6800, the standard logic operations of AND, OR, and EOR are provided
along with the various arithmetic and logic shift functions. The
reader is encouraged to consult a 6800 text if a more detailed discus-
80
...
sion is needed on these instructions. The arithmet~c shift left (ASL)
and logic shift left (LSL) use the same operation symbol (Table
4-3). This is because they perform exactly the same operation and,
as you will see shortly, use the same op codes. Therefore there is no
functional difference between ASL and LSL. Motorola has simply
provided some duplication here since some users think of this opera-
tion as an arithmetic shift left, while others think of it as a logic shift
left operation.
Two surprises are provided in this instruction listing. They are the
ANDCC and ORCC instructions. These two instructions do not ap-
pear in the 6800 instruction set. However, they are meant to replace
several 6800 instructions. With the 6800 there are eight instructions
that allow you to operate on the condition code register. Two of the
eight (TAP and TPA) are used to transfer data between accumula-
tor A and the CCR. These have been replaced with the two 6809
exchange (EXG) and transfer (TFR) instructions. The remaining
six 6800 condition code register instructions are used to set and clear
the C, I, and V flags. They are: SEC, CLC, SEI, CLI, SEV, and
CLV. These six instructions have been replaced in the 6809 with two
instructions: ANDCC and ORCC. Both instructions use immediate
addressing to AND or OR a data byte immediately with the contents
of the condition code register for the purposes of setting or clearing
any CCR flag. To set any CCR flag, you simply OR a logic 1 immedi-
ately with that flag's bit position. To clear a flag, you AND a logic 0
with the respective flag bit position. Note, if you OR a logic 0 or AND
with a logic 1, the flag status will not change. This can be used to
preserve the state of various bits, while changing others. Some ex-
amples may help at this point.
Example 4-3: Clearing Condition Code Register Flags
Suppose that you wish to clear the C and I flags in the condition code
register. Determine the required instruction and immediate data
byte to be used.
To clear a flag you must AND a logic 0 with that flag's bit position.
Therefore, since the C and I flags are in bit positions 0 and 4, respec-
tively, the data byte must contain a logic 0 in these bit positions. All
other bit positions will contain a logic 1 so that the other flags are not
affected by the ANDing operation. Therefore the correct data byte
would be 1110 11102 or EE 16 • The complete instruction would then
be:
ANDCC #
EE
Example 4-4: Setting Condition Code Register Flags
Suppose that you wish to set the Nand F flags. Determine the re-
quired instruction and immediate data byte to be used.
81
To set a flag you must OR a logic 1 with that flag's bit position. The
Nand F flags are in bit positions 3 and 6, respectively. Therefore the
data byte must contain a logic 1 in these bit positions. All other bit
positions will contain a logic 0 so that the other flags are not affected
by the oRing operation. Thus the correct data byte would be 0100
10002 or 4816 • The complete instruction would then be:
ORCC#
48
Example 4-5: Instruction Interpretation
Interpret the following:
1. ANDCC #
00
2. ORCC #
10
3. ANDCC #
FF
TEST INSTRUCTIONS
The 6809 test instructions can be used to test data in the following
ways:
• Arithmetic compare memory with A, B, D, X, Y, U, and S.
• Logical compare memory with A and B.
• Test for zero, positive or minus on memory, A, and B.
There are no real big surprises in the 6809 test instructions over
those of the 6800. The 6809 test instructions are listed in Table 4-5.
The three main categories of testing are: logic bit test (BIT), arith-
metic compare test (CMP), and byte test (TST) for zero, positive,
or negative.
The bit test allows you to test for single bit status (logic 1 or 0)
in accumulator A or B using a data mask byte supplied (immedi-
82
Table 4·4. Logic Instruction Op Codes
6809 Addressing Mode
Instructionl Inherent Direct Extended Immediate Indexed 5 3 2 1 0
Forms OP ru # OP ru # OP ru # OP ru # OP ru # Description H N Z V C
AND ANDA 94 4 2 B4 5 3 84 2 2 A4 4+ 2+ A /\ M-A • ~ ~ 0 •
ANDB D4 4 2 F4 5 3 C4 2 2 E4 4+ 2+ B/\M-B • ~ ~ 0 •
ANDCC 1C 3 2 CC/\ IMM-CC 1
ASL ASLA 48 2 1 8 ~ ~ ~ ~
ASLB 58 2 1 A] ~ 8 ~ ~ ~ ~
B O-OIIIIIJ] ~ 0
ASL 08 6 2 78 7 3 68 6+ 2+ M C b, bo 8 ~ ~ ~ ~
ASR ASRA 47 2 1 8 ~ ~ • ~
ASRB 57 2 1 ~ ] CCrr:Iio::IJ-o 8 ~ ~ • ~
M b, bo C
ASR 07 6 2 77 7 3 67 6+ 2+ 8 ~ ~ • ~
COM COMA 43 2 1 A-A • ~ ~ 0 1
COMB 53 2 1 B-B • ~ ~ 0 1
COM 03 6 2 73 7 3 63 6+ 2+ M-M • ~ ~ 0 1
EOR EORA 98 4 2 B8 5 3 88 2 2 A8 4+ 2+ AVM-A • ~ ~ 0 •
EORB D8 4 2 F8 5 3 C8 2 2 E8 4+ 2+ BvM-B • ~ ~ 0 •
LSL LSLA 48 2 1 • ~ ~ ~ ~
LSLB
LSL
58 2 1
08 6 2 78 7 3 68 6+ 2+
A
B
M
I C b,
~
D-OIITIIIJ ~
bo
0
•
•
~
~
~
~
~
~
~
~
LSR LSRA 44 2 1 A] _ • 0 ~ • ~
LSRB 54 2 1 B
M
0 -OIITIIIJ-D
b, bo C
• 0 ~ • ~
LSR 04 6 2 74 7 3 64 6+ 2+ • 0 ~ • ~
OR ORA 9A 4 2 BA 5 3 8A 2 2 AA 4+ 2+ Av M-A • ~ ~ 0 •
ORB DA 4 2 FA 5 3 CA 2 2 EA 4+ 2+ BvM-B • ~ ~ 0 •
ORCC 1A 3 2 CCv IMM-CC 7
ROL ROLA 49 2 1 • ~ ~ ~ ~
ROLB 59 2 1 • ~ ~ ~ ~
ROL 09 6 2 79 7 3 69 6+ 2+ ~ ] l{]-OIITIIIJ] • ~ ~ ~ ~
ROR RORA 46 2 1 M C b( - bo
• ~ ~ • ~
:3 RORB 56 2 1 ~lLD-~ • ~ ~ • ~
ROR 06 6 2 76 7 3 66 6+ 2+ M C b b 7 - o • ~ ~ • ~
Table 4·5. Test Instructions
Mnemonic Operation Operation Symbol
BIT BITA Bit test A AAM
BITB Bit test B BAM
CMP CMPA Compare with A A-M
CMPB Compare with B B-M
CMPD Compare with D D - M:M + 1
CMPS Compare with S S - M:M + 1
CMPU Compare with U U - M:M + 1
CMPX Compare with X X - M:M + 1
CMPY Compare with Y Y - M:M + 1
TST TSTA Test A A -0
TSTB Test B B -0
TST Test Memory M -0
84
ter. These instructions will normally be used just prior to conditional
branch instructions such as branch if plus (BPL), branch if minus
( BMI ), branch if equal zero (BEQ), and branch if not equal zero
(BNE). Note from the operation symbol that zero is subtracted from
the respective register. Only the Nand Z Hags are affected and no
result is generated with the byte test operation.
The following examples illustrate the effect of the test instructions
on the condition code register (CCR). You will observe their use in
conjunction with the branch instructions in the next chapter. You may
wish to execute these examples on a 6809-based computer and then
check the condition code register for the correct Hag status. The in-
struction op codes are supplied in Table 4-6.
Example 4-6: Using the Bit Test (BIT) Instruction
Suppose that you wish to check the logic status of bit 6 in accumula-
tor A. Which test instruction is required and what would be the
correct data mask byte?
To test for bit status in accumulator A you would use the BITA
instruction. The mask byte must be 010000002 or 4016 to check for
bit 6 status. Note that all other bit positions in the mask byte are
"masked out" with zeros. Therefore the proper instruction listing
would be:
BITA #
40
85
CICl
ca
87
Table 4·7. Performing Additional Arithmetic, Logic, and Test
Operations With 6809 Instructions
Arithmetic
Operations Instructions
Add A to B PSHS A
(A + B-B) AOOB ,S+
Add X to 0 PSHS X
(X + 0-+0) AOOO ,S++
Add 0 to X LEAX O,X
(0 + X-X)
Add Y to X EXG O,Y
(Y + X-X) LEAX O,X
EXG O,Y
Decrement 0 EXG O,X
(0 -1-0) LEAX -1,X
EXG O,X
Increment 0 EXG O,X
(0 + 1-0) LEAX 1,X
EXG O,X
r:iegate 0 COMA
(0 + 1-0) COMB
AOOO #
01
tiegate X EXG O,X
(X + 1-X) COMA
COMB
AOOO #
01
EXG O,X
Subtract X from 0 PSHS X
(0 -X-D) SUBO ,S++
Subtract 0 from X PSHS 0
(X - O-X) COMA
COMB
AOOO #
01
LEAX O,X
PULS 0
Logic Operations Instructions
AND B to A PSHS B
(BAA-A) ANOA ,S+
AND A to B PSHS A
(AAB-B) AN DB ,S+
Arithmetic shift left 0 ASLB
ROLA
Logic shift right 0 LSRA
RORB
Test Operations Instructions
Bit test B to A PSHS B
(B/\A) BITA ,S+
Compare B to A PSHS B
(A- B) CMPA ,S+
Compare A to B PSHS A
(B-A) CMPB ,S+
Compare Y to X PSHS Y
(X -V) CMPX ,S++
88
REVIEW QUESTIONS
1. What is the diHerence between ABX and LEAX B, X?
3. Which 6809 arithmetic instruction will allow you to convert an 8-bit signed
number in accumulator B to a 16-bit signed number in accumulator D?
4. Write an instruction sequence which will compute the U stack pointer with
the product of accumulators A and B. Then, stack all the internal register
contents on the U stack defined by this pointer.
5. Write the correct op-code listing for the instruction sequence in Question 4.
7. What is the diHerence between arithmetic shift left (ASL) and logic shift
left (LSL)?
89
9. How would you clear a CCR flag bit?
90
17. Which CCR Hags are affected by the CMP instruction?
18. What can be tested with the TST instruction and what does the test
indicate?
20. Determine the CCR Hag status after execution of the following instruc-
tions (assume accumulator A contains 5F):
a. BITA # b. CMPA c. TSTA
20 5F
ANSWERS
1. ABX is an inherent instruction which will add the unsigned contents of
accumulator B to the X register. LEAX B, X is a 2-byte instruction which
will add the signed contents of accumulator B to the X register.
2. To facilitate multiprecision (multibyte) multiplication operations.
3. Signed extend (SEX)
4. MUL
TFR D, U
PSHU CC, A, B, DP, X, Y, S, PC
5. From Tables 3-2 and 4-2 and Figs. 2-7 and 3-6 the correct op-code listing
would be: .
MUL 3D
TFR D, U 1F
03
PSHU 36
FF
6. From Tables 3-2 and 4-2 the above program would require 35 MPU cycles
to execute. The MUL instruction requires 11, the TFR requires 7, and the
PSHU requires 17. Note that 5 MPU cycles plus 1 cycle for each byte
pushed are required for the PSHU instruction.
7. There is no functional difference between these two instructions.
8. The ANDCC and ORCC instructions are used to set and clear the CCR
Hags.
9. To clear a CCR Hag bit you would AND a logic 0 with the respective Hag
bit position using the ANDCC instruction.
10. To set a CCR Hag bit you would OR a logic 1 with the respective Hag bit
position using the ORCC instruction.
91
11. a. This instruction will set all the CCR flags since a logic 1 is being oRed
with all CCR bit positions.
b. This instruction will clear the F and I flags since logic Os are being
ANDed with CCR bit positions 4 and 6.
c. This instruction will not accomplish anything since logic Os are being
oRed with all the CCR flags.
12. Logic bit test (BIT), arithmetic compare test (CMP), and byte test (TST)
for zero, positive, or negative
13. To test data, affecting only the condition code register for conditional
branch purposes. No result is generated.
14. ANDing, N, Z
15. Subtract
16. Accumulators A, B, and D and any of the indexible registers (X, Y, S, U)
17. The N, Z, V, and C flags
18. The TST instruction can be used to test the contents of accumulators
A and B or any memory location for a positive, negative, or zero quantity.
19. Only the N and Z flags
20. a. The N flag will be cleared. The Z flag will be set indicating a zero result
from the ANDing operation. All other flags are not affected and might be
set or cleared as the result of some previous operation.
b. The Z flag will be set, indicating a zero result from the subtract operation.
The C flag will also set since a last carry (borrow) is generated as a
result of the twos complement operation. The N and V flags will be
cleared, and all other flags are not affected by the operation and might
be set or cleared as the result of some previous operation.
c. The N flag is cleared, indicating a positive value in accumulator A.
The Z flag is also cleared, indicating a nonzero value in accumulator A.
The V flag will always clear with the TST operation. All other flags
are not affected by the operation and might be set or cleared as the
result of some previous operation.
92
..
CHAPTER 5
INTRODUCTION
The last two instruction categories that we need to discuss are the
branch and miscellaneous instructions.
The instructions that give the 6809 decision-making capability or
intelligence are branch instructions. These instructions are normally
used after arithmetic, logic, or test instructions which set or clear the
condition code register (CCR) flags according to the result of the
operation. The branch instruction will make a decision based on the
results, as indicated by the CCR flags status. When a branch is ini-
tiated, a new address is loaded into the program counter and this
causes the program to alter its flow so that program execution con-
tinues starting at the new address specified by the branch operation.
The 6809 instruction set contains 18 branch instructions. Each of
these instructions is available in a short- or long-branch version
which utilizes relative addressing, as discussed in Chapter 2.
The last instruction category, miscellaneous, is made up of instruc-
tions that do not fit conveniently in any of the previously discussed
categories. Such instructions as jump (JMP), jump to subroutine
(JSR), software interrupt (SWI), return from interrupt (RTI), etc.,
are included in this category. Many of these instructions will be
familiar to 6800 users; however, there are a few surprises. The 6809
includes three separate software interrupts such that there will al-
ways be one available to the end user. Many 6800 firmware packages
used the one software interrupt available and left the end user with-
out this capability. The 6809 CWAI instruction replaces the 6800
93
WAI instruction. The CWAI instruction is similar to W AI; however,
it is a 2-byte instruction which allows you to clear any of the CCR
flags. Finally, the 6809 instruction set includes an instruction that
will allow you to synchronize the system software to an external
hardware process. This instruction is called SYNC and should prove
valuable in large system applications where rapid data transfers are
common.
OBJECTIVES
At the end of this chapter you will be able to do the following:
BRANCH INSTRUCTIONS
The 6809 branch instructions are listed in Table 5-1. All of the
6809 branch instructions use relative addressing (refer to Chapter
2). Branch instructions can be divided into two general categories:
unconditional branches and conditional branches.
The unconditional branch is one that causes the program to
branch (or not branch) regardless of any conditions. In the 6809
these branches are the branch always (BRA), branch to subroutine
( BSR), and branch never (BRN) instructions. The BRA and BSR
instructions will cause the 6809 to branch to the destination address
94
Table 5-1. 6809 Branch Instructions
Mnemonic Operation Branch Test
BCS BCS Branch if the carry (C) flag is set C= 1
lBCS
BEQ BEQ Branch if the register contents are Z= 1
lBEQ equal to the memory contents
(Z flag set)
BGE BGE Branch if the signedregistercontents N'tV=O
lBGE are greaterthan orequalto the signed
memory contents
BGT BGT Branch if the signed reg ister contents Z v (N 'I V) = 0
lBGT are greater than the signed memory
contents
BHI BHI Branch if the unsigned register con- CvZ=O
lBHI tents are higher than the unsigned
memory contents
BHS BHS Branch if the unsigned register con- C=O
lBHS tents are higher than or the same as
the unsigned memory contents
BlE BlE Branch ifthe signed register contents Z v (N 't V) = 1
lBlE are less than or equal to the signed
memory contents
BlO BlO Branch if the unsigned register con- C= 1
lBlO tents are lower than the unsigned
memory contents
BlS BlS Branch if the unsigned register con- C vZ = 1
lBlS tents are lower than or the same as
the unsigned memory contents
BlT BlT Branch if the signed register contents
lBlT are less than the signed memory
contents
BMI BMI Branch if minus (N flag set) N= 1
lBMI
BNE BNE Branch if the register contents Z=O
lBNE are not equal to the memory contents
(Z flag cleared)
BPl BPl Branch if plus (N flag cleared) N =0
lBPl
BRA BRA Branch always (unconditional) None
lBRA
BRN BRN Branch never None
lBRN
BSR BSR Branch to subroutine None
lBSR
BVC BVC Branch if the overflow (V) flag is V =0
lVBC cleared
BVS BVS Branch if the overflow (V) flag is set V=1
lBVS
95
regardless of any conditions. However, the BSR instruction is used
to call subroutines with the program counter's contents being saved
on the hardware (S) stack such that proper return to the main pro-
gram is accomplished. This instruction is very similar to the jump to
subroutine (JSR) instruction to be discussed shortly. The BRN in-
struction is new and was not available in the 6800. This instruction
is actually a 2- or 4-byte no-operation (NOP) instruction. The 6809
will cycle through the instruction byte ( s) and relative address offset
without altering its execution. On the surface you might think this is
a meaningless instruction and wonder why it was included in the
6809 instruction set. You can, however, bury or hide an instruction
op code as the relative address offset. For example, when the 6809
first cycles through the BRN instruction, it will read the buried (hid-
den) op code as a relative address offset and no operation will result.
Then, later in the program, you can jump back to the buried (hid-
den) op code for its execution. This saves programming steps and
is a useful trick to remember.
The remaining 6809 branch instructions are conditional branches.
The conditional branch is one which is dependent upon some condi-
tion as indicated by the condition code register. If the condition is
met, the branch will occur. If not, the program will continue to the
next sequential instruction without branching. Conditional branch
instructions will normally be used after one of the test or arithmetic/
logic instructions discussed in Chapter 4. However, these instruc-
tions can be used after any instruction that operates on a register,
setting or clearing the condition code register flags according to the
result of the operation. The branch will occur (or not occur) based
on the condition code register flag ( s) status at the time the condi-
tional branch instruction is encountered. Several of the conditional
branch instructions, such as the BEQ, BNE, BCS, BCC, BVS, and
BVC, involve a simple check of one of the condition code register's
status flags, and are obvious. For example, BEQ/BNE is a direct
check of the Z-flag status. We will refer to these as simple branches.
The remaining conditional branches can be subdivided into two
categories, signed conditional branches and unsigned conditional
branches. The signed branches are used when operating on twos
complement data. Unsigned branches are used for operating on non-
twos-complement data. The unsigned branches are not, in general,
useful after instructions such as LD, ST, INC, DEC, TST, CLR, or
COM.
Note from Table 5-1 that both the signed and unsigned branches
cause the program to alter its execution as the result of some logical
combination of the condition code register flags.
Finally, Table 5-2 lists the three categories of conditional branch
instructions just discussed, that is, simple, signed and unsigned. In
96
Table 5-2. 6809 Conditional Branch Instructions
Simple Conditional Branches
Condition Complement Condition
BEQ BNE
BMI BPL
BCS BCC
BVS BVC
Signed Conditional Branches
Condition Complement Condition
BGT BLE
BGE BLT
BEQ BNE
Unsigned Conditional Branches
Condition Complement Condition
BHI BLS
BHS BLO
BEQ BNE
97
Table 5·3. Branch Instruction Op Codes
Instructionl Relative 5 3 2 1 0
Forms OP ,,-,' # Description H N Z V C
BCC BCC
LBCC
24
10
24
3
5(6)
2
4
Branch C =0
Long branch
C=O
·· ·· ·· ·· ··
BCS BCS
LBCS
25
10
25
3
5(6)
2
4
Branch C = 1
Long branch
C=1
·· ·· ·· ·· ··
BEQ BEQ
LBEQ
27
10
27
3
5(6)
2
4
Branch Z = 1
Long branch
Z=1
·· ·• ·· ·· ··
BGE BGE
LBGE
2C
10
2C
3
5(6)
2
4
Branch ;;?;zero
Long branch ;;?;
zero ·· ·· ·· ·· ··
BGT BGT
LBGT
2E
10
2E
3
5(6)
2
4
Branch >zero
Long branch>
zero
·· ·· ·· ·· ··
BHI BHI
LBHI
22
10
22
3
5(6)
2
4
Branch higher
Long branch
higher
·· ·· ·· ·· ··
BHS BHS 24 3 2 Branch higher
or same · · · · ·
LBHS 10
24
5(6) 4 Long branch
higher or same · · · · ·
·· ·· ·· ·· ··
BLO BLO 25 3 2 Branch lower
LBLO 10 5(6) 4 Long branch
25 lower
BLS BLS 23 3 2 Branch lower
or same · · · · ·
LBLS 10
23
5(6) 4 Long branch
lower or same · · · ·• ·
·· ·· ·· ··
BLT BLT 20 3 2 Branch <zero
LBLT 10
20
5(6) 4 Long branch <
zero ·
·· ·· ·· ·· ··•
BMI BMI 2B 3 2 Branch minus
LBMI 10 5(6) 4 Long branch
2B minus
BNE BNE
LBNE
26
10
26
3
5(6)
2
4
Branch Z = 0
Long branch
Z=O
·· ·· ·· ·· ·
BPL BPL
LBPL
2A
10
2A
3
5(6)
2
4
Branch plus
Long branch
plus
·· ·· ·· ··• ··
·· ·· ·· ··
BRA BRA 20 3 2 Branch always
LBRA 16 5 3 Long branch
always ·
·· ·· ·· ··• ··•
BRN BRN 21 3 2 Branch never
LBRN 10 5 4 Long branch
21 never
BSR BSR 80 7 2 Branch to • • •
subroutine
LBSR 17 9 3 Long branch to
subroutine · · · · ·
BVC BVC
LBVC
28
10
28
3
5(6)
2
4
Branch V = 0
Long branch
V =0
·· ·· ·· ·· ··
BVS BVS
LBVS
29
10
29
3
5(6)
2
4
Branch V = 1
Long branch
V=1
·· ·· ·· ·· ··
98
tion. After decrementing, the Y register is compared immediately to
0000. Recall that the compare operation subtracts its operand from
the specified register (Y in this case) and sets or clears the condition
code register flags accordingly. In this example you are concerned
with the Z flag and it will be set only when the Y register contents
are 0000. The BNE instruction will cause the program to branch
back to the LEAY instruction until the Z flag is set. Therefore, the
program will loop until the Y register is decremented down to zero.
This type of routine can be used to create time delays within your
program. You might want to verify the correct relative address offset
( F8) for the BNE instruction by counting the number of bytes re-
quired by each instruction in the loop.
Example 5-2: Using the BLT Instruction
Suppose that the 6809 encounters the following instruction se-
quence:
CMPA, x+
[ BLT
FC
LDB,-X
99
tents are less than the unsigned memory contents. Thus the program
would be searching consecutive memory locations for a value which
is less than or equal to the existing unsigned contents of accumula~
tor A.
Example 5-4: Character Search
Suppose you wish to search a memory table of 3210 (2016 ) characters
for a specific character. Once that character is found, you will store
its address in the Y register. This character you wish to locate is an
"S," which has an ASCII representation of 5316 • The character table
begins at memory location 0100.
The instruction sequence in Fig. 5-1 win accomplish the character
search. Note that no instruction addresses need to be specified. Thus
LOA #
53 Load character to find
LOX #
01 Load beginning table address
00
LOB # Load length of table
20
MPA'X+ Same character?
BEa
If no, compare next 05 If yes, save character
1
character OECB address in V-register
[ BNE
F9
CWAI
LEA~-l,X
CWAI
00
100
J
LDA#
08 Load control byte
LDX #
00 Load beginning address
10 of vector table
CLRB
LBRN
DDB#
02
LSRA
[ BCC
If carry clear, check FB ~ If carry set, vector
next bit position JMP[B,Xj.............J to proper table
purposes, that bit 3 of the control byte is set and the eight vectors
are located in sixteen (2 bytes per vector) consecutive memory loca-
tions beginning at address 0100. (Therefore the vector we wish to
access is located at address 0106.) Write an instruction sequence
which will access the proper vector, based on the control byte, and
transfer the program execution to the corresponding table.
The instruction sequence in Fig. 5-2 will accomplish the given
task. The control byte is first loaded into accumulator A. Then the
index register is loaded with 0100, which is the beginning address
of the vector table. Accumulator B will be used as a constant offset
to locate the proper vector. Each time a control byte bit is tested via
the LSRA and BCC instructions, accumulator B will be incremented
by 2. Therefore, since bit 3 of the control byte is set, accumulator B
will contain 0616 when the branch loop is broken. Thus the vector
at address 0100 + 06, or 0106, will be accessed by the JMP instruc-
tion. By using indirect addressing with the JMP instruction, program
control will be transferred to the table which is "pointed to" by the
vector located at address 0106. Note the significance of the long
branch never instruction (LBRN). The ADDB instruction is not
executed the first time through the routine, since it forms the relative
address offset of the LBRN instruction. However, if the C Hag is clear
after the LSRA instruction, the routine will branch back to execute
the buried (hidden) op code (ADDB). This will allow the begin-
ning address of the vector table to be initially loaded into the X reg-
ister, rather than an address which is two less than the beginning
vector table address. Think about it! This is an excellent example of
using the BRN instruction to hide or bury an instruction op code.
MISCELLANEOUS INSTRUCTIONS
The remaining instructions in the 6809 instruction set we have
categorized as miscellaneous, since they do not fit into any of the
101
Table 5-4. 6809 Miscellaneous Instructions
Mnemonic Operation Operation Symbol
CWAI AND CC, then wait CC /\ 1M M-+CC
for interrupt Wait for interrupt
JMP Jump EA-+PC
JSR Jump to subroutine None
NOP No operation None
RTI Return from interrupt None
RTS Return from subroutine None
SWI SWI1 Software interrupt 1 None
SWI2 Software interrupt 2 None
SWI3 Software interrupt 3 None
SYNC Synchronize to interrupt None
102
( CWAI )
S-12 CC
t-----,
S-11 A
S-10 t----::'8----1
S-9 DP
S-8 XH
S-7 Xl
S-6 YH
S-5 Yl
S-4 UH
S-3 Ul
S-2 PC H
STACK 6809
REGISTER S-l PCl
CONTENTS S
RESET NMI
SEQUENCE SEQUENCE
YES YES
shown in Fig. 5-3. When the 6809 encounters the CWAI instruction,
it ANDS the CWAI data byte with the contents of the condition code
register, placing the result in the condition code register. Then the
E Hag of the condition code register is set. Why? The E Hag is set
since the next operation is to stack all the internal register contents
in the S stack. Recall that the E Hag is used for unstacking purposes
to tell the 6809 that, when set (logic 1), all the registers (except S)
have been stacked by a previous stacking operation. Note from Fig.
5-3 that the order of register stacking is the same as for the PSH and
PUL instructions discussed in Chapter 4. This stacking order is the
same for all the automatic stacking operations that the 6809 per-
forms. After the internal registers are stacked on the S stack, the 6809
enters a wait loop. The wait loop may be broken only by any of the
four hardware interrupts-RESET, NMI, IRQ, or FIRQ. Note from
Fig. 5-3 that the I Hag in the condition code register must be cleared
to allow the IRQ interrupt to break the wait loop, and the F Hag
103
must be cleared to allow the FIRQ interrupt to break the loop. The
CWAI ANDing operation will allow you to have some control over
the "breaking" of the wait loop. For example, setting the I flag just
prior to CWAI and using a 1016 CWAI data byte to preserve the I
flag's status will prevent an IRQ interrupt from breaking the wait
loop. The same can be done with the F flag to prevent an FIRQ
from breaking the wait loop. On the other hand, you can use CWAI
to assure that an IRQ, FIRQ, or both will be enabled. For example,
a CWAI data byte of EF 16 will enable IRQ; BF 16 will enable FIRQ;
and AF 16 will enable both IRQ and FIRQ. The hardware interrupts
will be discussed in detail in the next chapter.
Example 5-6: Executing the CWAI Instruction
Suppose the 6809 encounters the following instruction sequence:
LOA #
40
TFR A, CC
CWAI
40
104
stacked at address (E6oo16 - 12 10 ), or E5F4 16 • Verify the above re-
sults on your 6809-based system or trainer.
105
5,12 CC
5-11 A
5-10 B
5-9 DP
5-8 XH
5-7 Xl
1- E 5-6 YH
5-5 Yl
5-4 UH
5-3 Ul
5TACK 6809 5-2 PC H
REGI5TER
CONTENT5
¢ 5·1 PCl
5
1 - F,I
0- BA
1 - B5 Fig. 5·4. SWI1, SWI2, and
SWI3 sequence of events.
LOAD INTERRUPT
VECTOR INTO
PC
0- B5
INTERRUPT
SERVICE
ROUTINE
CONTINUE
RTI MAIN
PROGRAM
101
Table 5-5. Memory Map for the 6809 Interrupt Vectors
Vector Locations Vector Assignment Relative Priority
FFFO:FFF1
FFF2:FFF3
FFF4:FFF5
FFF6:FFF7
Reserved
SWI3
SWI2
FIRQ
j
Low
FFF8:FFF9 IRQ
FFFA:FFFB SWI1
FFFC:FFFD NMI
FFFE:FFFF RESET High
107
In the second case, however, the SYNC instruction can be used to
synchronize the main program with an external hardware process.
Recall that one of the main disadvantages to using interrupts is that
they are not synchronous with program execution, meaning that they
are not scheduled and can happen at any time within the main pro-
gram. The SYNC instruction provides you with a means of using in-
terrupts and at the same time allows you to schedule the interruption
for optimum system efficiency. For example, an if 0 device, such as
a high-speed disk, can use a 6809 interrupt request line (IRQ or
FIRQ) and activate the line to indicate it is ready for data transfer.
Prior to SYNC you will set the respective interrupt mask bit (lor F)
and thus mask out a normal interrupt request. But, the active if 0
device strobe will cause the next instruction to be executed instead
of the normal service routine for that interrupt. The next instruction
would begin the data transfer process and the main program would
continue. In this way the hardware and software activities are syn-
chronized and time is saved since no vectoring or stacking is in-
volved. The program in Example 5-7 illustrates this process.
Example 5-7: Using the SYNC Instruction
Suppose that you wish to load 10010 bytes of data into memory from
a disk system at a particular point in the program. The program in
Fig. 5-5 will accomplish this task.
t
(Disc Address) Transfer disk data
Get next data byte if STA,X + into 10010 consecutive
transfer not complete DECB memory locations specified
BNE by the X register
F9(8)
ANDCC # Clear I flag
00
It is assumed that the disk system is using the IRQ (interrupt re-
quest) line to initiate the data transfer. The first instruction sets the
I Hag in the condition code register to mask out any normal IRQ in-
terrupt. The SYNC instruction then halts the main program execu-
tion until the IRQ line is activated by the disk system. When acti-
vated, the main program will cause 10010 (64 16 ) bytes of data to be
stored in 10010 (6416 ) consecutive memory locations specified by the
108
Table 5·6. Miscellaneous Instruction Op Codes
JMP OE 3 2 7E 4 3 6E 3+ 2+
JSR 90 7 2 80 8 3 AD 7+ 2+
NOP 12 2 1
SWI SWI 3F 19 1
SWI2 10 20 2
3F
SWI3 11 20 2 Software Interrupt 3 •
3F
SYNC 13 ..2 1 Synchronize to
Interrupt
RTI 38 6/15 1 Return from 7
Interrupt
RTS 39 5 1 Return from
subroutine
...
i
X register using auto-increment indexed addressing. The main pro-
gram then clears the I flag and continues. If, during the sync state,
an emergency situation developed, any of the other hardware inter-
rupts (NMI, FIRQ, RESET) could be used to break the sync state.
The miscellaneous instruction op codes are listed in Table 5-6. A
complete description of all the 6809 instructions is provided in Ap-
pendix A, and a 6809 instruction set summary is provided in the last
appendix for quick reference.
Finally, as you are now probably aware, many of the 6800 instruc-
tion mnemonics are not included in the 6809 instruction set. For run-
ing 6800 software on 6809-based systems, the translations provided
in Table 5-7 can be made to provide functionally equivalent 6809
operations. Some of these translations have already been discussed.
This completes the discussion of the 6809 software. Before going
on, it is important that you understand the material that has been
presented in the last five chapters, especially the addressing modes
110
(Chapter 2). If you still feel uncomfortable with programming the
6809, go over the material again. If at all possible, obtain a 6809-
based system or trainer to get some "hands-on" programming experi-
ence. Run the examples presented here on the system and make up
your own short routines. The more programming practice you get,
the better you'll understand how to use the 6809.
REVIEW QUESTIONS
and _
4. BLO can be replaced with since the branch test is the same
for both branches.
111
8. Why is the E flag of the condition code register set during the execution
of CWAI?
9. You want to clear the I flag such that an interrupt request (IRQ) will be
acknowledged during CWAI. All other Hags should remain unchanged.
What would be the proper CWAI assembly code?
10. What 6800 code listing does the above CWAI code replace?
11. If bit 7 of the control byte in Example 5-5 were set, what vector address
would be accessed?
12. Which software interrupt automatically sets the F and I flags to mask out
FIRQ and IRQ interrupts?
17. Why is the above instruction sequence not exactly like SWI2?
112
19. What instruction could be used in lieu of RTI?
21. When in the syncing state, what will happen if an FIRQ is received and
the F flag of the condition code register is set?
22. What would happen if the F flag is cleared in the previous question?
ANSWERS
1. Branch always (BRA), branch to subroutine (BSR ) and branch never
(BRN).
2. They are similar since they are both used to call subroutines and cause
the program counter contents to be saved on the S stack. In addition,
they both require the use of RTS as the last subroutine instruction for
proper return to the main program. They are different because BSR uses
relative addressing and JSR can use direct, extended or indexed addressing.
3. Simple, signed, and unsigned
4. BCS (reference Table 5-1)
113
5. BPL,BLT,BLS
6. Position independence
7. There is no functional difference. The JMP instruction will cause the
program to branch to the same location as the BRA instruction. Note that
the JMP is using program counter relative addressing and therefore is
also position independent.
8. The E flag of the condition code register is set during the execution of
CWAI since all of the internal registers (except S) are stacked during this
operation.
9. CWAI #
EF
10. CLI
WAI
11. OOIE
12. SWIl
13. Bus status (BS) output line.
14. FFF4:FFF5
15. Absolute indirect addressing
16. SWI2
17. The E flag is not necessarily set for stacking. To set the E flag, the instruc-
tion ORCC #80 should be added prior to the PSHS instruction.
18. RTS
19. PULS ALL
20. To synchronize the main program with external hardware events such as
data transfers
21. The syncing state will be cleared and the next sequential instruction will
be executed.
22. The syncing state will be cleared and the FIRQ interrupt service routine
will be executed.
23. SYNC does not cause the 6809 registers to be stacked as does CWAI. In
addition, CWAI does not allow for external hardware synchronization as
does SYNC.
24. PSHS B
ADDA ,S+
25. LEAX -1, X
114
CHAPTER 6
6809/6809Elnput and
Output Signals
INTRODUCTION
Now that you have completed the chapters about the 6809 soft-
ware, you are ready to begin learning about the hardware aspects
of both the 6809 and 6809E. It should be pointed out at this time
that everything which has been discussed to this point will apply
to both the 6809 and 6809E, except where noted otherwise. Recall
that the 6809E is the off-chip clock version of the 6809. Thus the
differences between the two devices are in the available i/o sig-
nals and not the instruction set. Because the 6809E does not require
a crystal connection, two extra status lines are available. These two
lines will facilitate multiprocessor system applications.
In this chapter we will discuss the 6809 and 6809E i/o signals
in detail. For convenience, these signals have been broken down
into five functional categories. They are: powerIclock, datal address,
bus status, bus timing, and control. You will find that both the 6809
and 6809E provide much better capabilities in all of these categories
than did the 6800. For example, by decoding only five lines you can
determine exactly which interrupt vector is being fetched and thus
provide a complete interrupt acknowledge to an i/o device. In ad-
dition, the direct memory access (DMA) capabilities of the 6809 are
greatly enhanced over the 6800 by the addition of the DMAREQ
control line. In this chapter we will discuss three types of DMA
which are available for the 6809 and 6809E. They are: halt mode,
cycle stealing, and bus multiplexing DMA. Now, let's begin our
discussion.
115
OBJECTIVES
At the end of this chapter you will be able to do the following:
6809 PIN-OUTS
The 6809 "footprint," or pin configuration, is shown in Fig. 6-1.
As stated earlier, the 6809 is a 4O-pin HMOS (high-density NMOS)
device available in either a standard plastic package (P suffix) or
ceramic package (L suffix). In discussing the pin functions we will
divide the pin-outs into the follOwing five functional categories:
power/ clock, datal address, bus status, bus timing, and control. A
detailed discussion of each follows:
Power/Clock
As with all 6800 family devices, the 6809 requires a single +5-Vdc
±5-percent supply voltage. Maximum current drain is 200 mA, for
a maximum power dissipation of 1 watt. The two power connec-
tions are Vss at pin 1 (ground) and V DD at pin 7 (+5 Vdc ).
The 6809 has an internal clock oscillator/driver and therefore does
not require an external clock source as does the 6800. However, you
must supply an external parallel-resonant crystal between pins 38
and 39 (EXTAL and XTAL) to provide crystal control of the internal
oscillator's frequency. The standard 6809 operates with a maximum
internal frequency of 1 MHz. There is, however, an internal circuit
that divides the external crystal frequency by 4 to obtain the inter-
116
MC6809
I
A9
18
;~:
A10
A11 19 ADDRESS LINES
A12 20 A13
117
line" is what the application requires. Once a processor( s) can do
the job in the time required, processor speed ceases to be an im-
portant design consideration.
Y1 C in Coul
4MHz 24 pF 24 pF (8) Component values.
6MHz 20 pF 20 pF
8 MHz 18 pF 18 pF
'--
118
loading effect of the bus. The data lines will typically drive 130 pF
and the address lines 90 pF. Both the data and address lines are
internally three-state buffered. The particular on/ off state of any
given line is a function of the various 6809 control signals. The asso-
ciated control signals and data/address bus timing will be discussed
shortly.
Bus Status
Two of the 6809's pins are used to communicate the MPU status
to peripheral devices. They are: bus status (BS) at pin 5 and bus
available (BA) at pin 6. Bus available (BA) provides an indication
of the three-state logic status of the data, address and R/W lines.
If BA=O, the processor is running and the data, address and R/W
three-state logic is on. If BA=I, the processor is in a halt condition
and the data, address, and R/W three-state logic are off or in the
high-impedance state, thereby effectively disconnecting the proces-
sor from the external data and address buses and making those buses
available to external devices. However, BA=1 does not imply that
the datal address bus structure will be free for more than one MPU
cycle. Bus status (BS) is used together with BA to indicate the MPU
state. There are four possible logic combinations of these two lines
and thus four unique MPU states. They are: normal (or running),
interrupt acknowledge (lACK), SYNC acknowledge, and halt (or
bus grant).
The above MPU states are shown with their respective BA/ BS
logic in Table 6-1. The normal or running state is obvious and needs
no further discussion. The interrupt acknowledge (lACK) state will
provide an indication (via BA/BS) to external devices that one of
the 6809 interrupts (RESET, NMI, IRQ, FIRQ, SWIl, SWI2, or
SWI3) has been accepted. The obvious use for the lACK state is to
provide an external i/o device with an indication that its interrupt
has been accepted. This can be done with external decoding logic
to detect the BA=O, BS=1 (lACK) state. In addition, if address
lines AI, A2, and A3 are also decoded with BA/ BS, the decoding
logic can indicate exactly which interrupt has been accepted. Recall
that when an interrupt is accepted, its interrupt vector is fetched.
119
Since each interrupt has a unique vector address assignment, one
of fourteen addresses (FFF2-FFFF) will be placed on the address
bus when the vector is fetched. Thus the BA/ BS logic will indicate
that an interrupt has been accepted and address lines AI-A3 will
indicate exactly which interrupt vector is being fetched. The simple
74154 decoding circuit shown in Fig. 6-3 could be used for this
15
14
••
A3 o •
A2 C 74154 •
•
A1 B
••
A • Fig. 6-3. lACK decoding
circuit.
2
1
G1
o
G2
BA-~~--~
BS--~
120
was discussed in the previous chapter. In the next chapter you will
see how this state is decoded to provide external hardware synchro-
nization.
The halt (or bus grant) MPU state means exactly what it says.
The MPU has halted all execution and the data, address and R/ W
lines are in their high-impedance state, thus making the data and
address buses available for external use such as direct memory ac-
cess (DMA). This state will normally exist as the result of a low
level on the DMAREQ or HALT pins (to be discussed presently).
Another line which could be considered a status line is the read/
write (R/W~ line at pin 32. This line serves the same purpose as
the 6800 R/W line, that is, to indicate the direction of data transfer
on the data bus. If R/W = 1, the 6809 is performing a read opera-
tion, while R/W = 0 indicates a write operation is being performed.
This line is three-state and is placed in its high-impedance state
whenever BA = 1, indicating that the data bus is available for ex-
ternal use. Another use for the R/W line is to determine valid mem-
oryaddresses. Recall that the 6800 has a valid memory address line
(VMA) which is used to indicate the validity of addresses placed
on the address bus. You had to use this line in your external decod-
ing circuits such that all external devices were disabled if a nonvalid
address (VMA=O) existed on the address bus. The 6809 does not
have a VMA line. Instead, when the 6809 is not using the data bus
for data transfer, it will place FFFF16 on the address bus and out-
put R/W = 1 and BS = O. This will replace the 6800 VMA function
since external decoding circuits can be designed to recognize the
above conditions as a nonvalid memory address state. Note that the
nonvalid memory address condition is distinguished from a RESET
interrupt vector fetch by the bus state (BS) line, since BS = 1 for a
vector fetch.
Bus Timing
The E out (pin 34) and Qout (pin 35) lines provide external clock
signals for timing and synchronization. E out is the standard 6800
family timing signal similar to the4J2 clock signal on the 6800.
When E out goes high, this indicates to i/o devices that the address
information has been placed on the address bus to provide a suffi-
cient setup time and that data is being placed on the data bus. This
line defines the MPU cycle and should be part of any external de-
coding scheme. The Qout line is a quadrature clock signal which
leads E out by 90°. The relationship between E out and Qout is shown
in Fig. 6-4. The frequency of each equals the internal operating fre-
quency, but they are displaced by 90° and thus provide four sepa-
rate clock edges for interfacing purposes. The 6809 read/write tim-
ing diagrams are shown in Fig. 6-5. Note that address information
121
Eout
START CYCLE
_--""""\J
END CYCLE
E 2.4V
o 2.4V
RtW
ADDR
~-+----tACC - - - - - + I
DATA
MRDY
DMAIBREO
NOTVALID ~
(A) Read data from memory or peripherals.
j
E 2.4V
O.5V
o 2.4V.
O.5V
R/IN
ADDR
BA,BS
tooW-....,1
2.4V~""""""""""""""""""===~~~
DATA >--------cs:': DATA VALID
O.5V .....,............................_~H'""=n.:
NOTVALID ~
122
is valid at the leading edge of Quut with data being valid during
E out . Data, in or out, is latched with the falling edge of E out •
The memory ready (MREADY) line (pin 36) is used in conjunc-
tion with the E uut and Qout timing signals. Recall that data is valid
on the data bus as long as E out is high. For some i/o devices, espe-
cially slow memories, this is not long enough to satisfy the data
setup, access, and hold time requirements of the device. Therefore
some means must be provided to stretch the E out and Qout pulses
such that slow memories will have time to respond to the 6809's
signals. This is the function of the MREADY line. By holding
MREADY low, you can stretch the E out and Qout pulses to extend
data access time. As long as MREADY is held low, the data valid
period will be extended until the MREADY line is returned high.
However, the maximum stretch period is 10 microseconds. (A 100-
microsecond stretch period can be obtained from a special-order
6809, at a higher price.) The effect of MREADY on E out and Qout
is shown in Fig. 6-6. Some of the 6809s produced early in the prod-
uct cycle (mask numbers G7F, T5A, P6F, and T6j\1) require that
the MREADY signal be synchronized with the crystal frequency.
Consult the 6809 specification in Appendix C for a synchronization
circuit, if you have one of these earlier devices.
I
,MAXIMUM
10p.s j
I ,~i
\_---~
r
MREADY
\\\\\\\\
Fig. 6·6. Effects of MREADY on E ont and Onnt.
Control
The remaining 6809 pins are used for control purposes. Our dis-
cussion will begin with HALT and DMAREQ and end with the
6809 hardware interrupts. The HALT pin provides for a hardware
salt of the 6809 operation. When you supply a logic 0 state to
pin 40, the 6809 will stop running at the end of the current instruc-
tion. When this happens the three-state buffers on the data, ad-
dress, and R/W lines will go into their high-impedance state and
effectively disconnect the 6809 from the external data and address
buses. As long as a low level exists at pin 40, the 6809 will remain
halted without any loss of internal register data, the E ollt and Qout
bus timing signals will continue normal operation, and the BA/BS
123
logic will indicate the HALT' MPU state. When halted, the 6809
will not respond to any external control~s ex~ DMAREQ
(to be discussed shortly). However, if RESET or NMI interrupts
are received, they will be latched for execution after the halt mode.
The HALT function is normally used for hardware troubleshooting
and program debugging, since it allows an external device to con-
trol program execution one step at a time. It can also be used for a
halt mode direct memory access (DMA), since an external device
can gain control of the external buses. When not in use, you can
connect the HALT pin to the +5-volt dc supply for uninterrupted
system operation.
DMAREQ (pin 33) provides for another external method of stop-
ping the 6809. This line will normally be used to allow fast access
to the bus for direct memory access (DMA) or dynamic memory
refresh. It is appropriate at this time to say a few words about di-
rect memory access. This technique provides a means for high-speed
data transfers directly between a peripheral device, such as a Hoppy
disc, and memory without going through the MPU. The direct mem-
ory access function is normally controlled by a single-chip direct
memory access controller (DMAC). The DMAC takes bus control
away from the MPU and controls the data transfer directly between
memory and a selected peripheral device. The Motorola 6800 fam-
ily DMAC is the MC6844.
With the 6809, DMA can be performed by one of three methods.
They are: halt mode, cycle stealing, and bus multiplexing. With
halt-mode DMA the DMAC pulls the 6809 HALT pin low and takes
control of the address and data buses. The 6809 remains halted un-
til the data transfer is completed. The bus timing signals (E011t and
QOllt) will continue to provide timing for the data transfer. Cycle-
stealing DMA is accomplished when the DMAC pulls the DMAREQ
line (pin 33) low. When this happens the 6809 will stop instruction
execution at the end of the current cycle and acknowledge the DMA
request by setting both the BA and BS bus status lines. The 6809
address, data, and R/W lines will then be placed in the high-imped-
ance state and the DMAC can then take control of the bus structure.
The DMAC will have up to fifteen MPU cycles for data transfer
before the 6809 will automatically steal the bus structure for one
MPU cycle to refresh the internal MPU registers. When this hap-
pens the BA line will be cleared to signal the DMAC to get off the
bus structure. After one cycle, control will be transferred back to
the DMAC, provided that the DMAREQ line (pin 33) is still held
low. This process will be repeated until DMAREQ is returned to
a high (logic 1) level. The DMAREQ sequence of events is sum-
marized in Fig. 6-7. The third method of D MA, bus multiplexing,
provides that DMA peripheral devices be gated onto the bus struc-
124
Fig. 6·7. DMAREQ sequence
of events.
125
hue when E is low (MPU data not valid). With this method the
Ollt
6809 shares the bus structure (50/50) with the DMA peripheral
devices. This method is less efficient than the other two and requires
more external decoding logic. Therefore it is less often used. Con-
sult the 6809 specification in Appendix C for halt-mode (HALT)
and cycle-stealing (DMAREQ) timing diagrams. In a typical ap-
plication, DMA peripherals such as floppy discs would use the halt-
mode of DMA, with the cycle-stealing DMA used to refresh dy-
namic memory. Dynamic memory devices require refreshing every
2 milliseconds and are very high priority. Recall that the 6809 will
respond to DMAREQ when in the halt mode.
The last four 6809 pins that remain to be discussed represent the
four 6809 hardware interrupts: RESET, non-maskable interrupt
( NMI ), fast interrupt request ( FIRQ ), and interrupt request
(IRQ). Refer to Fig. 6-1 for their respective pin assignments. All
but one of these should be familiar to 6800 users. The new kid on
the block is ,FIRQ, and our previous discussions have introduced
you to this one. Now, let's discuss each interrupt in more detail.
First, note from Fig. 6-1 that they are all "barred" ( - - ), meaning
that they are all active low. However, only NMI is edge triggered
and thus activated by a high-to~low transition on pin 2. The other
three (RESET, FIRQ, and IRQ) are all level triggered and must
remain low for at least one MPU cycle to be properly clocked or
sensed by the 6809.
RESET is used to initialize or restart the system. It provides a
starting point for program execution by placing the address of the
first instruction to be executed in the program counter. A reset sub-
routine, located in ROM, will be required to perform the initiali-
zation task. Reset is always required after power is applied to the
system and should be held low until the internal clock oscillator is
fully operational, and then released. Recall that it may take up to
20 milliseconds for the internal clock to become operational. This
is not normally a problem with a manual reset; however, it must be
considered for automatic resets. The RESET pin uses a Schmitt-
trigger input and therefore a simple RC network can be used to
reset the system. However, this Schmitt-trigger input requires a
minimum of 4.0 Vde to represent a high (logic 1) level, whereas
other 6809 signals may use the standard TTL-compatible 2.4 Vdc
as a minimum value to represent a higU!ogic 1) state. An advan-
tage of using an RC network on the RESET input is that, because
of the RC time constant, other peripheral devices will have had
enough time to completely reset themselves before the 6809 com-
pletes its reset routine and begins any peripheral initialization rou-
tines. For example, when the 6809 starts up and initializes a pe-
ripheral interface adapter (PIA), you can be assured that the PIA
126
Fig. 6·8. RESET sequence
of events.
127
S-12 CC
NMI S-11 A
S-10 B
! S-9
S-8
S-7
DP
XH
XL
1 - E S-6 YH
S-5 YL
~
S-4 UH
S-3 UL
STACK 6809 S-2 PC H
REGISTER
CONTENTS
Q S-1 PCL
S
!
1 - F,I
!
0- BA Fi~ 6·9. NMI sequence
1 - BS
of events.
!
FETCH
INTERRUPT
VECTOR
(FFFC:FFFD)
!
0- BS
~
NMI
SERVICE
ROUTINE
!
MAIN
RTI PROGRAM
All of the other hardware interrupts (NMI, IRQ, and FIRQ) are
either masked out or disarmed. However, if a non-maskable inter-
rupt (NMI) occurs during the reset sequence, its active edge will
be latched (saved) and the NMi sequence of events (Fig. 6-9)
will be executed immediately after any instruction which loads the
128
S register (LDS; EXG R, S; TFR R, S; LEAS 1, X; etc.). The only
event which can inter~he reset sequence is a HALT or
DMAREQ. If no active HALT or DMAREQ exists, the bus status
signals, BA and BS, will be cleared to indicate the MPU-running
state. When RESET goes back high (to 4.0 volts) the bus status
signals ~ill indicate an interrupt acknowledge (BA=O, BS=l). The
RESET interrupt vector will then be fetched from address FFFE:
FFFF, BS will be cleared to indicate the MPU-running state and
the reset interrupt service routine will be executed. Now, if HALT
or DMAREQ is active during the initial reset sequence, the halt-
mode or cycle-stealing mode of DMA will take place. If RESET
goes back high during a DMA operation, the 6809 will complete
the reset sequence after the DMA operation is completed. Note:
HALT or DMAREQ may interrupt the reset sequence; however,
RESET will not interrupt HALT or DMAREQ.
The 6809 non-maskable interrupt (NMI) is very similar to the
6800 NMI. As the name implies, this inter~cannot be masked
by the programmer. The only time that an NMI is not accepted is
during the reset operation. Recall from our discussion of RESET
that the NMI logic is disarmed during the reset sequence. How-
ever, any NMI occurring during the reset operation will be latched
( saved), with the NMI sequence occurring after the first load into
the S register. In addition, if a non-maskable interrupt occurs dur-
ing the HALT operation, the active NMI state will be latched and
the NMI sequence will not be executed until after the MPU is re-
leased from the HALT state. The NMI sequence of events is
shown in Fig. 6-9. The E Hag is set to indicate that all of the internal
registers are to be stacked. The registers are then stacked in the
order shown. The F and I Hags are set to mask out any FIRQ or
IRQ (maskable) interrupts such that the NMI sequence will not be
interrupted by a maskable-type interrupt. However, another active
NMI could interrupt an existing NMI sequence since NMI is not
masked by the execution of the NMi sequence. If this is allowed
to occur repeatedly before the sequence can be completed, the
stack will definitely overHow. When the NMI interrupt vector is
fetched at address FFFC:FFFD, the bus status lines (BAIBS)
indicate an interrupt acknowledge (lACK). Once the vector is
fetched and loaded into the program counter, the bus status (BS)
line is cleared to indicate the normal MPU running state and the
NMI interrupt service routine is executed. When the service rou-
tine has been completed, execution must be directed back to the
main program. This is done by inserting a return from interrupt
(RTI) instruction as the last instruction in the interrupt service
routine. The RTI returns the 6809 to its previous status by unstack-
ing the old register contents.
129
S 12 CC
--t
IRQ S-11 A
S-10 B
t
S-9 DP
S-8 XH
S-7 Xl
1 - E S-6 YH
S-5 Yl
UH
!
S-4
S-3 Ul
S-2 PC H
STACK 6809
REGISTER
CONTENTS
Q S-1
S
PCl
!
1 - I
t
0- BA Fig. 6-10. IRQ sequence
1 - BS of events.
t
FETCH
INTERRUPT
VECTOR
(FFF8:FFF9)
~
0- BS
~
IRQ
SERVICE
ROUTINE
~
MAIN
RTI PROGRAM
130
If the I Hag is cleared (logic 0), the interrupt will be accepted.
On~ccepted, the sequence of events for IRQ is similar to that
of NMI. The E Hag is set and all of the internal registers are stacked
on the S stack in the order shown. Then, the I Hag is set to mask out
any further IRQs until the present sequence is completed. Note,
however, that the F Hag is not set and therefore the IRQ sequence
may be interrupted by a fast interrupt request (FIRQ). You can
therefore conclude that FIRQ is of higher priority than TIITJ. When
the IRQ interrupt vector is fetched at address FFF8:FFF9, the bus
status lines indicate an interrupt acknowledge (lACK) MPU state.
Once the vector has been fetched, the bus status (BS) line is cleared
to indicate the normal running MPU state and the IRQ interrupt
service routine is executed. Again, you must use the RTI instruction
at the end of your interrupt service routine to get back to the main
program.
The sequence of events for FIRQ is shown in Fig. 6-11. Note the
differences from the IRQ sequence (Fig. 6-10). The E Hag is cleared
to indicate that only the program counter and condition code reg-
ister are to be stacked. Both the F and I H~are set such that !he
sequence will not be interrupted by any IRQs or further FIRQs.
However, your interr~ service routine could clear the I Hag if
the automatic FIRQ/IRQ priority was not desired. The remaining
events are the same as those of the IRQ sequence except that the
FIRQ interrupt vector is located at address FFF6: FFF7. As stated
earlier, the advantage of FIRQ over IRQ is in saving time when all
the internal register data need not be saved during the interrupt.
If additional register data need to be saved, you can always use
PSHS/PULS in your FIRQ interrupt service routine.
6809E PIN-OUTS
The 6809E, sister to the 6809, is also a 40-pin HMOS device and
is available in either a plastic (P) package or ceramic (L) package.
This device is intended primarily for multiprocessor system use,
since it provides extra signal lines for additional MPU status infor-
mation. An example of the 6809E's use in a multiprocessor system
will he given in the next chapter. The 6809E footprint is shown in
Fig. 6-12. Two extra signal lines (BUSY and LIC) are provided in
lieu of the standard 6809 crystal connect pins (XTAL and EXTAL).
Moreover, the 6809E includes an advanced valid memory address
( AVMA) line in place of the 6809 memory ready (MREADY) line
and a three-state control (TSC) line replaces the 6809 DMAREQ
line. As stated earlier, the 6809E is an off-chip clock version of the
6809. Therefore you must supply the required E in and Qin clock
signals at pins 34 and 35, respectively. The phase relationship be-
131
FIRQ
!
0- E
! S-3
S-2
CC
PC H
STACK
PC,CC c> S·1
S
PCl
!
1 - F,I
~
0- BA
1 - BS Fig. 6-11. FIRQ sequence
of events.
!
FETCH
INTERRUPT
VECTOR
(FFF6:FFF7)
!
0- BS
!
FIRQ
SERVICE
ROUTINE
!
MAIN
RTI
PROGRAM
tween E in and Qin is the same as that of E out and Qout for the stan-
dard 6809 (Refer to Fig. 6-4). The Qin pin (pin 35) is fully TTL
compatible. However, the E in pin (pin 34) drives internal MOS
circuits which require levels which are above and below normal
TTL values. Fig. 6-13 shows a circuit which will provide the proper
132
MC6809E
(V ss ) GROUND HALT
(NMI) NON-MASKABLE INTERRUPT TSC
(IRQ) INTERRUPT REQUEST (L1C) LAST INSTRUCTION CYCLE
(FIRQ) FAST INTERRUPT REQUEST 4..--------, RESET
(BS) BUS STATUS 5 '-------' (AVMA) VALID MEMORY ADDRESS
(BA) BUS AVAILABLE 6..--------, Ein
Y
(V OO ) + 5-VOLT POWER 7 '-------' Q out
AO 8..---------, BUSY
S
A1 9 '-------' R/W
A2 10 DO
U
A3 11 1·....- - - - ' 01
A4 12 02
PC
1 ' - - - - -.....
A5 13 03
14
04 DATA LINES
ADDRESS LINES A6
A7 15 05
A8 16 06
:::I
A9 17 07
A10 18
A11 19 ADDRESS LINES
A12 20 A13
Ein/Qin phase relationships and levels from one oscillator. The Einl
Qin lines from this circuit can be applied directly to pins 34 and 35,
respectively, of the 6809E. The EoutlQout lines will provide the
I
I 4f c OSC
I
J Q J Q
+5V
L-.c 74LS73(A) L-.c 74LS73(B)
680fl
~K Q K Q
I 74LS04
Ein
I ,
J '---
Qjn
If \
I r\
138
proper TTL signals for external timing. Note that the oscillator
frequency is four times the desired clock frequency (fe ). The clock
frequency obtained from this circuit will drive the 6809E directly
and is not divided by 4 with internal 6809E logic. The standard
operating frequency for the 6809E is 1 MHz (f e = 1 MHz). How-
ever, the 6809E is also available in 1.5-MHz (68A09E) and 2-MHz
(68B09E) versions.
Two additional status lines, BUSY (pin 33) and last instruction
cycle (LIC, pin 38) are provided with the 6809E. The BUSY out-
put line indicates that the 6809E is accessing memory. This line will
be high through the entire read/ write cycle, then return low when
the cycle is completed. In multiprocessor systems this signal is used
to supervise the system, so that only one processor has access to
global memory or peripheral devices at a given time.
134
earlier, there is no difference between the 6809E and 6809 instruc-
tion sets.
That concludes our discussion of the 6809/6809E hardware. In
the next chapter some interfacing hints and ideas as well as some
special applications of both the 6809 and 6809E will be given.
REVIEW QUESTIONS
1. A 3.2·MHz crystal would provide a 6809 internal clock frequency of
2. How must the XTAL and EXTAL pins be connected to drive the 6809 with
an external TTL or CMOS clock signal?
9. Which 74154 output line would be active in Fig. 6·3 for the conditions
given in Question 8?
135
10. Which MPU state will be indicated on the bus status lines when a low
level (logic 0) is applied to the DMAREQ pin?
12. How is the nonvalid memory address state distinguished from a RESET
interrupt vector fetch?
13. What is the relationship between EOll t (E in) and QOll t (Q in) ?
16. What will happen if a non-maskable interrupt (NMI) occurs when a low
level is being applied to the HALT pin?
17. What will happen if a low level is applied to the DMAREQ pin when the
HALT pin is low?
136
20. Using the DMAREQ line for cycle-stealing DMA, the MPU will steal the
_~ _ _ interrupt.
22. How long should RESET be held low when power is applied to the
system?
and .
26. What are the diHerences between the IRQ and FIRQ sequences of events?
_ _ _ _-), and _
30. The 6809E line which is similar to the 6809 DMAREQ line is _
ANSWERS
1. 0.8 MHz
137
2. The TTL or CMOS signal is applied to EXTAL with XTAL connected to
ground. The applied frequency must be four times the desired clock fre-
quency.
3. Processor throughput
4. One standard Schottky TTL load plus eight 6800 family devices at the
rated bus speed
5. Bus available (BA), bus status (BS), read/write (R/W)
6. High
7. Normal, interrupt acknowledge (lACK), SYNC acknowledge and halt/bus
grant
8. BA=O and BS=1 represents the interrupt acknowledge (lACK) MPU
state and indicates that an interrupt vector is being fetched. Since A3 A2 Al
= 1102, the lower four address lines (A3 A2 Al AO) will represent either
11002 (C16) or 110116 (D16). In either case the non-maskable interrupt
(NMI) vector is being fetched. Note the status of AO does not have to be
known to decode the proper interrupt vector.
9. Line 12
10. Halt/bus grant
11. Address lines AO-A15 are all high (FFFF16), R/W = 1, and BS = 0
12. BS=O for a nonvalid memory address and BS=1 for a RESET interrupt
vector fetch
13. Eont (Eln) is similar to the 6800 <1>2 clock. Qont (Qln) is called the quadra-
ture clock. Eont (E 1n ) and Qont (Qln) are all the same frequency; however,
Qont (Qin) leads Eont (E 1n ) by 90° or ~~ clock cycle.
14. When E ont (Eln) is at a logic 1 level (high)
15. To stretch the Eont and Qont pulses a maximum of 10 microseconds such that
slow peripheral devices will have time to respond to the 6809's signals.
16. The HALT state will not be interrupted. However, the active NMI state
will be latched and the NMI sequence will be executed when the HALT
pin returns high.
17. The DMAREQ sequence of events (Fig. 6-7) will be executed.
18. Direct memory access controller (DMAC), MC6844
19. Halt-mode (HALT pin), cycle-stealing (DMAREQ pin), and bus multi-
plexing (external logic)
20. Fifteen
21. Non-maskable (NMI)
22. Until the internal clock oscillator becomes fully operational (approximately
20 milliseconds)
138
25. Any of the following:
Another NMI
RESET
DMAREQ
HALT
26. a. !!!Q sets the E Hag, FIRQ clears the E Hag.
b. lliQ stacks all internal registers; FIRQ stacks only PC and CCR.
c. !!!Q sets the I Hag; FIRQ sets both the F and I Hags.
d. !.!!!Lvector is at address FFF8:FFF9;
FIRQ vector is at address FFF6:FFF7.
27. FIRQ
28. Multiprocessor
29. BUSY, LIe, and AVMA
30. Three-state control (TSC)
139
CHAPTER 7
6809/6,809E
Interfacing and Applications
INTRODUCTION
You are now ready to apply your knowledge of the 6809 to the
"real world." Interfacing the 6809 is very similar to interfacing the
6800. The major difference is in the use of the bus status (BS) and
DMAREQ signals, which were discussed in the previous chapter.
We will begin our discussion by developing a minimum 6809 system
consisting of scratch-pad RjW memory, ROM, and a peripheral in-
terface adapter (PIA). The 6820 j 6821 PIA will be used in just about
every 6809 system; thus a thorough understanding of this device
should be attained. A complete discussion of the PIA is provided in
Appendix B, if a review is needed.
Since the 6809 is mainly a systems device, most of our discussion
in this chapter will center on 6809 systems applications. After devel-
oping a minimum system we will discuss an expanded system which
provides serial data communication for crt's, modems, and printers
along with mass storage via a floppy disc system. Such a system can
stand alone or can be integrated into a multiprocessor system. The
1980s will see the development of many multiprocessor systems with
8-bit devices, such as the 6809, handling dedicated tasks and 16-bit
devices, such as the 68000, providing system control and supervision.
You will see how the 6809 can be interfaced to a 16-bit data bus for
such multiprocessor applications. In addition, you will see how the
6809E can be used in an 8-bit multiprocessor system. A 6809 data
acquisition system will also be presented.
Finally, for any new processor to be marketable the manufacturer
140
must develop a broad family of devices which support the processor.
To this end Motorola has developed a complete line of support de-
vices for the 6800. All of these devices are also directly compatible
with the 6809. In addition, several new devices are being developed
specifically for the 6809. For example, the 6809 has been referred to
as "a SOO-horsepower engine with a three-gallon gas tank" because it
is capable of addressing only a 64K memory space. However, Mo-
torola has developed a 6829 Memory Management Unit (MMU)
which expands the 6809 address space to 2 megabytes. This device,
along with others, will be presented in this chapter. Furthermore, in
an effort to support understanding of the 6809, Motorola has mar-
keted the MEK6809D4 evaluation system. One version of the system,
the D4A, is complete with power supply, hex keypad, and LED dis-
play module. Another version, the D4B, can be interfaced directly to
a crt data terminal. Both systems contain an excellent ROM monitor
(D4BUG) to provide efficient engineering evaluation or student
learning of the 6809. A general description of the D4A will be pro-
vided in this chapter. Now, let's open up the unending world of 6809
applications.
OBJECTIVES
At the end of this chapter you will be able to do the following:
141
+5Vdc
vee 16 16
AO-A15
V ss
6809
MPU
XTAL
CJ 8 8
DO-D7
EXTAL 13
CONTROU
STATUSI
TIMING
6810 6830 6821
128 BYTE 1K BYTES PIA
R/W ROM PARALLEL
MEMORY 1/0
(pages FC,
AS REQUIRED (page 00) (page 50)
FD,FE,FF)
AS REQUIRED
142
0000
6810 R/W MEMORY
Page 00
OOlF
NOT USED
5000
PIA - Page 50
5003
NOT USED
FCOO
6830 ROM
Pages FC, FD, FE AND FF
FFFF
143
Table 7·1. PIA Memory Map for RSO to AO and RS1 to A1
PIA
Address Register Selected
5000 DDRA or DRA *
5001 CRA
5002 DDRB or DRB *
5003 CRB
'Depends on bit 2 of the control register.
LDA #
50
TFR A,DPR
LDD $
00
Note that we nrst store the PIA page number (50) into the direct
page register. Then direct addressing can be used to input the l6-bit
data directly into accumulator D. The port A data will form the most
signincant data byte and port B data will form the least significant
byte.
Example 7-2: Data Input Synchronization
Now suppose that your PIA is connected as shown in Fig. 7-3. You
want to synchronize the data input operation with the peripheral in-
put device such that each time the peripheral device interrupts the
6809 via CAl of the PIA, the 6809 will read a l6-bit data word and
store it in a memory location specified by the X register. In addition,
you want to provide complete handshaking with the input device.
Therefore you must acknowledge the data read operation via CA2 of
the PIA. Write a routine which will properly initialize the PIA, then
read a block of 10010 (6416 ) l6-bit data words using the synchroniza-
tion handshake method described above.
The routine in Fig. 7-4 will accomplish the given task. As in the
previous example it is assumed that the PIA is assigned to addresses
5000-5003 with RSO connected to Al and RSI connected to AO. The
routine nrst configures the PIA. The port A control register (CRA)
144
16
16·BIT
PERIPHERAL
INPUT
DEVICE
LDA#
50
TFR A,DPR
J- Load DPR with PIA
page number
CLRA ]
CLRB
Select DDRA and DDRB
STD$
02
STD$ ~ Configure ports A and B
00 ----.J for input
LDA#
27 } Configure CRA for
LDB # input handshaking
Fig. 7-4. Routine for data 04 via CA I and CA2.
input synchronization. STD$ Set CRB bit 2
02
ORCC# --1
Set I flag
10 --F
SYNC Syncing state
LDB #
}
C8 Read 10010 (64 16) 16-bit
LDY$ data words from PIA and
00 store in 200 10 (C8 16)
STY,X+ + consecutive 8-bit
DECB memory locations
BNE specified by X register
F4
ANDCC# ~
Clear syncing state
00 -S
145
in the syncing state by the SYNC instruction. Each time CAl is
active, the 6809 will read the l6-bit word into the Y register and then
store the data in two consecutive memory locations specified by the
X register. The routine will then branch back to the syncing state
until another IRQ is received. The read cycle will repeat until 10010
(64 16 ) 16-bit words have been read and stored in 20010 (C8 16 ) con-
secutive 8-bit memory locations. Note that a complete handshake
takes place between the 6809 and input device (via the PIA) each
time a data word is transferred.
In the coming years you will be seeing many 6809s being used in
multiprocessor 16-bit systems. The 6809s will handle dedicated tasks,
while a 16-bit microprocessor, such as the MC68000, will supervise
the system activity. Thus 16-bit data transfers similar to the ones
just shown will be quite common in such a system. The 16-bit
peripheral input device in Example 7-2 could be a 16-bit processor.
MULTIPROCESSOR SYSTEMS
Multiprocessor systems will be the wave of the future. Many ded-
icated system functions can be handled by separate processors, each
a complete system in its own right. The separate processor systems
will contain dedicated R/W memory, ROM, and peripheral devices.
146
16
16
EXTAL
OMAREO t-------i
Eoul
°out
R/W
6309
SA
SS
IRO
FIRO
16 NMI
RESET
HALT
MREAOY
00-07
RfW
MEMORY
147
~2 {2
a:
DEDICATED DEDICATED wO
~~~
~
MEMORY MEMORY
0
Z AND AND <DOO
PERIPHERALS PERIPHERALS °oz
~if
8 DATA DATA , 8
16, , ADDR ADDR ' 16
5 ... STATUS STATUS' 5
4 ... ' CONTROL CONTROL'
, ,4
,
3 ... '
INTI I I liNT
, ,3
2
,, BUS ARBITRATION LOGIC CONTROL = RESET
HALT
VMA
TSC
a--' STATUS = R/IN
<{ a:
Cf)
:::l
f-
g: BA
BS
0 <{ Z
/' 2 f-
<{ 0 f- a f-
z BUSY
o <{ Cf) 0
L1C
, if
I~ I ~61 ~5 I 4 '3 INT = NMI
FTRQ
IRQ
2 GLOBAL MEMORY
CLOCK
GEN , ... AND
PERIPHERALS
148
R/W
MEMORY ROM
+5VdC~VCC
~VSS AO-A15 I AS~AS~
REQUIR~~EQU;R~~
,
1~
r'-
16
"11 DXTAL
cp" C1
..... 6809
~ EXTAL MPU
:D AS REQUIRED CONTROL/
-~------'STATUS/TIMING
t~
CD
g ~...-oo;JIC---:----,BA
~!
;- 1 BS 07
8 ~.
8
e-
ll)
S'
~----:7"'--.., FIRQ 00- 1- 7' }5 - 8 ;NVERSION
A'4 }8
c
Il)
n
.a
'RQA
CA1
, I
1
~
r- CQNVERTER~
AID 1 4:1 r=
t====
ANALOG
In
!0" MUX INPUT
::s
en
'<
~
~
TTY
OR
CRT 0 20mA
TO
EIA
tJ Rx
6850
ACIA
PORT A
6821
PIA
8
START
CONVERSION
I
CHANNEL
SELECT
PORTSI < ~
~
, ~
1
~
J"START CONVERSION (SYNCING STATE) 1
,
~
~
.
...
CD ! .. CONTROL/STATUS/TIMING AS REQUIRED
cations. A high-level language interpreter could also be provided in
the local system ROM to enhance local engineering data analysis.
Operator communication is provided via a teletypewriter (tty) and/
or crt data terminal. Interfacing these devices to the 6809 would
require a 6850 ACIA for serial/parallel translations and external
logic to establish the required RS-232C (EIA) or 20-mA current-loop
serial communication formats. Four analog inputs are multiplexed
with a 4: 1 multiplexer circuit. Channel selection can be accom-
plished by using any two of the PIA port B data lines as output lines.
Anyone of the four analog inputs may then be selected by writing
the proper Is and Os to the respective port B data register (DRB)
bits. The A/ D converter will convert the selected analog signal to
digital. The digital information is then fed to port A of the PIA. A
syncing routine will be used to control the data transfer. After the
PIA is properly initialized, you will insert a SYNC instruction in
your program. When the 6809 executes the SYNC, BA=l and BS=O
to indicate the syncing state. The external digital logic will decode
BA/BS to provide a low-to-high transition to the A/D converter.
This transition will signal the conversion process to begin. Once the
analog signal has been converted to a digital byte of information, the
A/D converter will activate CAl on the PIA to provide an active
FIRQ for the 6809. If the F flag has been previously set, the 6809
will clear the syncing state and execute the next sequential program
instruction, which will read the port A data. Then, a branch back to
the SYNC instruction will cause the process to be repeated for the
next data byte. Thus a complete handshake is provided between the
6809 and A/D converter for each data byte transferred. All the soft-
ware details should now be familiar to you and you should now have
no trouble writing a routine which will properly configure the PIA
and acquire the data in the manner just described.
150
Table 7·3. 6800 Family Peripherals That Are Directly
Compatible With the 6809
Part Number Device
6821 Peripheral interface adapter
6828 Priority interrupt controller
6840 Programmable timer module
6843 Floppy disc controller
6844 DMA controller
6845 Crt controller
6846 ROM ilo timer
6847 Video display generator
6850 Asynchronous communication interface adapter
6852 Synchronous serial data adapter
6854 Advanced data link controller
6859 Data security device
6860 0- to 600·bps digital modem
6862 2400-bps modulator
68488 General-purpose interface adapter
68120 Intelligent peripheral controller
68540 Error detection and correction circuit
5 10 2M-BYTE
16 (A11'~15) (PA1~-PA20)
680916809E
MPU , J
, 6829
MMU , , ~ ADDRESS
SYSTEM
21 BUS
'11 ~ 11
I (AO-A10) J (AO-A10)
Fig. 7-8. Expanding from 65K to 2M bytes using the 6829 MMU.
7-8. The 6829 MMU combines the 11 lower 6809 address lines (AO-
A10) with ten address lines (PA11-PA20) of its own to form the
2-megabyte address space. This space consists of 1024 pages of 2K
bytes each. The 6829 address lines (PA11-PA20) specify the page
number, and the lower 11 6809 address lines (AO-A10) specify the
particular byte within the page. An internal mapping R/W memory
uses the upper five 6809 address lines (A11-A15) along with the
contents of an internal5-bit task register to form the ten most signifi-
151
cant address lines (PA11-PA20) of the 2-megabyte address space.
Dp to eight 6829s can be used in a system.
The 6839 floating-point ROM will facilitate the use of high-level
languages, such as Pascal, BASIC, and FORTRAN, on 6809-based
systems. The 6839 includes such floating-point operations as add,
su1:?tract, multiply, divide, square root, absolute value, negate, and
routines which provide binary/decimal conversions and allow you
to convert between integer and floating-point values.
Finally, the 6842 serial direct memory access (SDMA) processor
provides direct memory access for high-speed serial data links. Serial
data transfer rates of up to 4 megabits per second are possible. 'Nlany
future multiprocessor systems will be relying on a serial data link
for communication between processors. The SD'NfA can be used for
this purpose. The 6842 SDMA is a serial device, while the 6844
DMAC, which was previously discussed, is a parallel D'NIA device.
A brief product description of each of these new 6809 family de-
vices is provided in Appendix C. Consult the respective device data
sheets, obtainable from :Motorola Semiconductor Products, Inc., for
additional device information and interfacing details.
152
(A) MEK68KPD keypad/power/display board.
153
J J2 l
DISPLAYS
@I ~kAUX~
~~~~~~[@ ~~ I
USER PIA CONN CONN
'U'
If::jl _,
'WI IQI 1i::::J1
@I~
lr-"J ~
WIRE·WRAP AREA
CD ®
KEYPAD
E20 :.0::
~E§]E9~~
0000~
0~~~~
POWER SUPPLY
II ~- EXT +5V
(2) 0-- RED
C2JIT][]@]§ 0-- GREEN
@]0[I]~~ E3
--<::}- I -0-- BLACK
Fig. 7·10. MEK68KPD keyboard /power/display board.
RS·232C INTERFACE
® ItID STOP PIA
STOP COMPARATOR
®
ADDRESS
DECODE R/W MEMORY
®w
LOGIC
@
~~~
XTAL
EJ I (j) 6809
ABC 0
J3D~
ROM
-----------------, (j)
(2)
EDGE CONNECTOR BUFFERS
E F G H
154
vent display flickering. The keypad/ display PIA is assigned to
addresses EOF8-EOFB as follows:
ORA/DORA EOF8
CRA EOF9
DRB/DDRB EOFA
CRB EOFB
4. User PIA-This PIA is entirely available for user configuration
and use. All of the port A and port B data lines, along with their
associated control lines (CAl, CA2, CB1, CB2), are brought
out to the adjacent J2 edge connector. See the system user's
manual for the proper connector pin assignments. The user PIA
is assigned to addresses EOFC-EOFF as follows:
ORA/DORA EOFC
CRA EOFD
DRB/DDRB EOFE
CRB EOFF
5. Power supply-The MEK68KPD contains two +5-Vdc power
supplies. One supply is used to drive the 8 LED displays via
regulator VR1 and the other used to supply power for the D4A
logic via regulator VR2. An external 18-V center-tap trans-
former is supplied with the system and is to be connected as
shown in Fig. 7-10.
CAUTION: The on-board supply is designed to provide only
enough power for the minimum system configuration. If addi-
tional devices are added, an external supply is required. To con-
nect an external supply you must first remove the E2 and E3
connecting links. This will prevent damage to the on-board
supply regulators. Then, connect the external TTL quality +5-
Vdc source to the J1 connector as shown in Fig. 7-10.
6. Wire-wrap area-This area is provided for you to wire-wrap
your own external devices to the system. Both ground and +5-
Vdc supply buses are provided in this region for convenience.
The 6809 data, address, timing, status, and control signals are
available at the KPD and AUX connectors on the microcomputer
module board. See the system user's manual for the proper con-
nector pin assignments.
MEK6809D4 Microcomputer Board (Fig. 7-11)
1. 6809 MPU and crystal-This is the microprocessor· «heart" of
the system together with its 4x crystal, which establishes the
internal clock frequency.
2. Clock select-The jumper connector (J3) provides for selec-
tion of either internal or external clock control. See the system
user's manual for the proper jumper connections.
155
3. R/W memory-Sockets are provided for 5K bytes of R/W
memory via five pairs of 2114 (lKx4) or equivalent R/W
memory chips. The minimum system includes two 2114s (lK
bytes) to provide for storing variables and to support the sys-
tem stack. These two chips are assigned to addresses E400-
E7FF. Any additional user R/W memory address assignments
are determined by the R/ W memory map connector.
4. R/W memory map-This is a jumper connector (]2) which
allows mapping of the additional user R/W memory in any
one of 16 possible 4K-byte blocks within the 64K-byte memory
space. See the system user's manual for the proper jumper
connections.
5. ROM-Eight ROM/EPROM sockets, A through H, are pro-
vided in this area for up to 48K bytes of ROM or EPROM.
Theminimum system includes one MCM68332 ROM (4Kx8),
which provides the system monitor called D4BUG. Any addi-
tional ROM address assignments are determined by the map-
ping ROM and RO"A-I type connector. ROM sockets A through
D will normally be used for larger ROMs (4K-8K) containing
editor/ assembler type programs. ROM sockets E and F can
be used for smaller (lK, 2K, or 4K) user ROMs/EPROMs of
the singleor triple supply variety. ROM socket G is reserved
for a special 2K ROM (R2-RS-232) required for the RS-232C
interface which is available on the D4B version of the
MEK6809D4 system. ROM socket H is reserved for the 4K
D4BUG ROM on both the D4A and D4B system versions.
6. Mapping ROM-The mapping ROM is provided with both the
D4A and D4B systems. This ROM provides you with a unique
and flexible means of mapping the eight ROM devices into
the 64K memory space. See the system user's manual for the
ROM mapping details.
7. ROM type connectors (J4 and J5)-These are jumper connec-
tors which allow you to select anyone of the following ROM
type options for ROM sockets A through G:
156
Connector J5 configures sockets A through F, and the J4 con-
nector configures sockets G and H. Note the extreme flexibility
that you have in the selection of the type of ROM to be used
in your system. See the system user's manual for the proper
jumper connections for your ROM configuration.
8. RS-232C interface-With the D4B system this area provides
the required RS-232C interfacing devices (ACIA, baud rate
generator, etc.). The sockets in this area will be omitted or
empty with the D4A system.
9. Stop PIA and comparator-The D4 system provides you with
a stop-an-address capability via a PIA and associated com-
parator logic. The purpose of a stop address is to enable a user
program to be executed until a certain predetermined address
is reached. The stop address is stored in the stop address PIA
ports A and B. When the address on the address bus is the
same as the stop address, the comparator generates a non-
maskable (NMI) interrupt via CAl of the PIA to stop the
program execution. The stop PIA is automatically initialized
as part of the system reset routine. -
10. Cassette interface-This will provide you with a means to in-
terface an inexpensive cassette recorder to the system. The
D4BUG monitor provides for the proper data formatting and
recovery functions via the P / Land FS keys on the keypad.
Data is stored and recovered by D4BUG software in a Kansas
City Standard, 300- or 1200-bps data format.
11. KPD connector-This 24-pin connector interfaces the micro-
computer board to the MEK68KPD board. The 6809 data and
selected address/ control lines are provided via this connector.
All the signals supplied to this connector are buffered. See the
system user's manual for the respective pin assignments.
12. AUX connector-This 16-pin connector is provided to allow
you to extend all of the 6809 address and control signals to the
MEK68KPD, for use in the wire-wrap area. All the signals
supplied to this connector are buffered. See the system user's
manual for the respective pin assignments.
Finally, the key functions of the ~1EK68KPD keypad are sum-
marized in Fig. 7-12. The control keys will allow you to do the fol-
lowing:
157
Reset System causes (?) Used with Fs to change number
prompt in left-most display. of times in stop-address
Clears A,B,CC,DP,X.Y.U. routine.
Sets I & F flags.
I Loads E600 into S.
~unch/Load data between
nemory and cassette recorder.
158
3. After "GO," depressing "EX" will automatically enter the reg-
ister display routine without altering any of the internal register
contents. Then, pressing "GO" will advance the register dis-
play and pressing "M" will back up the display routine.
4. The system stack begins at address E6oo. If the S register is
loaded with a non-R/W memory address value or there is not
enough R/W memory available to stack the internal register
contents, the display will indicate "Bad SP??"
5. The system uses SWIl for the breakpoint routine.
6. To use SWI2, store the SWI2 interrupt service routine vector
at address E777: E778.
7. To use SWI3, store its interrupt service routine vector at ad-
dress E775:E776.
8. The single-step function (T / B) sets the E flag.
The following will help familiarize you with your D4A and illus-
trate the versatility of both the 6809 and D4A system.
Example 7-3: Using the SWI2 Interrupt
Step 1: Load the program in Fig. 7-13 into the D4 system beginning
at address E400. Refer to the D4 user's manual for the pro-
gram loading procedure.
NOTE: Do not press RS (reset) after entering the program, use the
escape (EX) key.
Step 2: Depress RD and set the program counter to the beginning
address of the above program (E4oo).
Step 3: Depress T / B. The first instruction was executed and the D4
HEX HEX MNEMONICI OPERATION
ADDRESS CONTENTS CONTENTS REMARKS
E400 C6
E401 BB LDS#
BB }
E402 86 LDA # Main Program
E403 AA AA
E404 1F TFR A,CC
E405 8B 8B
E406
E407
10
3F
SWI2 J Software Interrupt (SWI2)
E408 3C CWAI#
E409 FF FF
•
•
E500 CE LDU #
E501
E502
E503
CC
CC
3B
CC
CC
RTI
} SWI2 Interrupt
Service Routine
•
•
E777
E778
E5
00
E5
00
J Our SWI2 Interrupt
Vector
159
is now in the register display routine. The program counter
contents should be the address of the next instruction to be
executed (E402).
Step 4: Verify that accumulator B was loaded with the value BB
by depressing the GO key twice. Also, at this time, you
might want to note the contents of the other registers by
successiv~ly pushing the GO key.
Step 5: Depress T / B a second time. Verify the proper PC contents
( E404) and that accumulator A was loaded with the value
AA.
Step6: Single step the program a third time and verify that the
accumulator A value of AA was transferred to the direct
page register (DP).
Step 7: Single step the program again and observe the PC contents
of FDBC. Why? Because the software interrupt (SWI2)
was just executed and the processor was vectored to this
address by the SWI2 software interrupt vector located at
address FFF4: FFF5. Escape (EX) from the register dis-
play routine and verify that the SWI2 vector, located at
address FFF4:FFF5, is FDBC.
Step 8: The SWI2 instruction also caused the internal register data
to be stacked. The S stack pointer was originally set to E600
by the reset operation. Thus, examine memory locations
E600 through E5F4 and verify the correct register stacking
and the proper stacking order. Note also that the S register
now contains E5F4. You should find the registers stacked in
the following manner:
S-12~ E5F4 CCR
S-ll ~ E5F5 A
S-10~ E5F6 B
S·9 ~ E5F7 DPR
S-8 ~ E5F8 XII
S-7 ~ E5F9 XL
S-6 ~ E5FA Yn
S-5 ~ E5FB YL
S-4 ~ E5FC Un
S-3 ~ E5FD UL
S-2 ~ E5FE PC H
S-l ~ E5FF PC L
S ~ E600
Step 9: Now, return to the register display routine by depressing
EX, then RD. The PC should still contain FDBC, which is
in ROM. Continue to single step through this ROM routine
until the PC contains address E500. Note that E500 is our
160
SWI2 interrupt vector. You might say that the ROM routine
converted the system SWI2 interrupt vector (FDBC) lo-
cated at FFF4:FFF5 to our SWI2 interrupt vector (E500)
located at address E777:E778. If you want a real challenge
and learning experience, interpret the ROM routine instruc-
tions which begin at address FDBC to understand how the
above vector conversion is accomplished.
Step 10: With the PC set at E500, single step the program and verify
that the U register was loaded with the value CCCC by our
SWI2 interrupt service routine.
Step 11: Single step the program again. This time, the RTI instruc-
tion was executed and therefore control was returned back
to the main program. Verify that the original register data
has been restored as a result of the unstacking operation
caused by the RTI instruction.
Step 12: You might want to rewrite the program to use the SWI3
interrupt. To do this, you must insert the SWI3 op code at
address E406: E407 and an interrupt vector of your choos-
ing at address E775:E776. Remember to also include an in-
terrupt service routine.
Example 7-4: Buried Op Code and Computed Vector Fetch
Step 1: Load the program in Fig. 7-14 into the D4 system beginning
at address E400.
Step 2: The program is from Example 5-5. Turn back to this example
and review the program explanation.
Step 3: The vector table in the program of Fig. 7-14 begins at ad-
dress FFFO, which is the beginning of the 6809 vector table.
Thus, we will be using a control byte to determine which of
the 6809 vectors will be accessed by the program. Because
E400 86 LDA# ~
E401
E402
E403
Control Byte
8E
FF
LOX #
FF
J-
Control Byte~ Load control byte
Load beginning
address of vector
E404 FO FO table
E405 5F CLRB
E406 10 LBRN
E407 21
E408 CB ADDB # Vector to table
E409 02 02 determined by
R40A 44 LSRA control byte
R40B 24 BCC
R40C FB FB
R40D 6E JMP[B,Xj
E40E 95 95
Fig. 7-14. Program for Example 7-14.
161
of the fixed 6809 vector table mapping, the control byte will
access the 6809 vectors in the following manner:
C antral Byte Vector Accessed
00 Reserved
02 SWI3
04 SWI2
08 FIRQ
10 IRQ
20 SWIl
40 NMI
80 RESET
Step 4: Insert 80 at address E401 for the control byte. This should
access the RESET interrupt vector.
Step 5: Execute the program. A question mark ( ?) should appear in
the left-most display as the result of the accessed reset oper-
ation.
Step 6: You might want to access the other interrupt vectors by
changing the control byte. In all cases you will end up in the
respective interrupt service routine located in ROM. The dis-
play will either remain blank or revert to the register display
routine, depending on the particular interrupt which is being
accessed.
Step 7: Now, create your own vector table in RjW memory as in
Example 5-5. Remember to also include some type of vector
service routine such that you can verify proper vectoring.
Try it! In addition, go back and execute the text examples on
your D4. In this way you will gain a better understanding of
both the 6809 and the D4 system.
162
APPENDIX A
A-1. Nomenclature
Operation Notation
-E-= is transferred to EB = Boolean exclusive OR
/\ = Boolean AND = (overline) = Boolean NOT
V = Boolean OR = concatenation
Register Notation
ACCA = A = accumulator A
ACCB = B = accumulator B
ACCX = either ACCA or ACCB
ACCA:ACCB = D = double accumulator
IX = X = index register X
IY = Y = index register Y
SP =
S= hardware stack pointer
US = U = user stack pointer
DPR = DP = direct page register
CCR = CC = condition code register
PC = program counter
R= a register before the operation: A, B, D, X, Y, U, S, PC,
DP, or CC (usually, only a subset of registers is legal,
these are specified by "Register Addressing Mode" in the
individual instructions)
R'= a register after the operation.
ALL= all registers, Le., A, B, D, X, Y, U, S, PC, DP, and CC
zz= a pointer register, Le., X, Y, U, S
MSB= most significant bit
MS byte = most significant byte
LS byte = least significant byte
IXH= ms byte of index X
IXL= Is byte of index X
163
A-2. Definitions of Executable Instructions
Add ACCS into IX ABX
Source Form: ABX
Operation: IX' ~ IX + ACCB
Condition Codes: Not affected.
Description: Adds the 8-bit unsigned value in accumulator B into the X index
register.
Addressing Mode: Inherent
164
Memory Addressing Modes: Immediate
Direct
Indexed
Extended
165
Description: Performs a logical AND between the CCR and the MI byte and
places the result in the CCR.
Register Addressing Modes: CCR
Memory Addressing Mode: Memory immediate
166
Branch on Carry Clear Bee
Source Forms: BCC dd; LBCC DDDD
Operation: TEMP ~ MI
=
IFF C 0 then PC' ~ PC + TEMP
Condition Codes: Not affected.
Description: Tests the state of the C bit and causes a branch if C is clear.
Memory Addressing Mode: Memory immediate
Effective Addressing Modes: Relative
Long relative
Comments: When used after a subtract or compare on unsigned binary values,
this instruction could be called "branch if the register was higher or the
same as the memory operand."
167
Operation: TEMP ~ MI
IFF [N EB V] = 0 then PC' ~ PC + TEMP
Condition Codes: Not affected.
Description: Causes a branch if N and V are either both set or both clear, i.e.,
branch if the sign of a valid twos complement result is-or would be-positive.
M emory Addressing Mode: Memory immediate
Effective Addressing Modes: Relative
Long relative
Comments: Used after a subtract or compare operation on twos complement
values, this instruction will «branch if the register was greater than or equal
to the memory operand."
168
Branch if Higher or Same BHS
Source Form: BHS dd; LBHS DDDD
Operation: TEMP ~ MI
IFF C= 0 then PC' ~ PC + MI
Condition Codes: Not affected.
Description: Tests the state of the C bit and causes a branch if C is clear.
Memory Addressing Mode: Memory immediate
Effective Addressing Modes: Relative
Long relative
Comments: When used after a subtract or compare on unsigned binary values,
this instruction will «branch if register was higher than or same as the
memory operand." This is a duplicate assembly-language mnemonic for the
single machine instruction BCe. Not useful, in general, after INC/DEC,
LD/ST, TST/CLR/COM.
169
Comments: Used after a subtract or compare operation on twos complement
values, this instruction will "branch if the register was less than or equal to
the memory operand."
170
M emory Addressing Mode: Memory immediate
Effective Addressing Modes: Relative
Long relative
Comments: Used after a subtract or compare operation on twos complement
binary values, this instruction will "branch if the register was less than the
memory operand."
171
Memory Addressing Mode: Memory immediate
Effective Addressing Modes: Relative
Long relative
Comments: Used after an operation on twos complement binary values, this
instruction will "branch if the possibly invalid result is positive."
172
Branch on Overflow Clear BVC
Source Form: BVC dd; LBVC DDDD
Operation: TEMP ~ MI
IFF V = 0 then PC' ~ PC + TEMP
Condition Codes: Not affected.
Description: Tests the state. of the V bit and causes a branch if the V bit is
clear. That is, branch if the twos complement result was valid.
Memory Addressing Mode: Memory immediate
Effective Addressing Modes: Relative
Long relative
Comments: Used after an operation on twos complement binary values, this
instruction will «branch if there was no overflow."
Clear CLR
Source Form: CLR Q
Operation: TEMP ~ M
M ~OO16
Condition Codes: H: Not affected.
N: Cleared.
z: Set.
V: Cleared.
c: Cleared.
Description: ACCX or M is loaded with 00000000. The C flag is cleared for 6800
compatibility.
Addressing Modes: Accumulator
Direct
Indexed
Extended
173
Compare Memory from a Register-8 Bits CMP
Source Form: CMPA P; CMPB P
Operation: TEMP ~ R - M [Le., TEMP ~ R + :M + 1]
Condition Codes: H: Undefined.
N: Set IFF bit 7 of the result is set.
z: Set IFF all bits of the result are clear.
V: Set IFF the operation caused an 8-bit twos complement
overflow.
C: Set IFF the subtraction did not cause a carry from bit 7
in the ALU.
Description: Compares the contents of M from the contents of the specified
register and sets appropriate condition codes. Neither M nor R is modified.
The C flag represents a borrow and is set inverse to the resulting binary
carry.
Register Addressing: Accumulator
Memory Addressing: Immediate
Direct
Indexed
Extended
Flag Results: (N EB V) = 1 R .LT. M (twos complement)
C = 1 R .LO. M (unsigned)
Z = 1 R.EQ.M
Compare Memory From a Register-16 Bits CMP
Source Forms: CMPD P; CMPX P, CMPY P; CMPU P; CMPS P
Operation: TEMP ~ R - M:M+l [Le., TEMP ~ R + M:M+l +1]
Condition Codes: H: Unaffected.
N: Set IFF bit 15 of the result is set.
Z: Set IFF all bits of the result are clear.
V: Set IFF the operation caused a 16-bit twos complement
overflow.
c: Set IFF the operation on the MS byte did not cause a
carry from bit 7 in the ALU.
Description: Compares the l6-bit contents of M:M+l from the contents of the
specified register and sets appropriate condition codes. Neither R nor M:M+l
is modified. The C flag represents a borrow and is set inverse to the resulting
binary carry.
Register Addressing: Double accumulator
Pointer (X, Y, S, or U)
Memory Addressing: Immediate
Direct
Indexed
Extended
Flag Results: (N EB V) = 1 R .LT. M (twos complement)
C = 1 R .LO. M (unsigned)
Z = lR.EQ.M
174
Complement COM
Source Form: COM Q
Operation: M' ~ 0 +M
Condition Codes: H: Not affected.
N: Set IFF bit 7 of the result is set.
z: Set IFF all bits of the result are clear.
V: Cleared.
C: Set.
Description: Replaces the contents of M or ACCX with its ones complement
(also called the logical complement). The carry Hag is set for 6800 com-
patibility.
Memory Addressing Modes: Accumulator
Direct
Indexed
Extended
Comments: When operating on unsigned values, only BEQ and BNE branches
can be expected to behave properly. When operating on twos complement
values, all signed branches are available.
175
Comments: An FIRQ interrupt may enter its interrupt handler with its entire
machine state saved. The RTI will automatically return the entire machine
state after testing the E bit of the recovered CCR.
Decrement DEC
Source Form: DEC Q
Operation: M' ~ M - 1 [i.e., M' ~ M + FFl o]
Condition Codes: H: Not affected.
N: Set IFF bit 7 of result is set.
Z: Set IFF all bits of result are clear.
V: Set IFF the original operand was 10000000.
C: Not affected.
Description: Subtract one from the operand. The carry Hag is not affected,
thus allowing DEC to be a loop counter in multiple-precision computations.
Memory Addressing Modes: Accumulator
Direct
Indexed
Extended
Comments: When operating on unsigned values only BEQ and BNE branches
176
can be expected to behave consistently. When operating on two complement
values, all signed branches are available.
Exclusive OR EOR
Source Forms: EORA P; EORB P
Operation: R' ~ R E9 M
Condition Codes: H: Not affected.
N: Set IFF bit 7 of result is set.
Z: Set IFF all bits of result are clear.
V: Cleared.
C: Not affected.
Description: The contents of memory is exclusive-oRed into an 8-bit register.
Register Addressing Modes: Accumulator
Memory Addressing Modes: Direct
Extended
Immediate
Indexed
Increment INC
Source Form: INC Q
Operation: M' ~ M +1
Condition Codes: H: Not affected.
N: Set IFF bit 7 of the result is set.
Z: Set IFF all bits of the result are clear.
V: Set IFF the original operand was 01111111.
C: Not affected.
177
Description: Add one to the operand. The carry Hag is not affected, thus allow-
ing INC to be used as a loop counter in multiple-precision computations.
Memory Addressing Modes: Accumulator
Direct
Indexed
Extended
Comments: When operating on unsigned values, only the BEQ and BNE
branches can be expected to behave consistently. When operating on twos
complement values, all signed branches are correctly available.
178
Memory Addressing Modes: Immediate
Direct
Indexed
Extended
179
Operation: C' ~ b 7 , b/ ... bt' ~ b6 ... bo, bo' ~ 0
Condition Codes: H: Undefined.
N: Set IFF bit 7 of the result is set.
z: Set IFF all bits of the result are clear.
V: Loaded with the result of (b7 EB b 6) of the original op-
erand.
C: Loaded with bit 7 of the original operand.
Description: Shifts all bits of ACCX or M one place to the left. Bit 0 is loaded
with a zero. Bit 7 of ACCX or M is shifted into the carry flag. This is a
duplicate assembly-language mnemonic for the single machine instruction
ASL.
Addressing Modes: Accumulator
Direct
Indexed
Extended
ob- = - I T
b
J
7 o
Operation: C' ~ bo, bo' ... b o' ~ III ... !h, !h' ~ 0
Condition Codes: H: Not affected.
N: Cleared.
Z: Set IFF all bits of the result are clear.
V: Not affected.
C: Loaded with bit 0 of the original operand.
Description: Performs a logical shift right on the operand. Shifts a zero into
bit 7 and bit 0 into the carry flag. The 6800 processor also affects the V flag.
Addressing Modes: Accumulator
Direct
Indexed
Extended
180
Addressing Modes: Inherent
Negate NEG
Source Form: NEG Q
Operation: M' ~ 0 - M i.e., M' ~ M + 1
Condition Codes: H: Undefined.
N: Set IFF bit 7 of result is set.
z: Set IFF all bits of result are clear.
V: Set IFF the original operand was 10000000.
C: Set IFF the operation did not cause a carry from bit 7 in
the ALU.
Description: Replaces the operand with its twos complement. The C flag
represents a borrow and is set inverse to the resulting binary carry. Note that
8016 is replaced by itself and only in this case is V set. The value 0016 is also
replaced by itself, and only in this case is C cleared.
Addressing Modes: Accumulator
Direct
Indexed
Extended
Flag Results: (N EB V) = 1 if 0 .LT. M (twos complement)
C = 1 if 0 .LO. M (Unsigned)
Z = 1 if 0 .EQ. M
No Operation NOP
Source Form: Nap
Condition Codes: Not affected.
Description: This is a single-byte instruction that causes only the program counter
to be incremented. No other registers or memory contents are affected.
Addressing Modes: Inherent
181
Indexed
Extended
~luIY~
push order-
~
push order-
182
Operation: IFF B7 of MI set, then: US' ~ us - 1, (US) ~ PCL
US' ~ US -1, (US) ~PCH
IFF B6 of MI set, then: US' ~ US - 1, (US) ~ SPL
US' ~ US -1, (US) ~SPH
IFF B5 of MI set, then: US' ~ US - 1, (US) ~ IYL
US' ~ US -1, (US) ~IYH
IFF B4 of MI set, then: US' ~ US - 1, (US) ~ IXL
US' ~ US - 1, (US) ~ IXH
IFF B3 of MI set, then: US' ~ US - 1, (US) ~ DPR
IFF B2 of MI set, then: US' ~ US - 1, (US) ~ ACCB
IFF Bl of MI set, then: US' ~ US - 1, (US) ~ ACCA
IFF BO of MI set, then: US' ~ US - 1, (US) ~ CCR
~
-pull order
~
- pull order
183
Operation: IFF BO of MI set, then: CCR' ~ (US), US' ~ US + 1
IFF BI of MI set, then: ACCA' ~ (US), US' ~ US + 1
IFF B2 of MI set, then: ACCB' ~ (US), US' ~ US + 1
IFF B3 of MI set, then: DPR' ~ (US), US' ~ US + 1
IFF B4 of MI set, then: IXH' ~ (US), US' ~ US + 1
IXL' ~ (US), US' ~ US + 1
IFF B5 of MI set, then: IYH' ~ (US), US' ~ US + 1
IYL' ~ (US), US' ~ US + 1
IFF B6 of MI set, then: SPH' ~ (US), US' ~ US + 1
SPL' ~ (US), US' ~ US + 1
IFF B7 of MI set, then: PCH' ~ (US), US' ~ US + 1
PCL' ~ (US), US' ~ US + 1
Condition Codes: May be pulled from stack; otherwise unaffected.
Description: Any, all, any subset, or none of the MPU registers are pulled from
the user stack (excepting only the user stack pointer itseU). A single register
may be "PULLED" with condition flags set by doing an auto-increment load
from the stack (EX: LDX, U++).
Memory Addressing Mode: Memory immediate
~
Operation: C' ~ b 7, ~' ••• bl' ~~ ... bo, bo' ~ C
Condition Codes: H: Not affected.
N: Set IFF bit 7 of the result is set.
z: Set IFF all bits of the result are clear.
V: Loaded with the result of (b7 ffi be) of the original op-
erand.
c: Loaded with bit 7 of the original operand.
Description: Rotate all bits of the operand one place left through the carry
Hag; this is a 9-bit rotation.
Addressing Modes: Accumulator
Direct
Indexed
Extended
~
184
Operation: C' ~ bo, b6' ... bo' ~ b7 ... In., b/ ~ C
Condition Codes: H: Not affected.
N: Set IFF bit 7 of result is set.
Z: Set IFF all bits of result are clear.
V: Not affected.
C: Loaded with bit 0 of the previous operand.
Description: Rotates all bits of the operand right one place through the carry
Hag; this is a 9-bit rotation. The 6800 processor also affects the V Hag.
Addressing Modes: Accumulator
Direct
Indexed
Extended
185
Subtract with Borrow ssc
Source Forms: SBCA P; SBCB P
Operation: R' ~ R - M - C [Le., R' ~ R + M + C]
Condition Codes: H: Undefined.
N: Set IFF bit 7 of the result is set.
z: Set IFF all bits of the result are clear.
V: Set IFF the operation causes an 8-bit twos complement
overflow.
C: Set IFF the operation did not cause a carry from bit 7 in
the ALU.
Description: Subtracts the contents of M and the borrow (in the carry flag)
from the contents of an 8-bit register, and places the result in that register.
The C flag represents a borrow and is set inverse to the resulting binary carry.
Register Addressing Mode: Accumulator
Memory Addressing Modes: Immediate
Direct
Indexed
Extended
186
Memory Addressing Modes: Direct
Indexed
Extended
187
Condition Codes: H: Unaffected.
N: Set IFF bit 15 of result is set.
z: Set IFF all bits of result are clear.
V: Set IFF the operation caused a 16-bit twos complement
overflow.
c: Set IFF the operation on the MS byte did not cause a
carry from bit 7 in the alu.
Description: This information subtracts the value in M:M+l from the 16-bit
accumulator. The C flag represents a borrow and is set inverse to the re-
sulting binary carry.
Register Addressing Mode: Double accumulator
Memory Addressing Modes: Immediate
Direct
Indexed
Extended
Subtract Sets: (N EEl V) = 1 if R .LT. M (twos complement)
C = 1 if R .LO. M (unsigned)
Z = 1 if R .EQ. M
Software Interrupt SWI
Source Form: SWI
Operation: Set E (Entire state will be saved)
SP' ~ SP - 1, (SP) ~ PCL
SP' ~ SP - 1, (SP) ~ PCH
SP' ~ SP - 1, (SP) ~ USL
SP' ~ SP - 1, (SP) ~ USH
SP' ~ SP -1, (SP) ~IYL
SP' ~SP -1, (SP) ~IYH
SP' ~ SP - 1, (SP) ~ IXL
SP' ~ SP - 1, (SP) ~ IXH
SP' ~ SP - 1, (SP) ~ DPR
SP' ~SP-l, (SP) ~ACCB
SP' ~ SP - 1, (SP) ~ACCA
SP' ~ SP - 1, (SP) ~ CCR
Set I, F (mask interrupts)
PC' ~ (FFFA):(FFFB)
Condition Codes: Not affected.
Description: All of the MPU registers are pushed onto the hardware stack (ex-
cepting only the hardware stack pointer itself), and control is transferred
through the SWI vector.
Addressing Mode: Absolute indirect
188
SP' +- SP - 1, (SP) +- USL
SP' +- SP - 1, (SP) +- USH
SP' +- SP - 1, (SP) +- IYL
SP' +- SP - 1, (SP) +- IYH
SP' +- SP - 1, (SP) +- IXL
SP' +- SP - 1, (SP) +- IXH
SP' +- SP - 1, (SP) +- DPR
SP' +- SP - 1, (SP) +- ACCB
SP' +- SP - 1, (SP) +- ACCA
SP' +- SP - 1, (SP) +- CCR
PC' +- (FFF4):(FFF5)
Condition Codes: Not affected.
Description: All of the MPU registers are pushed onto the hardware stack (ex-
cepting only the hardware stack pointer itself), and control is transferred
through the SWI2 vector. SWI2 is available to the end user and must not
be used in packaged software.
Addressing Mode: Absolute indirect
189
the interrupt is enabled, and the interrupt lasts three cycles or more, the
processor will perform the interrupt routine. If the interrupt is masked or is
shorter than three cycles, the processor simply continues to the next instruc-
tion (without stacking registers). While SYNCING, the address and data
buses are tri-state.
Addressing Modes: Inherent
Comments: This instruction provides software synchronization with a hardware
process. Consider the high-speed acquisition of data:
FAST SYNC WAIT FOR DATA _____ interrupt
Operation: R2 ~ Rl
Condition Codes: Not affected (unless R2 CCR). =
Description: Bits 7-4 of the immediate byte of the instruction define the source
register, while bits 3-0 define the destination register, as follows:
0000 = A:B 1000 = A
0001 =X 1001 = B
0010 =Y 1010 = CCR
0011 = US 1011 = DPR
0100 = SP 1100 = Undefined
0101 = PC 1101 = Undefined
0110 = Undefined 1110 = Undefined
0111 = Undefined 1111= Undefined
Registers may only be transl ~r:ed between registers of like size, Le., 8-bit
to 8-bit, and 16-bit to 16-bit.
Addressing Modes: Inherent
Test TST
Source Form: TST Q
Operation: TEMP ~ M- 0
Condition Codes: H: Not affected.
N: Set IFF bit 7 of the result is set.
Z: Set IFF all bits of the result are clear.
V: Cleared.
C: Not affected.
190
Description: Set condition code Hags N and Z according to the contents of M,
and clear the V Hag. The 6800 processor clears the C Hag.
Memory Addressing Modes: Accumulator
Direct
Indexed
Extended
Comments: The TST instruction provides only mllllIllum information when
testing unsigned values; since no unsigned value is less than zero, BLO and
BLS have no utility. While BHI could be used after TST, it provides exactly
the same control as BNE, which is preferred. The signed branches are
available.
191
APPENDIX B
192
configures its corresponding port data line. A 1 in a DDR bit will cause its
corresponding port line to be configured as an output line, while a 0 will cause
it to be configured as an input line. For example, if DDRA bit 3 contains a 1,
the PA3 line will be configured as an output data line. If DDRA bit 4 con-
tained a 0, the PA4 line would be configured as an input data line. The ports
DATA REGISTER A
DATA DIRECTION REG A
CONTROL REG A
682016821
PIA
DATA REGISTER B
DATA DIRECTION REG B
CONTROL REG B
are configured by storing a data byte into each data direction register. To
configure port A as an input port and port B as an output port, you would store
00 in DDRA and FF in DDRB. Remember that since the data direction register
and the data register are considered to be memory locations, they are loaded
with memory-reference instructions.
Control Registers (CRA and CRB)
The control registers are 8-bit registers which are used for a variety of
control functions. Each bit within the register controls a particular function.
The control register will allow four of the peripheral control lines of the PIA
to be used for interrupt servicing and polling routines. The control register is
also used to select either the DR or DDR for use in a data transfer operation.
A more detailed discussion of the control register is included later in this
appendix.
193
Vss 1 CA1
PAO 2 CA2
PA1 3 IROA
PA2 4 IROB
PA3 5 RSO
PM 6 RS1
PA5 7 RESET
PA6 8 00
PA7 9 01
682016821
PBO 10 PIA 02
PB1 11 03
PB2 12 04
PB3 13 05
PB4 14 06
PB5 15 07
PB6 16 E
PB7 17 CS1
CB1 18 CS2
CB2 19 CSO
Vee 20 R/W
194
Interrupt Input-Port B (CB1: Pin 18)
This is an input-only line used to set bit 7 of control register B which is
used as a flag to indicate that a peripheral wishes to interrupt the 6809. This
will be discussed in more detail later in this appendix (see PIA Control Reg-
isters) .
Peripheral Control-Port B (CB2: Pin 19)
This line can be programmed through the use of control register B to act
as an interrupt input or as a peripheral control output to provide handshaking.
When in the output mode it is TTL compatible, and when configured as an
interrupt input it represents one TTL load. This pin will be discussed in more
detail later in this appendix (see PIA Control Registers).
Vee (Pin 20)
This pin is connected to the system +5-volt dc power supply.
Read/Write (R/W: Pin 21)
This pin is connected directly to the R/W line on the 6809. A low state
on this line allows data to be transferred from the 6809 to the PIA. A high state
allows for data transfer from the PIA to the 6809. Data will only be transferred
when the proper address and enabling pulse are present at the PIA. PIA ad-
dressing and enabling will be discussed shortly.
Chip Selects (CSO, CS2, CS1: Pins 22-24)
These pins are used in the same way that the chip-select signals were used
on the 6810 R/W memory and 6830 ROM chips. They will partially decode
the address bus to select the PIA. To select the PIA, CSO and CSI must be
high and CS2 must be low.
Enable (E: Pin 25)
This pin is used to supply a timing signal to the PIA and, therefore, is
normally connected directly to the E clock. To completely enable the PIA,
the chip selects must be held in their active state for the duration of the E pulse.
Data (00-07: Pins 33-26)
These pins are connected directly to the eight data bus lines DO through D7.
The data bus lines are bidirectional and allow data transfer between the 6809
and PIA. The output drivers are three-state buffered and remain in their high-
impedance state except when a PIA read operation is being performed.
Reset (Reset: Pin 34)
A high-to-Iow transition at this pin will cause all register bits in the PIA
to be reset to a logical 0 state. It can be used with a power-on reset signal or
tied to the 6809 reset interrupt pin to reset the PIA when the entire system
is reset.
Register Selects (RSO, RS1: Pins 36, 35)
These two lines are used to select the various registers within the PIA. They
are normally tied to address lines AO and Al and are used in conjunction with
the control registers to select the specific register that is desired. This selection
process is discussed in the next section of this appendix.
Interrupt Requests (IRQA, IRQB: Pins 38,37)
These are output lines that can be wire-oRed together to be connected
directly to the 6809 IRQ line. When an if 0 device generates an interrupt, an
interrupt flag bit of the respective PIA control register will be set which, in
195
turn, causes the respective IRQ line to go low. This generates an interrupt re-
quest that is sent to the 6809. Each of these lines has two interrupt flag bits
in its respective control register that can cause the IRQ line to go low. Each
of these internal flags corresponds to a particular peripheral interrupt line;
CAl and CA2 correspond to port A and CBl and CB2 correspond to port B.
Once an internal interrupt flag has been set, the IRQ line will remain low
until the flag is cleared by servicing the interrupt with a PIA read or write
operation. Therefore, an interrupt request is not lost if the I flag in the 6809
condition code register is set, which disables it from recognizing interrupts. These
lines could also connect to the 6809 FIRQ or NMI lines.
Peripheral Control (CA2: Pin 39)
This line is used in essentially the same way as the CB2 line (pin 19). It
can be programmed through the use of control register A to act as an interrupt
input line or it may be used as a peripheral control output line. When in the
output mode it is TTL compatible, and when configured as an interrupt input
it represents one TTL load. A more detailed discussion of this pin function
will follow in this appendix (see PIA Control Registers).
Interrupt Input (CA1: Pin 40)
This line is similar to the CBl line (pin 18). It is an input-only line used
to set bit 7 of control register A which is used as a flag to indicate a peripheral
interrupt. This, in turn, will cause the IRQA line to go low, generating an
interrupt request.
196
DO CA1} A CONTROLS
D1 A DATA CA2
D2
D3 DATA DIRECTION REG A PAO
D4 PA1
D5 PA2
D6 PA3
PM
~lD7
CONTROL REG A
I I
U
'11
ca' PA5
ID
~ en -' r RSO PA6
l
en ::;) 0
-a ::;) co a:: RS1 PAl
); co en
en
-, ()
<t:
f-
Li.J
a::
::!.g <t:
Cl
Cl en PBO
CD ~ Cl ::;)
~Cll
m en
<t: co esa
CS2 PB1
n, ~ PB2
~~
, 0 CS1 PB3
(3
iii" E B DATA PB4
Cf)
Cll
3
R/W PB5
o'
0 RESET DATA DIRECTION REG B PB6
:::l
0-
c IROA PBl
U
s;
t:=
IROB
"tJ
+ 5V
(3
0-
c
U
GND I CONTROL REG B
I CB2)
CB1
J
B CONTROLS
....
CD
'fl
;-
..... ~
...
U)
ClIt
A SIDE B SIDE
."
cp'
m
I
CRA2* =1 CRA2 =0 CRB2* =1 CRB2 =0
~
.."
S;
CD
CO
..~
en
RSO :. 0 RSO =1 RSO =0 RSO =1
!!.
~
0'
?
RS1 =0 RS1 =1
oo
c
it
Ul
'<
I
ro *CRA2 is BIT 2 of control register A
el.
::T DATA PATH BETWEEN MPU AND PIA REGISTERS CRB2 is BIT 2 of control register B
o
9
will be selected. However, if bit 2 of the control register is high, the data
register is selected. For example, suppose RS1 = 1, RSO = 0, and bit 2 of control
register B is low. With these conditions, the data direCtion register of port B
(DDRB) will be selected.
Fig. B-5 shows how a PIA might be connected to the 6809 system. It is
necessary only to allocate four addresses to select any register in the PIA. In
this example we have used addresses 5000 through 5003. Naturally we are
only partially decoding the address bus since from the decoding chart you can
see that the PIA will be enabled for addresses 5000 through 7FFF. This does
not create a problem as long as no other chips are assigned to any of these
+5V
DO DO
••
07 •
07
A1 RSO
AO RS1
A14 eso
6820/6821
A12 eS1 PIA
A15 eS2
E E
R/W R/W
RESET RESET
Key:eS == 1
IROA
=
CS 0
IROB RS = 1 or 0
• = not used
Fig. B-S. PIA pin connections and decoding chart.
addresses. Using this decoding scheme the information in Fig. B-6 shows how
the PIA would respond to addresses 5000 through 5003 and which register
would be selected for each address. Note that with addresses 5000 and 5001,
the data direction or data register can be selected. The specific register that is
PIA REGISTER
ADDRESS CSO CS1 CS2 RS1 RSO SELECTED
5000 0 0 DORA or ORA·
5001 0 1 OORB or ORB·
5002 0 0 eRA
5003 0 1 eRB
199
selected will depend on the status of bit 2 in the respective control register. The
control registers are selected with addresses 5002 and 5003.
In the above procedure, Step 1 clears bit 2 of both control registers so that
the data direction register will be selected rather than the data register. The
ports will then be configured by storing a binary number in each data direction
register (Steps 2 and 3). After each port has been configured, bit 2 of the
control register is set such that the data register will be selected for subsequent
data transfer.
First, resetting the system will reset the PIA if the RESET pin on the PIA
is connected to the system reset, as is usually the case. This will cause all of the
registers in the PIA to be cleared, and therefore the first step of the initialization
procedure is accomplished. The initialization routine first stores the PIA page
number (50) into the direct page register such that direct addressing can be
used for data transfers. Port A is then configured as an input port and port B
as an output port by storing the accumulator D contents (OOFF) to address
5000. Note that since DDRA and DDRB are assigned to consecutive memory
200
locations, the STD instruction will store 00 to address 5000 (DDRA) and FF
to address 5001 (DDRB). Bit 2 of both control registers is then set by storing
0404 to address 5002:5003.
Example B-2: PIA Data I/O
Assuming that the PIA has been configured as in Example B-1, the following
routine will input data from port A, then output the same data to port B.
LDA $
00
STA $
01
To input data from port A, you can use any load instruction which addresses
the port A data register (DRA at address 5000). The data register will be
selected rather than the data direction register since you have already set bit 2
of the control register in your initialization program. To output the data to
port B, you will use a store instruction that addresses the port B data register
(DRB at address 5001). This is a velY simple program since data is just being
transferred from an input to an output port. Once the data is in the 6809,
however, you have the full power of the 6809 instruction set available to
analyze that data to determine the output conditions.
PIA Control Registers
Now we will discuss the control registers of the PIA in more detail. Besides
the bit-2 function of the control register which has already been discussed, the
control register is used mainly for control of interrupts. The bit format of each
control register is shown in Fig. B-7. Actually, each control register is identical
in format and function. Therefore we will confine our discussion to control
register A, keeping in mind that the function of control register B is the same.
Our discussion will begin with bit 0 (CRA-0) and bit 1 (CRA -1) .
7 6 5 I 4 I 3 2 1 I 0
DORA
CRA IROA1 IROA2 CA2 CONTROL CA1 CONTROL
ACCESS
7 6 5 I 4 I 3 2 1 I 0
DDRB
CRB IROB1 IROB2 CB2 CONTROL CB1 CONTROL
ACCESS
Bits 0 and 1 (CRA-O and CRA-I) of the control register are labeled CAl
Control since they are used to define the effect and active state of the CAl pin
on the PIA. Recall that CAl is an input-only pin that can be used by an i/o
device to generate interrupt requests. When the pin is activated, the interrupt
flag bit (CRA-7) of the control register will be set, indicating an interrupt re-
quest has been generated. Bit 0 (CRA-O) of the control register will determine
the effect of setting this flag. If CRA-O is set (1), the flag will cause the IRQA
output pin to go low, thu~erating an interrupt request to the 6809. If
CRA-O is cleared (0), the IRQA pin will remain high, masking out any inter-
rupt request. Thus CRA-O determines whether the interrupt mode for the port
is active or inactive. Bit 1 of control register A (CRA-l) defines the active state
of pin CAL If CRA-1 is set (1), a low-to-high transition on the CAl pin
201
will cause the interrupt flag bit (CRA-7) of the control register to be set. If
CRA-l is cleared (0), a high-to-Iow transition will cause the interrupt flag to
be set. Thus, either a positive pulse or a negative pulse may be used to generate
an interrupt signal. Fig. B-8 summarizes the function of these two control
register bits.
Bit 2 of the control register (CRA-2) has already been discussed and is used
entirely for register selection. Bits 3, 4, and 5 of the control register (CRA-3,
CRA-4, and CRA-5) are labeled CA2 Control since they are used to define
the function, effect, and active states of the CA2 pin on the PIA. Recall that
the CA2 pin can be designated as either input or output. This designation is
accomplished by CRA-5 of the control register. When CRA-5 is cleared, the
CA2 pin is configured as an input line. When CRA-5 is set, CA2 is designated
as an output line.
CA21nput
When configured as an input line, the CA2 pin is used as an interrupt line
similar to CAL In this mode an active level on CA2 will cause bit 6 (CRA-6)
of the control register to be set. CRA-6 is the interrupt flag used in conjunction
with the CA2 pin in the same way that CRA-7 is used in conjunction with
CAL When being used as an interrupt input, the CA2 active state and effect are
defined by bits 3 and 4 of the control register (CRA-3 and CRA-4). CRA-3
is used to determine the effect of setting the CRA-6 flag similar to the way
CRA-O was used in conjunction with the CRA-7 flag. If CRA-3 is set, the
CRA-6 flag will cause the IRQA pin to go low, thus generating an interrupt
request to the 6809. If CRA-3 is cleared, the IRQA pin will remain high, thus
masking out the interrupt request. Bit 4 of control register A (CRA-4) will
define the active state of pin CA2 similar to the way CRA-l defines the active
state of CAL If CRA-4 is set (1), a low-to-high transition on the CA2 pin will
cause the interrupt flag bit (CRA-6) to be set. If CRA-4 is cleared (0), a
high-to-Iow transition will cause the interrupt flag bit to be set. Fig. B-9 sum-
marizes the function of these control register bits when CA2 is used as an
input line.
CA2 Output
Recall that CA2 will be configured as an output line when bit 5 of the
control register is set. When CA2 is designated as an output line, the interrupt
202
CONTROL OF CA2 AND CB2 AS INTERRUPT INPUTS CRA5(CRB5) IS LOW
CRA·5 CRA·4 CRA·3 INTERRUPT INPUT INTERRUPT FLAG MPU INTERRUPT REQUEST
(CRB·5) (CRB·4) (CRB·3) CA2(CB2) CRA·6(CRB·6) IRQA(IRQB)
Hag (CRA -6) will be cleared and remain in that state as long as bit 5 is set.
You will use CA2 as an output for polling and handshaking routines. Hand-
shaking or polling requires the use of status bits that would indicate when a
peripheral device has requested service and when the 6800 has completed the
service. The use of CAl as an input and CA2 as an output as shown in Fig.
B-lO will provide the proper status levels to permit handshaking between the
6809 and a peripheral device. The procedure will be as follows.
ADDRESS
I ~/
PORT A
I\J
V:-NPUT DATA
(pAO-PA7)
CA1
CA2
6809
~
DATA \
(00-07) vi PIA
PERIPHERAL
DEVICE
OUTPUT DAT-t\
PORT B
(PBO-PB7)y
CB1
CB2
I ~~
CONTROL
203
1. The peripheral device will generate an interrupt by activating the CAl
line on the PIA, signaling that it has data to give the 6809.
2. The CAl interrupt causes the interrupt flag bit CRA-7 to set.
3. The interrupt flag causes an interrupt request to be generated to the 6809
and also causes CA2 to go high.
4. When the interrupt request is acknowledged, the 6809 will read the data
from the port A data register (DRA).
5. After the read operation takes place, the CA2 line will go low and CRA-7
is cleared, signaling the peripheral that the interrupt has been serviced
and that the 6809 is ready for more data. Thus, the handshake is complete.
To achieve this complete handshake, CRA-5 must be set with CRA-3 and CRA-4
cleared. Therefore bits .5, 4, and 3 of control register A would be 100.
If you do not desire to use interrupts and decide to use programmed if 0,
CAl could be eliminated from Fig. B-lO and CA2 would be used as an output
to signal the peripheral device. Here, the peripheral device would make data
available on a continuing basis to the PIA port, but it needs to know when the
6809 has read the data from the data register so that new data can be supplied.
This is a partial handshake. In this mode, CA2 will normally be high, then go
low after a read-port A operation is executed. It will remain low for one
enable signal (E) cycle. To achieve this mode, CRA-5 and CRA-3 must be set
with CRA-4 cleared. Therefore, bits 5, 4, and 3 of control register A would
be 101.
There are two other possibilities for the output condition of CA2. They are:
1. CRA-5, CRA-4, CRA-3 110 =
2. CRA-5, CRA-4, CRA-3 = 111
In the first case the CA2 output line will be held in a low state and in the
second case CA2 will be held high.
When CA2 and CB2 are used as output lines, they have slightly different
functions. When handshaking, port A will be used completely as an input port
and port B will be used as an output port. Therefore, CA2 will indicate when
the 6809 has read (loaded) data from the port A data register (DRA) and
CB2 will indicate when the 6809 has written (stored) data into the port B
data register (DRB). Figs. B-l1 and B-12 summarize the functions of CA2
CRA·5 IS HIGH
CA2
CRA·5 CRA-4 CRA·3
CLEARED SET
HIGH WHEN THE INTERRUPT FLAG BIT
LOW ON NEGATIVE TRANSITION OF E AFTER
1 0 a AN MPU READ "A" DATA OPERATION.
CRA-? IS SET BY AN ACTIVE TRANSITION
OF THE CAl SIGNAL.
LOW ON NEGATIVE TRANSITION OF E AFTER HIGH ON THE NEGATIVE EDGE OF THE FIRST
1 0 1 AN MPU READ "A" DATA OPERATION. "E" PULSE WHICH OCCURS DURING A DESELECT.
LOW WHEN CRA-3 GOES LOW AS A RESULT ALWAYS LOW AS LONG AS CRA-3 IS LOW.
1 1 a OF AN MPU WRITE TO CONTROL REGISTER" A".
WILL GO HIGH ON AN MPU WRITE TO CONTROL
REGISTER" A" THAT CHANGES CRA-3 TO "ONE".
204
CRB·5 IS HIGH
CB2
CRB·5 CRB-4 CRB·3
CLEARED SET
LOW ON THE POSITIVE TRANSITION OF THE HIGH WHEN THE INTERRUPT FLAG
1 0 0 FIRST EPULSE FOLLOWING AN MPU WRITE BIT CRB-? IS SET BY AN ACTIVE TRANSITION
"B" OATA REGISTER OPERATION. OF THE CB1 SIGNAL.
LOW ON THE POSITIVE TRANSITION OF THE HIGH ON THE POSITIVE EDGE OF THE FIRST
1 0 1 FIRST E PULSE AFTER AN MPU WRITE "E" PULSE FOLLOWING AN "E" PULSE WHICH
"B" DATA REGISTER OPERATION. OCCURED WHILE THE PART WAS DESELECTED.
and CB2, respectively, when used as an output line. The following examples
should help to clarify the preceding discussion.
Example 8-3
Suppose you store the hex number 27 into control register B. How will this
control port B? The control register would be configured as shown below:
CRB-? CRB-6 CRB-5 CRB-4 CRB-3 CRB-2 CRB-1 CRB-O
This configuration will provide complete data output handshaking through port
B. The following is a description of each bit function:
CRB-O set will cause an interrupt to be generated when the interrupt flag
( CRB-7) is set.
CRB-l set will cause the CRB-7 interrupt flag to set on a low-to-high transi-
tion of the CBl pin.
CRB-2 set selects the data register of port B.
CRB-3 and CRB-4 cleared permits CB2 to go high when the interrupt flag bit
is set by an active transition of CBl and to go low after the 6800 stores data
to the port B data register.
CRB-5 set designates CB2 as an output line.
C RB-6 cleared as a result of CRB-5 being set.
CRB-7 cleared to be used as an interrupt flag for CAL
Example 8-4
Suppose you store the hex number 27 into control register A. How will this
control port A? The control register bit structure would be the same as control
register B was in Example B-3. However, here CA2 would go high after an
interrupt is generated on CAl and go low after a read (load) operation has
been performed on the port A data register. Therefore this would provide for
complete data input handshaking through port A.
Example 8-5
Suppose you store the hex number OF into control register A. How will this
control the port? The control register bit structure would be as shown below:
205
CRA-7 CRA-6 CRA-5 CRA-4 CRA-3 CRA-2 CRA-1 CRA-O
CRA-O set will cause an interrupt to be generated when the interrupt flag bit
( CRA-7) is set.
CRA-J set will cause the CRA-7 interrupt flag to set on a low-to-high transi-
tion of the CAl pin.
CRA-2 set selects the data register of port A.
CRA-3 set will cause an interrupt to be generated when the interrupt flag bit
( CRA-6) is set.
CRA-4 cleared will cause the CRA-6 interrupt flag bit to set on a high-to-Iow
transition of CA2.
CRA-5 cleared designates CA2 as an input pin.
CRA-6 cleared to be used as an interrupt flag for CA2.
CRA-7 cleared to be used as an interrupt flag for CAL
REVIEW QUESTIONS
1. List the six internal registers of the PIA.
PIA? _
5. To configure PAO through PA3 as input and PA4 through PA7 as output,
6. Port of the PIA can always be used to drive the base of a tran-
sistor directly.
7. Two pins on the PIA that are always used as interrupt inputs are
____ and _
~
206
Determine Active CAl (Cal) Transition for Setting
Interrupt Flag IRQAIB)l -(bit b7)
o IRQA(B)l set by high-to-low transition on
CA1ICBlI
1 IRQA(B)l set by low-to-high transition on
CA1ICBli
I
L b7 I b6 I b5
'---------------L
I I bl I
~
b<j> I
I
IRQAIBl111RQAIBI21
Flag Flag
CA21CB21
Control
I DDR
Access
I CA11CBlI
Control
I
I I
CA2 (CB2) Established as Output by b5 = 1
CA2 (CB21 Established as Input by b5 = 0
(Note that operation of CA2 and CB2
output functions are not identical) b4 b3
L
~CA2
Read Strobe With CA 1 Restore
207
9. When CA2 (CB2 ) is used as an interrupt input, bit of the
control register is used as the CA2 (CB2) interrupt Hag bit.
10. The E (enable) pin of the PIA is usually connected to the _ _-+--~.
11. A high-to-Iow transition on the Reset pin of the PIA will cause what to
happen?
12. How are the interrupt request pins (IRQA and IRQB) usually connected?
14. Assuming the PIA has been initialized as in problem 12, write a program
to input data from port B, and output the complement of that data to
port A.
208
15. When would CA2 (CB2) be used as an output pin?
17. How would the PIA ports be configured to provide complete input and
output handshaking?
ANSWERS
1. Data Register A (DRA)
Data Direction Register A (DDRA)
Control Register A (CRA)
Data Register B (DRB)
Data Direction Register B (DDRB)
Control Register B (CRB)
2. 16
3.
. . .1- - - - - PIA -------,1
PORT A PORT B
I RSI
I I
iRSI'Oi i • ,
4. NMOS
5. F016
6. B
7. CAl and CBl
209
8. Five
9. Six
10. E clock
11. All internal PIA registers will be cleared.
12. Wire-oRed together, then connected to the 6809 IRQ/FIRQ lines.
13.
LDA #
80
TFR A,DPR
LDD #
FF
00
STD $
00
LDD #
04
04
STD $
02
14.
LDA $
01
COMA
STA $
00
15. To provide complete or partial handshaking between the 6809 and a
peripheral device.
16. A peripheral device requests service from the 6809; the 6809 acknowledges
the request and signals the peripheral device when the service is completed.
17. Port A as an input port with CAl as an interrupt input line and CA2 as
an output peripheral control line. Port B as an output port with CBl as an
interrupt input line and CB2 as an output peripheral control line.
18. Bit 7 of control register A is the CAl interrupt request flag for port A
( IRQAl ). It is used as an interrupt flag for interrupts generated on pin
CAL
19. One and four
20. 100
210
APPENDIX C
Specification Sheets
211
MC6809/MC68A09/MC68B09
HMOS
(HIGH DENSITY N-CHANNEL. SILICON-GATE)
8-BIT
MICROPROCESSING
UNIT
MC6800 COMPATIBLE
• Hardware - Interfaces with All M6800 Peripherals
• Software - Upward Source Code Compatible Instruction Set and
Addressing Modes
ARCHITECTURAL FEATURES
• Two 16-bit Index Registers
• Two 16-bit Indexable Stack Pointers
• Two 8-bit Accumulators can be Concatenated to Form One 16-8it
Accumulator
• Direct Page Register Allows Direct Addressing Throughout Memory
HARDWARE FEATURES
• On Chip Oscillator 14 x fo XT AU
• DMA/BREO Allows DMA Operation or Memory Refresh PIN ASSIGNMENT
• Fast Interrupt Request Input Stacks Only Condition Code Register
and Program Counter
• MRDY Input Extends Data Access Times for Use With Slow
Memory
• Interrupt Acknowledge Output Allows Vectoring By Devices VSS HALT
• SYNC Acknowledge Output Allows for Synchronization to External
NMI XTAL
Event
• Single Bus-Cycle RESET iRO EXTAL
• Single 5-Volt Supply Operation FIRQ RESET
• NMI Blocked After RESET Until After First Load of Stack Pointer BS MROY
• Early Address Valid Allows Use With Slower Memories
BA 0
• Early Write-Data for Dynamic Memories
SOFTWARE FEATURES Vee E
• 10 Addressing Modes AO OMA/BREO
• M6800 Upward Compatible Addressing Modes At R/W
• Direct Addressing Anywhere in Memory Map
A2 00
• Long Relative Branches
• Program Counter Relative A3 01
• True Indirect Addressing A4 02
• Expanded Indexed Addressing: A5 03
0, 5, 8, or 16-bit Constant Offsets
A6 04
8, or 16-bit Accumulator Offsets
Auto-Increment/Decrement by 1 or 2 A7 05
• Improved Stack Manipulation AS 06
• 1464 Instructions with Unique Addressing Modes
A9 07
• 8 x 8 Unsigned Multiply
AlD Al5
• 16-bit Arithmetic
• Transfer/Exchange All Registers All Al4
• Push/ Pull Any Registers or Any Set of Registers Al2 Al3
• Load Effective Address
212
MC6809/MC68A09/MC68B09
MAXIMUM RATINGS
Rating Symbol Value Unit This device contains circuitry to protect the
inputs against damage due to high static
Supply Voltage - 0.3 to + 7.0 Vdc
VCC voltages or eleCtrlc fields; however, It is ad
Input Voltage Vin -0.3 to + 7.0 Vdc vised that normal precautions be taken to
Operating Temperature Range o to+ 70 'c avoid application of any voltage higher than
Storage Temperature Range -55 to + 150 'c maximum rated voltages to this high im-
Thermal Resistance Ceramic 50 'C/W pedance circuit
Plastic 100 'C/W
213
MC6809/MC68A09/MC68B09
1 4 - - - - - - - - - teye ---------~
05V
2.4 V
R/W
ADDR
SA, SS' I""""::-~'_+-+_--------_---_+++->--.....-
Data ----------------c:::C\
~NotValld
R/W
---+~...l....I:::::.;.--+-----_t_--------H"""..>....>
ADDR
SA, SS·_~'--"1...o:::::_....:::>"t-_+_-------------++...--
Data
214
MC6809/MC68A09/MC68B09
~VCC
~VSS
IR
DMA/BREO
Riw
HALT
BA
BS
XTAL
EXTAL
MROY
E
Q
ACCUMULATORS lA, B, D)
MM06150 The A and 8 registers are general purpose accumulators
Test POint ~~_---f'III-"" or Equiv which are used for anthmetic calculations and manipulation
of data
MM0700J Certain instructions concatenate the A and 8 registers to
or Equiv form a single 16-bit accumulator. ThiS is referred to as the D
Register, and is formed with the A Register as the most
Significant byte
215
MC6809/M C68A09/MC68B09
15
x- Index Register }
Y - Index Register
1---------~------_____4 Pomter Registers
U - User Stack Pointer
S - Hardware Stack Pointer
PC Program Counter
A I Accumulators
v
D
216
MC6809/MC68A09/MC68B09
217
....
N
CD
FIGURE 7 - RESET TIMING
. ' . 8~ !e-",---¥m. '~m. ,+' ,3+ . ,+" . 5-1-,' . 8+" , 7+" . 8+" , 3+",. '0-1
&~,e'S8 I
.-k",....--------------\\.~, ;D/$${~=,1-'8(-S8----------
3:
8A~ ~:~:; ::~~; = ",:,,~:c. H
()
Q)
CD
o
8S~~ r---\ II r---\L- _ CD
·Note: Parts with data codes prefixed by 7F will come out of RESET one cycle sooner than shown i()
0)
CD
FIGURE 8 - CRYSTAL CONNECTIONS ANO OSCILLATOR START UP o»
MC6809 Nominal Crystal Parameters" CO
3.58 MHz 4.00 MHz 6.0 MHz 8.0 MHz i()
RS 600 500 30-50 0 20-400
Q)
Co 35 pF 6.5 pF 4-6 pF 4·6 pF (ll)
C, 0.015 pF 0.025 pF 0.01-0.02 pF 001-002 pF aI
>30K >20 K >20 K
o
0 >40K CO
All parameters are 10%
RESET----f----c>~ "NOTE: These are representative AT-cut crystal parameters only
types of cut may also be used
Crystals of other
tRC~
MC6809 -------il DI 39
~~
381 Yl I 39
D .l- 38~CE-------J39
Cin ::c TCout
Co
MC6809/MC68A09/MC68B09
)}---~~ ~~~~---e.,!"'.~C,-,,VO-,-I' ••
."!4f--,-F,=,,-,-h.~I E-,-,e-'-""-"tte.""I.t-c-,-YC_"-'.'!"I.I----H'_he~d
o~
E~
t~'PCSH 'PCI
HALT 201.1 Y.2..BV~ ~, -,,-,,-~.
Ad::;"~\-, ~.....- _
FelCh becule
R/W~)-'-------~--'------
-------'"~)-'
--------,\'-----~/
_ _ _ _ _ _~~S \ ;'---
~~':~> ~>----
InstructIon
Interrupt Acknowledge is indicated during both cycles of a recognition of an NM I, the entire machine state is saved on
hardware-vector-fetch IRESET, NMI, FIRQ, iRQ, SWI, the hardware stack. After reset, an NMI will not be recogniz-
SWI2, SW131. This signal, plus decoding of the lower four ed until the first program load of the Hardware Stack POinter
address lines, can provide the user with an indication of lSI The pulse width of NMIIow must be at least one E cycle
which interrupt level is being serviced and allow vectoring by If the NMI input does not meet the minimum set up With
device. See Table 1 respect to Q, the interrupt will not be recognized until the
Sync Acknowledge IS indicated while the MPU IS waitmg next cycle. See Figure 10
for external synchronization on an interrupt line
Halt/Bus Grant is true when the MC6809 is In a Halt or Bus FAST-INTERRUPT REQUEST (FIRQ)"
Grant condition A low level on this input pin Will initiate a fast Interrupt se-
quence, proVided its mask bit IFI in the CC IS clear. This se-
TABLE 1: MEMORY MAP FOR INTERRUPT VECTORS quence has priority over the standard Interrupt Request
(lRm, and IS fast in the sense that It stacks only the contents
Memory Map For of the condition code register and the program counter. The
Vector Locations Interrupt Vector Interrupt service routine should clear the source of the Inter-
Description rupt before doing an Rn See Figure 11
MS LS
FFFE FFFF RESET INTERRUPT REQUEST (iRQ)"
FFFC FFFD NMI A low level Input on this pin will initiate an Interrupt Re-
FFFA FFFB SWI quest sequence provided the mask bit I I) in the CC is clear
FFF8 FFF9 iRO Since IRQ stacks the entire machine state it provides a
FFF6 FFF7 FiRi5 slower response to Interrupts than FIRQ. IRQ also has a
FFF4 FFF5 SWI2 lower priority than FIRQ Again, the interrupt service routine
should clear the source of the interrupt before dOing an RTI
FFF2 FFF3 SWI3
See Figure 10
FFFO FFFI Reserved
"NOTE: NMI, FIRQ and IRQ requests are latched by the fail-
NON MASKABLE INTERRUPT (NMI)" ing edge of every Q, except during cycle steal-
A negative edge on this input requests that a non- ing operations le.g., DMAI where only NMI is
maskable interrupt sequence be generated. A non-maskable latched. From this pOint, a delay of at least one bus
interrupt cannot be inhibited by the program, and also has a cycle Will occur before the interrupt is serviced by
higher priority than FIRQ, IRQ or software interrupts During MPU
219
MC6809/MC68A09/MC68B09
I
i
i
i
-1
i 1
-1 t
i i
Cl
z
-! t
~
i= i t
Ii:
~
f-
1 i-
~
I~
i t
c
z
~
,~
i t
~
I
1 i
w
a::
:::>
Cl
-t !
u::
1 t
1 t
i t
1 1
I~
i ~ '"
~ci3
I~
t
11
I~
~~ i~l~
220
MC6809/MC68A09/M C68B09
XTAL, EXTAL
These inputs are used to connect the on-chip oscillator to the MPU into a Halt mode to three-state the machine, but
an external parallel-resonant crystal. Alternately, the pin MRDY will not stretch the clocks.
EXTAL may be used as a TTL level input for external timing
by grounding XT AL. The crystal or external frequency is four
times the bus frequency. See Figure 8. Proper RF layout
techniques should be observed in the layout of printed circuit DMA/BREQ
boards. The DMA/BREQ input provides a method of suspending
execution and acquiring the MPU bus for another use, as
E, a shown in Figure 14. Typical uses include DMA and dynamic
memory refresh.
E is similar to the MC6800 bus timing signal <1>2; 0 is a
Transition of DMA/BREQ should occur during Q. A low
quadrature clock signal which leads E. 0 has no parallel on
level on this pin will stop instruction execution at the end of
the MC6800. Addresses from the MPU will be valid with the
the current cycle. The MPU will acknowledge DMA/BREQ
leading edge of Q. Data is latched on the falling edge of E.
by setting BA and BS to a one. The requesting device will
Timing for E and 0 is shown in Figure 12.
now have up to 15 bus cycles before the MPU retrieves the
bus for self-refresh. Self-refresh requires one bus cycle with
MRDY a leading and trailing dead cycle. See Figure 15.
This input control signal allows stretching of E and 0 to Typically, the DMA controller will request to use the bus
extend data-access time. E and 0 operate normally while by asserting DMA/BREQ pin low on the leading edge of E.
MRDY is high. When MRDY is low, E and 0 may be stretch- When the MPU replies by setting BA and BS to a one, that
ed in integral multiples of quarter (1/4) bus cycles, thus cycle will be a dead cycle used to transfer bus mastership to
allowing interface to slow memories, as shown in Figure the DMA controller.
13(A). A maximum stretch is 10 microseconds. During non- False memory accesses may be prevented during any dead
valid memory access lVMA cycles) MRDY has no effect on cycles by developing a system DMAVMA signal which is
stretching E and 0; this inhibits slowing the processor during LOW in any cycle when BA has changed
"don't care" bus accesses. MRDY may also be used to When BA goes low leither as a result of DMA/BREQ =
stretch clocks lfor slow memory) when bus control has been HIGH or MPU self-refresh), the DMA device should be taken
transferred to an external device (through the use of HALT off the bus. Another dead cycle will elapse before the MPU
and DMA/BREQI. accesses memory, to allow transfer of bus mastership
NOTE: Four of the early production mask sets (G7F, T5A, without contention.
P6F, T6M) require synchronization of the MRDY input with
the 4f clock. The synchronization necessitates an external
oscillator as shown in Figure 13 lBI. The negative transition
of the MRDY signal, normally derived from the chip select MPU OPERATION
decoding, must meet the tPCSM timing. With these four During normal operation, the MPU fetches an instruction
mask sets, MRDY's positive transition must occur with the from memory and then executes the requested function.
rising edge of 4f. This sequence begins at RESET and is repeated indefinitely
In addition, on these same mask sets, MRDY will not unless altered by a special instruction or hardware occur-
stretch the E and 0 signals if the machine is executing either rence. Software instructions that alter normal MPU opera-
a TFR or EXG instruction during the HALT high to low transi- tion are: SWI, SWI2, SWI3, CWAI, RTI and SYNC. An in-
tion. If the MPU executes a CWAI instruction, the machine terrupt, HALT or DMA/BREQ can also alter the normal ex-
pushes the internal registers onto the stack and then awaits ecution of instructions. Figure 16 illustrates the flow chart for
an interrupt. During this waiting period, it is possible to place the MC6009.
E ~:--",O.,,-5":"V -,/r----------.~
I I
I+-tAvsj 1
I 24V \ 1
o I ......_ _..J..I _
I Address Valid I
221
MC6809/MC68A09/MC68B09
\"------'/ \"------'/
/
MRDY
+5V
+5
+5
To
System 24
as
Required
MC6809
MRDY Stretch
Stretch = 07 RC
XTAL 12
222
MC6809/MC68A09/MC68B09
2.0 V
~tPCSD
------------------"""""
BA, BS
\-------
DMAVMA"
\'----~/ \,--_~r
ADDR
IMPUI
-J»)-------------------------<C
IDAS~~I------------«I... ....J)>-----
IDEAD I
.... t - - - - - - - - 1 4 DMA CyCleS--------~.IDEADIMPulocJ.__DMA-
I I I I I I
I I I I I I
I
Q I
I
5M"ATi3illii \ : I
BA, BS ---r
I
I
I
,..-+:- - - - -
DMAVMA .--\...J...------------------------lJ---\J:------
*5"M"AV'M'A is a signal which is developed externally, but is a system requirement for OMA
223
~
FIGURE 16 - FLOWCHART FOR 6809 INSTRUCTIONS
~.l'
s:
o
~
o
~
s:
o
0)
C»
»
o
~
s:
o
0)
C»
I:D
o
CD
ADDRESSING MODES
225
MC6809/MC68A09/MC68B09
FIGURE 17 - INDEXED ADDRESSING POSTBYTE Zero-Offset Indexed - In this mode, the selected pointer
REGISTER BIT ASSIGNMENTS register contains the effective address of the data to be used
Indexed by the Instruction. This is the fastest indexing mode
Post-Byte Register B~
Addressing
Examples are
7 6 5 4 3 2 1 0 Mode
a R R x x x x x EA - ,R + 5 Bit Offset
LOO a,x
LOA 5
1 R R a a a a a ,R +
1 R R I a a a 1 ,R+ +
1 R R a a a 1 a ,- R
Constant Offset Indexed - In this mode, a
1 R R I a a 1 1 ,- - R
two's-complement offset and the contents of one of the
1 R R I a 1 a a EA ~ ,R + a Offset pOinter registers are added to form the effective address of
1 R R I a 1 a 1 EA ~ ,R + ACCB Offset the operand The pointer register's Initial content IS un-
1 R R I a 1 1 a EA - ,R + ACCA Offset changed by the addition
1 R R I 1 a a a EA = ,R + B Bit Offset Three sizes of offsets are available
1 R R I 1 a a 1 EA - ,R + 16 Bit Offset 5 -bit {-16 to + 151
1 R R I 1 a 1 1 EA - ,R + 0 Offset 8 -bit 128 to + 1271
1 x x I 1 1 a a EA - .PC + 8 Bit Offset 16-blt {- 32768 to + 327671
1 x x I I 1 a 1 EA - ,PC + 16 Bit Offset
The two's complement 5-bit offset IS Included In the
1 R R 1 1 1 1 1 EA - [ Address] post byte and, therefore, IS most efftcient in use of bytes and
'-v- ~ cycles. The two's complement 8-blt offset IS contained In a
L
C
Add.reSSlng. Mode Field single byte follOWing the postbyte. The two's complement
16-blt offset IS In the two bytes following the postbyte. In
- Indirect Field
most cases the programmer need not be concerned with the
(Sign bit when b7 = 01
size of this offset since the assembler will select the optimal
size automatically
Register Field RR Examples of constant-offset IndeXing are
oo~ X LOA 23,X
01 ~ y
LOX - 2,5
10= U
11 = S LOY 300,X
LOU CAT,Y
x = Don't Care
3
+
#
~ and; indicate the number of additional cycles and bytes tor the particular variatlor.
226
MC6809/MC68A09/MC68B09
Accumulator-Offset Indexed - This mode is similar to All modes of indexed Indirect are included except those
constant offset indexed except that the two's-complement which are meaningless (e.g., auto increment/decrement by
value in one of the accumulators lA, B or Dl and the con- 1 indirect). Some examples of indexed indirect are
tents of one of the pointer registers are added to form the ef- LDA [,Xl
fective address of the operand. The contents of both the ac-
LDD [lO,SJ
cumulator and the pointer register are unchanged by the ad-
dition. The postbyte specifies which accumulator to use as LDA [B,Y]
an offset and no additional bytes are required. The advan- LDD [,X+ +]
tage of an accumulator offset is that the value of the offset
can be calculated by a program at run-time.
Some examples are:
RELATIVE ADDRESSING
LDA B,Y The bytelsl following the branch opcode is (are) treated as
LDX D,Y a signed offset which may be added to the program counter
LEAX B,X If the branch condition is true then the calculated address
Auto Increment/Decrement Indexed - In the auto incre- IPC + signed offset I is loaded into the program counter
ment addressing mode, the pointer register contains the ad- Program execution continues at the new location as in-
dress of the operand. Then, after the pointer register is used dicated by the PC; short 11 byte offset I and long 12 bytes off-
it is incremented by one or two. This addressing mode is setl relative addressing modes are available. All of memory
useful in stepping through tables, moving data, or for the can be reached in long relative addressing as an effective ad-
creation of software stacks. In auto decrement, the pointer dress is interpreted modulo 216 Some examples of relative
register is decremented prior to use as the address of the addressing are
data. The use of auto decrement is similar to that of auto in-
crement; but the tables, etc., are scanned from the high to
low addresses. The size of the increment/ decrement can be BEQ CAT (shortl
either one or two to allow for tables of either B or 1f3..bit data BGT DOG Ishortl
to be accessed and is selectable by the programmer. The CAT LBEQ RAT Iiong)
pre-decrement, post-increment nature of these modes allow DOG LBGT RABBIT lIongl
them to be used to create additional software stacks that
behave identically to the U and S stacks.
Some examples of the auto increment/decrement ad-
dressing modes are:
LDA ,X+ RAT NOP
RABBIT NOP
STD ,Y+ +
LDB ,- Y
LDX ,- - S
227
MC6809/MC68A09/MC68B09
The instruction set of the MC6809 is similar to that of the LEAX/ LEA Y/ LEAU / LEAS
MC6800 and is upward compatible at the source code level The LEA (Load Effective Address) works by calculating
The number of opcodes has been reduced from 72 to 59, but the effective address used in an indexed instruction and
because of the expanded architecture and additional ad- stores that address value, rather than the data at that ad-
dressing modes, the number of available opcodes Iwith dif- dress, in a pointer register. This makes all the features of the
ferent addressing modesI has risen from 197 to 1464. internal addressing hardware available to the programme!.
Some of the new instructions and addressing modes are Some of the implications of this instruction are illustrated in
described in detail below: Table 3.
The LEA instruction also allows the user to access data in
PSHU/PSHS a position independent manner. For example:
The push instructions have the capability of pushing onto LEAX MSG1, PCR
either the hardware stack lSI or user stack lUI any single LBSR PDATA !Print message routine)
register, or set of registers with a single instruction
PULU/PULS MSGl FCC 'MESSAGE'
The pull instructions have the same capability of the push This sample program prints: 'MESSAGE'. By writing
instruction, in reverse order. The byte immediately following MSG1, PCR, the assembler computes the distance between
the push or pull opcode determines which register or the present address and MSG1. This result is placed as a
registers are to be pushed or pulled. The actual PUSH/PULL constant into the LEAX instruction which will be indexed
sequence is fixed; each bit defines a unique register to push from the PC value at the time of execution. No matter where
or pull, as shown in below the code is located, when it is executed, the computed offset
from the PC will put the absolute address of MSG 1 into the X
- Pull Order Push Order- pointer register. This code is totally position independent.
PC U Y X DP B A CC
FFFF .... - increasing memory address .... OOOO
MUL
PC S Y X DP B A CC
Multiplies the unsigned binary numbers in the A and B ac-
TFR/EXG cumulator and places the unSigned result into the 16-bit D
Within the MC6809, any register may be transferred to or accumulator. This unsigned multiply also allows multiple-
exchanged with another of like-size; i.e., B-bit to S-bit or precision multiplications
16-M to 16-bit. Bits 4-7 of postbyte define the source
register, while bits 0-3 represent the destination register. Long And Short Relative Branches
These are denoted as follows· The MC6809 has the capability of program counter relative
0000 - D 0101 - PC branching throughout the entire memory map. In this mode,
0001 - X 1000 - A If the branch is to be taken, the S or 16-bit signed offset is ad:
0010 - Y 1001 - B ded to the value of the program counter to be used as the ef-
fective address. This allows the program to branch anywhere
0011 - U 1010 - CC in the 64K memory map. Position independent code can be
0100 - S 1011 - DP easily generated through the use of relative branching. Both
NOTE: All other combinations are undefined and INVALID short IB-bit) and long 116-bit) branches are available.
228
MC6809/MC68A09/MC68B09
229
tIo
Sync
SYNC Acknowledge
~
o
(7)
(ll)
o
~~ ( !e
Fetch ~
o
(7)
''"
- )
" I , c=x::=x:=:c=
(ll)
o»
R/W ( ) !e
BA ==:x==J.. I (. ~
o
BS~
(7)
d (ll)
m
iRO{
FiRQ
See Note 2 o
CD
NMI tpcs
NOTE: 1. If the associated mask bit is set when the interrupt is requested, this cycle will continue the instruction fetched from the previous cycle. However, if
the interrupt ,s accepted INMI or an unmasked FiRO or iRQI the opcode address (placed on the bus from cycle m + 11 remains on the bus and inter-
rupt processing continues with this cycle as (m + 21 on Figures 10 and 11 (Interrupt Timing!.
2. If mask bits are clear, IRO and FIRO must be held low for three cycles to guarantee interrupt to be taken, although only one cycle is necessary to
bring the processor out of SYNC
FIGURE 19 - ADDRESS BUS CYCLE-BY-CYCLE PERFORMANCE
~
Opeode (Fetch)
...t: NOTES: 1. All subsequent PAGE 2 and PAGE 3 opcodes will be Ignored after inttlal opcode fetch
2. Write operation during store instruction
MC6809/MC68A09/MC68B09
Inherent Page
AS LA ASX RTS TFR EXG MUL PSHU PULU SWI CWAI RTI
AS LS PSHS PULS SWI2
AS RA SWI3
AS RS
CL RA
CL RS
CO MA VMA ADDR STACK
CO MS VMA I
DA A VMA VMA VMA VMA
DE CA VMA VMA VMii
DE CS
IN CA
I I I
VMA VMA STACK 12"STACK 12"STACK 1
IN CS I VMA VMA
I (W~lle) (Wnte)
LS LA VMA VMii E
~
{STACK}12 I
LS LB VMA VMA
LS RA STACK
I VMA VMA
(Write) 0
VMA {VJA} )
LS RB STACK VMA VMA
NE GA VMA VMA
NE GS
NO P
VMA
VMA VMA VECTOR
I
VECTOR
I
RO LA VMA VECTOR VECTOR
2"STACK
P'
RO LS VMA VMA
RO RA
RO RS I CK
S EX {STACK} 12
(Write) 0
I
STACK STACK
j j j
•
232
MC6809/MC68A09/MC68B09
Non-Inherents
END
'l
ADDR + STACK ADDR+
ADDR+ VMA
'I"'
233
MC6809/MC68A09/MC68B09
Mnemonicls) Operation
ADCA, ADCB Add memory to accumulator with carry
ADDA, ADDB Add memory to accumulator
ANDA, ANDB And memory with accumulator
ASL, ASLA, ASLB Arithmetic shift of accumulator or memory left
ASR, ASRA, ASRB Arithmetic shift of accumulator or memory right
BITA, BITB Bit test memory with accumulator
CLR, CLRA, CLRB Clear accumulator or memory location
CMPA, CMPB Compare memory from accumulator
COM, COMA, COMB Complement accumulator or memory location
DAA Decimal adjust A accumulator
DEC, DECA, DECB Decrement accumulator or memory location
EORA, EORB Exclusive or memory with accumulator
EXG Rl, R2 Exchange Rl with R2IRl, R2 = A, B, CC, DPI
INC, INCA, INCB Increment accumulator or memory location
LDA, LDB Load accumulator from memory
LSL, LSLA, LSLB Logical shift left accumulator or memory location
LSR, LSRA, LSRB Logical shift right accumulator or memory location
MUL Unsigned multiply (A x B - D)
NEG, NEGA, NEGB Negate accumulator or memory
ORA, ORB Or memory with accumulator
ROL, ROLA, ROLB Rotate accumulator or memory left
ROR, RORA, RORB Rotate accumulator or memory right
SBCA, SBCB Subtract memory from accumulator with borrow
STA, STB Store accumulator to memory
SUBA, SUBB Subtract memory from accumulator
TST, TSTA, TSTB Test accumulator or memory location
TFR Rl, R2 Transfer Rl to R2 IR1, R2 = A, B, CC, DPI
NOTE: A, B, CC or DP may be pushed to (pulled from) either stack with PSHS, PSHU
(PULS, PULUJ instructions.
Mnemonic(s) Operation
ADDD Add memory to D accumulator
CMPD Compare memory from 0 accumulator
EXG D, R Exchange D with X, Y, S, U or PC
LDD Load D accumulator from memory
SEX Sign Extend B accumulator into A accumulator
STD Store D accumulator to memory
SUBD Subtract memory from 0 accumulator
TFR D, R Transfer D to X, Y, S, U or PC
TFR R, 0 Transfer X, Y, S, U or PC to D
NOTE: D may be pushed (pulled) to either Slack with PSHS, PSHU (PULS, PULU)
instructions.
234
MC6809/MC68A09/MC68B09
235
MC6809/MC68A09/MC68B09
:
00 NEG Direct 6 30 LEAX Indexed 4+ 2+ 60 NEG Indexed 6+ 2+
01 31 LEAY 4+ 2+ 61
02 32 LEAS 4+ 2+ 62
03 COM 33 LEAU Indexed 4+ 2+ 63 COM 6+ 2+
04 lSR 34 PSHS Inherent 5+ 2 64 lSR 6+ 2+
05 35 PUlS 5+ 2 65
06 ROR 36 PSHU 5+ 2 66 ROR 6+ 2+
07 ASR 37 PUlU 5+ 2 67 ASR 6+ 2+
08 ASL. lSl 36 66 ASl, lSl 6+ 2+
09 ROl 39 RTS 5 69 ROl 6+ 2+
OA DEC 3A ABX 3 6A DEC 6+ 2+
OB 3B RTI 6,15 6B
OC INC 3C CWAI 20 6C INC 6+ 2+
OD TST 3D MUl 11 6D TST 6+ 2+
OE JMP 3E 6E JMP 3+ 2+
OF ClR Direct 3F SWI Inherent 19 6F ClR Indexed 6+ 2+
lEGEND
- Number of MPU cycles Iless possible push pull or Indexed-mode cycles)
I Number of program bytes
• Denotes unused opcode
236
MC6809/MC68A09/MC68B09
T
93 SUBD C9 ADCB FF STU Extended 6
94 ANDA CA ORB
95 BITA CB ADDS Page 2 and 3 Machine
96 LDA CC LDD Codes
97 STA CD
9B EORA CE LDU Immed 1021 LBRN Relative 5 4
99 ADCA CF 1022 LBHI 5161 4
9A ORA 1023 LBLS 5161 4
9B ADDA DO SUBB Di ect 1024 LBHS, LBCC 5161 4
9C CMPX Dl CMPB 1025 LBCS, LBLO 5161 4
9D JSR D2 SBCB 1026 LBNE 5161 4
9E LDX D3 ADDD 1027 LBEQ 5161 4
9F STX Direct D4 ANDB 1028 LBVC 5161 4
D5 BITB 1029 LBVS 5161 4
AO SUBA Indexed 4+ 2+ D6 LDB 102A LBPL 5161 4
Al CMPA 4+ 2+ D7 STB 102B LBMI 5161 4
A2 SBCA 4+ 2+ D8 EORB 102C LBGE 5161 4
A3 SUBD 6+ 2+ D9 ADCB 102D LBLT 5161 4
A4 ANDA 4+ 2+ DA ORB 102E LBGT 5161 4
A5 BITA 4+ 2+ DB ADDB 102F LBLE Relative 5161 4
A6 LDA 4+ 2+ DC LDD 103F SWI2 Inherent 20 2
A7 STA 4+ 2+ DD STD 1083 CMPD ed 5 4
Imr
A8 EORA 4+ 2+ DE LDU lOBC CMPY 5 4
A9 ADCA 4+ 2+ DF STU Direct lOBE LDY Immed 4 4
AA ORA 4+ 2+ 1093 CMPD 7 3
ADDA 4+ 2+ EO SUBB Indexed 4+ l09C CMPY Dft 7 3
AB 2+
AC CMPX 6+ 2+ El CMPB 4+ 2+ l09E LDY 6 3
AD JSR 7+ 2+ E2 SBCB 4+ 2+ l09F STY Direct 6 3
AE LDX 5+ 2+ E3 ADDD 6+ 2+ lOA3 CMPD ed 7+ 3+
Indexed 5+ 2+ E4 ANDB lOAC CMPY In1' 7+ 3+
AF STX 4+ 2+
E5 BITB 4+ 2+ 10AE LDY 6+ 3+
BO SUBA Extended 5 E6 LDB 4+ 2+ lOAF STY Indexed 6+ 3+
~
B1 CMPA 5 E7 STB 4+ 2+ 10B3 CMPD 4
10BC CMPY Extred 4
B2 SBCA 5 E8 EORB 4+ 2+
B3 SUBD 7 E9 ADCB 4+ 2+ lOBE LDY 4
B4 ANDA 5 EA ORB 4+ 2+ lOBF STY Extended 7 4
B5 BITA 5 EB ADDB 4+ 2+ 10CE LDS Immed 4 4
B6 LDA 5 EC LDD 5+ 2+ lODE LDS Direct 6 3
B7 STA 5 ED STD 5+ 2+ 10DF STS Direct 6 3
BB EORA 5 EE LDU 5+ 2+ lOEE LDS Indexed 6+ 3+
B9 ADCA 5 EF STU Indexed 5+ 2+ 10EF STS Indexed 6+ 3+
BA ORA 5 lOFE LDS Extended 7 4.
BB ADDA 5 FO SUBB Extended 5 lOFF STS Extended 7 4
BC CMPX 7 Fl CMPB 5 113F SWI3 Inherent 20 2
BD JSR B F2 SBCB 5 1183 CMPU Immed 5 4
BE LDX 6 F3 ADDD 7 118C CMPS Immed 5 4
BF STX Extended 6 F4 ANDB 5 1193 CMPU Direct 7 3
F5 BITB 5 119C CMPS Direct 7 3
CO SUBB 2 F6 LDB 5 l1A3 CMPU Indexed 7+ 3+
T
C1 CMPB 2 F7 STB 5 llAC CMPS Indexed 7+ 3+
C2 SBCB 2 F8 EORB 5 11B3 CMPU Extended B 4
C3 ADDD 4 F9 ADCB 5 l1BC CMPS Extended 8 4
C4 ANDB 2 FA ORB 5
C5 BITB Immed 2 FB ADDB Extended 5
237
MC6809/MC68A09/MC68B09
~::::::::::::::::::J
MILLIMETERS INCHES
DIM MIN MAX MIN MAX
A 51.69 52.45 2.035 2.065
B 13.12 14.22 0.540 0.560
C 3.94 5.08 0155 0.200
0 036 0.56 0.014 0022
F 102 1.52 0.040 0060
G 254 BSC 0.100 BSC
H 1.65 2.16 0.065 0.085
J 0.20 038 0.008 0.015
K 292 3.43 0115 0135
L 15.24 BSC 0.600 BSC
M 0° 15° 0° 15°
N 0.51 102 0.020 0.040
NOTES
1. POSITIONAL TOLERANCE OF LEADS 101,
SHALL BE WITHIN 0.25 mm (0.010) AT
MAXIMUM MATERIAL CONDITION, IN P SUFFIX
RELATION TO SEATING PLANE AND PLASTIC PACKAGE
EACH OTHER. CASE 711
2. DIMENSION L TO CENTER OF LEADS
WHEN FORMED PARALLEL
3. DIMENSION B ODES NOT INCLUDE
MOLD FLASH
MILLIMETERS INCHES
DIM MIN MAX MIN MAX
A 50.29 51.31 1.9BO 2.020
B 14.94 15.34 0.588 0.604
C 3.05 4.06 0.120 0.160
0 0.38 0.53 0.015 0.021
F 0.76 1.40 0.030 0.055
G 2.54 BSC 0.100 BSC
H 0.76 1.78 0.030 0.070
J 0.20 0.33 O.OOB 0.013
K 2.54 4.19 0.100 0.165
L 14.99 15.49 0.590 0.610
M - 100 - 100
N 1.02 1.52 0.040 0.060
NOTES:
1. LEADS, TRUE POSITIONED WITHIN 0.25 mm
(0.010) OIA (AT SEATING PLANE), AT MAX
MAT'L CONDITION.
2. DIMENSION "L" TO CENTER OF LEADS
WHEN FO RMED PARALLEL.
L SUFFIX
CERAMIC PACKAGE
CASE 715
238
MC6809E/MC68A09E/MC68B09E
HMOS
(HIGH DENSITY N-CHANNEL, SILICON-GATE)
a-BIT
MICROPROCESSING
UNIT
239
MC6809EJMC68A09EJMC68B09E
2
~
{ t Lr-
MC6809E Dedicated Dedicated MC6809E
Processor Memory Memory Processor
No.1 and and No.2
Penpherals Penpherals
a Data a Data
116 ADDR
II ,16 ADDR
5 Status 5 Status Control = RESET
4 Control 4 Contr HALT
AVMA
31nt 3 Int BREQ
I II II I Status= R/W
BA
Clock Bus Arbitration BS
Generator Logic BUSY
L1C
Int= NMI
FIRQ
IRQ
~
0
lX)
"
<J)
'"
J.,. E
'"
Global
~ Memory and
Peripherals
• Position Independent Programs - Program Executes Properly Anywhere in the Address Space
• Re-Entrant Programs - A Routine Usable By Interrupt and Non-Interrupt Programs Without Losing Data
• Structured High Level Languages - More Efficient Compilers and Compiler Generated Code
• Recursive Routines
MC6829
HMOS
(HIGH DENSITY N-CHANNEl, SILICON-GATE)
MEMORY
MANAGEMENT
UNIT (MMUI
A15 2
• Each MMU is Capable of Handling 4 Separate Tasks
A14 3
RSO 14
BA 18
• 6809/6800 Bus Compatible
BS 19
RESEr 20
• Single 5-Volt Power Supply
241
MC6829
Task 0
10SI
,
r-
-It---~'__
~/~,
pa_ge_l- - - - - - 1
IXXXJ
"-----------~-'/ ~'----------------I
,-_ _ Shared Task
FFFF
Task 1
1XXXJ1--------------1e--------
IDMAI
~---------'
L----===::::::::~{=========~
TaskF~FFI
IUser! 1 - ,- - - - - - - - - - ,
r=-=--== ~I--------------i
AD-Al0
, ;1/
/
11 lihYSICal Address Lines
Al1-A15 '\
MC6809
~ Chip
Select 1 f-- F1i'i
MMU
I Main
Memorv
BA, BS "1'10
t
t
~
MMU
00-07
" '1
F1i'i I--
242
MC6839
HMOS
(HIGH DENSITY N-CHANNEL, SILICON-GATE)
M6809 FLOATING
POINT ROM
243
MC6842
HMOS
SERIAL DIRECT
MEMORY ACCESS
PROCESSOR
D5
• Internal Bit and Byte Synchronization
A5 D4
• Point-to-Point, Multidrop, and Loop Modes
A6
• CRC Generator and Detection
• Primary/Secondary Configurations
244
MC6842
BLOCK DIAGRAM
h-T7...,.,r-rTTT7...,.,r-r""''''''T7...,.,r-r-,--r'''i~ Address
Bus
Serial
Lines
245
MEK6809AC
The MEK6809EAC is a software package designed to operate in conjunction with systems based on the MEK6809D4
Microcomputer Module It is available in audio cassette form recorded at 300 Baud. It is compatible with the tape format of the
MEK6809D4
General Features
• ROMabie
• Assembles both 6800 and 6809 mnemonics to 6809
object
• Able to Operate with 04 or Stand-Alone 6809
• Self-Sizing of Memory
• Can Read Tapes Produced by MEK6802EA Using
MEK681/0
• Serial or Parallel Printer Supported
• Interactive Editor
• Uses MEK6809D4 Cassette for Program Storage
• Uses MEK68R2D for Video Display
246
MEK6809AC
247
MEK6809D4/MEK68KPD
MEK6809D4
MEK68KPD
The MEK6809D4 Advanced Microcomputer Evaluation Board and MEK68KPD Keypad/Display Unit provide the necessary hard-
ware and firmware for a computer system based on the Motorola MC6809 High Performance Microprocessor. The system forms an
evaluation tool to facilitate the application of Motorola microprocessors and associated components.
The MEK6809D4A is used with an MEK68KPD and is complete with a power supply. The MEK6809D4B requires an external
power supply and is used with RS-232 terminal or an MEK68R2D CRT Interface plus a CRT and an ASCII keyboard.
The user can prototype dedicated systems plus write and evaluate software programs in machine language, using a cassette
recorder/player for data storage. Provisions are made for extensive system expansion.
MEK6809D4
MEK68KPD
248
MEK6809D4/M EK68KPD
PRODUCT FEATURES
MEK6lmD4 DIMENSIONS
• MC6809 High Performance Microprocessor • MEK680904:
• D4BUG Monitor Firmware 14K) Expandable to 6K Two-Sided PC Board
309.8 mm (12 in) Wide by
• Direct Memory Access
177.8 mm (7 in) High by
• Interrupt by Device 1.59 mm (0.062 in) Thick
• Audio Cassette Interface, 300 or 1200 Baud
• MEK68KPD:
• Optional RS-232 Port with MC6B50 ACIA Two-Sided PC Board
• System RAM, 512 Bytes Expandable to 1K 304.8 mm (12 in) Wide by
• User RAM, 512 Bytes Expandable to 4K 157.5 mm (6.2 in) High by
1.59 mm (0.062 in) Thick
• RAM/ROM Page Select Register
• ROM Mapping Technique
• All I/O and Memory Fully Decoded
• Stop-On-Address Comparator SUPPLY VOLTAGES (±5%1
• System Clock Internal or External • MEK680904:
• Test Signal and Control Logic for Bidirectional Address 5 Vdc at 2.0 A max (with all optionsl
Bus + 12 Vdc at 25 mA max
- 12 Vdc at - 23 mA max
• Control and Status Lines
• System Buffers • MEK68KPD:
120 Vac.60 Hz, produces 18 Vac lcll input to board. An
MEK68KPD on-board regulator provides power required to operate
the KPD plus D4 board in minimum configuration.
• Eight 7-Segment Displays
• 25-Key Keypad
• On-Board Power Supply ENVIRONMENTAL
• User PIA, MC6821 Op6rating Temperature: O°C to 55°C (32°F to 131°;=)
• Wire-Wrap Area
• H,-Pin Auxiliary Socket Relative Humidity: to 80% without condensation
HIGHLIGHTS
• System buffers are used between sections of the store and recover Kansas City Standard 300-baud or
MEK680904 board and between the board and its edge 1200-baud format cassette tape data.
connectors. • Interrupt driven stop-on-address comparator.
• Hardware RAM and ROM page select register. • System clock derived from 3.579 MHz on-board XT AL
• 4K static User RAM leight sockets) may be mapped with or from a 4 x TTL compatible external source.
jumpers to appear at any 4K block in the 6411. basic mem- • "Test" signal and logic provided to allow control of on-
ory space, and in addition may be jumpered to appear on board memory and I/O, from an external processor
a selected "RAM Page/or Pages" as controlled by a 3- through the 7a-pin edge connector.
bit hardware RAM Page register. • Control and status lines provided for flexible hardware
• Eight 24-pin ROM sockets may be configured to accept control of MPU and Bus Decode/Drive logic. This allows
combinations of ROM/EPROM types including 1K x 8 for:
single or triple supply.EPROMs or ROMs, 2K x 8 single • Testing and Debug
or triple supply EPROMs or ROMs, 4K x 8 ROMs or • Interrupts (RESET, NMI, IRQ, FIRQ)
EPROMs, or 8K x 8 ROMs or EPROMs. • Interrupt Vectoring by Device (IVE, STKOP)
• A ROM-based mapping technique is used to allow com- • Interrupt Disable (IRQE, FIRQE)
pletely general address mapping of the eight ROM sock- • HALT and Bus Request (BREQ)
ets anywhere in the 64K basic memory space with 1K • Slow Memory (MEMRDY)
resolution. In addition, the sockets may be mapped on ·DMA
any "ROM Page/or Pages" as controlled by a 3-bit
hardware ROM page register. The following features are standard on the MEK6809D4B
• All memory and I/O on the board is fully decoded, so that and may be included as options on the MEK6809D4A:
address space not specifically required on the 04 is avail- 1. RS-232 compatible serial port including buffered
able for off-board mapping. handshake signals.
• A - 12 volt to - 5 volt regulator is provided to allow use 2. Baud rate generator prOViding baud rate clocks for 110,
of 3-supply EPROMs on the 04. Supply voltages of + 12, 300, 600, 1200, 4800, and 9600 baud rates.
- 12, and + 5 must be provided by the user. 3. Address, data, and control lines fully buffered at bus
• Hardware is provided which allows Monitor software to interface.
249
MEK6809D4/MEK68KPD
MODEL TYPES
MEK6809D4 MOKEP M-60 and M-70 products are compatible with the
MEK6909D4A - This variation has no RS-232 circuitry or D4B thus allowing expansion to an ASCII keyboard interface
address and data buffers to the edge connector. The D4A is to the microcomputer system. The MEK68KPD (with its on-
intended for use with the MEK68KPD Keypad/Display Unit board power supply disconnected I may be used with the
which has an on-board power supply to operate the system. MEK6809D4B.
No RAMs are provided in the "User RAM" array. A 4K
monitor program is provided.
MEK6809D4B - This variation is intended for use with an
RS-232 serial terminal or an MEK68R2D CRT interface as the MEK68KPD
system terminal. The D4B has RS-232 circuitry and data and The MEK68KPD is the Keypad/Display unit intended for
address buffers. use with the M EK6809D4 board and interfaces electrically
To operate the RS-232 interface, the user must supply with the MEK6809D4. Standard interface to the 04 is via a
+ 12 V, + 5 V, and -12 V power A 4K + 2K monitor is pro- 24-conductor cable and plug assembly supplied with the
vided. No RAMs are provided in the "User RAM" array. KPD unit.
EXPANSION
With the rapid adva')cements in the microprocessor in- MEK68EP EPROM Programmer Module
dustry, there is a vital need to provide educational and The MEK68EP has provisions for programming both single
evaluation material to help engineering/technical personnel and triple power supply types of 1K, 2K, and 4K EPROMs.
stay abreast of this technology
In response to this need Motorola Memory Systems has
MEK68RR ROM/RAM Module
evolved a series of kit boards intended for the educational
evaluation of the MC6800 family of integrated circuits. The The MEK68RR has provisions for eight ROM sockets
series is called "MOKEP" Ifor Motorola Kit Expansion Pro- which may be configured to accept 1K, 2K, 4K, or 8K single
ducts) and includes the following wide range of boards: or triple supply ROMs or EPROMs. The board also has
sockets for up to 8K bytes of static RAM
250
MEK6809D4/MEK68KPD
Access Time
251
MEK6809D4/MEK68KPD
SOFnNAREFEATURES
252
MEK6809D4/MEK68KPD
Memory Dump After the mask has been specified, the search function will
The memory dump command allows the user to display btl performed over the specified address range.
blocks of memory with ASCII equivalents. The display for- Each time the comparison algorithm is successful, the ad-
mats differ slightly depending on the display device con- dress of the first location of the match is displayed. If the list
figuration. The ending address must be a larger hexadecimal of successful addresses is being displayed too quickly, the
number than the beginning address or a warning will be listing may be temporarily halted by typing (ESCAPE) as in
issued, followed by a new request for a begin address. The the memory dump command.
dump command cannot proceed until a satisfactory address
range has been specified. Memory Move
Allows the user to move a block of data from one area in
memory to a new area.
Memory Fill The beginning and ending addresses are entered the same
Allows the user to fill a block of memory with a four byte way as in memory dump. FollOWing entry of the end ad-
pattern. The beginning and ending addresses are entered as dress, a message will appear requesting entry of the new
in the memory dump command. beginning address where the block of data is to be moved.
ASCII Entry
Memory Search Allows a user to store ASCII data to memory quickly and
Allows search of a specified block of memory for a 4 byte easily without having to look up each ASCII character to
pattern subject to a corresponding 4 byte mask. For all bits in determine its hexadecimal equivalent.
the mask which are zero, the corresponding bit in the pattern Features are incorporated to assist in setting up messages
is considered to be "don't care." for the D4BUG callable subroutine "PDATA."
MEK68l9D4 DESCRIPTION
CPU ROM
The CPU consists of an MClBl9 high performance The ROM system consists of eight ROM sockets which
microprocessor, a 3.579 MHz crystal, and buffers which in- may be configured to accept various combinations of ROM
terface the MClBl9 to other circuit blocks on the D4 Board. types. These include single or triple power supply varieties of
The MC6809 supports programming techniques such as 1K, 2K, 4K, or BK x 8 ROMs or EPROMs.
position independence, re-entrancy, and modular program- The ROM type configurations are controlled by mini-
ming. The MClBl9 has hardware and software features jumpers which may be easily moved without the need for any
which make it a suitable processor for higher level language tools.
execution or standard controller application.
253
MEK6809D4/MEK68KPD
Mapping of the eight ROMs in memory space is ac- The Data Bus System
complished by a mapping ROM which is used as a program- There are four bi-directional data buffers used in the 04; a
med logic array. A paging technique allows up to 192K bytes ROM buffer, RAM/IO buffer, Edge buffer, and MPU buffer
of ROM to be used In the 04 system Each buffer has an enable and a direction input. Control logic
configures these buffers to route data between sections of
RAM the 04 board
There are two groups of 1K x 4 RAMs. One group is the
stack RAM and the other is the user RAM. The Stop-Dn-Address Circuit
The stack RAM is used mainly for the 04 operating system The purpose of a stop address is to enable a user program
stack and scratch RAM. Also, 512 bytes are available for user to be executed until a certain address is reached.
RAM application. This RAM is always located in the 04 The address to be stopped on is stored and when the
system at memory location $E4OO through $E7FF. board address bus bits coincide, an output results. This
The user RAM is a 4K x 8 block of memory that can be causes a nonmaskable interrupt to occur which switches the
positioned anywhere in the 04 memory map, using jumper microprocessor to a service routine.
connectIons. When a coincidence of address occurs, an NMI is not
It is possible to disable the eight user RAM sockets to necessarily generated. In these cases, the comparator output
allow use of a MOKEP MEK68MM Memory Board for system is available at a test point to provide a trigger signal to an
expansion. oscilloscope.
Another jumper, when removed, prevents the user RAM
from being written into (write protect), but the stack RAM is The RS-232 Circuit
not affected. With the jumper in place, read and write to the The RS-232 specification defines a standard for intercon-
user RAM is normal. necting computer terminals of different makes. The ACIA
converts the parallel data on the buses to serial data. The
The Address Bus System serial data is then translated into RS-232 levels.
In some microprocessor systems, the address flow is from
the microprocessor through buffers and to the motherboard The Cassette Circuit Interface
bus. The 04 uses a more complex arrangement that permits The 04 uses very few components to interface a tape
disabling the microprocessor. This allows addresses to be recorder to its operating system. Most of the cassette opera-
fed to the 04 from an external source, to access board com- tion occurs in software, to create tapes and recover data
ponents and permits OMA (direct memory access) for some from tapes. The tape information consists of a stream of
applications. 1200 and 2400 Hz serial audio data.
254
M EK6809D4/M EK68KPD
MEK68KPD DESCRIPTION
The MEK68KPD Includes a 25-key keypad, eight The display consists of eight seven-segment LEDs with a
7-segment LED displays, an on-board + 5 volt power supply, character height of 0.5 Inches. The grouping of the displays
and an uncommitted MC6821 PIA. ProvIsions are made to is in a 4-2-2 linear array A sUitable anti-glare filter IS provided
allow disconnection of the on-board regulators when an ex with each MEK68KPD
ternal + 5 volt supply IS used. A wire-wrap area is provided The PIAs used on the KPD are fully decoded via a
for custom circuitry and a 16-pln socket allows for additional Peripheral Chip Select signal and Address lines AO-A2 from
signals to be brought to or from thiS wire-wrap area the M EK6809D4. Data IS furnished via the input cable
ORDERING INFORMATION
255
APPENDIX D
MC6809
Instruction Set Summary
256
MC6809 MICROPROCESSOR
INSTRUCTION SET SUMMARY
C PC I PROGRAM COUNTER
I A B I ACCUMULATORS
'-- ,/
o
UO DIRECT PAGE REGISTER
I
FH I NZV CC - CONDITION CODE
CARRY-BORROW
OVERFLOW
ZERO
NEGATIVE
IRQ INTERRUPT MASK
HALFCARAY
FAST INTERRUPT MASK
ENTIRE STATE ON STACK
257
MC6809 MICROPROCESSOR
INSTRUCTION SET SUMMARY
POWERS OF TWO
HEXADECIMAL AND DECIMAL CONVERSION
MS
CHAR 0 1 2 3 4 5 6 7
LS 001 010 011 101 110
CHAR
000 '00
"'
0 INDEXED ADDRESSING
NUL DLE SP @
POST BYTE REGISTER
,
0000
SOH DC' Q BIT ASSIGNMENTS
0001
2 INDEXED
STX DC2 POST-BYTE REGISTER BIT ADDRESSING
0010
7 6 5 4 3 2 1 0 MODE
3
ETC DC3 0 X X X X X X X EA - • A , 4 BIT OFFSET
0011
4 1 X X 0 0 0 0 0 R+
0100
EDT DC<
1 X X X 0 0 0 , ,A++
5 1 X X 0 0 0 1 0 ,-R
ENQ NAK
010'
1 X X X 0 0 1 1 ,--R
6
ACK SYN X X 1 EA -.R, o OFFSET
0110 1 X 0 0 0
7 1 X X X 0 , 0 1 EA ,R ~ ACeS OFFSET
,
eo
BEL ETB
0111
X X X 0 1 1 0 EA =--' ,A :!: ACCA OFFSET
8
BS CAN 1 X X X 1 0 0 0 EA - ,R , 7 BIT OFFSET
'000
1 X X X 1 0 1 EA -'" ,R 15 BIT OFFSET
9 HT EM , 0
, 1 EA - .R , D OFFSET)
::!:
'001
A
1
1
X
X
X
X
X
X , 0
1 0 0 EA '-" , PC ~ 7 BIT OFFSET
1010
SUB
, X X X 1 1 0 1 EA =, PC, 15 BIT OFFSEl
B
1011
ESC 1 X X 1 1 1 1 , EA - ,ADDRESS
~
C
FS i. ADDRESSING MODE FIELD
I FIELD
D FOR 87 = 1: INDIAECT
CR GS
1101 FOA 87 -= 0: SIGN B!T
E
1110
F
SO RS
• REGISTER FIELD
OQR
01:R =- Y
= X
SI VS DEL IO,R = U
1111
11:R = S
258
MC6809 MICROPROCESSOR
INSTRUCTION SET SUMMARY
CCA
A
'-- B
L...- DPA
L-- X
'-----------y
'-- S/U
'------ PC
259
MC6809 MICROPROCESSOR
INSTRUCTION SET SUMMARY
OP MNEM MODE ~
# OP MNEM MODE ~
# OP MNEM MODE - #
OP MNEM MODE ~
# OP MNEM MODE ~
# OP MNEM MODE ~
260
MC6809 MICROPROCESSOR
INSTRUCTION SET SUMMARY
OP MNEM MODE ~
# OP MNEM MODE ~
# OP MNEM MODE ~
#
OP MNEM MODE ~
I
FC LDD 6 3 102F LBLE RELATIVE 5(6) 4 10DE LDS DIRECT 6 3
FD STD 6 3 103F SWI/2 INHERENT 20 2 10DF STS DIRECT 6 3
FE LDU 6 3 1083 CMPD IMMED 5 4 10EE LDS INDEXED 6 3
FF STU EXTENDED 6 3 108C CMPY t 5 4 10EF STS INDEXED 6 3
1021 LBRN RELATIVE 5 4 108E LDY IMMED 4 4 10FE LOS EXTENDED 7 4
1022 LBHI 5(6) 4 1093 CMPD DIRECT 7 3 10FF STS EXTENDED 7 4
1023 LBLS 5(6) 4 109C CMPY 7 3 113F SWI/3 INHERENT 20 2
1024
1025
LBHS/LBCC
LBCS/LBLO
5(6) 4
5(6) 4
109E LOY
109F STY
I
DIRECT
6
6
3
3
1183 CMPU
118C CMPS
IMMED
IMMED
5
5
4
4
1026 LBNE 5(6) 4 10A3 CMPD INDEXED 7 3 1193 CMPU DIRECT 7 3
1027 LBEQ 5(6) 4 10AC CMPY 7 3 119C CMPS DIRECT 7 3
H'l28
1029
LBVC
LBVS
5(6) 4
5(6) 4
lllAE LOY
10AF STY
I
INDEXED
6
6
3
3
11A3 CMPU
l1AC CMPS
INDEXED
INOEXED 7
7 3
3
102A LBPL 5(6) 4 10B3 CMPD EXTENDED 8 4 11B3 CMPU EXTENDED 8 4
102B LBMI
102C LBGE
1020 LBLT RELATIVE
5(6) 4
5(6) 4
5(6) 4
10BC CMPY
10BE LOY
1eBF STY
I
EXTENDED 7
8
7
4
4
4
11BC CMPS EXTENDED 8 4
281
MC6809 MICROPROCESSOR
INSTRUCTION SET SUMMARY
BCS BCS
LBCS
25 3 2 Branch C = 1
10 5(6) 4 Long Branch
·. · ..
· .·..
25 C= 1
BEQ BEQ
LBEQ
27 3 2 Branch Z=O
105(6 4 Long Branch
27 Z=O
··..··....
BGE BGE
LBGE
2C 3 2 Branch ;,. Zero
105(6) 4 Long Branch
2C Zero
;,.
· .·· ....
·.
BGT BGT
LBGT
2E 3 2 Branch > Zero
10 5(6) 4 Long Branch >
2E Zero
·.··....
·.
BHI BHI
LBHI
22 3 2 Branch Higher
105(6) 4 Long Branch
· .··....
·.
22 Higher
BHS BHS 24 3 2 Branch Higher ·. ·..
LBHS
24
or Same
10 5(6) 4 Long Branch
Higher or Same
·.· ..
BIT BITA 95 4 2 B5 5 3 85 2 2 AS 4+ 2+ Bit Test A (M A A)
• t to·
• t to·
··..··....
BITB 05 4 2 F5 5 3 C5 2 2 E5 4+ 2+ Bit Test B (M f\ B)
2F 3 2 Branch ., Zero
BLE BLE
LBLE 105(6 4 Long Branch .,
2F Zero
262
MC6809 MICROPROCESSOR
INSTRUCTION SET SUMMARY
263
MC6809 MICROPROCESSOR
INSTRUCTION SET SUMMARY
- HN ZVC
COM COMA 2 1 A-+A
43 • t to 1
COMB 2 1 B-+B
53 • t t01
COM 03 6 2 73 7 3 63 6+ 2+ M-+ M • t t01
CWAI 3C 20 2 CC t IMM -+CC; 1
Wait for Interrupt
DAA 19 2 1 Decimal Adjust A • t tot
DEC DECA 4A 2 1 A-1-+A
• t t t •
DECB 5A 2 1 B-1-+B
• t t t •
DEC OA 6 2 7A 7 3 6A 6+ 2" M-1-+M • t t t •
EOR EORA 98 4 2 B8 5 3 88 2 2 A8 4+ 2+ AvM-+A
• t to·
EORB D8 4 2 F8 5 3 C8 2 2 E8 4+ 2+ BVM-+B • t to·
EXG
INC
R1, R2
INCA
1E
4C
7
2
2
1
R1 .... R2'
A+1-+A
· . · ..
• t t t •
INCB 5C 2 1 B+1-+B
• t t t •
INC OC 6 2 7C 7 3 6C 6+ 2+ M+ l-+M
• t t t •
JMP OE 3 2 7E 4 3 6E 3+ 2+ EA' -+ PC ·. ··....
JSR
LO LDA
90
96
7
4
2 BD
2 B6 5
8 3
3 86 2 2 A6
AD 7+ 2+
4+ 2+
~umptoSubroutine
M-+A
·. to·
• t
LOB D6 4 2 F6 5 3 C6 2 2 E6 4+ 2+ M-+B to·
• t
LDD DC 5 2 FC 6 3 CC 3 3 EC 5+ 2+ M: M + 1 -+ D to·
• t
LDS 10 6 3 10 7 4 10 4 4 10 6+ 3+ M: M + 1 -+ S to·
• t
DE FE CE EE
LDU DE 5 2 FE 6 3 CE 3 3 EE 5+ 2+ M: M t 1 -+ U
• t to·
LDX 9E 5 2 BE 6 3 8E 3 3 AE 5+ 2+ M: M + 1 -+ X • t to·
LDY 10 6 3 10 7 4 10 4 4 10 6+ 3+ M: M + 1 -+ Y
• t to·
9E BE 8E AE
LEA LEAS
LEAU
32
33
4+
4+
2
2+
EA'-+
EA'-+
S
U ···...··....
LEAX
LEAY
48 2 1
30
31
4+
4+
2
2
EA'-+
EA'-+
X
Y ·. t ••
t ••
LSL LSLA • t t t t
LSLB 58 2 1 BD~~o
A} -
• t t t t
08 6 2 78 7 3 68 6+ 2+ M C b7 bo
LSL • t t t t
~
LSR LSRA 44 2 1 ·0 t • t
LSRB 54 2 1
M b7 bo c
0
} 0 -IIlIIIID-+ • 0 t • t
LSR 04 6 2 74 7 3 64 6+ 2+ • t
MUL 3D 11 1 AxB-+D
(Unsigned)
·.
• 0 t
t • 9
264
MC6809 MICROPROCESSOR
INSTRUCTION SET SUMMARY
PULU 37 5+ 2
S Stack
Pull Registers from
U Stack
·. ·..
··· ~~~
~ }UJ.-rnIIIIIlJ
~ ~ ~
ROL ROLA 49 2 1
ROLB 59 2 1 ~ ~ ~
ROL 09 6 2 79 7 3 69 6+ 2+ M C b7 .- bo ~ ~ ~
t• ~
~}LO--+d}J •• tt t • t
ROR RORA 46 2 1
1
RTI
RORB
ROR
56 2
3B /15 1
06 6 2 76 7 3 66 6+ 2+ M
Return From
·~ t • t
C b7 --+ bo
7
Interrupt
RTS 39 5 1 Return From
Subroutine
·. ·..
SBC SBCA 92 4 2 B2 5 3 82 2 2 A2 4+ 2+ A-M-C--+A 8 ~ ~ t t
SBCB 02 4 2 F2 5 3 C2 2 2 E2 4+ 2+ B-M-C--+B 8 t tt~
SEX 10 2 1 Sign Extend B
into A
• t to'
ST STA 97 4 2 B7 5 3 A7 4+ 2-+ A--+ M
• t to'
STB 07 4 2 F7 5 3 E7 4+ 2-+ B--+M
• t to.
STD DO 5 2 FD 6 3 ED 5+ 2+ 0--+ M: M + 1
• t ~0•
STS 10
OF
6 3 10
FF
7 4 10
EF
6+ 3+ S--+ M:M + 1
• t to'
STU OF 5 2 FF 6 3 EF 5+ 2+ U--+ M:M + 1
• t to'
STX 9F 5 2 BF 6 3 AF 5+ 2+ X--+ M: M + 1
•t ~0•
STY 10
9F
6 3 10
BF
7 4 10
AF 6+ 3+
Y--+ M:M + 1
• t to'
265
MC6809 MICROPROCESSOR
INSTRUCTION SET SUMMARY
NOTES:
1. Given in the table are the base cycles and byte counts. To determine the total cycles and byte counts add the values
from the '6809 indexing modes' table.
2. R1 and R2 may be any pair of 8 bit or any pair of 16 bit registers.
The 8 bit registers are: A, B, CC, DP
The 16 bit registers are: X, Y, U, S, 0, PC
3. EA is the effective address.
4: The PSH and PUL instructions require 5 cycles plus 1 cycle for each byte pushed or pulled.
5. 5(6) means: 5 cycles if branch not taken, 6 cycles if taken.
6. SW1 sets I&F bits. SW12 and SW13 do not affect I&F.
7. Conditions Codes set as a direct result of the instruction.
8. Value of half-carry flag is undefined.
9. Special Case-Carry set if b7 is SET.
LEGEND:
OP Operation Code (Hexadecimal); Z Zero (byte)
Number of MPU Cycles; V OverflOW, 2's complement
II Number of Program Byles; C Carry from bit 7
+ Arithmetic Plus; t Test and set if true, cleared otherwise
Arithmetic Minus; Not Affected
Multiply CC Condition Code Register
M Complement of M; Concatenation
Transfer Into; v Logical or
H Half-carry from bit 3; 1\ Logical and
N Neg~tive (sign bit) v Logical Exclusive or
266
Index
A B
Accumulator Branch
addressing, see Inherent addressing and miscellaneous instructions,
offset, indexed addressing, 32-34 93-114
branch instructions, 94-101
Accumulators A, B, D, 53-54 introduction, 93-94
Addressing miscellaneous instructions,
mode field, post byte, 24, 35-40 101-111
modes, 6809, 23-50 objectives, 94
direct addressing and direct page questions and answers, 111-114
register, 26-27 relative addressing, 27-30
inuexed addressing, 32-34 Bus
accumulator-offset, 34 status, pin-outs, 119-121
auto-increment/decrement, 34 timing, pin-outs, 121-123
constant-offset, 33
zero-offset, 33 C
indirect addressing, 40-43 Carry flag, CCR, 55
inherent, immediate, and Chip structure, 6809,20
extended addressing, 25-26 Concepts, fundamental 6809, 7 ~22
introduction, 23-24 chip structure, 20
objectives, 24 evolution and design philosophy,
post-byte, 24, 35-40 8-11
addressing mode field, 35-36 improvements, 11-19
5-bit offset field, 36-37 architectural, 11-14
indirect field, 36 hardware, 16-19
pointer register field, 36 software, 14-16
questions and answers, 45-50 introduction, 7
register addressing, 43-45 objectives, 7-8
relative addressing, 27-32 questions and answers, 20-22
branch relative, 27-30 Conditional branch, 96
PC relative, 30-32 Condition code register, 55-56
Applications and interfacing, 6809/ Constant-offset, indexed addressing,
6809E, 140-162 33
expanded 6809 system, 146 Control, pin-outs, 123-131
family, 6809, 150-152 D
introduction, 140-141 Data
microcomputer evaluation system, /address, pin-outs, 118-119
152-162 movement instructions and registers,
MEK68KPD,153-155 6809,51-72
MEK6809D4 board, 155-162 data movement instructions, 57-68
minimum 6809 system, 141-146 internal register format, 53-56
multiprocessor systems, 146-147 accumulators, A, B, D, 53-54
objectives, 141 condition code register, 55-56
remote data acquisition, 147-149 direct page register, 55
Architectural improvements, 6809, program counters, 55
11-14 S register, 54-55
Arithmetic, logic, and test instructions, U register, 54
73-92 X register, 54
arithmetic instructions, 74-79 Y register, 54
introduction, 73 introduction, 51-52
logic instructions, 80-82 objectives, 52
objectives, 74 questions and answers, 68-72
questions and answers, 89-92 Design philosophy and evolution, 8-11
test instructions, 82-88 Direct
Auto-increment/decrement, indexed addressing and the direct page
addressing, 34 register, 26-27
268
Direct-cont Intelligence, 93
page register, 55 Interfacing and applications, 6809/
6809E, 140-162
E expanded 6809 system, 146
Evolution and design philosophy, family, 6809, 150-152
6809,8-11 introduction, 140-141
Expanded 6809 system, 146 microcomputer evaluation system,
Extended addressing, 25-26 152-162
minimum 6809 system, 141-146
F multiprocessor systems, 146-147
Family, 6809, 150-152 objectives, 141
Fast interrupt request flags, CCR, 56 remote data acquisition, 147-149
5-bit offset field, post byte, 36-37 MEK68KPD, 153-155
Fundamental 6809 concepts, 7-22 MEK6809D4 board, 155-162
chip structure, 20 Internal register format, 53-56
evolution and design philosophy, accumulators, A, B, D, 53-54
8-11 condition code register, 55-56
improvements, 11-19 direct page register, 55
architectural, 11-14 program counters, 55
hardware, 16-19 S register, 54-55
software, 14-16 U register, 54
introduction, 7 X register, 54
objectives, 7-8 Y register, 54
questions and answers, 20-22 Interrupt flag, CCR, 56
H
L
Half-carry flag, CCR, 56 Logic, arithmetic, and test instructions,
Hardware improvements, 6809, 16-19 73-92
I arithmetic instructions, 74-79
Immediate addressing, 25 introduction, 73
Improvements, 6809, 11-19 logic instructions, 80-82
architecture, 11-14 objectives, 74
hardware, 16-19 questions and answers, 89-92
software, 14-16 test instructions, 82-88
Indexed addressing, 32-34 Long-branch instructions, 28
accumulator offset, 34
auto-increment/decrement, 34 M
constant-offset, 33 Microcomputer evaluation system,
zero-offset, 33 152-162
Indirect MEK68KPD, 153-155
addressing, 16,40-43 MEK6809D4 board, 155-162
field, post byte, 36 Minimum 6809 system, 141-146
Inherent addressing, 25 Miscellaneous and branch instructions,
Input and output signals, 6809/6809E, 93-114
115-139 branch instructions, 94-101
introduction, 115 introduction, 93-94
objectives, 116 miscellaneous instructions, 101-111
pin-outs objectives, 94
6809, 116-131 questions and answers, 111-114
bus status, 119-121 Multiprocessor systems, 146-147
bus timing, 121-123
control, 123-131 N
data/address, 118-119 Negative flag, CCR, 56
power/clock, 116-118
6809E, 131-135
questions and answers, 135-139 o
Instructions, data movement, see Data Op codes, 63, 64
movement instructions Output and input signals, 6809/6809E,
Instruction set 115-139
6809/6809E, 163-192 introduction, 115
summary, MC6809, 256-267 objectives, 116
269
Output and input signals, 6809/ Registers and data movement
6809E-cont instructions-cont
pinouts U register, 54
6809, 116-131 X register, 54
bus status, 119-121 Y register, 54
bus timing, 121-123 introduction, 51-52
control, 123-131 objectives, 52
dataladdress, 118-119 questions and answers, 68-72
power/clock, 116-118 Relative addressing, 27-32
6809E, 131-135 branch relative, 27-30
questions and answers, 135-139 PC relative, 30-32
p Remote data acquisition, 147-149
PC relative addressing, 30-32 S
Peripheral interface adapter (PIA), Short branching, 28
6820/6821, 192-210 Software improvements, 6809, 14-16
functional description, 6821, Specification sheets, 211-255
192-193 MC6809/MC68A09/MC68B09,
initialization and servicing, 200-206 211-238
interfacing and addressing, 196-200 MC6809E/MC68A09E/
pin assignments, 6820/6821, MC68B09E, 239-240
193-196 MC6829, 241-242
questions and answers, 206-210 MC6839,243
Pin-outs MC6842,244-245
6809, 116-131 MEK6809EAC, 246-247
bus MEK6809D4/MEK68KPD, 248-255
status, 119-121 S register, 54-55
timing, 121-123 Stack processor, 60
control, 123-131
data/address, 118-119 T
power/clock, 116-118
6809E, 131-135 Test, arithmetic, and logic instructions,
Pointer register field, post byte, 36 73-92
Post byte, 24, 35-40 arithmetic instructions, 74-79
addressing mode field, 35-36 introduction, 73
5-bit offset field, 36-37 logic instructions, 80-82
indirect field, 36 objectives, 74
pointer register field, 36 questions and answers, 89-92
Power/clock, pin-outs, 116-118 test instructions, 82-88
Program Twos complement overflow Hag, 55-56
counter, 55
position independence, 9 U
re-entrancy, 9 Unconditional branch, 94-95
U register, 54
R
Register addressing, 43-45 x
Registers and data movement X register, 54
instructions, 51-72
data movement instructions, 57-68 y
internal register format, 53-56 Y register, 54
accumulators A, B, D, 53-54
condition code register, 55-56 z
direct page register, 55 Zero
program counter, 55 Hag, CCR, 56
S register, 54-55 -offset, indexed addreSSing, 33
270
READERSER~CECARD
To better serve you, the reader, please take a moment to fill out
this card, or a copy of it, for us. Not only will you be kept up to date
on the Blacksburg Series books, but as an extra bonus, we will
randomly select five cards every month, from all of the cards sent to
us during the previous month. The names that are drawn will win,
absolutely free, a book from the Blacksburg Continuing Education
Series. Therefore, make sure to indicate your choice in the space
provided be10w. For a complete listing of all the books to choose
from, refer to the inside front cover of this book. Please, one card
per person. Give everyone a chance.
In order to find out who has won a book in your area, call (703)
953-1861 anytime during the night or weekend. When you do call,
an answering machine will let you know the monthly winners. Too
good to be true? Just give us a call. Good luck.
It has been our objective, as The Blacksburg Group, to develop timely and effective educational
materials and aids that will permit students, engineers, scientists and others to quickly learn how
to apply new technologies to their particular needs. We are doing this through a number of
means, textbooks, short courses, and through the development of educational "hardware" or
training aids.
Our group members make their home in Blacksburg, found in the Appalachian Mountains of
southwestern Virginia. While we didn't actively start our group collaboration until the Spring
of 1974, members of our group have been involved in digital electronics, minicomputers and
microcomputers for some time.
Some of our past experiences and on-going efforts include the following:
-The development of the Mark-S computer, an SOOS-based device that was featured in Radio-
Electronics magazine in 1974, and generally recognized as the first widely available hobby
computer. We have also designed several SOSO-based computers, including the Mini·Micro De·
signer (MMD·1). More recently we have been working with SOS5-based computers and the TRS-SO.
-The Blacksburg Continuing Education Series™ covers subjects ranging from basic electronics
through microcomputers, operational amplifiers, and active filters. Test experiments and examples
have been provided in each book. We are strong believers in the use of detailed experiments and
examples to reinforce basic concepts. This series originally started as our Bugbook series and many
titles are now being translated into Chinese, Japanese, German and Italian.
-We have pioneered the use of small self-contained computers in hands-on courses aimed at
microcomputer users. The solderless breadboarding modules developed for use in circuit design
and development make it easy for people to set up and test digital circuits and computer inter·
faces. Some of our technical products are marketed by Group Technology, ltd., Check, VA 24072,
USA. (703) 651·3153.
-Our short course programs have been presented throughout the world, covering digital elec-
tronics through TRS-SO computer interfacing. Programs are offered through the Blacksburg Group
and the Virginia Tech Extension Division. Each course offers a mix of lectures and hands-on
laboratory sessions. Courses are presented on a regular basis in Blacksburg, and at various times
to open groups, companies, schools, and other sponsors.
For additional information about course offerings, we encourage you to write or call Dr. Chris
Titus at The Blacksburg Group, Box 242, Blacksburg, VA 24060, (703) 951-9030, or Dr. Linda
Leffer at the Center for Continuing Education, Virginia Tech, Blacksburg, VA 24061, (703) 961·
5241.
Mr. David Larsen is on the faculty of the Department of Chemistry at Virginia Polytechnic Insti-
tute and State University. Dr. Jonathan Titus and Dr. Christopher Titus are with The Blacksburg
Group, Inc., all of Blacksburg, Virginia.