[go: up one dir, main page]

0% found this document useful (0 votes)
357 views244 pages

Mikro Komputer

This document provides an introduction to computers and microcomputers. It defines a computer and outlines the five generations of computers from the 1940s to present. The first generation used vacuum tubes, the second used transistors, the third used integrated circuits, the fourth used very large scale integration (VLSI) introducing microprocessors, and the fifth aims to develop artificial intelligence. It also describes different types of computers from supercomputers to mainframes, workstations, and microcomputers. Microcomputers are the most common computers individuals use directly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
357 views244 pages

Mikro Komputer

This document provides an introduction to computers and microcomputers. It defines a computer and outlines the five generations of computers from the 1940s to present. The first generation used vacuum tubes, the second used transistors, the third used integrated circuits, the fourth used very large scale integration (VLSI) introducing microprocessors, and the fifth aims to develop artificial intelligence. It also describes different types of computers from supercomputers to mainframes, workstations, and microcomputers. Microcomputers are the most common computers individuals use directly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 244

Microkomputer

INTRODUCTION TO COMPUTER, MICROCOMPUTER’S and


MICROCOMPUTER BLOC DIAGRAM

Dosen Pembimbing:
ISRAM RASYAL, ST.,MMSI,MSc

Anggota

Anjar Syaefa Ibrahim (20112943)


Abdul Ghafiqi Yamini (20112028)
Rafi Sukran (25112881)
Siti Anshila Putri (27112044)
Trina Putri Andini (27112478)

UNIVERSITAS GUNADARMA
FAKULTAS ILMU KOMPUTER DAN TEKNOLOGI INFORMASI
SISTEM KOMPUTER
2014
University of Technology Introduction to Computer &
Department of Electrical & Electronic Eng. Microcomputers
Fourth Year-Microprocessor Eng. II Lecture One-Page 1 of 11
Dr. Hadeel Nasrat

INTRODUCTION TO COMPUTER AND


MICROCOMPUTERS

What is a Computer?
An electronic device that accepts input, stores large quantities of data, execute
complex instructions which direct it to perform mathematical and logical operations
and outputs the answers in a human readable form.
Computers are not very intelligent devices, but they handle instructions
flawlessly and fast. They must follow explicit directions from both the user and
computer programmer. Computers are really nothing more than a very powerful
calculator with some great accessories. Applications like word processing and games
are just a very complex math problem.

Computer Generations

From the 1950’s, the computer age took off in full force. The years since then
have been divided into periods or generations based on the technology used.
1. First Generation Computers (1945-1954): Vacuum Tubes
These machines were used in business for accounting and payroll applications.
Valves were unreliable components generating a lot of heat. They had very limited
memory capacity. Magnetic drums were developed to store information and tapes
were also developed for secondary storage. They were initially programmed in
machine language (binary). A major breakthrough was the development of
assemblers and assembly language.
2. Second Generation (1955-1964): Transistors
The development of the transistor revolutionized the development of
computers. Invented at Bell Labs in 1948, transistors were much smaller, more
rugged, cheaper to make and far more reliable than valves. Core memory was
introduced and disk storage was also used. The hardware became smaller and more
reliable, a trend that stills continues. Another major feature of the second generation
University of Technology Introduction to Computer &
Department of Electrical & Electronic Eng. Microcomputers
Fourth Year-Microprocessor Eng. II Lecture One-Page 2 of 11
Dr. Hadeel Nasrat

was the use of high-level programming languages such as Fortran and Cobol. These
revolutionized the development of software for computers.
3. Third Generation (1965-1974): Integrated Circuits (ICs)
IC’s were again smaller, cheaper, faster and more reliable than transistors.
Speeds went from the microsecond to the nanosecond (billionth) to the picosecond
(trillionth) range. ICs were used for main memory despite the disadvantage of being
volatile. Minicomputers were developed at this time. Terminals replaced punched
cards for data entry and disk packs became popular for secondary storage. IBM
introduced the idea of a compatible family of computers, 360 family easing the
problem of upgrading to a more powerful machine. Operating systems were
developed to manage and share the computing resources and time-sharing operating
systems were developed. These greatly improved the efficiency of computers.
Computers had by now pervaded most areas of business and administration. The
number of transistors that be fabricated on a chip is referred to as the scale of
integration (SI). Early chips had SSI (small SI) of tens to a few hundreds. Later chips
were MSI (Medium SI): hundreds to a few thousands. Then came LSI chips (Large
SI) in the thousands range.

4. Fourth Generation (1975-1984): VLSI (Very Large SI)


The term fourth generation is occasionally applied to VLSI-based computer
architecture. VLSI has made it possible to fabricate an entire CPU, main memory, or
similar devices with a single IC. This has resulted in new classes of machines such as
inexpensive personal computers, and high- performance parallel processors that
contain thousands of CPUs. VLSI allowed the equivalent of tens of thousand of
transistors to be incorporated on a single chip. This led to the development of the
microprocessor a processor on a chip. Intel produced the 4004 which was followed
by the 8008,8080, 8088 and 8086 etc. Other companies developing microprocessors
included Motorolla (6800, 68000), and Zilog. Personal computers were developed
and IBM launched the IBM PC based on the 8088 and 8086 microprocessors.
Mainframe computers have grown in power. Memory chips are in the megabyte
range. VLSI chips had enough transistors to build 20 ENIACs. Secondary storage has
also evolved at fantastic rates with storage devices holding gigabytes (1024Mb = 1
Gb) of data. On the software side, more powerful operating systems are available
such as Unix. Applications software has become cheaper and easier to use.
University of Technology Introduction to Computer &
Department of Electrical & Electronic Eng. Microcomputers
Fourth Year-Microprocessor Eng. II Lecture One-Page 3 of 11
Dr. Hadeel Nasrat

5. Fifth Generation (1991-Present):


The race is now on building the next or “fifth” generation of computers,
machine that exhibit artificial intelligence (AI). Thus new generations of computers
will involve robotics and computer networks. Developments are still continuing.
Computers are becoming faster, smaller and cheaper. Storage units are increasing in
capacity. Distributed computing is becoming popular and parallel computers with
large numbers of CPUs have been built.

Technology & Software &


Generation Systems
Architecture Applications
Machine & Assembly
Vacuum tubes, Relay
language, Single user ENIAC TIFRAC
First memories, CPU driven by
Basic I/O using IBM 701
(1945-54) PC and accumulator; fixed
programmed and Princeton IAS
point Arithmetic
Internet mode.
Discrete Transistors, Core
HLL used with
Memories, Floating point, IBM7099
Second compilers, batch
Arithmetic I/O, processors,
(1955-64) processing, Monitoring, CDC 1604
Multiplexed memory
Libraries
access
Integrated circuits,
Multiprogramming, IBM 360/700
Third Microprogramming,
Time sharing OS, CDC 6000
(1965-74) Pipelining, Caching,
Multi-user applications TA-ASC PDP-8
Lookahead Processing
LSI/VLSI and
VAX 9800, Cray
Semiconductor memory,
X-MP, IBM
Microprocessors
Fourth Multiprocessor OS, 3600, Pentium
technology,
(1975-84) languages, Compilers Processor based
Multiprocessors, vector
systems (PCs),
super-computing, multi
UltraSPARC etc.
computer
Cray/MPP,
Fifth Massively parallel
VLSI/VHSIC processors, TMC/CM-5, Intel
(1991- processing, Grand
scalable architecture paragon, Fujitsu
present) challenge Applications
VP500
University of Technology Introduction to Computer &
Department of Electrical & Electronic Eng. Microcomputers
Fourth Year-Microprocessor Eng. II Lecture One-Page 4 of 11
Dr. Hadeel Nasrat

Types of Computers
Computer now comes in a variety of shapes and sizes, which could be roughly
classified according to their processing power into five sizes: super large, large,
medium, small, and tiny.
Microcomputers are the type of computers that we are most likely to notice and use in
our everyday life. In fact there are other types of computers that you may use directly
or indirectly:
 Supercomputers-super large computers: supercomputers are high- capacity
machines with hundreds of thousands of processors that can perform more than
1 trillion calculations per second. These are the most expensive but fastest
computers available. "Supers," as they are called, have been used for tasks
requiring the processing of enormous volumes of data, such as doing the U.S.
census count, forecasting weather, designing aircraft, modeling molecules,
breaking codes, and simulating explosion of nuclear bombs.
 Mainframe computers - large computers: The only type of computer available
until the late 1960s, mainframes are water- or air-cooled computers that vary in
size from small, to medium, to large, depending on their use. Small
mainframes are often called midsize computers; they used to be called
minicomputers. Mainframes are used by large organizations such as
banks, airlines, insurance companies, and colleges-for processing millions of
transactions. Often users access a mainframe using a terminal, which has a
display screen and a keyboard and can input and output data but cannot by
itself process data.
 Workstations - medium computer: Introduced in the early 1980s,
workstations, are expensive, powerful computers usually used for complex
scientific, mathematical, and engineering calculations and for computer-aided
design and computer-aided manufacturing. Providing many capabilities
comparable to midsize mainframes, workstations are used for such tasks as
designing airplane fuselages, prescription drugs, and movie special effects.
Workstations have caught the eye of the public mainly for their graphics
capabilities, which are used to breathe three-dimensional life into movies such
as Jurassic Park and Titanic. The capabilities of low-end workstations overlap
those of high-end desktop microcomputers.
 Microcomputer - small computers: Microcomputers, also called personal
computers (PC), can fit next to a desk or on a desktop, or can be carried
around. They are either stand-alone machines or are connected to a computer
network, such as a local area network. A local area network (LAN) connects,
usually by special cable, a group of desktop PCs and other devices, such as
printers, in an office or a building. Microcomputers are of several types:
 Desktop PCs: are those in which the case or main housing sits on a
University of Technology Introduction to Computer &
Department of Electrical & Electronic Eng. Microcomputers
Fourth Year-Microprocessor Eng. II Lecture One-Page 5 of 11
Dr. Hadeel Nasrat

desk, with keyboard in front and monitor (screen) often on top.


 Tower PCs: are those Microcomputer in which the case sits as a
"tower," often on the floor beside a desk, thus freeing up desk surface
space.
 Laptop computers (also called notebook computers): are lightweight
portable computers with built-in monitor, keyboard, hard-disk drive,
battery, and AC adapter that can be plugged into an electrical outlet;
they weigh anywhere from 1.8 to 9 pounds.
 Personal digital assistants (PDAs) (also called handheld computers or
palmtops) combine personal organization tools-schedule planners,
address books, to-do lists. Some are able to send e-mail and faxes. Some
PDAs have touch-sensitive screens. Some also connect to desktop
computers for sending or receiving information.
 Microcontrollers-tiny computers: Microcontrollers, also called
embedded computers, are the tiny, specialized microprocessors installed
in "smart" appliances and automobiles. These microcontrollers enable
PDAs microwave ovens, for example, to store data about how long to
cook your potatoes and at what temperature.

Basic Blocks of a Microcomputer


If we think of the computer as an information manipulation device the basic
components of a microcomputer are:
Input Units -- "How to tell it what to do"
Devices allow us to enter information into the computer. A keyboard and
mouse are the standard way to interact with the computer. Other devices include
mice, scanners, microphones, joysticks and game pads used primarly for games.

Output Units -- "How it shows you what it is doing"


Devices are how the manipulated information is returned to us. They
commonly include video monitors, printers, and speakers.
Memory -- "How the processor stores and uses immediate data"
University of Technology Introduction to Computer &
Department of Electrical & Electronic Eng. Microcomputers
Fourth Year-Microprocessor Eng. II Lecture One-Page 6 of 11
Dr. Hadeel Nasrat

When you use a program, the computer loads a portion of the program from
the hard drive to the much faster memory (RAM). When you "save" your work or
quit the program, the data gets written back to the hard drive.

Fig. (1): Basic Block of a Microcomputer

Processor – Central Processing Unit


Datapath - consists of register file and ALU
 Register is a storage location. Used to hold data or a memory address
during execution of an instruction
 ALU receives data from main memory and/or register file, performs
computations and writes result back to main memory or registers
Control unit – decodes and monitors the execution of instructions and also acts
as an arbiter while various systems compete for resources of CPU.
University of Technology Introduction to Computer &
Department of Electrical & Electronic Eng. Microcomputers
Fourth Year-Microprocessor Eng. II Lecture One-Page 7 of 11
Dr. Hadeel Nasrat

Computer Architecture
In computer engineering, computer architecture is the conceptual design and
fundamental operational structure of a computer system. It is a blueprint and
functional description of requirements (especially speeds and interconnections) and
design implementations for the various parts of a computer — focusing largely on the
way by which the central processing unit (CPU) performs internally and accesses
addresses in memory.
Computer architecture comprises at least three main subcategories
 Instruction set architecture, or ISA, is the abstract image of a computing
system that is seen by a machine language (or assembly language)
programmer, including the instruction set, memory address modes, processor
registers, and address and data formats.
 Microarchitecture, also known as Computer organization is a lower level,
more concrete, description of the system that involves how the constituent
parts of the system are interconnected and how they interoperate in order to
implement the ISA. The size of a computer's cache for instance, is an
organizational issue that generally has nothing to do with the ISA.
 System Design which includes all of the other hardware components within a
computing system such as:
 system interconnects such as computer buses and switches
 memory controllers and hierarchies
 CPU off-load mechanisms such as direct memory access issues like
multi-processing.
Once both ISA and microarchitecture has been specified, the actual device needs to
be designed into hardware. This design process is often called implementation.
Implementation is usually not considered architectural definition, but rather hardware
design engineering.
Computer Organization deals with the advances in computer architecture right from
the Von Neumann machines to the current day super scalar architectures.

Von Neumann Architecture


The earliest computing machines had fixed programs. Some very simple
computers still use this design, either for simplicity or training purposes. For
example, a desk calculator (in principle) is a fixed program computer. It can do basic
mathematics, but it cannot be used as a word processor or to run video games. To
change the program of such a machine, you have to re-wire, re-structure, or even re-
design the machine. Indeed, the earliest computers were not so much "programmed"
University of Technology Introduction to Computer &
Department of Electrical & Electronic Eng. Microcomputers
Fourth Year-Microprocessor Eng. II Lecture One-Page 8 of 11
Dr. Hadeel Nasrat

as they were "designed". "Reprogramming", when it was possible at all, was a very
manual process, starting with flow charts and paper notes, followed by detailed
engineering designs, and then the often-arduous process of implementing the physical
changes.
The idea of the stored-program computer changed all that. By creating an
instruction set architecture and detailing the computation as a series of instructions
(the program), the machine becomes much more flexible. By treating those
instructions in the same way as data, a stored-program machine can easily change the
program, and can do so under program control.
The von Neumann architecture is a computer design model that uses a
processing unit and a single separate storage structure to hold both instructions and
data as shown in Fig. (2). It is named after mathematician and early computer
scientist John von Neumann. Such a computer implements a universal Turing
machine, and the common "referential model" of specifying sequential architectures,
in contrast with parallel architectures. The term "stored-program computer" is
generally used to mean a computer of this design, although as modern computers are
usually of this type, the term has fallen into disuse. All general-purpose computers
are now based on the key concepts of the von Neumann architecture.

Fig.(2): The Von-Neumann Architecture


University of Technology Introduction to Computer &
Department of Electrical & Electronic Eng. Microcomputers
Fourth Year-Microprocessor Eng. II Lecture One-Page 9 of 11
Dr. Hadeel Nasrat

Though the von Neumann model is universal in general-purpose computing, it


suffers from one obvious problem. All information (instructions and data) must flow
back and forth between the processor and memory through a single channel, and this
channel will have finite bandwidth. When this bandwidth is fully used the processor
can go no faster. This performance limiting factor is called the von Neumann
bottleneck.

Hardvard Architecture
A Harvard Architecture as shown in Fig. (3) has one memory for instructions
and a second for data. The name comes from the Harvard Mark 1, an
electromechanical computer which pre-dates the stored-program concept of von
Neumann, as does the architecture in this form. It is still used for applications which
run fixed programs, in areas such as digital signal processing, but not for general-
purpose computing. The advantage is the increased bandwidth available due to
having separate communication channels for instructions and data; the disadvantage
is that the storage is allocated to code and data in a fixed ratio.

Fig. (3): The Hardvard architecture

In Harvard architecture, there is no need to make the two memories share


characteristics. In particular, the word width, timing, implementation technology, and
memory address structure can differ. Instruction memory is often wider than data
memory. In some systems, instructions can be stored in read-only memory while data
memory generally requires read-write memory. In some systems, there is much more
instruction memory than data memory so instruction addresses are much wider than
data addresses.
University of Technology Introduction to Computer &
Department of Electrical & Electronic Eng. Microcomputers
Fourth Year-Microprocessor Eng. II Lecture One-Page 10 of 11
Dr. Hadeel Nasrat

A pure Harvard architecture computer suffers from the disadvantage that


mechanisms must be provided to separately load the program to be executed into
instruction memory and any data to be operated upon into data memory.
Additionally, modern Harvard architecture machines often use a read-only
technology for the instruction memory and read/write technology for the data
memory. This allows the computer to begin execution of a pre-loaded program as
soon as power is applied. The data memory will at this time be in an unknown state,
so it is not possible to provide any kind of pre-defined data values to the program.
The solution is to provide a hardware pathway and machine language
instructions so that the contents of the instruction memory can be read as if they were
data. Initial data values can then be copied from the instruction memory into the data
memory when the program starts. If the data is not to be modified (for example, if it
is a constant value, such as pi, or a text string), it can be accessed by the running
program directly from instruction memory without taking up space in data memory
(which is often at a premium).
For instance each port may be supplied from its own local cache memory (fig.
(4)). The cache memories reduce the external bandwidth requirements sufficiently to
allow them both to be connected to the same main memory, giving the bandwidth
advantage of a Harvard architecture along with most of the flexibility of the simple
von Neumann architecture. (The flexibility may be somewhat reduced because of
cache consistency problems with self-modifying code). Note that this type of
Harvard architecture is still a von Neumann machine.
The Modified Harvard architecture is very like the Harvard architecture but
provides a pathway between the instruction memory and the CPU that allows words
from the instruction memory to be treated as read-only data. This allows constant
data, particularly text strings, to be accessed without first having to be copied into
data memory, thus preserving more data memory for read/write variables. Special
machine language instructions are provided to read data from the instruction memory.
University of Technology Introduction to Computer &
Department of Electrical & Electronic Eng. Microcomputers
Fourth Year-Microprocessor Eng. II Lecture One-Page 11 of 11
Dr. Hadeel Nasrat

Fig. (4): A modified Harvard Architecture


University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Two-Page 1 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

2.1 Microprocessor
A microprocessor is a computer processor on a microchip. It's sometimes called
a logic chip. It is the "engine" that goes into motion when you turn your computer on.
A microprocessor is designed to perform arithmetic and logic operations that make
use of small number-holding areas called registers. Typical microprocessor operations
include adding, subtracting, comparing two numbers, and fetching numbers from one
area to another. These operations are the result of a set of instructions that are part of
the microprocessor design. When the computer is turned on, the microprocessor is
designed to get the first instruction from the basic input/output system (BIOS) that
comes with the computer as part of its memory. After that, either the BIOS, or the
operating system that BIOS loads into computer memory, or an application program
is "driving" the microprocessor, giving it instructions to perform.

2.2 Evaluation of the Microprocessors


The evolution of microprocessors has been known to follow Moore's Law
when it comes to steadily increasing performance over the years. This law suggests
that the complexity of an integrated circuit, with respect to minimum component
cost, doubles every 18 months. This dictum has generally proven true since the early
1970s. From their humble beginnings as the drivers for calculators, the continued
increase in power has led to the dominance of microprocessors over every other form
of computer; every system from the largest mainframes to the smallest handheld
computers now uses a microprocessor at its core.
 Intel 4004 was a 4 bit up. Only 45 instructions P Channel Mosfet technology. 50
K instructions per second (ENIAC).
 Later 8008 as an 8 bit µ processor then 8080 and Motorolla 6800.
 8080 was 10x faster than 8008 and TTL compatible.
 MITS Altair 8800 in 1974. The BASIC Interpreter was written by Bill Gates.
Assembler program was written by Digital Research Corporation.
 In 1977, 8085 microprocessor. Internal clock generator, higher frequency at
reduced cost and integration. There are 200 million 8085’s around the world.
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Two-Page 2 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

 In 1978, 8086+8088 microprocessors 16 bit. Addressed 1 Mbyte of memory.


Small instruction cache (4-6 bytes) enabled prefetch of instructions.
 IBM decided to use 8088 in PC.
 In 1983, 80286 released, identical to 8086 except the addressing and higher clock
speed.
 32 bit microprocessor: In 1986 major overhaul on 80286 architecture, 80386 DX
with 32bit data + 32 bit address (4 G bytes).
 In 1989, 80486 = 80386 + 80387 co processor + 8KB cache.
 In 1993, Pentium (80586). Includes 2 execution engines.
 Pentium Pro included 256K Level 2 cache mechanism as well as Level 1 cache.
Also 3 execution engines which can execute at the same time and can conflict and
still execute in parallel. The address bus was expended to 36.
 Pentium 2 included L2 cache on its circuit board (called slot)
 Later Pentium 3 and 4 released with several architectural and technological
innovations.

2.3 Block diagram of a simple CPU


As mentioned before, the microprocessor is the CPU of the microcomputer.
Therefore, the power of the microcomputer is determined by the capabilities of the
microprocessor. Its clock frequency determines the speed of the microcomputer. The
number of data and address pins on the microprocessor chip make up the
microcomputer's word size and maximum memory size. The microcomputer's I/O and
interfacing capabilities are determined by the control pins on the microprocessor chip.
The logic inside the microprocessor chip can be divided into three main areas:
the register section, the control unit, and the Arithmetic and Logic Unit (ALU). A
microprocessor chip with the above three sections is shown in Fig. (2.1).
A typical CPU has three major components: (1) register set, (2) arithmetic logic unit
(ALU), and (3) control unit (CU). The register set differs from one computer
architecture to another. It is usually a combination of general-purpose and special-
purpose registers. General-purpose registers are used for any purpose, hence the name
general purpose. Special-purpose registers have specific functions within the CPU.
For example, the program counter (PC) is a special-purpose register that is used to
hold the address of the instruction to be executed next. Another example of special-
purpose registers is the instruction register (IR), which is used to hold the instruction
that is currently executed. The ALU provides the circuitry needed to perform the
arithmetic, logical and shift operations demanded of the instruction set. In Chapter 4,
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Two-Page 3 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

we have covered a number of arithmetic operations and circuits used to support


computation in an ALU. The control unit is the entity responsible for fetching the
instruction to be executed from the main memory and decoding and then executing it.
Figure (2.1) shows the main components of the CPU and its interactions with the
memory system and the input/output devices.
The CPU fetches instructions from memory, reads and writes data from and to
memory, and transfers data from and to input/output devices. A typical and simple
execution cycle can be summarized as follows:
1. The next instruction to be executed, whose address is obtained from the PC, is
fetched from the memory and stored in the IR.
2. The instruction is decoded.
3. Operands are fetched from the memory and stored in CPU registers, if needed.
4. The instruction is executed.
5. Results are transferred from CPU registers to the memory, if needed.

Microprocessor

CCR CL

ACC IR
PC

ALU MAR MDR

Arithmetic Unit Control Unit

Main memory Input/Output

Fig. (2.1): Central processing unit main components and interactions with the
memory and I/O.
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Two-Page 4 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

The execution cycle is repeated as long as there are more instructions to execute. A
check for pending interrupts is usually included in the cycle. Examples of interrupts
include I/O device request, arithmetic overflow, or a page fault.
When an interrupt request is encountered, a transfer to an interrupt handling routine
takes place. Interrupt handling routines are programs that are invoked to collect the
state of the currently executing program, correct the cause of the interrupt, and restore
the state of the program. The actions of the CPU during an execution cycle are
defined by micro-orders issued by the control unit. These micro-orders are individual
control signals sent over dedicated control lines. For example, let us assume that we
want to execute an instruction that moves the contents of register X to register Y.
Let us also assume that both registers are connected to the data bus, D. The control
unit will issue a control signal to tell register X to place its contents on the data bus D.
After some delay, another control signal will be sent to tell register Y to read from
data bus D. The activation of the control signals is determined using either hardwired
control or microprogramming. These concepts are explained later.

2.4 Register Set


The number, size, and types of registers vary from one microprocessor to
another. However, the various registers in all microprocessors carry out similar
operations. The register structures of microprocessors play a major role in designing
the microprocessor architectures. Also, the register structures for a specific
microprocessor determine how convenient and easy it is to program this
microprocessor.
2.4.1. Memory Access Registers
Two registers are essential in memory write and read operations: the memory
data register (MDR) and memory address register (MAR). The MDR and MAR are
used exclusively by the CPU and are not directly accessible to programmers. In order
to perform a write operation into a specified memory location, the MDR and MAR
are used as follows:
1. The word to be stored into the memory location is frst loaded by the CPU
intoMDR.
2. The address of the location into which the word is to be stored is loaded by the
CPU into a MAR.
3. A write signal is issued by the CPU.
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Two-Page 5 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

Similarly, to perform a memory read operation, the MDR and MAR are used as
follows:
1. The address of the location from which the word is to be read is loaded into the
MAR.
2. A read signal is issued by the CPU.
3. The required word will be loaded by the memory into the MDR ready for use by
the CPU.

2.4.2. Instruction Fetching Registers


Two main registers are involved in fetching an instruction for execution: the
program counter (PC) and the instruction register (IR). The PC is the register that
contains the address of the next instruction to be fetched. The fetched instruction is
loaded in the IR for execution. After a successful instruction fetch, the PC is updated
to point to the next instruction to be executed. In the case of a branch operation, the
PC is updated to point to the branch target instruction after the branch is resolved, that
is, the target address is known.
2.4.3. Condition Registers
Condition registers, or flags, are used to maintain status information. Some
architectures contain a special program status word (PSW) register. The PSW
contains bits that are set by the CPU to indicate the current status of an executing
program. These indicators are typically for arithmetic operations, interrupts, memory
protection information, or processor status.

2.4.4. Special-Purpose Address Registers


1. Index Register:
The address of the operand is obtained by adding a constant to the content of a
register, called the index register. The index register holds an address displacement.
Index addressing is indicated in the instruction by including the name of the index
register in parentheses and using the symbol X to indicate the constant to be added.
2. Segment Pointers:
In order to support segmentation, the address issued by the processor should
consist of a segment number (base) and a displacement (or an offset) within the
segment. A segment register holds the address of the base of the segment.
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Two-Page 6 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

3. Stack Pointer:
A stack is a data organization mechanism in which the last data item stored is
the first data item retrieved. Two specific operations can be performed on a stack.
These are the Push and the Pop operations. A specific register, called the stack pointer
(SP), is used to indicate the stack locationm that can be addressed. In the stack push
operation, the SP value is used to indicate the location (called the top of the stack).
After storing (pushing) this value, the SP is incremented (in some architectures, e.g.
X86, the SP is decremented as the stack grows low in memory).

80386 Registers

The Intel basic programming model of the 386, 486, and the Pentium consists
of three register groups. These are the general-purpose registers, the segment
registers, and the instruction pointer (program counter) and the flag register. Fig. (2.2)
shows the three sets of registers. The first set consists of general purpose registers A,
B, C, D, SI (source index), DI (destination index), SP (stack pointer), and BP (base
pointer). The second set of registers consists of CS (code segment), SS (stack
segment), and four data segment registers DS, ES, FS, and GS. The third set of
registers consists of the instruction pointer (program counter) and the flags (status)
register. Among the status bits, the first five are identical to those bits introduced as
early as in the 8085 8-bit microprocessor. The next 6 – 11 bits are identical to those
introduced in the 8086. The flags in the bits 12 – 14 were introduced in the 80286
while the 16 – 17 bits were introduced in the 80386. The flag in bit 18 was introduced
in the 80486.

Fig. (2.2): The main register sets in 80X86 (80386 and above
extended all 16 bit registers except segment registers).
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Two-Page 7 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

2.5 Arithmetic Logic Unit


In computing, an arithmetic logic unit (ALU) is a digital circuit that performs
arithmetic and logical operations. The ALU is a fundamental building block of the
central processing unit of a computer, and even the simplest microprocessors contain
one for purposes such as maintaining timers. The processors found inside modern
CPUs and GPUs have inside them very powerful and very complex ALUs; a single
component may contain a number of ALUs.
An ALU must process numbers using the same format as the rest of the digital
circuit. For modern processors, that almost always is the two's complement binary
number representation. Early computers used a wide variety of number systems,
including one's complement, sign-magnitude format, and even true decimal systems,
with ten tubes per digit.
Most of the computer’s actions are performed by the ALU. The ALU gets data from
processor registers. This data is processed and the results of this operation are stored
into ALU output registers. Other mechanisms move data between these registers and
memory. Most ALUs can perform the following operations:
 Integer arithmetic operations (addition, subtraction, and sometime
multiplication and division, though this is more expensive)
 Bitwise logic operations (AND, NOT, OR, XOR)
 Bit-shifting operations (shifting or rotating a word by a specified number of
bits to the left or right, with or without sign extension). Shifts can be
interpreted as multiplications by 2 and divisions by 2.

2.6 Datapath
The CPU can be divided into a data section and a control section. The data
section, which is also called the datapath, contains the registers and the ALU. The
datapath is capable of performing certain operations on data items. The control
section is basically the control unit, which issues control signals to the datapath.
Internal to the CPU, data move from one register to another and between ALU and
registers.
Internal data movements are performed via local buses, which may carry data,
instructions, and addresses. Externally, data move from registers to memory and I/O
devices, often by means of a system bus. Internal data movement among registers and
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Two-Page 8 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

between the ALU and registers may be carried out using different organizations
including one-bus, two-bus, or three-bus organizations. Dedicated datapaths may also
be used between components that transfer data between themselves more frequently.
For example, the contents of the PC are transferred to the MAR to fetch a new
instruction at the beginning of each instruction cycle. Hence, a dedicated datapath
from the PC to the MAR could be useful in speeding up this part of instruction
execution.

2.6.1. One-Bus Organization


Using one bus, the CPU registers and the ALU use a single bus to move outgoing
and incoming data. Since a bus can handle only a single data movement within one
clock cycle, two-operand operations will need two cycles to fetch the operands for the
ALU. Additional registers may also be needed to buffer data for the ALU.
This bus organization is the simplest and least expensive, but it limits the amount
of data transfer that can be done in the same clock cycle, which will slow down the
overall performance. Figure (2.3) shows a one-bus datapath consisting of a set of
general-purpose registers, a memory address register (MAR), a memory data register
(MDR), an instruction register (IR), a program counter (PC), and an ALU.

Fig. (2.3): One-Bus Datapath.

2.6.2. Two-Bus Organization


Using two buses is a faster solution than the one-bus organization. In this case,
general-purpose registers are connected to both buses. Data can be transferred from
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Two-Page 9 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

two different registers to the input point of the ALU at the same time. Therefore, a
two-operand operation can fetch both operands in the same clock cycle. An additional
buffer register may be needed to hold the output of the ALU when the two buses are
busy carrying the two operands. Figure (2.4a) shows a two-bus organization. In some
cases, one of the buses may be dedicated for moving data into registers (in-bus),
while the other is dedicated for transferring data out of the registers (out-bus). In this
case, the additional buffer register may be used, as one of the ALU inputs, to hold one
of the operands. The ALU output can be connected directly to the in-bus, which will
transfer the result into one of the registers. Figure (2.4b) shows a two-bus
organization with in-bus and out-bus.

(a)

(b)
Fig. (2.4): Two-bus organizations. (a) An Example of Two-Bus Datapath.
(b) Another Example of Two-Bus Datapath with in-bus and out-bus
.
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Two-Page 10 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

2.6.3. Three-Bus Organization


In a three-bus organization, two buses may be used as source buses while the
third is used as destination. The source buses move data out of registers (out-bus), and
the destination bus may move data into a register (in-bus). Each of the two out-buses
is connected to an ALU input point. The output of the ALU is connected directly to
the in-bus. As can be expected, the more buses we have, the more data we can move
within a single clock cycle. However, increasing the number of buses will also
increase the complexity of the hardware. Figure (2.5) shows an example of a three-
bus datapath.

Fig. (2.5): Three-Bus Datapath.


University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Three-Page 1 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

3.1 CPU INSTRUCTION CYCLE

The sequence of operations performed by the CPU during its execution of


instructions is presented in Fig. (3.1). As long as there are instructions to execute, the
next instruction is fetched from main memory. The instruction is executed based on
the operation specified in the opcode field of the instruction. At the completion of the
instruction execution, a test is made to determine whether an interrupt has occurred.
An interrupt handling routine needs to be invoked in case of an interrupt.

Fig. (3.1): CPU Functions.

The basic actions during fetching an instruction, executing an instruction, or


handling an interrupt are defined by a sequence of micro-operations. A group of
control signals must be enabled in a prescribed sequence to trigger the execution of a
micro-operation. In this section, we show the micro-operations that implement
instruction fetch, execution of simple arithmetic instructions, and interrupt handling.

3.1.1 Fetch Instructions


The sequence of events in fetching an instruction can be summarized as follows:
1. The contents of the PC are loaded into the MAR.
2. The value in the PC is incremented. (This operation can be done in parallel with a
memory access).
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Three-Page 2 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

3. As a result of a memory read operation, the instruction is loaded into the MDR.
4. The contents of the MDR are loaded into the IR.

Let us consider the one-bus datapath organization shown in Fig. (2.3). We will
see that the fetch operation can be accomplished in three steps as shown in the table
below, where t0 < t1 < t2 . Note that multiple operations separated by “;” imply that
they are accomplished in parallel.

Step Micro-Operation
t0 MAR ← (PC); A ← (PC)
t1 MDR ← Mem MAR; PC ← (A)+4
t2 IR ← (MDR)

using the three-bus datapath shown in Fig. (2.5), the following table shows the steps
needed.

Step Micro-Operation
t0 MAR ← (PC); A ← (PC)+4
t1 MDR ← Mem MAR;
t2 IR ← (MDR)

3.1.2 Execute Simple Arithmetic Operation


Add R1, R2, R0 : This instruction adds the contents of source registers R1 and R2, and
stores the results in destination register R0. This addition can be executed as follows:
1. The registers R0 , R1 , R2 are extracted from the IR.
2. The contents of R1 and R2 are passed to the ALU for addition.
3. The output of the ALU is transferred to R0.
Using the one-bus datapath shown in Fig. (2.3), this addition will take three steps as
shown in the following table, where t0 < t1 < t2 .
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Three-Page 3 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

Step Micro-Operation
t0 A ← (R1)
t1 B ← (R2)
t2 R0 ← (A)+(B)

Using the two-bus datapath shown in Fig. (2.4a), this addition will take two steps as
shown in the following table, where t0 < t1 .

Step Micro-Operation
t0 A ← (R1) + (R2)
t1 R0 ← (A)

Using the two-bus datapath with in-bus and out-bus shown in Fig. (2.4b), this
addition will take two steps as shown in the following table, where t0 < t1 .

Step Micro-Operation
t0 A ← (R1)
t1 R0 ← (A) + (R2)

Using the three-bus datapath shown in Fig. (2.5), this addition will take one steps as
shown in the following table.

Step Micro-Operation
t0 R0 ← (R1) + (R2)
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Three-Page 4 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

Add X, R0 : This instruction adds the contents of memory location X to register R0


and stores the result in R0. This addition can be executed as follows:
1. The memory location X is extracted from IR and loaded into MAR.
2. As a result of memory read operation, the contents of X are loaded into MDR.
3. The contents of MDR are added to the contents of R0.

Using the one-bus datapath shown in Fig. (2.3), this addition will take five steps as
shown in the following table, where t0 < t1 < t2 < t3 < t4.

Step Micro-Operation
t0 MAR ← X
t1 MDR ← Mem[MAR]
t2 A ← (R0)
t3 B ← (MDR)
t4 R0 ← (A)+(B)

Using the two-bus datapath shown in Fig. (2.4a), this addition will take four steps as
shown in the following table, where t0 < t1< t2 < t3 .

Step Micro-Operation
t0 MAR ← X
t1 MDR ← Mem[MAR]
t2 A ← (R0) + (MDR)
t3 R0 ← (A)
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Three-Page 5 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

Using the two-bus datapath with in-bus and out-bus shown in Fig. (2.4b), this
addition will take four steps as shown in the following table, where t0 < t1< t2 < t3 .

Step Micro-Operation
t0 MAR ← X
t1 MDR ← Mem[MAR]
t2 A ← (R0)
t3 R0 ← (A) + (MDR)

Using the three-bus datapath shown in Fig. (2.5), this addition will take three steps as
shown below, where t0 < t1< t2.

Step Micro-Operation
t0 MAR ← X
t1 MDR ← Mem[MAR]
t2 R0 ← (R0) + (MDR)

3.1.3 Interrupt Handling


After the execution of an instruction, a test is performed to check for pending
interrupts. If there is an interrupt request waiting, the following steps take place:
1. The contents of PC are loaded into MDR (to be saved).
2. The MAR is loaded with the address at which the PC contents are to be saved.
3. The PC is loaded with the address of the first instruction of the interrupt handling
routine.
4. The contents of MDR (old value of the PC) are stored in memory.
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Three-Page 6 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

The following table shows the sequence of events, where t1< t2< t3.

Step Micro-Operation
t1 MDR ← PC
MAR ← Address1 (where to save PC);
t2
PC ← Address 2 (interrupt handling routine)
t3 Mem[MAR] ← (MDR)

3.2 Control Unit


Even though the datapath is capable of performing all the operations of the
microprocessor, it cannot, however, do it on its own. In order for the datapath to
execute the operations automatically, the control unit is required. The control unit,
also known as the controller, controls the operations of the datapath, and therefore,
the operations of the entire microprocessor.
The control unit is the main component that directs the system operations by
sending control signals to the datapath. These signals control the flow of data within
the CPU and between the CPU and external units such as memory and I/O. Control
buses generally carry signals between the control unit and other computer
components in a clock-driven manner. The system clock produces a continuous
sequence of pulses in a specified duration and frequency. A sequence of steps (t0, t1,
t2, … where t0 < t1< t2 < …) are used to execute a certain instruction. The op-code
field of a fetched instruction is decoded to provide the control signal generator with
information about the instruction to be executed. Step information generated by a
logic circuit module is used with other inputs to generate control signals. The signal
generator can be specified simply by a set of Boolean equations for its output in terms
of its inputs. Fig. (3.2) shows a block diagram that describes how timing is used in
generating control signals.
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Three-Page 7 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

There are mainly two different types of control units:


1. Microprogrammed.
2. Hardwired.
In microprogrammed control, the control signals associated with operations are
stored in special memory units inaccessible by the programmer as control words. A
control word is a microinstruction that specifies one or more micro-operations. A
sequence of microinstructions is called a microprogram, which is stored in a ROM or
RAM called a control memory CM.
In hardwired control, fixed logic circuits that correspond directly to the Boolean
expressions are used to generate the control signals. Clearly hardwired control is
faster than microprogrammed control.

Fig. (3.2): Timing of control signals.


University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Three-Page 8 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

However, hardwired control could be very expensive and complicated for


complex systems. Hardwired control is more economical for small control units. It
should also be noted that microprogrammed control could adapt easily to changes in
the system design. We can easily add new instructions without changing hardware.
Hardwired control will require a redesign of the entire systems in the case of any
change.
Example 1:
Let us revisit the add operation in which we add the contents of source registers
R1, R2, and store the results in destination register R0.We have shown earlier that this
operation can be done in one step using the three-bus datapath shown in Fig. (2.5).
Let us try to examine the control sequence needed to accomplish this addition at step
t0. Suppose that the op-code field of the current instruction was decoded to Inst-x
type. First we need to select the source registers and the destination register, then we
select Add as the ALU function to be performed. The following table shows the
needed step and the control sequence.

Instruction Control
Step Micro-operation
Type
t0 Ins-x R0 ← (R1) + (R2) Select R1 as source 1 on out-bus1 (R1 out-bus1)
Select R2 as source 2 on out-bus2 (R2 out-bus2)
Select R0 as destination on in-bus (R0 in-bus)
Select the ALU function Add (Add)

Fig. (3.3) shows the signals generated to execute Inst-x during time period t0. The
AND gate ensures that these signals will be issued when the op-code is decoded into
Inst-x and during time period t0. The signals (R1out-bus 1), (R2out-bus2), (R0in-bus),
and (Add) will select R1 as a source on out-bus1, R2 as a source on out-bus2, R0 as
destination on in-bus, and select the ALUs add function, respectively.
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Three-Page 9 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

Fig. (3.3): Signals generated to execute Inst-x on three-bus datapath


during time period t0 .

Example 2 :
Let us repeat the operation in the previous example using the one-bus datapath
shown in Fig. (2.3). We have shown earlier that this operation can be carried out in
three steps using the one-bus datapath. Suppose that the op-code field of the current
instruction was decoded to Inst-x type. The following table shows the needed steps
and the control sequence.

Instruction Control
Step Micro-operation
Type
t0 Inst-x A ← (R1) Select R1 as source (R1 out)
Select A as destination (A in)
t1 Inst-x A ← (R2) Select R2 as source (R2 out)
Select B as destination (B in)
t2 Inst-x R0 ← (R1) + (R2) Select the ALU function Add (Add).
Select Ro as destination (R0 in)
University of Technology Microprocessors Architecture
Department of Electrical & Electronic Eng. Lecture Three-Page 10 of 10
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

Fig. (3.4) shows the signals generated to execute Inst-x during time periods t0 , t1, and
t2. The AND gates ensure that the appropriate signals will be issued when the op-code
is decoded into Inst-x and during the appropriate time period. During t0, the signals
(R1out) and (A in) will be issued to move the contents of R1 into A. Similarly during
t1, the signals (R2 out) and (B in) will be issued to move the contents of R2 into B.
Finally, the signals (R0in) and (Add) will be issued during t2 to add the contents of A
and B and move the results into R0.

Fig. (3.4): Signals generated to execute Inst-x on one-bus datapath


during time period t0, t1, t2.
University of Technology The 80386 Microprocessors
Department of Electrical & Electronic Eng. Lecture Four-Page 1 of 8
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

3.1 Introduction
The 80386 microprocessor is a full 32-bit version of the earlier 8086/80286 16-
bit microprocessors, and represents a major advancement in the architecture, a switch
from a 16-bit architecture to a 32-bit architecture. Along with this larger word size are
many improvements and additional features. The 80386 microprocessor features
multitasking, memory management, virtual memory (with or without paging),
software protection, and a large memory system. All software written for the early
8086/8088 and the 80286 are upward-compatible to the 80386 microprocessor. The
amount of memory addressable by the 80386 is increased from the 1M bytes found in
the 8086/8088 and the 16M bytes found in the 80286, to 4G bytes in the 80386.
Before the 80386 or any other microprocessor can be used in a system, the
function of each pin must be understood. Figure (3-1a) illustrates the pin-out of the
80386DX microprocessor. The 80386DX is packaged in a 132-pin PGA (pin grid
array). Two versions of the 80386 are commonly available: the 80386DX, which is
illustrated and described in this section; the other is the 80386SX, which is a reduced
bus version of the 80386. A new version of the 80386-the 80386EX-incorporates the
AT bus system, dynamic RAM controller, programmable chip selection logic, 26
address pins, 16 data pins, and 24 I/O pins. Figure (3-1b) illustrates the 80386SX
embedded PC.
The 80386DX addresses 4G bytes of memory through its 32-bit data bus and
32-bit address. The 80386SX, more like the 80286, addresses 16M bytes of memory
with its 24-bit address bus via its 16-bit data bus. The 80386SX was developed after
the 80386DX for applications that didn't require the full 32-bit bus version. The
80386SX is found in many personal computers that use the same basic motherboard
design as the 80286. At the time that the 80386SX was popular, most applications,
including Windows, required fewer than 16M bytes of memory, so the 80386SX is a
popular and a less costly version of the 80386 microprocessor.
University of Technology The 80386 Microprocessors
Department of Electrical & Electronic Eng. Lecture Four-Page 2 of 8
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

Fig. (3.1): The pin-outs of the 80386DX and 80386SX microprocessors.

A31-A2: Address bus connections address any of the 1Gx32 memory locations found
in the 80386 memory system. Note that A0 and A1 are encoded in the bus
enable ( BE 3  BE 0 ) to select any or all of the four bytes in a 32-bit wide
memory location. Also note that because the 80386SX contains a 16-bit data
bus in place of the 32-bit data bus found on the 80386DX, A1 is present on the
80386SX, and the bank selection signals are replaced with BHE and BLE .
The BHE signal enables the upper data bus half; the BLE signal enables the
lower data bus half.
University of Technology The 80386 Microprocessors
Department of Electrical & Electronic Eng. Lecture Four-Page 3 of 8
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

D31-D0: Data bus connections transfer data between the microprocessor and its
memory and I/O system. Note that the 80386SX contains D15-DO.
BE 3  BE 0 : Bank enable signals select the access of a byte, word, or double word
of data. These signals are generated internally by the microprocessor from
address bits A1 and A0. On the 80386SX, these pins are replaced by BHE ,
BLE , and A1.
M / IO : Memory/IO selects a memory device when a logic 1 or an I/O device when a
logic 0. During the I/O operation, the address bus contains a 16-bit I/O address
on address connections A15-A2.
W / R : Write/read indicates that the current bus cycle is a write when a logic 1 or a
read when a logic 0.
ADS : The address data strobe becomes active whenever the 80386 has issued a
valid memory or I/O address. This signal is combined with the W / R signal to
generate the separate read and write signals present in the earlier 8086-80286
microprocessor-based systems.
RESET: Reset initializes the 80386, causing it to begin executing software at
memory location FFFFFFF0H. The 80386 is reset to the real mode, and the
leftmost 12 address connections remain logic 1s (FFFH) until a far jump or far
call is executed. This allows compatibility with earlier microprocessors.
CLK2: Clock times 2 is driven by a clock signal that is twice the operating frequency
of the 80386. For example, to operate the 80386 at 16 MHz, we apply a 32
MHz clock to this pin.
READY : Ready controls the number of wait states inserted into the timing to
lengthen memory accesses. .
LOCK : Lock becomes a logic 0 whenever an instruction is prefixed with the
LOCK:prefix. This is used most often during DMA accesses.
University of Technology The 80386 Microprocessors
Department of Electrical & Electronic Eng. Lecture Four-Page 4 of 8
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

D / C : Data/control indicates that the data bus contains data for or from memory or
I/O when a logic 1. If D / C is a logic 0, the microprocessor is halted or
executes an interrupt acknowledge.
BS 16 : Bus size 16 selects either a 32-bit data bus ( BS 16 = 1) or a 16-bit data bus
( BS 16 =0). In most cases, if an 80386DX is operated on a 16-bit data bus, we
use the 80386SX that has a 16-bit data bus.
NA : Next address causes the 80386 to output the address of the next instruction or

data in the current bus cycle. This pin is often used for pipelining the address.
HOLD: Hold requests a DMA action.
HLDA: Hold acknowledge indicates that the 80386 is currently in a hold condition.
PEREQ : The coprocessor request asks the 80386 to relinquish control and is a
direct connection to the 80387 arithmetic coprocessor.
BUSY : Busy is an input used by the WAIT or FWAIT instruction that waits for the
coprocessor to become not busy. This is also a direct connection to the 80387
from the 80386.
ERROR : Error indicates to the microprocessor that an error is detected by the
coprocessor.
INTR: An interrupt request is used by external circuitry to request an interrupt.
NMI: A non-maskable interrupt requests a non-maskable interrupt as it did on the
earlier versions of the microprocessor.

3.2 Internal Architecture of the 80386DX Microprocessor


The internal architecture of the 8086 family of microprocessors has changed a
lot as part of the evolutionary process from the original 8086 to the 80386. All
members of the 8086 family employ what is called parallel processing. That is, they
are implemented with simultaneously operating multiple processing units. Each unit
University of Technology The 80386 Microprocessors
Department of Electrical & Electronic Eng. Lecture Four-Page 5 of 8
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

has a dedicated function and they operate at the same time. The more the parallel
processing, the higher the performance of the microprocessor.
The 8086 microprocessor contains just two processing units: the bus interface
unit and execution unit. In the 80286 microprocessor, the internal architecture was
further partitioned into four independent processing elements: the bus unit, the
instruction unit, the execution unit, and the address unit. This additional parallel
processing provided an important contribution to the higher level of performance
achieved with the 80286, architecture.
The 80386DX's internal architecture: is illustrated in Fig. (3.2). Here we see
that to enhance the performance, more parallel processing elements are provided.
Notice that now there are six functional units: the execution unit, the segment unit,
the page unit, the bus unit, the prefetch unit, and the decode unit. Let us now look
more closely at each of the processing units of the 80386DX.
The bus unit is the 80386DX's interface to the outside world. By interface, we
mean the path by which it connects to external devices. The bus interface provides a
32-bit data bus, a 32-bit address bus, and the signals needed to control transfers over
the bus. In fact, 8-bit, l6-bit, and 32-bit data transfers are supported. These buses are
demultiplexed like those of the 80286. That is, the 80386DX has separate pins for its
address and data bus lines. This demultiplexing of address and data results in higher
performance and easier hardware design. Expanding the data bus width to 32 bits
further improves the performance of the 80386DX's hardware architecture as
compared to that of either the 8086 or 80286.
The bus unit is responsible for performing all external bus operations. This
processing unit contains the latches and drivers for the address bus, transceivers for
the data bus and control logic for signaling whether a memory, input/output or
interrupt-acknowledg bus cycle is being performed. Looking at Fig. (3.2), we find
that for data accesses, the address of the storage location that is to be accessed is input
University of Technology The 80386 Microprocessors
Department of Electrical & Electronic Eng. Lecture Four-Page 6 of 8
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

from the paging unit, and for code accesses the address is provided by the prefetch
unit.
The prefetch unit implements a mechanism known as an instruction stream
queue. This queue permits the 80386DX to prefetch up to 16 bytes of instruction
code. Whenever the queue is not full-that is, it has room for at least 4 more bytes and,
at the same time, the execution unit is not asking it to read or write operands from
memory-the prefetch unit supplies addresses to the bus interface unit and signals it to
look ahead in the program by fetching the next sequential instructions. Prefected
instructions are held in the FIFO queue for use by the instruction decoder. Whenever
bytes are loaded at the input end of the queue, they are automatically shifted up
through the FIFO to the empty locations near the output. With its 32-bit data bus. the
80386DX fetches 4 bytes of instruction code in a single memory cycle. Through this
prefetch mechanism, the fetch time for most instructions is hidden. If the queue in the
prefetch unit is full and the execution unit is not requesting access to operands in
memory the bus interface unit does not need to perform any bus cycle.
The execution unit includes the arithmetic/logic unit (ALU), the 80386DX's
registers, special multiply, divide, and shift hardware, and a control ROM. By
registers, we mean the 80386DX's general-purpose registers, such as EAX, EBX, and
ECX. The control ROM contains the microcode sequences that define the operation
performed by each of the 80386DX's machine code instructions. The execution unit
reads decoded instructions from the instruction queue and performs the operations
that they specify. It is the ALU that performs the arithmetic, logic, and shift
operations required by an instruction. If necessary, during the execution of an
instruction, it requests the segment and page units to generate operand addresses and
the bus interface unit to perform read or write bus cycles to access data in memory or
I/O devices. The extra hardware that is provided to perform multiply, divide, shift,
and rotate operations improves the performance of instructions that employ these
University of Technology The 80386 Microprocessors
Department of Electrical & Electronic Eng. Lecture Four-Page 7 of 8
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat

functions.
The segment and page units provide the memory-management and protection
services for the 80386DX. They off-load the responsibility for address generation,
address translation, and segment checking from the bus interface unit, thereby further
boosting the performance of the MPU. The segment unit implements the
segmentation model of the 80386DX's memory management. That is, it contains
dedicated hardware for performing high-speed address calculations, logical-to-linear
address translation, and protection check. For instance, when in the real mode, the
execution unit requests the segment unit to obtain the address of the next instruction
to be fetched by adding an appended version of the current contents of the code
segment (CS) register with the value in the instruction pointer (IP) register to obtain
the 20-bit physical address that is to be output on the address bus. This address is
passed on to the bus unit.
For protected mode, the segment unit performs the logical-to-linear address
translation and various protection checks needed when performing bus cycles. It
contains the segment registers and the 6-wordx64-bit cache that is used to hold the
current descriptors within the 80386DX.
The page unit implements the protected mode paging model of the 80386DX's
memory management. It contains the translation lookaside buffer that stores recently
used page directory and page table entries. When paging is enabled, the linear address
produced by the segment unit is used as the input of the page unit. Here the linear
address is translated into the physical address of the memory or I/O location to be
accessed. This physical memory or I/O address is output to the bus interface unit.
University of Technology The 80386 Microprocessors
Department of Electrical & Electronic Eng. Lecture Four-Page 8 of 8
Fourth Year-Microprocessor Eng. II Dr. Hadeel Nasrat
University of Technology Software Model of the 80386DX
Department of Electrical & Electronic Eng. Microprocessor
Fourth Year-Microprocessor Eng. II Lecture Five-Page 1 of 8
Dr. Hadeel Nasrat

SOFTWARE MODEL OF THE 80386DX


MICROPROCESSOR

The purpose of a software model is to aid the programmer in understanding


the operation of the microcomputer system from a software point of view. To be
able to program a microprocessor, one does not necessarily need to know all its
hardware architecture features. For instance, we do not need to know the function of
the signals at its various pins, their electrical connections, or their electrical
switching characteristics. The function interconnection, and operation of the internal
circuits of the microprocessor also need not normally be considered. What is
important to the programmer is to know the various registers within the device and
to understand their purpose, functions, operating capabilities, and limitations.
Furthermore, it is essential to know how external memory is organized and
how it is accessed to obtain instructions and data.

4.1 Memory Organization and Segmentation

The physical memory of an 80386 system is organized as a sequence of 8-bit


bytes. Each byte is assigned a unique address that ranges from zero to a maximum of
232-1 (4 gigabytes). 80386 programs, however, are independent of the physical
address space. This means that programs can be written without knowledge of how
much physical memory is available and without knowledge of exactly where in
physical memory the instructions and data are located.
The model of memory organization seen by applications programmers is determined
by systems-software designers. The architecture of the 80386 gives designers the
freedom to choose a model for each task. The model of memory organization can
range between the following extremes:
● A "flat" address space consisting of a single array of up to 4 gigabytes.
● A segmented address space consisting of a collection of up to 16,383 linear
address spaces of up to 4 gigabytes each.

With the flat memory model (see Figure 4-1), memory appears to a program as a
single, continuous address space, called a linear address space. Code (a program’s
instructions), data, and the procedure stack are all contained in this address space.
The linear address space is byte addressable, with addresses running contiguously
University of Technology Software Model of the 80386DX
Department of Electrical & Electronic Eng. Microprocessor
Fourth Year-Microprocessor Eng. II Lecture Five-Page 2 of 8
Dr. Hadeel Nasrat

from 0 to 232 - 1. An address for any byte in the linear address space is called a
linear address.

Fig. (4.1): Three Memory Management Models

`
With the segmented memory model, memory appears to a program as a group
of independent address spaces called segments. When using this model, code, data,
and stacks are typically contained in separate segments. To address a byte in a
segment, a program must issue a logical address, which consists of a segment selector
and an offset. (A logical address is often referred to as a far pointer.) The segment
selector identifies the segment to be accessed and the offset identifies a byte in the
address space of the segment. The programs running on an Intel Architecture
University of Technology Software Model of the 80386DX
Department of Electrical & Electronic Eng. Microprocessor
Fourth Year-Microprocessor Eng. II Lecture Five-Page 3 of 8
Dr. Hadeel Nasrat

processor can address up to 16,383 segments of different sizes and types, and each
segment can be as large as 232 bytes.
The real-address mode model uses the memory model for the Intel 8086 processor,
the first Intel Architecture processor. It was provided in all the subsequent Intel
Architecture processors for compatibility with existing programs written to run on the
Intel 8086 processor. The real address mode uses a specific implementation of
segmented memory in which the linear address space for the program and the
operating system/executive consists of an array of segments of up to 64K bytes in
size each. The maximum size of the linear address space in real-address mode is 220
bytes.

4.2. REGISTERS

The processor provides 16 registers for use in general system and application
programing. These registers can be grouped as follows:
1. General-purpose data registers. These eight registers are available for storing
operands and pointers.
2. Segment registers. These registers hold up to six segment selectors.
3. Status and control registers. These registers report and allow modification of
the state of the processor and of the program being executed.

4.2.1. General-Purpose Data Registers

The 32-bit general-purpose data registers EAX, EBX, ECX, EDX, ESI, EDI, EBP,
and ESP are provided for holding the following items:
• Operands for logical and arithmetic operations
• Operands for address calculations
• Memory pointers.
Although all of these registers are available for general storage of operands, results,
and pointers, caution should be used when referencing the ESP register. The ESP
register holds the stack pointer and as a general rule should not be used for any other
purpose. Many instructions assign specific registers to hold operands. For example,
string instructions use the contents of the ECX, ESI, and EDI registers as operands.
When using a segmented memory model, some instructions assume that pointers in
certain registers are relative to specific segments. For instance, some instructions
assume that a pointer in the EBX register points to a memory location in the DS
segment.
The following is a summary of these special uses:
• EAX—Accumulator for operands and results data.
• EBX—Pointer to data in the DS segment.
University of Technology Software Model of the 80386DX
Department of Electrical & Electronic Eng. Microprocessor
Fourth Year-Microprocessor Eng. II Lecture Five-Page 4 of 8
Dr. Hadeel Nasrat

• ECX—Counter for string and loop operations.


• EDX—I/O pointer.
• ESI—Pointer to data in the segment pointed to by the DS register; source pointer
for string operations.
• EDI—Pointer to data (or destination) in the segment pointed to by the ES register;
destination pointer for string operations.
• ESP—Stack pointer (in the SS segment).
• EBP—Pointer to data on the stack (in the SS segment).

Fig. (4.2): Alternate General-Purpose Register Names

4.2.2. Segment Registers

The segment registers (CS, DS, SS, ES, FS, and GS) hold 16-bit segment
selectors. A segment selector is a special pointer that identifies a segment in memory.
When using the segmented memory model, each segment register is ordinarily loaded
with a different segment selector so that each segment register points to a different
segment within the linear-address space (as shown in Figure 4-3).
Code segment (CS) is a 16-bit register containing address of 64 KB segment
with processor instructions. The processor uses CS segment for all accesses to
instructions referenced by instruction pointer (IP) register. CS register cannot be
changed directly. The CS register is automatically updated during far jump, far call
and far return instructions.

Stack segment (SS) is a 16-bit register containing address of 64KB segment


with program stack. By default, the processor assumes that all data referenced by the
stack pointer (SP) and base pointer (BP) registers is located in the stack segment. SS
register can be changed directly using POP instruction.
University of Technology Software Model of the 80386DX
Department of Electrical & Electronic Eng. Microprocessor
Fourth Year-Microprocessor Eng. II Lecture Five-Page 5 of 8
Dr. Hadeel Nasrat

Data segment (DS) is a 16-bit register containing address of 64KB segment


with program data. By default, the processor assumes that all data referenced by
general registers (AX, BX, CX, DX) and index register (SI, DI) is located in the data
segment. DS register can be changed directly using POP and LDS instructions.

Extra segment (ES) is a 16-bit register containing address of 64KB segment,


usually with program data. By default, the processor assumes that the DI register
references the ES segment in string manipulation instructions. ES register can be
changed directly using POP and LES instructions.

Figure (4-3): Use of Segment Registers in Segmented Memory Model

4.2.3. EFLAGS Register

The 32-bit EFLAGS register contains a group of status flags, a control flag, and a
group of system flags. Figure (4-4) defines the flags within this register. Some of the
flags in the EFLAGS register can be modified directly, using special-purpose
instructions (described in the following sections). There are no instructions that allow
the whole register to be examined or modified directly.
When a call is made to an interrupt or exception handler procedure, the processor
automatically saves the state of the EFLAGS registers on the procedure stack. When
University of Technology Software Model of the 80386DX
Department of Electrical & Electronic Eng. Microprocessor
Fourth Year-Microprocessor Eng. II Lecture Five-Page 6 of 8
Dr. Hadeel Nasrat

an interrupt or exception is handled with a task switch, the state of the EFLAGS
register is saved in the TSS for the task being suspended.

S Indicates a Status Flag


C Indicates a Control Flag
X Indicates a System Flag

Figure (4-4): EFLAGS Register

STATUS FLAGS

The status flags (bits 0, 2, 4, 6, 7, and 11) of the EFLAGS register indicate the
results of arithmetic instructions, such as the ADD, SUB, MUL, and DIV
instructions. The functions of the status flags are as follows:

CF (bit 0) Carry flag: Set if an arithmetic operation generates a carry or a borrow


out of the most-significant bit of the result; cleared otherwise. This flag indicates an
overflow condition for unsigned-integer arithmetic. It is also used in multiple-
precision arithmetic.
PF (bit 2) Parity flag: Set if the least-significant byte of the result contains an even
number of 1 bits; cleared otherwise.
University of Technology Software Model of the 80386DX
Department of Electrical & Electronic Eng. Microprocessor
Fourth Year-Microprocessor Eng. II Lecture Five-Page 7 of 8
Dr. Hadeel Nasrat

AF (bit 4) Adjust flag: Set if an arithmetic operation generates a carry or a borrow


out of bit 3 of the result; cleared otherwise. This flag is used in binarycoded decimal
(BCD) arithmetic.
ZF (bit 6) Zero flag: Set if the result is zero; cleared otherwise.
SF (bit 7) Sign flag: Set equal to the most-significant bit of the result, which is the
sign bit of a signed integer. (0 indicates a positive value and 1 indicates a negative
value.)
OF (bit 11) Overflow flag: Set if the integer result is too large a positive number or
too small a negative number (excluding the sign-bit) to fit in the destination operand;
cleared otherwise. This flag indicates an overflow condition for signed-integer (two’s
complement) arithmetic.

Control Flags

DF (bit 10) Direction flag: Controls the string instructions (MOVS, CMPS, SCAS,
LODS, and STOS). Setting the DF flag causes the string instructions to auto
decrement (that is, to process strings from high addresses to low addresses). Clearing
the DF flag causes the string instructions to auto-increment (process strings from low
addresses to high addresses). The STD and CLD instructions set and clear the DF
flag, respectively.

TF (bit 8) Trap flag: Set to enable single-step mode for debugging; clear to disable
single-step mode.

IF (bit 9) Interrupt enable flag: Controls the response of the processor to maskable
interrupt requests. Set to respond to maskable interrupts; cleared to inhibit maskable
interrupts.

System Flags and IOPL field

The system flags and IOPL field in the EFLAGS register control operating-
system or executive operations. They should not be modified by application
programs. The functions of the status flags are as follows:
IOPL (bits 12 and 13) I/O privilege level field: Indicates the I/O privilege level of
the currently running program or task. The current privilege level (CPL) of the
currently running program or task must be less than or equal to the I/O privilege level
to access the I/O address space. This field can only be modified by the POPF and
IRET instructions when operating at a CPL of 0.
NT (bit 14) Nested task flag: Controls the chaining of interrupted and called tasks.
Set when the current task is linked to the previously executed task; cleared when the
current task is not linked to another task.
University of Technology Software Model of the 80386DX
Department of Electrical & Electronic Eng. Microprocessor
Fourth Year-Microprocessor Eng. II Lecture Five-Page 8 of 8
Dr. Hadeel Nasrat

RF (bit 16) Resume flag. Controls the processor’s response to debug exceptions.
VM (bit 17) Virtual-8086 mode flag. Set to enable virtual-8086 mode; clear to
return to protected mode.
AC (bit 18) Alignment check flag: Set this flag and the AM bit in the CR0 register
to enable alignment checking of memory references; clear the AC flag and/or the AM
bit to disable alignment checking.
VIF (bit 19) Virtual interrupt flag: Virtual image of the IF flag. Used in
conjunction with the VIP flag. (To use this flag and the VIP flag the virtual mode
extensions are enabled by setting the VME flag in control register CR4.)
VIP (bit 20) Virtual interrupt pending flag: Set to indicate to that an interrupt is
pending; clear when no interrupts are pending. (Software sets and clears this flag. The
processor only reads it.) Used in conjunction with the VIF flag.
ID (bit 21) Identification flag: The ability of a program to set or clear this flag
indicates support for the CPUID instruction.
Microcomputer Block Diagram

A dd re ss Bu s
CPU

Da ta Bus

Co n tro l Bu s

In t e rf a ce Circ uit r y

RAM ROM

Perip h er a l D e vice s

F1-1

TM-1
CPU Functional Units

CPU

In st r uc t io n Re g ist e r ( IR) Pro gr am Co u nt er ( PC)

Re g ist e r 0
Inst r u ct io n De co d e
an d C on t r o l U nit
Re g ist e r 1

A r it h m et ic an d
Lo g ic Un it ( A LU )
Reg ist er n - 1

F1-2

TM-2
Opcode Fetch

CPU
A d dr e ss Bu s

Pr o g ram
Co u n t e r
D a t a Bu s

Op c od e RA M

Inst ru ct io n
Re g ist e r N+2

N+1
Co nt ro l
Bus Op co d e N
Clo ck N-1

Re ad

F1-3

TM-3
Memory Maps

1 Byte

F FFF 7 6 5 4 3 2 1 0 6 5 ,5 3 5 FF FF
4 K ROM
F0 0 0
EFFF

4 4 K Em pt y
H exa d ec im al De cim a l
A d dr esse s A dd re sse s

.
4000
. 3 FFF

.
0004 4
1 6 K RA M
0003 3
0002 2
0001 1
0000 0 0000

F1-6/7

TM-4
16-Bit Addresses

Bit 1 5 =
B it 0 =
m os t -sig n if ican t b it
lea st -sig n if ica nt bit

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

(a )

9 C F 3
1 0 0 1 1 1 0 0 1 1 1 1 0 0 1 1

(b )

F1-8

TM-5
The Development Cycle

Specify Design Preliminary


Edit Translat e
software software t est ing

Int egrate
Concept and Product
verify

Specify Design Build Preliminary


hardware hardware prot otype t est ing

1-11

TM-6
Steps in
the Development Cycle

List ing L ist in g


f ile f ile
( .L ST) ( .M A P)

Sou rc e Ob je ct A b so lut e
L in ke r/ So f t ware
Edit o r f ile A sse m b le r f ile o b je ct Sim ula t o r
lo ca t o r sim u lat io n
(. SRC) (. OBJ) f ile

(For a b solu t e f iles)

Ha rdw are
Em u lat o r
em u lat io n

He x Do wn lo ad /
Le g e nd : OBJHEX
f ile t e rm in al RA M
c o nv er sio n
(. HEX) e m ula t e
Ut ilit y p ro g ram o r
d ev elo p m e nt t o o l

Use r f ile
EPROM
EPROM
Pro g ram m er
Ex ec ut io n e nv iro nm e n t

Fact o ry
m ask ROM
p ro ce ss

1-13

TM-7
Motorola S-records

S00900006D796E616D656F
S11320003C3C000A327C201661000020534666F4F2
S11320101E3C00E44E4E53636F7474204D61634B59
S10C2020656E7A6965200D0A0061
S113202A1E3C00F81019670000064E4E60F64E7505
S9030000FC

(a)

S1 1 3 2 0 0 0 3 C3 C0 0 0 A 3 2 7 C2 0 1 6 6 1 0 0 0 0 2 0 5 3 4 6 6 6 F4 F2

Che ck sum
Da t a By t es
Lo ad A d d r ess
Byt e Co u n t
Re co r d T y pe

(b)

1-14

TM-8
68000 Programmer's Model

31 16 15 8 7 0

D0
D1
D2
D3 D at a
D4 Re g is t e rs
D5
D6
D7

31 16 15 0

A0
A1
A2 A dd re ss
A3
Reg ist ers
A4
A5
A6
31 16 15 0

A7 U ser St ack Po int e r ( USP)


A7 Su p erv iso r St ac k Po in t e r (SSP)

31 24 23 0

PC Pro g ra m Co un t er

15 8 7 0

SR St a t u s Re g ist e r
123
CCR

F2-1

TM-9
68000 Status Register

U ser By t e
Syst e m Byt e ( Co nd it io n Co d e Re gist er )

15 13 10 9 8 4 3 2 1 0

T S I2 I1 I0 X N Z V C

123

Carry
Ove rf lo w
Ze ro
Ne g at ive
Sig n Ex t e nd
Int er rup t M ask
Sup e rviso r St a t e
Trac e Mo d e

F2-4

TM-10
Condition Code Computation

1 1 1
00011001 C = Sm D m + Rm D m + Sm Rm
= 0 0 + 0 0 + 0 0
+ 01110000 = 0

10001001 Z = 0 V = Sm Dm Rm + Sm D m Rm
= 0 0 0 + 1 1 1
N = 1 = 1

X = C = 0
Rm = 1
Dm = 0
Sm = 0

F2-5

TM-11
68000 Memory Map

-- Byte View --

1 By t e
( 8 b it s)

F FFFF F

0 000 04
0 000 03
0 000 02
0 000 01
00 000 0

F2-7

TM-12
68000 Memory Map

-- Word View --

1 W ord ( 1 6 b it s)

FFF FFE

By t e FFF FFE By t e FFF FFF

N ot e :
Ev e n b y t e s co r re spo n d
t o u p pe r b yt es o n t h e
ex t e rn al d at a b us. Od d
b yt es c o r r esp o n d t o lo w e r
b yt es o n t h e e xt er n al
d at a b us.
By t e 4 By t e 5
By t e 2 Byt e 3

By t e 0 By te 1

0 000 04
0 000 02
00 000 0

F2-8

TM-13
68000 Memory Map

-- Longword View --

1 L o ng w or d ( 3 2 b it s )

W or d a dd re ss: n + 4

B yt e n + 4 et c.

n + 8
n + 4
L o ng w o rd s
n
ca n b e at a ny
e ve n a dd re ss

B yt e n B yt e n + 1 B y te n + 2 B y te n + 3
1 2 3 1 2 3
Wo rd ad d ress: n W o rd ad dr ess: n + 2

F2-9

TM-14
68000 Addressing Modes
Assembler Effective Address
Mode Syntax Generation
Data Register Direct Dn EA = Dn
Address Register Direct An EA = An
Absolute Short xxx.W or <xxx EA = (next word)
Absolute Long xxx.L or >xxx EA = (next two words)
Register Indirect (An) EA = (An)
Postincrement Register Indirect (An)+ EA = (An), An ` An + N
Predecrement Register Indirect -(An) An ` An - N, EA = (An)
Register Indirect with Offset d16(An) EA = (An) + d16
Register Indirect with Index & Offset d8(An,Xn) EA = (An) + (Xn) + d8
PC Relative with Offset d16(PC) EA = (PC) + d16
PC Relative with Index and Offset d8(PC,Xn) EA = (PC) + (Xn) + d8
Immediate #data DATA = next word(s)
Implied Register CCR, SR, USP, EA = CCR, SR, USP, SSP, PC
SSP, PC
Notes:
EA = effective address PC = program counter
An = address register ( ) = contents of
Dn = data register d8 = 8-bit offset (displacement)
Xn = address or data register used as index register d16 = 16-bit offset (displacement)
CCR = condition code register N = 1 for byte, 2 for word, 4 for longword. (If An is the
SR = status register stack pointer and the operand size is byte, N = 2 to
USP = user stack pointer keep the stack pointer on a word boundary.)
SSP = supervisor stack pointer ` = is replaced by

T2-1

TM-15
Data Register Direct

Instruction: MOVE.B D0,D3

Register Contents
Before:....D0.....10204FFF
...........D3.....1034F88A
On ly b it s 0 -7
af f ec t e d
After:.....D0.....10204FFF
...........D3.....1034F8FF

F2-10

TM-16
Address Register Direct

Instruction: MOVEA.L A3,A0

Register Contents Mo ve t o
a d dr e ss r e g ist e r
Before: A0.....00200000
A3.....0004F88A
3 2 bit s are
After: A0.....0004F88A m ov e d
A3.....0004F88A

F2-11

TM-17
Absolute Short

So urc e a dd re ssin g
m o d e is im m e d ia t e
Instruction: MOVE.L #$1E,$800

**** MEMORY ****


De st in at io n a dd re ssin g
Address Contents
m o d e is ab so lu t e sho rt
Before: 000800 12
000801 34
000802 56
000803 78

After: 000800 00 3 2 -b it o p e ran d siz e


000801 00 m o v es d at a t o f o u r
000802 00 c on se cu t iv e b y t e
lo ca t io n s
000803 1E

F2-13

TM-18
Absolute Long

Instruction: MOVE.B #$1E,$8F000

**** MEMORY ****


D est ina t io n ad d ressin g
Address Contents
m od e is a b so lut e lo n g
Before: 08F000 FF

After: 08F000 1E Op era n d siz e


is b yt e

F2-14

TM-19
Register Indirect

Instruction: MOVE.L D0,(A0) A0 co nt ain s t h e


a d dr ess o f t h e
d e st in at ion
**** MEMORY ****
Address Contents Registers
Before: 001000 55 A0 00001000
001001 02 D0 1043834F
001002 3F
001003 00 A0 do e s no t
ch an g e
After: 001000 10 A0 00001000
001001 43 D0 1043834F
001002 83
001003 4F A lo n g w o r d is w r it t e n t o
ad d r e ss $ 0 0 1 0 0 0

F2-17

TM-20
Postincrement Address
Register Indirect

Instruction: MOVE.W (A5)+,D0

**** MEMORY ****


Address Contents Registers
Before: 001000 45 A5 00001000
001001 67 D0 0000FFFF
A dd re ss re gist e r
001002 89 in cr em e n t e d b y
001003 AB nu m b e r o f b y t e s
m ov e d, 2
After: 001000 45 A5 00001002
001001 67 D0 00004567
001002 89
001003 AB

F2-18

TM-21
Predecrement Address
Register Indirect

Instruction: MOVE.W D0,-(A7)

**** MEMORY ****


Address Contents Registers
Before: 001000 10 A7 00001002
001001 12 D0 00000143
A dd re ss re gist e r
001002 83 d e cre m en t ed b y
001003 47 nu m b e r o f b y t e s
m ov e d, 2
After: 001000 01 A7 00001000
001001 43 D0 00000143
001002 83
001003 47

F2-19

TM-22
Register Indirect
With Offset

Instruction: MOVE.W 6(A0),D0 Ef f e ct ive a d dr ess is


6 p lu s va lu e in A 0

**** MEMORY ****


Address Contents Registers
Before: 001026 07 A0 00001020
001027 BF D0 00000000 A d dre ss r e g is t e r
do e s no t ch an g e
After: 001026 07 A0 00001020
001027 BF D0 000007BF

F2-20

TM-23
Register Indirect
With Index and Offset

A d dr ess r e g ist e r

Ind e x r eg ist er , 3 2 b it s
Instruction: MOVEA $10(A0,D0.L),A1

**** MEMORY ****


Address Contents Registers
Before: 00101C EF A0 0000100A
00101D 10 A1 00000000 W o r d v alu e is
D0 00000002 sig n-e xt en d ed
b e ca use d est ina t io n
After: 00101C EF A0 0000100A is a n a dd r e ss r e gist e r

00101D 10 A1 FFFFEF10
D0 00000002

No t e:
EA = $ 1 0 + $ 1 0 0 A + $ 2 = $ 1 0 1 C

F2-22

TM-24
PC-Relative
With Offset

Instruction: MOVE.W $1020(PC),D5

**** MEMORY ****


Address Contents Registers
Before: 001020 AB PC 00001000 In st r uc t io n is t w o
001021 CD D5 12345678 w o rd s lo ng , s o PC is
in cr em e n t e d b y f o ur

After: 001020 AB PC 00001004


001021 CD D5 1234ABCD

F2-23

TM-25
PC-Relative
With Index and Offset

Instruction: MOVE.W $1020(PC,D0.W),D5


On ly lo w - o rd er
**** MEMORY **** 1 6 b it s o f D 0 use d
Address Contents Registers a s ind e x
Before: 001026 FE PC 00001000
001027 DC D0 ABCD0006
D5 12345678

After: 001026 FE PC 00001004


001027 DC D0 ABCD0006
D5 1234FEDC

F2-26

TM-26
Immediate

Im m e dia t e d at a
f ollo w
Instruction: MOVE.L #$1FFFF,D0

Register Contents Base :


Before: D0 12345678 $ = he xa d ecim al
@ = oc tal
% = b in a ry
After: D0 0001FFFF & ( o r n o t h in g ) = d ec im al
' A B' = A SCII ch ara ct er s

F2-28

TM-27
68000 Signals

Vc c (2 )
A d dr ess Bu s A1 -A 2 3
GND (2 )
68000
D at a Bu s D0 -D1 5
CL K

AS
R/ W A syn ch ro n o us
FC0 UDS Bu s
Pro ce ssor Co n t ro l
FC1 L DS
St a t u s
FC2 D TA CK

MC 6 8 0 0 E BR Bu s
Perip h era l V MA BG A rb it ra t io n
Co n t ro l VPA BGAC K Co n t ro l

B ERR IPL0
Sy st e m In t e rrup t
RESET IPL1
Co n t r ol Co n t ro l
HA L T IPL2

F2-33

TM-28
Upper Data Strobe and
Lower Data Strobe

Int er n a l Bu s
Sig n als Sig n als

A2 3 A2 3

A1 A1

A0 WORD / BYT E A0 U DS L DS
UD S
( ev en b yt e) 1 X 0 0

0 0 0 1

LD S 0 1 1 0
WORD / BYT E
( o dd b yt e )

( a) (b )

F2-34

TM-29
Decoding with
-UDS and -LDS

68 0 00

A 1 -A2 3 A d d r e ss B us

D 8 -D 1 5 D a t a B us ( u pp e r b y t e)

D 0 -D7 D a t a B us ( l ow er b y t e )

A d dre ss
Up p er Lo wer
De co d ing RA M RAM

CS CS
UD S

L DS

F2-36

TM-30
Generation of -DTACK

A d dre ss Bu s

6 80 0 0
A dd re ss RA M Ad d re s s RA M
De co d ing D e co d ing

CS CS
74 07 740 7
+5 V

10 K
Fro m o t h e r RA Ms ,
DT A CK
ROM s, I/ O De v ic es , et c.

F2-36

TM-31
Function Code Outputs

Function Code

FC2 FC1 FC0 Address Space Type

0 0 0 (Undefined, reserved)

0 0 1 User Data

0 1 0 User Program

0 1 1 (Undefined, reserved)

1 0 0 (Undefined, reserved)

1 0 1 Supervisor Data

1 1 0 Supervisor Program
1 1 1 CPU Space (Interrupt Acknowledge)

T2-3

TM-32
Read Cycle Timing

DT AC K m u st b e D at a lat ch e d in t o
asse rt ed b ef o r e t h e e n d CPU at be g in nin g
o f S4 , ot h erw ise w ait o f S7
st at es ar e in sert ed

S0 S1 S2 S3 S4 S5 S6 S7

CLK

FC0 -FC2

A1 -A2 3

AS

UDS

L DS

R/ W

DT A CK

D8 - D1 5

D0 - D7

F2-39

TM-33
Write Cycle Timing

S0 S1 S2 S3 S4 S5 S6 S7

CL K

FC0 -FC2

A1 -A2 3

AS

UDS

L DS

R/ W

DT A CK

D8 - D1 5

D0 - D7
F2-40

TM-34
Data Movement Instructions

Instruction Operation

EXG Exchange registers

LEA Load effective address

LINK Link and allocate stack

MOVE Move source to destination

MOVEA Move source to address register

MOVEM Move multiple registers

MOVEP Move to peripheral

MOVEQ Move short data to destination

PEA Push effective address

UNLK Unlink stack


T3-3

TM-35
Integer Arithmetic Instructions
Instruction Operation
ADD Add source to destination
ADDA Add source to address register
ADDI Add immediate data to destination
ADDQ Add short data to destination
ADDX Add with extend bit to destination
CLR Clear operand
CMP Compare source to destination
CMPA Compare source to address register
CMPM Compare memory
DIVS Signed divide
DIVU Unsigned divide
EXT Sign extend
EXTB Sign extend byte
MULS Signed multiply
MULU Unsigned multiply
NEG Negate
NEGX Negate with extend
SUB Subtract source from destination
SUBA Subtract source from address register
SUBI Subtract immediate from destination
SUBQ Subtract short from destination
SUBX Subtract with extend bit from destination
T3-4

TM-36
CMP Example

Instruction: CMP.B #'z',D7 A SCII co d e f o r


'z ' is $ 7 A
Register Contents
D 7 also co n t a in s
Before: D7 FFFFFF7A
ASCII co d e f or ' z'
SR 001F

After: D7 FFFFFF7A D7 d o e s n o t
ch an g e
SR 0014

Notes: 01111010
- 01111010
00000000
12 3
Z= 1
N = 0
V = 0 ( sig n b it d oe s n ot ch an g e)
C = 0 ( b o rro w no t re q u ir ed )
X = 1 (n o ch an g e)

F3-5

TM-37
DIVS Example

Instruction: DIVS #-3,D7 Div is or , - 3

Register Contents
D ivid en d , 1 4
Before: D7 0000000E
SR 001F

After: D7 0002FFFC Qu o t ie n t , -4
SR 0018
Re m ain d er , 2

Notes: 14 / -3 = -4 with a remainder of 2


F3-8

TM-38
Boolean Instructions

Instruction Operation

AND AND source to destination

ANDI AND immediate data to destination

EOR Exclusive OR source to destination

EORI Exclusive OR immediate data to destination

NOT Complement destination

OR OR source to destination

ORI OR immediate data to destination

Scc Test condition codes and set operand

TST Test operand and set condition codes

T3-5

TM-39
EOR Example

Instruction: EOR.L D6,(A4)+

**** MEMORY ****


Address Contents Registers
Before: 003100 AB A4 00003100
So ur ce o p e ran d
003101 CD D6 12345678
003102 EF SR 0000
003103 10 De st ina t io n o p e ran d

After: 003100 B9 A4 00003104 A 4 in cre m en t ed


003101 F9 D0 12345678 by four
003102 B9 SR 0008
003103 68

Notes: ABCDEF10
+ 12345678
B9F9B968
1 2 3
Z= 0
N = 1
V = C = 0 ( alw a ys)
X = n ot af f e ct e d ( assu m e 0 )

F3-10

TM-40
Shift and Rotate Instructions
Instruction Operation Bit Movement

ASL Arithmetic shift left C Op era n d 0

Op er a nd C
ASR Arithmetic shift right
X

C Ope ra nd 0
LSL Logical shift left
X

0 Op e ran d C
LSR Logical shift right
X

ROL Rotate left


C Op e ran d

ROR Rotate right Op er an d C

ROXL Rotate left with extend bit C Op e ran d X

ROXR Rotate right with extend bit X Op era nd C

1 6 b it s 1 6 b it s
SWAP Swap words of a longword

T3-6

TM-41
ASR Example

A rit hm e t ic shif t
Instruction: ASR.B D3,D2 righ t : sig n b it
d o es n o t ch an g e !

Register Contents
Sh if t c o un t in D3
Before: D3 00000002
D2 00000068
SR 001F Sh if t d at a in D 2

After: D3 00000002
D2 0000001A
SR 0000

Notes: 01101000

00110100

00011010 0
1 2 3
C = X = 0
Z= 0
N = 0
V = 0 ( alw ay s)

F3-11

TM-42
Bit Manipulation Instructions

Instruction Operation

BCHG Change bit

BCLR Clear bit

BSET Set bit

BTST Test bit


T3-7

TM-43
BTST Example

Instruction: BTST #7,D5 T e st b it 7 o f D 5

Register Contents
Bit 7 = 0
Before: D5 FFFFFF7F
SR 0000

After: D5 FFFFFF7F
SR 0004 Z = 1

F3-12

TM-44
Binary-Coded Decimal Instructions

Instruction Operation

ABCD Add source to destination

NBCD Negate destination

SBCD Subtract source from destination


T3-8

TM-45
ABCD Example

O p e r an d siz e
alw a ys b y t e
Instruction: ABCD -(A3),-(A4)

**** MEMORY ****


Address Contents Registers
Before: 00200E 98 A3 0000200F
00210E 54 A4 0000210F X= 1

SR 001F
Bot h a d dr ess r e g ist e r s
After: 00200E 98 A3 0000200E d e cr e m en t ed b y o n e
00210E 53 A4 0000210E
SR 0011
1 ---XNZVC
Notes: 10011000 00010001
01010100
+ 1 (X = 1 ) 98 + 54 + 1 = 15 3
1 1 ( t h e h u nd r e d s d ig it
11101101 is st o r e d in C & X)
+ 00000110 ( ad d 0 6 )
11 1
11110011
+ 01100000 ( ad d 6 0 )

01010011
1 2 3
Z= 0
C = X = 1
N = V = u nd e f ine d ( a ssum e 0 )

F3-13

TM-46
Program Flow Instructions

Instruction Operation

Bcc Branch conditionally

BRA Branch always

BSR Branch to subroutine

DBcc Test, decrement, and branch

JMP Jump to address

JSR Jump to subroutine

NOP No operation

RTE+ Return and deallocate stack

RTR Return and restore condition codes

RTS Return from subroutine

+privileged instruction
T3-9

TM-47
BRA Example

Instruction: BRA $20A0 Br a n ch d e st in at io n

**** MEMORY ****


Address Contents Registers
Before: 002050 60 PC 00002050
002051 4E
In st r uc t io n w o r d

After: 002050 60 PC 000020A0


002051 4E

Notes: Displacement = X Bra n ch o f f s et , 8 b it s


2052 + X = 20A0
X = 20A0 - 2052
= 4E

F3-15

TM-48
BSR/RTS Example
BSR $ 4 0 F2
BEFO RE A FT ER
RE GIS T ERS: RE GIS T ERS:
PC 0 0 5 0 16 PC 0 0 4 0 F2
A7 0 000 305 0 A7 0 000 304 C

MEMO RY: MEMO RY:

MA IN MA IN
00 501 A PROGRA M 00 50 1A PROGRA M
0 0 5 0 1 8 F0 DA 0 0 5 0 1 8 F0 DA
BSR $ 4 0 F2 BSR $ 4 0 F2
00 501 6 6 1 0 0 00 50 16 6 1 00

0 0 4 0 F A 4 E7 5 RTS 0 0 4 0 F A 4 E7 5 RTS
SU BROU TIN E SU BROU TIN E

0 0 4 0 F2 0 0 4 0 F2

00 3 05 0 1 234 A7 00 3 05 0 1 234
00 3 04 E 5 678 STA CK 00 3 04 E 5 01A STA CK
0 0 3 0 4 C 9 A BC 00 3 04 C 0 000 A7

a dd re ss o f
ins t ru ct ion
f o llo w in g BSR

RT S
BEFORE A FT ER
REGIST ERS: REGIST E RS:
PC 0 0 4 0 FA PC 0 05 01A ret u r n t o
A7 0 00 0 3 04 C A7 0 00 0 30 5 0 in st r u ct io n
f o llo w in g BSR
MEMORY: MEMORY:

MA IN MA IN
00 5 01 A PROGRA M 00 5 01 A PROGRA M
0 0 5 0 1 8 F0 DA 0 0 5 0 1 8 F0 DA
BSR $ 4 0 F2 BSR $ 4 0 F2
00 5 01 6 61 00 00 5 01 6 61 00

0 0 4 0 FA 4 E7 5 RT S 0 0 4 0 FA 4 E7 5 RT S
SU BROU TINE SU BROU TINE

0 0 4 0 F2 0 0 4 0 F2

003 050 1 2 34 003 050 1 23 4 A7


003 04E 5 0 1A ST A CK 003 04E 5 01 A ST A CK
003 04C 0 0 00 A7 003 04C 0 00 0

F3-16

TM-49
System Control Instructions

Instruction Operation

ANDI++ AND immediate to status register/condition code register

CHK Trap on upper out-of-bounds operand

EORI++ Exclusive OR immediate to status register/condition code


register

ILLEGAL Illegal instruction trap

MOVE++ Move to/from status register/condition code register

ORI++ OR immediate to status register/condition code register

RESET+ Assert RESET line

STOP+ Stop processor

TAS Test and set operand


TRAP Trap unconditionally

TRAPV Trap on overflow

+privileged instruction

++privileged instruction if SR specified


T3-10

TM-50
TRAP Example

Instruction: TRAP #5

**** MEMORY ****


Address Contents Registers
Before: 002FFA 12 PC 00002000
Sy st e m
002FFB 34 A7' 00003000 St a ck Po int er
002FFC 56 SR 001F
002FFD 78
002FFE 9A
V ec t o r
002FFF BC
ad d r e ss
f o r t ra p 5 000094 00 V ec t o r f o r
000095 01 t rap 5 Exc ep t ion p ro ce ssing
b e gin s at ad d r ess
000096 80
$ 0 1 8 0 F0
000097 F0

After: 002FFA 00 PC 000180F0


002FFB 1F A7' 00002FFA Sy st e m
St a ck Po int er
002FFC 00 SR 201F
d e cr e m e nt ed
002FFD 00 by 6
002FFE 20
002FFF 02 SR sa ve d o n Su p er viso r St a t e
000094 00 syst em st ac k b it = 1

000095 01
000096 80
PC sav ed o n
000097 F0 sy st e m st a ck

Notes: Vector read from address $80 + (5 x 4) = $94


F3-18

TM-51
68000 Instruction Format

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

Operation Word

(1st word specifies operation and addressing modes)

Immediate Operand

(if any, one or two words)

Source Effective Address Extension

(if any, one or two words)

Destination Effective Address Extension

(if any, one or two words)

F3-19

TM-52
Effective Address Encoding

Addressing Mode Mode Bits Register Bits

Data Register Direct 000 register number

Address Register Direct 001 register number

Address Register Indirect 010 register number

Address Register Indirect with 011 register number


Postincrement

Address Register Indirect with 100 register number


Predecrement
Address Register Indirect with 101 register number
Displacement†

Address Register Indirect with Index* 110 register number

Absolute Short† 111 000

Absolute Long†† 111 001

Program Counter with Displacement† 111 010

Program Counter with Index* 111 011

Immediate or Status Register††† 111 100

† One extension word required


†† Two extension words required
††† For Immediate addressing, one or two extension words required
depending on the size of the operation
* One extension word required; see Table C-4 for the encoding

T3-11

TM-53
68000 Condition Code Encoding

Mnemonic Condition Encoding Test


T† true 0000 1
F† false 0001 0
HI high 0010 C •Z
LS low or same 0011 C+Z
CC(HS) carry clear 0100 C
CS(LO) carry set 0101 C
NE not equal 0110 Z
EQ equal 0111 Z
VC†† overflow clear 1000 V
VS†† overflow set 1001 V
PL plus 1010 N
MI minus 1011 N
GE†† greater or equal 1100 N• V + N • V
LT†† less than 1101 N• V + N •V
GT†† greater than 1110 N• V •Z +N • V • Z
LE†† less or equal 1111 Z + N• V + N •V
† Not available for Bcc instruction
†† Twos complement arithmetic
• = Boolean AND
+ = Boolean OR
T3-12

TM-54
Opcode Map

Bits
15 through 12 Operation

0000 Bit Manipulation/MOVEP/Immediate

0001 Move Byte

0010 Move Long

0011 Move Word

0100 Miscellaneous

0101 ADDQ/SUBQ/Scc/DBcc

0110 Bcc/BSR

0111 MOVEQ

1000 OR/DIV/SBCD

1001 SUB/SUBX

1010 (Unassigned)

1011 CMP/EOR

1100 AND/MUL/ABCD/EXG

1101 ADD/ADDX

1110 Shift/Rotate

1111 (Unassigned)

T3-13

TM-55
Assembler Operation

PROG.OBJ
L eg e nd :

Ut ilit y p ro g ram
PRO G.SRC A68 K

Use r f ile
PROG.L ST

( a)

Inp u t
C o m m an d f ile Lis t ing O b je ct co d e
o ut ut f ile o ut p ut f ile A ssem ble r
op t ion s

A 6 8 K PROG.SRC, PRO G.L ST , PROG.OBJ, X S


( b)

F4-1

TM-56
Assembler Files

La b el Mn e m o nic Op er an d C om m en t
f ield f ie ld f ie ld f ield (e m p t y )

ORG.....$1000
PROG LEA.....$800,A0
MOVE.B..#50,D0
CLR.W...D7
Sou r ce
LOOP ADD.W...(A0)+,D7 f ile
SUBQ.B..#1,D0
BRA.....*
END
( a)

L ine nu m b e r

A d d re ss Co n t e n t s So u rce f ile

1 00001000.................ORG.....$1000
2 00001000.41F80800.PROG...LEA.....$800,A0
3 00001004.103C0032........MOVE.B..#50,D0
4 00001008.4247............CLR.W...D7 L ist in g
5 0000100A.DE58.....LOOP...ADD.W...(A0)+,D7 f ile
6 0000100C.5300............SUBQ.B..#1,D0
7 0000100E.60FE............BRA.....*
8 00001010.................END

(b )

F4-2

TM-57
Listing Examples
1 00001000 ORG $1000
2 00001000 6006 BRA *+8 ;"*" location counter
3 00001002 60FE BRA * ;branch to itself
4 00001004 6000FFFE HERE BRA HERE ;branch to itself
5 00001008 181B MOVE.B (A3)+,D4 ;indirect addressing
6 00000064 COUNT EQU 100 ;equate symbol to value
7 0000100A 3A3C0064 MOVE.W #COUNT,D5 ;symbol as immed. data
8 0000100E 3A3C0064 MOVE.W #100,D5 ;decimal
9 00001012 3A3C0064 MOVE.W #$64,D5 ;hexadecimal
10 00001016 3A3C0064 MOVE.W #144Q,D5 ;octal (A68K format)
11 0000101A 3A3C0064 MOVE.W #%01100100,D5 ;binary
12 0000101E 3E3CFFFB MOVE.W #-5,D7 ;negative number, decimal
13 00001022 3E3CFFFB MOVE.W #$FFFB,D7 ;negative number, decimal
14 00001026 3A390000 MOVE $F000,D5 ;data address
0000102A F000
15 0000F000 PORT EQU $F000 ;equate symbol as address
16 0000102C 3A390000 MOVE PORT,D5 ;data address (symbol)
00001030 F000
17 00001032 4E71 BACK NOP ;code address (NOP =
18 00001034 4E71 NOP ; no operation)
19 00001036 67FA BEQ BACK
20 00001038 END

F4-4

TM-58
Assemble-Time Operators

Operator† Function Precedence Type


- Unary minus 1 Unary
.NOT. Logical NOT 1 Unary
.LOW. Low byte 1 Unary
.HIGH. High byte 1 Unary
.LWRD. Low word 1 Unary
.HWRD. High word 1 Unary
* Multiplication 3 Binary
/ Division 3 Binary
+ Addition 4 Binary
- Subtraction 4 Binary
.MOD. Modulo 3 Binary
.SHR. Logical shift right 3 Binary
.SHL. Logical shift left 3 Binary
.AND. Logical AND 5 Binary
.OR. Logical OR 6 Binary
.XOR. Logical XOR 6 Binary
.EQ. Equal†† 7 Binary
.NE. Not Equal†† 7 Binary
.GE. Greater or equal†† 7 Binary
.LE. Less or equal†† 7 Binary
.GT. Greater than†† 7 Binary
.LT. Less than†† 7 Binary
.UGT. Unsigned greater than†† 7 Binary
.ULT. Unsigned less than†† 7 Binary
†Operators apply to A68K. Different assemblers may support different
operators.
††Relational operators return 1s (true) or 0s (false).
T4-1

TM-59
Examples of
Assemble-Time Operators

1 00000064 COUNT EQU 100


2 00002000 ORG $2000
3 00002000 3A3CFFFF MOVE #-1,D5
4 00002004 3A3C0009 MOVE #4+50/10,D5
5 00002008 3A3C0001 MOVE #25.mod.6,D5
6 0000200C 3A3C0400 MOVE #$8000.shr.5,D5
7 00002010 3A3C0040 MOVE #$45&$F0,D5
8 00002014 3A3C0041 MOVE #.high.'AB',D5
9 00002018 3A3CFFFF MOVE #5.gt.4,D5
10 0000201C 3A3C0032 MOVE #COUNT/2,D5
11 00002020 END

F4-5

TM-60
Assembler Directives

Directive Operation Syntax

ORG set program origin ORG value

EQU equate value to symbol symbol EQU value

END end of source program END label

DC define data constant [label] DC number[,number][...]

DS define RAM storage [label] DS count

RSEG begin relocatable segment RSEG name

EXTERN define external symbol EXTERN symbol[,symbol][...]

PUBLIC define public symbol PUBLIC symbol[,symbol][...]

T4-2

TM-61
Listing Examples

Address Contents *************** CH4-6.SRC *********************


1 00001000 ORG $1000
2 00001000 1A3C0064 START MOVE.B #100,D5
3 00000064 COUNT EQU 100
4 00002000 ORG $2000
5 00002000 1A3C0064 HERE MOVE.B #COUNT,D5
6 0000000D CR EQU $0D define a symbol
7 00003000 ORG $3000 set origin
8 00003000 0005FFFF NUM DC 5,-1 word size default
9 00003004 05FF MORE DC.B 5,-1 byte size constants
10 00003006 4A4F484E NAME DC.B 'JOHN' ASCII string
11 0000300A 0D00 DC.B CR,0 CR is a symbol
12 00004001 ORG $4001
13 00004002 000F VALUE DC 15 decimal constant
14 00005000 ORG $5000
15 00005000 6100 DC.W 'a'
16 00000050 LENGTH EQU 80
17 00006000 ORG $6000
18 00006000 BUFFER DS.B LENGTH
19 00006050 TEMP DS.B 1
20 00007000 ORG $7000
21 00007000 7250 MOVE.L #LENGTH,D1 use R1 as counter
22 00007002 327C6000 MOVEA #BUFFER,A1 A1 points to buff
23 00007006 12FC0000 LOOP MOVE.B #0,(A1)+ clear location
24 0000700A 5301 SUBQ.B #1,D1 done?
25 0000700C 66F8 BNE LOOP no: clear again
26 00000000 RSEG EPROM
27 00000000 1A3C002C BEGIN MOVE.B #44,D5
28 00000004 END

F4-8

TM-62
Linker Operation

P ROG .H EX
F ILE 1 . OB J Le g en d :

FIL E 2 .O BJ Ut i lit y pr o g r a m
X LIN K
F ILE 3 . OB J
Us er f ile
F ILE 4 . O BJ
PRO G. MA P

( a)

O pt i o ns
Co m m an d
f o llo w A bso l u t e
CPU o u t p u t f i le
In p ut f o r m at t e d L ist in g
f ile s in S- r ec o r d s f ile

XL IN K 6 8 K F IL E1 .OBJ FIL E2 .O BJ FIL E3 .O BJ FIL E4 .OB J / O= PROG.H EX M= PRO G.M A P


( b)

F4-10

TM-63
User Mode vs. Supervisor Mode

Feature User Mode Supervisor Mode

Entered by Clearing S-bit in SR Exception processing

FC2 = 0 1

Active stack pointer USP SSP

Other stacks using A0 - A6 USP, A0-A6

SR access
Read: Entire SR Entire SR
Write: CCR bits only Entire SR

Instructions available All except All


AND #data,SR
EOR #data,SR
MOVE <ea>,SR
MOVE USP,An
MOVE An,USP
OR #data,SR
RESET
RTE
STOP

T6-1

TM-64
Changing Between
User Mode and Supervisor Mode

T ra ns it io n m a y o cc ur o n ly
d ur in g ex ce pt io n p r o ce ssing

U ser Su pe rv isor
M o de Mo d e

T ran sit io n m ay o ccu r


t h r o u gh f o u r in st r uc t io n s:
MOV E t o SR
A N DI t o SR
EOR t o SR
RT E

F6-1

TM-65
Exception Tree

Exc ep t ion

Ext e r n al Int e r na l

Exec ut io n
In t er r u p t In st r uc t io n
Er r o r

T RA P A - lin e o r
Use r A ut o Bu s D iv id e- Pr iv ileg e A d dr ess Ille g al
Re s e t T RA PV T r a ce F- line
V e ct o r V e ct o r Er r o r b y - ze r o V io la t io n Er r o r In s t r uc t io n
CH K Em ula t io n

F6-2

TM-66
Exception Processing Sequence

St art e xc ep t ion

Ma ke in t ern al
c op y of SR

S = 1, T = 0

y es Up d at e in t e rru p t
Int err up t
? m a sk lev el

no

Ob t a in v ec t o r
n um be r

V ec t o r a dd re ss =
ve ct or n u m b er x 4

Pus h PC an d c o pie d
SR o n t o st ac k

( V ec t o r ad d re ss)
-----> PC

C on t in u e e xe cu t io n

F6-3

TM-67
Stack Frame for Exceptions

(except bus error and address error)

Hig h -Me m o r y

15 0

n+6 SP ( old )

n+4 Pro g r am Co u nt e r ( lo w )

n+2 Pr o g ra m C o un t e r (h ig h )

n St at u s Re g ist e r SP ( n ew )

Lo w -Mem or y
F6-4

TM-68
Exception Vector Address

A3 1 A 10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0

all ze r o s V7 V6 V5 V4 V3 V2 V1 V0 0 0
1 4 4 4 2 4 4 4 3
V e ct o r n u m b er

F6-5

TM-69
Reset and Exception
Vector Assignments
Vector Hexadecimal
Number Address Assignment
0 000 Reset SSP†
– 004 Reset PC†
2 008 Bus Error
3 00C Address Error
4 010 Illegal instruction
5 014 Divide-by-zero
6 018 CHK instruction
7 01C TRAPV instruction
8 020 Privilege violation
9 024 Trace
10 028 Line 1010 emulator
11 02C Line 1111 emulator
12 030 (reserved)
13 034 (reserved)
14 038 Format error (68010)
15 03C Uninitialized interrupt vector
16-23 040-05C (reserved)
24 060 Spurious interrupt††
25 064 Level 1 interrupt autovector
26 068 Level 2 interrupt autovector
27 06C Level 3 interrupt autovector
28 070 Level 4 interrupt autovector
29 074 Level 5 interrupt autovector
30 078 Level 6 interrupt autovector
31 07C Level 7 interrupt autovector
32-47 080-0BC TRAP instruction vectors†††
48-63 0C0-0FC (reserved)
64-255 100-3FC User interrupt vectors
† The reset vector is four words and resides in the supervisor program (SP)
space. All other vectors reside in the supervisor data (SD) space.
†† The spurious interrupt vector is taken when there is a bus error during an
interrupt acknowledge cycle.
††† Trap #n uses vector number 32 + n. See Table 6-5.

T6-2

TM-70
Exception Grouping and Priority

Group Exception Processing

0 Reset Exception processing begins


Address Error within two CPU cycles
Bus Error

1 Trace Exception processing begins


Interrupt before the next instruction
Illegal Instruction
Privilege Violation

2 TRAP, TRAPV Exception processing begins by


CHK normal instruction execution
Zero Divide

T6-3

TM-71
Traps vs. Subroutines
Features Traps Subroutines

Initiated from user mode or user mode or


supervisor mode supervisor mode

Routine executes in supervisor mode user mode or


supervisor mode
Registers saved PC and SR PC

Registers saved on system stack user stack or


system stack
Routine ends with RTE RTS

Privilege state after is user mode or user mode or


supervisor mode supervisor mode

T6-4

TM-72
Vector Assignments for
TRAP Instructions
Instruction Vector Vector
Number Address
TRAP #0 32 $000080
TRAP #1 33 $000084
TRAP #2 34 $000088
TRAP #3 35 $00008C
TRAP #4 36 $000090
TRAP #5 37 $000094
TRAP #6 38 $000098
TRAP #7 39 $00009C
TRAP #8 40 $0000A0
TRAP #9 41 $0000A4
TRAP #10 42 $0000A8
TRAP #11 43 $0000AC
TRAP #12 44 $0000B0
TRAP #13 45 $0000B4
TRAP #14 46 $0000B8
TRAP #15 47 $0000BC
T6-5

TM-73
Stack Frame for
Bus Error and Address Error

Hig h - Me m o ry

15 0

n+1 4 SP (o ld )

n+1 2 Prog r a m Co u nt er ( lo w )

n+1 0 Pr o g ram Co u n t e r ( h ig h)

n+ 8 St at us Re g ist e r

n+ 6 In st ruc t io n Re g is t e r

n+ 4 Ac ce s s ad d r es s ( lo w )

n+ 2 A c c ess a dd re ss (h ig h )

n A cc es s t yp e SP ( ne w )

Lo w -M em o ry

( a)

15 5 4 3 2 1 0

u n de f in ed R/ W I/ N FC 2 FC1 FC 0
142 4 3

Fu nc t io n C o de
I/ N
0 = in s t r uc t io n
1 = n o t a n in st r u ct io n
R/ W
0 = w r it e c yc le
1 = re ad cy cle
( b)

TM-74
F6-6

TM-75
Power-on Reset Timing

...
CL K

+5V
Vcc
0V

> 100 ms

RESET

H A LT

< 4 c lo c ks 1
B u s Cyc les SS P H SSP L PC H PC L
14 42 44 3 1 44 24 43 144244
In it ializ e SSP In it ializ e P C E xec ut e 1 st
in st ru c t io n
L eg e nd :

A ll c o nt r o l sig n als in ac t ive .


1 Int er na l st art -u p t im e D at a b us in r ea d m o d e

Bus s t at e u n kn ow n Bu s c y cle ( m e m o ry r e ad o r m em o r y w r it e )

F6-7

TM-76
A Switch as an Input Device and an
LED as an Output Device

+5 V

Sw it c h L ED
Re sist o r
OPEN OF F
Sw it c h LED 22 0 Ω
CL OSED ON
W ir e

( a)

+5 V

Sw it c h L ED
Re sis t o r
OPEN ?
Sw it c h L ED 22 0 Ω
CL OSED ?
Co m p u t e r

( b)

F7-1

TM-77
Interface to Switches and LEDs
(conceptual)

D at a Bu s

Ad d re ss Bus
L ED # 7
+5 V
D15 D1 5
D Q
6 800 0
D14 D1 4
D Q
D13 D1 3
D Q
A23 A2 3
D12 D1 2
A22 A2 2 D Q
0 A21
A20
D11 0 A2 1
A2 0
D1 1
D Q
A19 D10 A1 9 D1 0
D Q

0 A18
A17
A16
D9 0 A1 8
A1 7
A1 6
D9
D Q
D8 D8
A15 A1 5 D Q
A14 A1 4
C A13
A12
C A1 3
A1 2 WRIT E LED S
L ED # 0

REA D SWIT C HES


A11 A1 1
A10 A1 0
0 A9
A8
0 A9
A8
A7 A7
A6 A6
0 A5
A4
0 A5
A4
A3 A3
A2 A2
0 A1
UD S
+5 V
0 A1
U DS
AS AS
R/ W R/ W

D T A CK

Co n t ro l Bu s

F7-2

TM-78
Timing for MOVE.B $00C000,D0

Hig h- w o rd o f Lo w - w o rd o f Me m o ry
Op co d e a d dr ess ad d re ss lo ca t io n
f et ch ( $0 000 ) ( $ C0 0 0 ) $ 0 0 C0 0 0

Mem or y M em o ry Me m o r y M em or y
r e ad r e ad r ea d r e ad

CPU clo ck :
123
One clo ck
t im e
p er io d

t hre e - st a t e
b uf f ers e na b led
D a t a f r o m sw it ch e s
lat ch ed int o r eg ist er
S0 S1 S2 S3 S4 S5 S6 S7
D 0 , b it s 0 -7 , a t
t h e st ar t of S7
CL K

F C0 -FC2

A1 - A 2 3 $ 0 0 C0 0 0

AS

UDS

LD S

R/ W

DT A CK

D 8 -D1 5 sw it c h d at a

D 0 -D7

F7-3

TM-79
Example of Partial Decoding

A 23 A 23
A 22 A 22
0 A 21
A 20
0 A 21
A 20
A 19 A 19

0 A 18
A 17
A 16
0 A 18
A 17
A 16
REA D SW IT CH ES W RIT E L ED S
A 15 A 15
A 14 A 14
C A 13
A 12
C A 13
A 12
UDS UDS
AS AS
R/ W R/ W

( a)

A d dr e ss:

A23 A19 A15 A1 1 A7 A3 A0


0 0 0 0 0 0 0 0 1 1 0 0 X X X X X X X X X X X 0

0 0 C X X XXX0
(b )

F7-5

TM-80
Flowcharts for
Program-Conditional I/O

In pu t F lo w c h ar t : O ut p ut Flo w c h a r t :

E nt er En t e r

Rea d D e v ic e Re ad D ev ice
S t a t u s Flag S t at us F la g

NO D e vic e NO De v ic e
Re ad y Rea d y
? ?

YE S Y ES

In p ut Ou t p u t
D at a Da t a

Clea r Flag Cle ar Fla g

Ex it Exit

( a) (b )

F7-7

TM-81
Keyboard Interface

D a ta Bu s

D8
Ke yb o ard

D1 5
KBD D Q
D A TA D1 4
D Q
D1 3
D Q
D1 2
D Q
D1 1
D Q
D1 0
D Q

D Q D9

D8
D Q

F L AG

K EYH IT
S
Q
R

REA D K BD D A T A

REA D KBD ST A T U S

( a)

Da t a ar e st o re d
A k ey is in lat ch an d
pr ess e d f la g is se t

KBD DA T A V alid D at a

K EYH IT

( b)

F7-6

TM-82
Interface Using a
Peripheral Interface IC

Da t a B us

CPU A d dr ess Bu s

Co nt ro l Bus

Pe r ip h e r al In t er f a ce IC
A1 Re ad W rit e
A0
St at us C o nt ro l
R/ W e t c. etc .

e t c. etc .
A d d r e ss
CS In p u t Ou t p u t
D ec o din g

Pe ri p h er a l Dev ic e
F7-9

TM-83
Program Execution
Without Interrupts or
With Interrupts

t im e

M ain P r o g r am

( a)

Int er r up t - le v el
ISR ISR ISR
exe c u t io n

* ** * ** * **

Base - lev el
M ain Ma in M ain Ma in
exe c u t io n

* Int er r up t
** Ret ur n f r o m int e r r up t in s t r uc t io n
( b)

F7-11

TM-84
Interrupt Priority Conditions on -
IPL2, -IPL1, and -IPL0

Signal

IP2 IP1 IP 0 Interrupt Condition Maskable Priority

1 1 1 0 No interrupt - -

1 1 0 1 Interrupt Yes Lowest

1 0 1 2 Interrupt Yes (etc.)

1 0 0 3 Interrupt Yes (etc.)

0 1 1 4 Interrupt Yes (etc.)

0 1 0 5 Interrupt Yes (etc.)

0 0 1 6 Interrupt Yes (etc.)

0 0 0 7 Interrupt No Highest

T7-3

TM-85
Autovectors for
Automatic IACK Cycles
Vector Address
Interrupt (Autovector)

0 -

1 $000064

2 $000068

3 $00006C

4 $000070

5 $000074

6 $000078

7 $00007C
T7-4

TM-86
Vector Addresses for
User IACK Cycles

Vector Number Vector Address

0 $000000

1 $000004

2 $000008

etc. etc.

255 $0003FC
T7-5

TM-87
Interrupt Circuitry

+5 V
74 07
1 0K
V PA

680 00 7 4 HC 1 3 8

A3 C 7 IA C K 7
A2 B 6 IA C K 6
N o n - Mas k ab le
A1 A 5 IA C K 5
In t er r u p t ( NM I)
4 IA C K 4
+5 V
3 IA C K 3
E1 2 IA C K 2
E2 1 IA C K 1
+5 V 7 4 H C1 4 8 E3 0

IN T 7 7 A2 IPL 2
IN T 6 A1 7 4 H C1 3 8
6 IPL 1
IN T 5 5 A0 IPL 0 FC 2 C 7 IA ( In t e rr up t Ac k n o w led g e )
IN T 4 4 FC 1 B 6 S P ( Sup e r v is o r P r og r a m )
IN T 3 3 FC 0 A 5 S D ( Su p e r v is o r Da t a )
IN T 2 2 4
IN T 1 1 +5 V 3
+5 V 0 E1 2 UP ( Us er P ro g ram )
AS E2 1 UD ( Us er D at a)
E1 E3 0

F7-12

TM-88
Bus Connections for DMA Interface

Da t a Bu s
CPU
A dd re ss Bu s

C o nt ro l Bu s

DMA
Me m o r y Dev ic e
Co n t r o lle r

F7-13

TM-89
Device-to-Memory
Transfer Using DMA

D at a Bu s

A dd re ss Bu s

Co n t r o l Bus

DMA
Me m o r y Dev ic e
Co n t ro l le r

F7-14

TM-90
68000 Bus Arbitration
Control Signals

68 000
CPU D MA
Co nt ro lle r

BR BR

BG BG

BGA CK BGA CK

F7-15

TM-91
Bus Arbitration

6 8 0 0 0 CPU DMA Co n t r ol le r

Re qu e st t he Bus

1 . A ssert b us r e q ue st
( BR = 0 )

Gr an t t he Bus

1 . A sse r t b u s g ran t ( BG = 0 )

A ckn o w le dg e Bus M ast er sh ip

1 . A ssert b us g r a nt
a ck no w le d ge (B GA CK = 0 )

2 . Ne g at e b u s req u e st
( BR = 1 )

Ter m ina t e Bus A rb it r a t io n

1 . Ne g at e b u s gr an t ( BG = 1 )
a nd w a it f o r BGA CK t o be
n e ga t e d

Op er a t e as Bu s Mast e r

t im e 1 . Pe r f o r m d at a t r an sf e rs
acc o r d in g t o sam e r u les
t h e CPU u se s

Rele ase Bu s M ast ersh ip

1 . Ne g at e b u s g ran t
ack no w le d g e ( BGA CK = 1 )

Resu m e N o rm a l Pr o ce ssing

F7-16

TM-92
Timing for Bus Arbitration

t im e

BR

BG

BGA CK

1 2 3 1 4 4 2 4 4 3 1 2 3
CPU DM A C PU
cy cles cy cles cy cle s

F7-17

TM-93
Block Diagram of the 68KMB

T e rm ina l/ M isce lla n eo u s


H o st Co m p u t e r In pu t / Ou t p u t
68 000 De vic es
CPU

Sy st e m
Cloc k 6 8 6 8 1 DUA RT

Re s e t
Sy st e m Bu ses
Cir c uit

Int e r rup t A dd r e ss Mo nit o r U ser


RAM s
Circ u it D ec od e EPRO Ms EPRO Ms
( 1 6 K)
Cir c uit (1 6 K) ( 1 6 K)

Ext e rn al
Int err u p t s

F8-3

TM-94
68000 CPU

52
A2 3
A2 2 51

A2 1 50
14, 49 48
+5 V V cc A2 0
A1 9 47
16, 53 46
G ND A1 8
A1 7 45
68000 A1 6 44
43
15
CPU A1 5
A1 4 42
C LK
A1 3 41

A1 2 40 A d d r es s
+5 V 39 Bu s
A1 1
20 38
E A1 0
19 A9 37
V MA
21 A8 36
V PA
A7 35

13 A6 34
BR
11 33
BG A5
12 A4 32
B G A CK
A3 31
6 A2 30
AS
9 29
R/ W A1
Co n t r o l 7
U DS
Bu s 8 L DS
10 54
D T A CK D1 5
D1 4 55

28 56
F CO D1 3
27 57
F C1 D1 2
26 D1 1 58
F C2
D1 0 59
25 D9 60
IPL 0
24 61
IPL 1 D8 D at a
23 62
IPL 2 D7 Bu s
D6 63
22 64
B ERR D5
18 RESET D4 1
17 D3 2
H A LT
D2 3
7 X D1 4
1 0 KΩ 5
D0

F8-4

TM-95
68KMB Clock Circuit

7 4 HC 1 4
0 . 0 1 µF 47 Ω
1 2 3 4 5 6
C LK to
680 00

1K 1K

10
3.68 64 13 12
pF to
MHz BA U D CL K
686 81

F8-6

TM-96
68KMB Reset Circuit

+5 V +5 V

1N 1 0K
7 4 HC1 4 7 407
9 14
9 8 10
11 3 4
RESET
to
100 Ω 2
68 000
+ 1
2 2 µF H A LT

RESET

F8-7

TM-97
68KMB Interrupt Circuit

M ON IT OR
+ 2 2 µF

+5V 7 x 7 4 HC1 4 8
10K
4 6
IN T 7 7 A2 IPL 2
3 7
IN T 6 6 A1 IPL 1
9
Ext er na l IN T 5
2
5 A0 IPL 0 to
1 68 000
In t e r ru pt s IN T 4 4 740 7
13
IN T 3 3
12 15 13 12
IN T 2 2 E0 V PA
11 14
IN T 1 1 GS
10
+5 V 0 11 10

X1 6 5
E1
5 6

7 4 H C1 3 8
3 7
A3 C 7 IA CK7
2 9
A2 B 6 10 IA CK6
1
A1 A 5 IA CK5
11
4 12 IA CK4
+5V
7 4 H C1 3 8 6
3 IA CK3 to
13
E1 2 IA CK 2
f ro m 3 7 IA 4 14 686 81
FC 2 C 7 E2 1 IA CK1
680 00 2 9 5 15
FC 1 B 6 SP E3 0
1 10
FC 0 A 5 SD
11
4 12
+5 V 3
6 13
E1 2 UP
4 14
AS E2 1 UD
5 15
E3 0

F8-8

TM-98
68KMB Address Decoding

1 19
A20 I0 O8 EPROM 0 U
2 18
A19 I1 O7 EPROM 0 L
3 17
A18 I2 O6 EPROM 1 U t o EPRO M,
4 16
A17 I3 1 6 L8 O5 EPROM 1 L RA M , & D UA RT
5 15
A16 I4 O4 RA M0 U c hip se le ct inp u t s
f ro m 6 14
A15 I5 O3 RA M0 L
68 000 7 13
A14 I6 O2 D UA RT
8 12
UD S I7 O1
9
LDS I8 9 8
11
AS I9 D T A CK t o 6 800 0
20
+5 V Vc c 7 407
10
GN D

F8-9

TM-99
68KMB Memory Map

FFFFFE

Re f le ct ed 7 M w o rd s

200000
1FFFFE

Ex pa ns io n 9 9 2 K w o rd s

010000
8 M w o rd s
00FFFE ( 1 6 M b y t e s)
8 K w or d s
D UA RT
( I/ O)
00C000
1 M w o rd s
00BFFE
( 2 M b y t e s)
RA M0 U RA M 0 L 8 K w or d s
008000 ( syst e m / u ser )

007FFE
EPROM1 U EPROM1 L 8 K w or d s
( u ser )
004000
003FFE
8 K w o rd s
EPROM0 U EPROM0 L
( MON 6 8 K)
000000

F8-10

TM-100
Monitor EPROMs

2 19
A13 A1 2 D7 D15
23 18
A12 A1 1 D6 D14
A11
21 A1 0 2764A D5
17
D13
A10 24 A9 D4 16
25
EPROM 15
D12
A9 A8 D3 D11
3 A7 13
A8 D2 D10
f r om 4 ( m o nit or ) 12
A7 A6 D1 D9
68 000 A6
5 A5 D0
11
D8
6
A5 A4
7 + 5V
A4 A3
8 28
A3 A2 V cc
9 1
A2 A1 Vpp
10 A0 27
A1 PGM

22 t o / f ro m
OE
680 00
f ro m A d dr ess 20 14
EPROM0 U CS GN D
D ec od e Cir cu it

2 19
A13 A1 2 D7 D7
23 18
A12 A1 1 D6 D6
A11
21 A1 0 2764A D5
17
D5
24 16
A10 A9 EPROM D4 D4
25 15
A9 A8 D3 D3
3 A7 13
A8 D2 D2
4 12
f ro m A7 A6 ( m o nit or ) D1 D1
5 A5 11
680 00 A6 D0 D0
6
A5 A4
7 + 5V
A4 A3
8 28
A3 A2 V cc
9 1
A2 A1 Vpp
10 A0 27
A1 PGM

22
OE

f ro m A dd r e ss 20 14
EPROM0 L CS GN D
De co d e C ir cu it

F8-12

TM-101
User EPROMs

2 19
A13 A12 D7 D1 5
23 18
A12 A11 D6 D1 4
A11
21 A10 2764A D5
17
D1 3
24 16
A10 A9 EPROM D4 D1 2
25 15
A9 A8 D3 D1 1
3 A7 13
A8 (u se r ) D2 D1 0
f ro m 4 12
A7 A6 D1 D9
6 800 0 5 A5 11
A6 D0 D8
6
A5 A4
7 +5 V
A4 A3
8 28
A3 A2 Vc c
9 1
A2 A1 Vp p
10 A0 27
A1 PGM

22 t o/ f ro m
OE
68 000
f ro m A d d r ess 20 14
EPROM 1 U CS GND
D ec o de Cir cu it

2 19
A13 A12 D7 D7
23 18
A12 A11 D6 D6
A11
21 A10 2764A D5
17
D5
24 16
A10 A9 EPROM D4 D4
25 15
A9 A8 D3 D3
3 A7 13
A8 D2 D2
f ro m A7 4 A6 ( use r ) D1 12
D1
680 00 5 A5 11
A6 D0 D0
6
A5 A4
7 +5 V
A4 A3
8 28
A3 A2 Vc c
9 1
A2 A1 Vp p
10 A0 27
A1 PGM

22
OE

f ro m A d dr ess 20
CS 14
EPROM1 L GND
D ec od e Cir cu it

F8-13

TM-102
System/User RAM

2 19
A13 A12 D7 D1 5
23 18
A12 A11 D6 D1 4
A11
21 A10 6264 D5
17
D1 3
A10 24 A9 D4 16
25
RA M 15
D1 2
A9 A8 D3 D1 1
3 A7 13
A8 D2 D1 0
A7 4 A6 D1 12
D9
f ro m 5 A5 11
A6 D0 D8
6 800 0 6
A5 A4
7 +5V
A4 A3
8 28
A3 A2 Vcc
9 26
A2 A1
10 A0
A1

27 W
22 t o / f ro m
R/ W OE
68 000
f r o m A d dr ess 20 14
RA M0 U CS GND
D ec od e Cir cu it

2 19
A1 3 A12 D7 D7
23 18
A1 2 A11 D6 D6
A1 1
21 A10 6264 D5
17
D5
24 16
A1 0 A9 RA M D4 D4
25 15
A9 A8 D3 D3
3 A7 13
A8 D2 D2
4 12
A7 A6 D1 D1
f ro m 5 A5 11
A6 D0 D0
6 800 0 6
A4
A5 +5V
7
A4 A3
8 28
A3 A2 Vcc
9 26
A2 A1
10 A0
A1

27 22
R/ W W OE

f ro m A d dr e ss 20 14
RA M0 L CS GND
D ec od e Cir cu it

F8-14

TM-103
68681 DUART

J3
D B2 5 S
25 30 11 2 3
D7 D7 TxD A T1 I T1 O
16
D6 D6
24
D5 D5 31 12 2
17 14 T e r m ina l/
D4 D4 Rx DA R1 0 R1 I
23 7 H os t Co m p u t e r
D3 D3
18
D2
22
D2 68681 MA X
D1
19
D1
DUA RT 232 J8
D0 D0
t o / f ro m D B2 5 S
68 000 34 11 10 7 3
RESET RESET TxD B T2 I T2 O
8
R/ W R/ W
9 O p t io n al
D T AC K D T A CK 10 9 8 2
R2 0 R2 I Ser ia l
Rx DB
6 7 Por t
A4 RS4 +5V
5
A3 RS3 1 16
3
A2 RS2 + C1 + Vcc +
1
A1 RS1 3 2
4 X C1 - V+
t o / f ro m 21
IN T 2
37
IRQ 1 0 µF 4 6
In t e r r u pt Cir cu it IA CK 2 IA CK C2 + V-
+ +
f r om A d d r e ss 35 5 15
D UA RT CS C2 - G ND
D e co d e Cir c uit

f r o m Clo ck BA UD
32
C LK/ X1 J1
Cir cu it CL K
33 15 8
X2 O P7 26 7
O P6
14 9
O P5 27 3
O P4
13 17
O P3 28 4
40 O P2 12 11
+ 5V V cc O P1
29 5
O P0 Mis c ellan e ou s
20
G ND Inp u t / Ou t pu t
38 14
IP5 D ev ic e s
39 15
IP4 16
2
IP3 36 12
IP2 13
4
IP1
7 6
IP0
20
+5V
10

F8-15

TM-104
Expansion to 6800 Peripherals

J2
1
D7
2
D6
3
D5
4
D4
5
D3 6
D2
7
D1
8
D0

11
t o / f ro m A 16
680 00
14
A3
15
A2 Exp an sion t o
16 6 8 0 0 Pe rip he r a ls
A1

13
RESET
18
V PA
17
E
19
R/ W

t o / f ro m 12
IN T3
In t e r ru pt 9
SD
Circu it
20
+5V
10

2 0 - pin
h ea de r

F8-16

TM-105
68681 Interface to
LEDs and Switches

(I/O Board #1)

686 81
8 × +5 V
DU ART J1 7 4 LS2 4 4 220 Ω
15 8 17 3
OP7
26 7 15 5
OP6
14 9 13 7
OP5
27 3 11 9
OP4
13 17 8 12
OP3
28 4 6 14
OP2
12 11 4 16
OP1
29 5 2 18
OP0

20
1, 19
+5V
10

+5 V

38 14
IP5
39 15
IP4
2 16
IP3
36 12
IP2
4 13
IP1
7 6
IP0
6 ×
1 0 kΩ

F9-3

TM-106
Interface to Switches and
7-Segment LED

(I/O Board #2)

686 81
DU ART J1 +5 V
7 4 LS2 4 4
15 8 17 3 7 ×
OP7 22 0 Ω 14, 3
26 7 15 5 1
OP6 a
14 9 13 7 13 a
OP5 b
27 3 11 9 10
OP4 c f b
13 17 8 12 8 g
OP3 d
28 4 6 14 7
OP2 e e c
12 11 4 16 2 d
OP1 f
29 5 2 18 11
OP0 g

MA N 7 2 A
1, 19
20 7 -s eg m e nt
+5V
co m m o n
10
an od e LED
+5 V

2 16
IP3
36 12
IP2
4 13
IP1
7 6
IP0
4 ×
1 0 kΩ

F9-4

TM-107
4-Digit 7-Segment Display

(I/O Board #3)

+5 V

6 86 8 1 J1 18
V cc
28 4 5 8 × 4 × MA N 4 7 4 0 A
O P2 DA TA
47 Ω
12 11 13 4 14
O P1 CL OCK a aa
29 5 12 3 13
O P0 ENA BL E a a a a
b bb
2 8
20 c cc
+5 V MC1 4 4 9 9 f b f b f b f b
1 7 g g g g
10 d dd
17 6
e ee e c e c e c e c
16 1 d d d d
6 f ff
O SC
15 2 dp dp dp dp
0 .0 1 5 g g
µF 9
14 4
GN D h (d p ) dp

4 ,1 2 4,12 4 ,1 2 4 ,1 2
D4 D3 D2 D1
7 8 10 11 4 ×
2 N3 9 0 4

F9-6

TM-108
MC14499 Timing

t im e

ENA BL E ( OP0 )

CL OCK ( OP1 )

d1 d2 d3 d4 d1 9 d20
D AT A ( OP2 )

F9-7

TM-109
MC14499 Digit and Bit Sequence

t im e

Bit N o . 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

1 4 2 4 3 1 42 4 3 1 4 2 4 3 1 4 2 4 3 1 4 2 4 3
De cim a l Dig it D ig it D igit Dig it
Poin t s 1 2 3 4

F9-8

TM-110
8-Digit 7-Segment Display

(I/O Board #4)

D IGIT SEG D IGIT SEG

MC1 4 4 9 9 MC1 4 4 9 9

DA TA h D A TA h
CL OCK C LO CK
EN ABL E EN AB LE et c.

F9-9

TM-111
68681 Input Expansion
Using 74LS165s

Ex t e r n al Inp u t s

J1

L SB MSB
6 868 1 20
D UA RT + 5V
10 6 4 3 14 13 12 11 6 5 4 3 14 13 12 11
5
H G F E D C B A H G F E D C B A

7 6 9 D AT A DA T A 1 0 9 D AT A DA T A 10
IP0 7 4 L S1 6 5 7 4 L S1 6 5
O UT IN O UT IN

G ND Vcc L O AD CL K G ND Vc c L O AD CL K
8, 1 5 16 7 1 2 8, 1 5 16 7 1 2 etc .
+ 5V nc +5V nc

12 11
O P1
29 5
O P0

F9-10

TM-112
6821 Interface to the 68000

(I/O Boards #5 & #6)

J2
6 821
1 26 39
PIA CA 2
D7 D7
2 27 40
D6 D6 CA 1
3 28
D5 D5
4 29 9
D4 D4 PA 7
5 30 8
D3 D3 PA 6
6 31 7
D2 D2 PA 5
7 32 6
D1 D1 PA 4
8 33 5
D0 D0 PA 3
4
PA 2

9 23 3
PA 1
SD CS2
24 2
11 PA 0
A16 CS1
22
1 2 +5 V CS0

7 4 HC 0 0 17
3 PB 7
4
16
18 6 PB 6
VPA 5 15
34 PB 5
13
RESET RESET 14
21 PB 4
19
R/ W R/ W 13
PB 3
17 25
E E 12
PB 2
12 38
INT 3 IRQA 11
PB 1
14 37
A3 nc 10
IRQB PB 0
15 35
A2 RS1
16 36 19
A1 RS0 CB2
20 18
+5V 20 CB1
+5 V V cc
10
1
GN D

F9-11

TM-113
Keypad Interface to the 6821

(I/O Board #5)

68 21
2
PIA PA 0
3
PA 1
4
PA 2
5
PA 3

J H G F

0 1 2 3

6 N
PA 4

4 5 6 7

7 M
PA 5

8 9 A B
8 L
PA 6

C D E F
9 K
PA 7

Gra yh ill PN 8 8 BA 2

F9-12

TM-114
Output to a MC1408L8 DAC

(I/O Board #6, 1 of 4)

68 21 M C1 4 0 8 L 8
+5V
9 5 1 kΩ
PA 7 D7 1 50 Ω
14
8 6 V r ef +
PA 6 D6
7 7 10 0 Ω
PA 5 D5
1 kΩ
6 8 15
PA 4 D4 V r ef -
5 9
PA 3 D3
4 10 1
PA 2 D2 nc 4 .7 k Ω
3 11
PA 1 D1
2 12 + 1 2 V -1 2 V
PA 0 D0
7
4 4
2
13 IO 6
+5 V V CC
VO
3
16
COMP 8 L M3 0 1
1
2
1 5 pF GND
V EE
3 3 3 pF

-1 2 V

F9-13

TM-115
Low-Pass Filter and Audio Output

(I/O Board #6, 2 of 4)

0 .0 4 4 µ F
VO
( f ilt er ed )
2 .4 k Ω
A ux ilia r y
Jack
+12V -12V + 1 2 V -1 2 V

7 7

2 4
2
4
2 5 µF
1 .2 k Ω 1 .2 k Ω
6 6

VO
3 3 +
8 L M3 0 1 8 LM 3 0 1
5 kΩ Sp ea k e r
0 .0 2 2 µ F 1 ( lo w - pa ss 1
( vo lt ag e
f ilt e r ) f o llo w e r )

33 pF 3 3 pF

F9-15

TM-116
Interface to ADC0804
Analog-to-Digital Converter

(I/O Board #6, 3 of 4)

AD C0 8 0 4
682 1 20
V cc +5V

19 3
C B2 WR 6
10 k Ω
Vin ( + ) t r im p o t
18 5 Di f f e re nt ial In p ut s
C B1 IN TR V in( - ) ( t r an sd uc er)
7
1
CS
2
RD
9
Vr ef nc
17 11 19
PB7 D7 C LK R
16 12
PB6 D6
15 13 1 5 kΩ
PB5 D5
14 14 4
PB4 D4 CL K IN
13 15
PB3 D3
12 16 1 5 0 pF
PB2 D2
11 17 10
PB1 D1 D GN D
10 18 8
PB0 D0 A GN D

F9-16

TM-117
Timing for ADC0804 Conversions

Clea r St a r t o f En d o f C le ar St ar t Ne xt
INT R Co n ve rsio n Co nv er sion IN TR Co nv er sio n

WR

≈ 1 0 0 µs

IN T R

F9-17

TM-118
Microphone Input to the ADC0804

(I/O Board #6, 4 of 4)


1 kΩ 100 k Ω VA VB
1% 1% 1 kΩ 1 0 kΩ

+
+ 1 2 V -1 2 V
1 0 µF + 1 2 V -1 2 V

7 47 Ω 7 47 Ω
1 kΩ 2 4 2 4
6 6
Mic rop h o ne
1% 2 2 kΩ
3 3
200 Ω LM 3 0 1 +5V LM 3 0 1
8 8
( p r e -am p ) (a m p )
1 0 0 kΩ
1 1
2 2 kΩ
1%
33 pF 33 pF

+5 V

1N914
1 .2 k Ω

0 .0 4 4 µF
L F3 9 8
A DC0 8 0 4
( sa m p le an d h o ld )
2 .4 k Ω
+12V -1 2 V
1 .2 k Ω
+ 1 2 V -1 2 V 18 k Ω 5 . 6 kΩ 20
V cc +5 V
V 1
7 C 4
2 4
8
6 3
5
V
3 D
L M3 0 1
0 .0 2 2 µ F 8 6
1 ( lo w -p a ss f ilt e r ) 7
0 .0 0 1 µ F
6
1
V in (+ ) CS
7 2
33 pF V in (- ) RD

6 821
19 3
CB2 WR
18 5 9
CB1 IN T R V re f nc
19
17
CL K R
11
PB7 D7
16 12 15 k Ω
PB6 D6
15 13 4
PB5 D5 CL K IN
14 14
PB4 D4
13 15 1 50 pF
PB3 D3
12 16 10
PB2 D2 D GND
11 17 8
PB1 D1 A GND
10 18
PB0 D0

TM-119
F9-19

TM-120
Sample-and-Hold Waveforms

1 0 0 µ s m in im un
Sign a l a t V C

Sig n al at V D

V o lt a ge

T im e

F9-20

TM-121
68000-Family Features

48-pin 52-pin
68008 68008 68000 68010 68020 68030 68040

Data Bus (bits) 8 8 16 16 32 32 32

Address Bus (bits) 20 22 24 24 32 32 32

Data Cache (bytes) – – – – – 256 4096

Instruction Cache – – – – 256 256 4096


(bytes)

On-Chip Memory No No No No No Yes Yes


Management

On-Chip Floating- No No No No No No Yes


Point Unit

T10-1

TM-122
Comparison of Five Recent
Microprocessors †

Alpha
68040 80486 PowerPC Pentium 21064

Company Motorola Intel IBM/Motorola Intel DEC

Introduced 1989 6/91 4/93 3/93 2/92

Architecture CISC CISC RISC CISC RISC

Width (bits) 32 32 32 32 64

Registers 16/8 8/8 32/32 8/8 32/32


(general/FP)

Multiprocessing No No Yes Yes Yes


Support?

Device Size (mm) 10.8 x not 11 x 11 17.2 x 15.3 x 12.7


11.7 available 17.2

Transistors 1.2 1.2 2.8 3.1 1.68


(millions)

Clock (MHz) 25 50 80 66 200

SPECint 92†† 21 27.9 85 67.4 130

SPECfp 92†† 15 13.1 105 63.6 184

Peak Power 6 5 9.1 16 30


(Watts)

Price ($US/1000 $233 $432 $557 $898 $505


units)

† Source: IEEE Spectrum, December 1993, p. 21


†† Integer and floating-point performance benchmarks

T10-10

TM-123
1
SPECIFICATION AND IMPLEMENTATION OF A MICROCOMPUTER

• BASIC COMPONENTS OF A COMPUTER SYSTEM

• INFORMAL AND µvhdl-BASED DESCRIPTION

• ARCHITECTURE
• IMPLEMENTATION

• OPERATION OF SIMPLE MICROCOMPUTER SYSTEM:


XMC: eXample MicroComputer

• ITS CYCLE TIME

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


2
BASIC COMPONENTS OF A COMPUTER

• PROCESSOR;

• MEMORY SUBSYSTEM;

• INPUT/OUTPUT (I/O) SUBSYSTEM

Memory bus Processor I/O bus


(Address, data, control) (Address, data, control)

Memory I/O
subsystem subsystem

I/O devices

Figure 15.1: COMPUTER SYSTEM.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


3
MEMORY HIERARCHY

Virtual memory
(Disk) 2 Gbyte

Faster Larger
Main memory size
(Dynamic devices) 16 Mbyte

Cache memory
(Static devices) 64 Kbyte

Processor

Figure 15.2: MEMORY HIERARCHY.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


4
SPECIFICATION (architecture) OF A SIMPLE MICROCOMPUTER SYSTEM

11 IOAddr MemAddr 24
1 IOLength MemLength 1
1 IORd MemRd 1
1 IOWr MemWr 1
I/O I/O Memory
1 IOEnable
Processor MemEnable 1
devices subsystem subsystem
IORdy 1 1 MemRdy

32 IOData MemData 32

I/O Bus Memory Bus

Clk Reset Status

Figure 15.3: STRUCTURE OF XMC.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


5
µvhdl STRUCTURAL DESCRIPTION

LIBRARY ieee;
USE ieee.std_logic_1164.all;

PACKAGE comp_pkg IS
SUBTYPE WordT IS STD_LOGIC_VECTOR(31 DOWNTO 0);
SUBTYPE MAddrT IS STD_LOGIC_VECTOR(23 DOWNTO 0);
SUBTYPE IOAddrT IS STD_LOGIC_VECTOR(10 DOWNTO 0);
SUBTYPE ByteT IS STD_LOGIC_VECTOR( 7 DOWNTO 0);
TYPE StatusT IS (undef, p_reset, fetch, execute, memop, ioop);

FUNCTION get_carry(RA_Data,RB_Data,Imm,Opcode: STD_LOGIC_VECTOR)


RETURN STD_LOGIC;
FUNCTION get_ovf (RA_Data,RB_Data,Imm,Opcode: STD_LOGIC_VECTOR)
RETURN STD_LOGIC;
FUNCTION get_cc (RA_Data,RB_Data,Opcode: STD_LOGIC_VECTOR)
RETURN STD_LOGIC_VECTOR;
END comp_pkg;

PACKAGE BODY comp_pkg IS


FUNCTION get_carry(RA_Data,RB_Data,Imm,Opcode: STD_LOGIC_VECTOR)
RETURN STD_LOGIC
Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer
6
IS VARIABLE cy: STD_LOGIC:= ’0’;

BEGIN
-- description of carry generation included here
RETURN(cy);
END get_carry;

FUNCTION get_ovf (RA_Data,RB_Data,Imm,Opcode: STD_LOGIC_VECTOR)


RETURN STD_LOGIC
IS VARIABLE ovf: STD_LOGIC:= ’0’;
BEGIN
-- description of overflow generation included here
RETURN(ovf);
END get_ovf;

FUNCTION get_cc (RA_Data,RB_Data,Opcode: STD_LOGIC_VECTOR)


RETURN STD_LOGIC_VECTOR
IS VARIABLE cc: STD_LOGIC_VECTOR(3 DOWNTO 0):= "0000";
BEGIN
-- description of cc generation included here
RETURN(cc);
END get_cc;
END comp_pkg;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


7

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE WORK.ALL, WORK.comp_pkg.ALL;

ENTITY Computer IS
PORT (Reset, Clk : IN STD_LOGIC);
END Computer;

ARCHITECTURE structural OF Computer IS


SIGNAL MemAddr : MAddrT ; -- memory address bus
SIGNAL MemLength, MemRd : STD_LOGIC; -- memory control signals
SIGNAL MemWr, MemEnable : STD_LOGIC;
SIGNAL MemRdy : STD_LOGIC; -- memory status signal
SIGNAL MemData : WordT ; -- memory data bus

SIGNAL IOAddr : IOAddrT ; -- I/O address bus


SIGNAL IOLength, IORd : STD_LOGIC; -- I/O control signals
SIGNAL IOWr, IOEnable : STD_LOGIC;
SIGNAL IORdy : STD_LOGIC; -- I/O status signal
SIGNAL IOData : WordT ; -- I/O data bus

SIGNAL Status : StatusT;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


8

BEGIN
U1: ENTITY Memory
PORT MAP (MemAddr, MemLength, MemRd, MemWr, MemEnable,
MemRdy, MemData);

U2: ENTITY IO
PORT MAP (IOAddr, IOLength, IORd, IOWr, IOEnable,
IORdy, IOData);

U3: ENTITY Processor


PORT MAP (MemAddr, MemData, MemLength, MemRd, MemWr,
MemEnable, MemRdy,
IOAddr, IOData, IOLength, IORd, IOWr,
IOEnable, IORdy,
Status, Reset, Clk);
END structural;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


9
MEMORY SUBSYSTEM

24
Addr
Word 0 Byte 3 Byte 2 Byte 1 Byte 0
Length Word 4 Byte 7 Byte 6 Byte 5 Byte 4
32
Rd Memory Data

Wr Word 224 -4
Enable Rdy 32 bits

(a) (b)

Addr

Enable

Rd

Wr tmem = mem. cycle


tsu = setup time

Data t = data valid


dv

Rdy

tsu tmem tdv Idle tsu tmem Idle

tdv
(c)

Figure 15.4: MEMORY SUBSYSTEM. (a) EXTERNAL SIGNALS. (b) INTERNAL ORGANIZATION. (c) TIMING DIAGRAM

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


10
µvhdl ENTITY DECLARATION FOR MEMORY SUBSYSTEM

LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE WORK.comp_pkg.ALL;
ENTITY Memory IS
PORT (Addr : IN MAddrT ; -- memory address bus
Length : IN STD_LOGIC; -- byte/word operand
Rd, Wr : IN STD_LOGIC; -- access control signals
Enable : IN STD_LOGIC; -- enable signal
Rdy : OUT STD_LOGIC; -- access completion signal
Data : INOUT WordT ); -- memory data bus
END Memory;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


11
µvhdl BEHAVIORAL DESCRIPTION OF MEMORY SUBSYSTEM

LIBRARY ieee;
USE ieee.std_logic_unsigned.ALL;

ARCHITECTURE behavioral OF Memory IS


CONSTANT Tmem : TIME := 8 ns; -- nanoseconds
CONSTANT Td : TIME := 200 ps; -- picoseconds
CONSTANT Tsu : TIME := 200 ps; -- picoseconds
BEGIN
PROCESS (Rd, Wr, Enable)
CONSTANT byte_l: STD_LOGIC:= ’0’; -- constant declarations
CONSTANT word_l: STD_LOGIC:= ’1’;
-- memory declaration
CONSTANT MaxMem : NATURAL := 16#FFFFFF#; -- 2**24 bytes
TYPE MemArrayT IS ARRAY(0 TO MaxMem-1) OF ByteT;
VARIABLE Mem : MemArrayT;
-- working variables
VARIABLE tAddr : NATURAL;
VARIABLE tData : WordT ;
VARIABLE tCtrls: STD_LOGIC_VECTOR(2 DOWNTO 0);

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


12

BEGIN
tCtrls:= Rd & Wr & Enable; -- group signals for simpler decoding
CASE tCtrls IS
-- output to tri-state
WHEN "000" => Data <= (OTHERS => ’Z’) AFTER Td;

WHEN "011" => -- write access;


-- indicate module busy
Rdy <= ’0’ AFTER Td, ’1’ AFTER Tmem;
IF (Length = byte_l) THEN -- read address
tAddr:= CONV_INTEGER(Addr); -- bit-vector to integer
-- from pkg std_logic_unsigned
ELSE
tAddr:= CONV_INTEGER(Addr(23 DOWNTO 2) & "00");
END IF;
CASE Length IS
WHEN byte_l => Mem(tAddr) := (Data( 7 DOWNTO 0));
WHEN word_l => Mem(tAddr) := (Data( 7 DOWNTO 0));
Mem(tAddr+1):= (Data(15 DOWNTO 8));
Mem(tAddr+2):= (Data(23 DOWNTO 16));
Mem(tAddr+3):= (Data(31 DOWNTO 24));
WHEN OTHERS => NULL;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


13
END CASE;

WHEN "101" => -- read access


-- indicate module busy
Rdy <= ’0’ AFTER Td, ’1’ AFTER Tmem;
IF (Length = byte_l) THEN -- read address
tAddr:= CONV_INTEGER(Addr); -- bit-vector to integer
ELSE
tAddr:= CONV_INTEGER(Addr(23 DOWNTO 2) & "00");
END IF;
CASE Length IS
WHEN byte_l => tData( 7 DOWNTO 0):= (Mem(tAddr));
WHEN word_l => tData( 7 DOWNTO 0):= (Mem(tAddr));
tData(15 DOWNTO 8):= (Mem(tAddr+1));
tData(23 DOWNTO 16):= (Mem(tAddr+2));
tData(31 DOWNTO 24):= (Mem(tAddr+3));
WHEN OTHERS => NULL;
END CASE;
Data <= tData AFTER Tmem; -- deliver data

WHEN OTHERS => NULL; -- memory not enabled


END CASE;
END PROCESS;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


14

-- timing verifications
ASSERT NOT (Rd’EVENT AND Rd=’1’ AND NOT Addr’STABLE(Tsu))
REPORT "Read address setup time violation";

ASSERT NOT (Rd’EVENT AND Rd=’1’ AND NOT Enable’STABLE(Tsu))


REPORT "Read enable setup time violation";

ASSERT NOT (Wr’EVENT AND Wr=’1’ AND NOT Addr’STABLE(Tsu))


REPORT "Write address setup time violation";

ASSERT NOT (Wr’EVENT AND Wr=’1’ AND NOT Enable’STABLE(Tsu))


REPORT "Write enable setup time violation";

END behavioral;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


15
INPUT/OUTPUT (I/O) SUBSYSTEM

I/O Port 0
11 I/O Port 1
Addr
Length
I/O 32
Rd Data
subsystem
Wr
I/O Port 2047
Enable Rdy
32 bits
(a) (b)

Figure 15.5: INPUT/OUTPUT SUBSYSTEM.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


16
µvhdl I/O ENTITY DECLARATION

LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE WORK.comp_pkg.ALL;
ENTITY IO IS
PORT (Addr : IN IOAddrT ; -- I/O address bus
Length : IN STD_LOGIC; -- byte/word control
Rd, Wr : IN STD_LOGIC; -- I/O access control
Enable : IN STD_LOGIC; -- I/O enable control
Rdy : OUT STD_LOGIC; -- I/O completion signal
Data : INOUT WordT ); -- I/O data bus
END IO;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


17
PROCESSOR

Processor state
• 32 general-purpose registers (32-bits wide), called R0, R1, ..., R31;

• a 24-bit Program Counter register (PC);

• a 4-bit Condition Register (CR); and

• a 32-bit Instruction Register (IR).

General Purpose Registers


R0 IR
R1
R2
PC

CR Z N C V

R31

Memory Bus I/O Bus

Figure 15.6: PROCESSOR STATE.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


18
BEHAVIOR OF PROCESSOR

Clk

MemAddr Inst. Addr. Inst. Addr. Data Addr.

MemEnable
Fetch instruction
MemRd

MemRdy

Execute instruction and DataBus Inst. Inst. Data


compute address of next instr.

Execute Memory
Fetch Execute Fetch (Addr. access
calc.)
(a) (i) (ii)

Figure 15.7: BEHAVIOR OF THE PROCESSOR. (a) INSTRUCTION LOOP. (b) MEMORY BUS BEHAVIOR FOR REGISTER
OPERATION. (c) MEMORY BUS BEHAVIOR FOR LOAD OPERATION.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


19
BEHAVIOR OF INSTRUCTIONS

IR= add R7,R1,R5 IR= branch 2000

R1
addr.gen.
+4
R5

PC PC
R7
add R7,R1,R5 branch 2000

conds.

Memory Memory
CR
(a) (b)

IR= branch cond,2000

+4 addr.gen.

selector cond?

PC
branch cond,2000

Memory
(c)

Figure 15.8: BEHAVIOR OF INSTRUCTIONS. (a) ADD instruction. (b) UNCONDITIONAL BRANCH INSTRUCTION. (c) CON-
DITIONAL BRANCH INSTRUCTION.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


20
INSTRUCTION SEQUENCING

• SEQUENTIAL UNLESS
1. UNCONDITIONAL BRANCH
2. CONDITIONAL BRANCH

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


21

31 25 20 15 10 0
RT:= op(RA) Opcode RT RA --

RT:= RA op RB Opcode RT RA RB --
RT:= RA op SI Opcode RT RA SI
RT:= RA op UI Opcode RT RA UI

RT:= M[RA+D] Opcode RT RA D


M[RA+D]:= RS Opcode RS RA D

RT:= IO[PN] Opcode RT RA -- PN


IO[PN]:= RS Opcode RS RA -- PN

PC:= PC + 4 + D Opcode -- D
PC:= RA Opcode -- RA --
Figure 15.9: INSTRUCTION FORMATS.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


22

Table 15.2: INSTRUCTION SET

Name Opcode Function CR Assembly Language


No-op 000000 no operation nop

not 000010 RT:= not(RA) Y not RT,RA


Left shift 000100 RT:= lshift(RA) Y lsh RT,RA
Right shift 000110 RT:= rshift(RA) Y rsh RT,RA
Left rotate 001000 RT:= lrot(RA) Y lrt RT,RA
Right rot. 001010 RT:= rrot(RA) Y rrt RT,RA

Add 010000 RT:= RA + RB Y add RT,RA,RB


Add immed. 010001 RT:= RA + SI Y adi RT,RA,SI
Subtract 010010 RT:= RA - RB Y sub RT,RA,RB
Sub. immed. 010011 RT:= RA - SI Y sbi RT,RA,SI
and 010100 RT:= RA and RB Y and RT,RA,RB
and immed. 010101 RT:= RA and UI Y ani RT,RA,UI
or 010110 RT:= RA or RB Y or RT,RA,RB
or immed. 010111 RT:= RA or UI Y ori RT,RA,UI
xor 011000 RT:= RA xor RB Y xor RT,RA,RB
xor immed. 011001 RT:= RA xor UI Y xri RT,RA,UI

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


23

Table 15.3: INSTRUCTION SET (cont.)

Name Opcode Function CR Assembly Language


Load byte 100000 RT( 7 to 0):= Mem(RA+D,1) ldb RT,D(RA)
Load word 100001 RT(31 to 0):= Mem(RA+D,4) ldw RT,D(RA)
Store byte 100010 Mem(RA+D,1):= RS( 7 to 0) stb RS,D(RA)
Store word 100011 Mem(RA+D,4):= RS(31 to 0) stw RS,D(RA)
I/O Rd byte 100100 RT( 7 to 0):= IO(PN,1) irb RT,PN
I/O Rd word 100101 RT(31 to 0):= IO(PN,4) irw RT,PN
I/O Wr byte 100110 IO(PN,1):= RS( 7 to 0) iwb RS,PN
I/O Wr word 100111 IO(PN,4):= RS(31 to 0) iww RS,PN

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


24

Table 15.4: INSTRUCTION SET (cont.)

Name Opcode Function CR Assembly Language


Branch 111000 PC:= PC + 4 + D br D
Branch indirect 111001 PC:= RA bri RA
Branch if N=0 110000 If N=0 then PC:= PC+4+D brp D
Branch if N=1 110001 If N=1 then PC:= PC+4+D brn D
Branch if Z=0 110010 If Z=0 then PC:= PC+4+D bnz D
Branch if Z=1 110011 If Z=1 then PC:= PC+4+D brz D
Branch if C=0 110100 If C=0 then PC:= PC+4+D bnc D
Branch if C=1 110101 If C=1 then PC:= PC+4+D brc D
Branch if V=0 110110 If V=0 then PC:= PC+4+D bnv D
Branch if V=1 110111 If V=1 then PC:= PC+4+D brv D

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


25
µvhdl SPECIFICATION OF PROCESSOR

LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE WORK.comp_pkg.ALL;

ENTITY processor IS
PORT (MemAddr : OUT MAddrT ; -- memory address bus
MemData : INOUT WordT ; -- data bus to/from memory
MemLength: OUT STD_LOGIC; -- memory operand length
MemRd : OUT STD_LOGIC; -- memory read control signal
MemWr : OUT STD_LOGIC; -- memory write control signal
MemEnable: OUT STD_LOGIC; -- memory enable signal
MemRdy : IN STD_LOGIC; -- memory completion signal
IOAddr : OUT IOAddrT ; -- I/O address bus
IOData : INOUT WordT ; -- data bus to/from I/O
IOLength : OUT STD_LOGIC; -- I/O operand length
IORd : OUT STD_LOGIC; -- I/O read control signal
IOWr : OUT STD_LOGIC; -- I/O write control signal
IOEnable : OUT STD_LOGIC; -- memory enable signal
IORdy : IN STD_LOGIC; -- I/O completion signal
Status : OUT StatusT ; -- processor status signal
Reset : IN STD_LOGIC; -- reset signal
Clk : IN STD_LOGIC); -- clock signal
END processor;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


26
µvhdl SPECIFICATION OF BEHAVIOR

LIBRARY ieee;
USE ieee.std_logic_arith.all; -- use definitions and operations
USE ieee.std_logic_signed.all; -- on signed values

ARCHITECTURE behavioral OF processor IS


-- registers (processor state)
TYPE RegFileT IS ARRAY(0 to 31) OF WordT;
SIGNAL GPR: RegFileT ; -- general registers
SIGNAL PC : MAddrT ; -- Program Counter register
SIGNAL CR : STD_LOGIC_VECTOR( 3 DOWNTO 0); -- Condition Register
SIGNAL IR : STD_LOGIC_VECTOR(31 DOWNTO 0); -- Instruction register

-- signals used by output function


SIGNAL Phase: StatusT ; -- instr. cycle phase
SIGNAL tMemAddr: WordT ; -- memory address
SIGNAL tData : WordT ; -- memory/io data

ALIAS Z : STD_LOGIC IS CR(0) ; -- Condition code Zero


ALIAS N : STD_LOGIC IS CR(1) ; -- Condition code Negative
ALIAS C : STD_LOGIC IS CR(2) ; -- Condition code Carry
ALIAS O : STD_LOGIC IS CR(3) ; -- Condition code Overflow
Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer
27

ALIAS Opcode : STD_LOGIC_VECTOR(5 DOWNTO 0) IS IR(31 DOWNTO 26);


ALIAS RT : STD_LOGIC_VECTOR(4 DOWNTO 0) IS IR(25 DOWNTO 21);
ALIAS RA : STD_LOGIC_VECTOR(4 DOWNTO 0) IS IR(20 DOWNTO 16);
ALIAS RB : STD_LOGIC_VECTOR(4 DOWNTO 0) IS IR(15 DOWNTO 11);
ALIAS RS : STD_LOGIC_VECTOR(4 DOWNTO 0) IS IR(15 DOWNTO 11);
ALIAS Imm : STD_LOGIC_VECTOR(15 DOWNTO 0) IS IR(15 DOWNTO 0);
ALIAS D : STD_LOGIC_VECTOR(15 DOWNTO 0) IS IR(15 DOWNTO 0);
ALIAS PN : STD_LOGIC_VECTOR(10 DOWNTO 0) IS IR(10 DOWNTO 0);
ALIAS dlength: STD_LOGIC IS IR(26) ;

-- other declarations
CONSTANT delay : TIME := 200 ps; -- register delay
CONSTANT Reset_delay: TIME := 5 ns;
CONSTANT Exec_delay : TIME := 10 ns; -- Execute delay
CONSTANT Mdelay : TIME := 600 ps; -- MemEnable signal delay
CONSTANT Pulse_Width: TIME := 2.6 ns; -- memory signals width
CONSTANT Fetch_delay: TIME := 3 ns; -- disable memory after
-- access completed

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


28

BEGIN
PROCESS -- transition function
-- working variables
VARIABLE RS_data, RA_data, RB_data : WordT;
VARIABLE RT_addr, RA_addr, RB_addr, RS_addr : Natural;

BEGIN
WAIT ON Clk,Reset;

IF (Reset’Event AND Reset = ’1’) THEN -- reset function


PC <= (OTHERS => ’0’); CR <= "0000"; IR <= (OTHERS => ’0’);

FOR i IN 0 TO 31 LOOP
GPR(i) <= (OTHERS => ’0’);
END LOOP;

Phase <= p_reset;


Status <= p_reset;

WAIT UNTIL (Reset = ’0’) AND (Clk = ’1’);


END IF;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


29

IF (Clk’Event AND Clk=’1’) THEN


-- Instruction cycle
Status <= Fetch AFTER delay;
Phase <= Fetch AFTER delay;
-- instruction fetch
PC <= PC + 4 AFTER Exec_delay;
WAIT UNTIL MemRdy=’1’; -- wait instr. fetch completed
IR <= MemData;
WAIT FOR Fetch_delay;

-- instruction execution
Status <= Execute;
Phase <= Execute;
RA_addr := CONV_INTEGER(’0’ & RA); RB_addr := CONV_INTEGER(’0’ & RB);
-- ’0’ to force bit-vector to positive value
RA_data := GPR(RA_addr) ; RB_data := GPR(RB_addr) ;
RT_addr := CONV_INTEGER(’0’ & RT);
RS_addr := CONV_INTEGER(’0’ & RS); -- source reg. for store
RS_data := GPR(RS_addr) ; -- or I/O write
WAIT FOR Exec_delay;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


30

CASE Opcode IS
WHEN "000000" =>
null; -- nop
WHEN "000010" =>
GPR(RT_Addr)<= not(RA_data); -- not
WHEN "000100" =>
GPR(RT_Addr)<= RA_data(30 DOWNTO 0) & ’0’; -- lshift
WHEN "000110" =>
GPR(RT_Addr)<= ’0’ & RA_data(31 DOWNTO 1); -- rshift
-- lrotate
WHEN "001000" => GPR(RT_Addr)<= RA_data(30 DOWNTO 0) & RA_data(31);
-- rrotate
WHEN "001010" => GPR(RT_Addr)<= RA_DATA(0) & RA_data(31 DOWNTO 1);

WHEN "010000" => GPR(RT_Addr)<=


RA_data + RB_data ; -- add
WHEN "010001" => GPR(RT_Addr)<=
RA_data + Imm;
WHEN "010010" => GPR(RT_Addr)<=
RA_data - RB_data ; -- sub
WHEN "010011" => GPR(RT_Addr)<=
RA_data - Imm;
WHEN "010100" => GPR(RT_Addr)<=
RA_data and RB_data ; -- and
WHEN "010101" => GPR(RT_Addr)<=
RA_data and ext(Imm,RA_data’LENGTH);
-- ext: zero extension from ieee pkg
WHEN "010110" => GPR(RT_Addr)<= RA_data or RB_data ; -- or
WHEN "010111" => GPR(RT_Addr)<= RA_data or ext(Imm,RA_data’LENGTH);

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


31
WHEN "011000" => GPR(RT_Addr)<= RA_data xor RB_data ; -- xor
WHEN "011001" => GPR(RT_Addr)<= RA_data xor ext(Imm,RA_data’LENGTH);

WHEN "100000" | "100001" => -- ldb, ldw


Phase <= MemOp;
Status <= MemOp;
tMemAddr <= RA_data + D; -- mem.addr.
WAIT until MemRdy = ’1’;

WHEN "100010" | "100011" => -- stb, stw


Phase <= MemOp;
Status <= MemOp;
tMemAddr <= RA_data + D; -- mem. addr.
tData <= RS_data; -- mem. data
WAIT until MemRdy = ’1’;

WHEN "100100" | "100101" => -- irb, irw


Phase <= IOOp;
Status <= IOOp;
WAIT until IORdy = ’1’ ;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


32
WHEN "100110" | "100111" => -- iwb, iww
Phase <= IOOp;
Status <= IOOp;
tData <= RS_data; -- io data
WAIT until IORdy = ’1’ ;

WHEN "111000" => PC <= PC + D; -- branch


WHEN "111001" => PC <= RA_data(23 DOWNTO 0); -- br.ind.
WHEN "110000" | "110001"
=> IF (N = Opcode(0)) THEN -- br on N
PC <= PC + D;
END IF;
WHEN "110010" | "110011"
=> IF (Z = Opcode(0)) THEN -- br on Z
PC <= PC + D;
END IF;
WHEN "110100" | "110101"
=> IF (C = Opcode(0)) THEN -- br on C
PC <= PC + D;
END IF;
WHEN "110110" | "110111"
=> IF (O = Opcode(0)) THEN -- br on V
PC <= PC + D;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


33
END IF;
WHEN others => null;
END CASE;

IF ((Opcode(5 DOWNTO 4) = 0) or (Opcode(5 DOWNTO 4) = 1))


and (Opcode /= 0) THEN
-- set condition register
IF (GPR(RT_Addr) = 0) THEN CR(0) <= ’1’; -- zero result
ELSE CR(0) <= ’0’;
END IF;
IF (GPR(RT_Addr)(31) = ’1’) THEN CR(1) <= ’1’; -- negative result
ELSE CR(1) <= ’0’;
END IF;
-- check if operation Opcode generates carry out
CR(2) <= get_carry(RA_Data,RB_Data,Imm,Opcode);
-- check if operation Opcode generates overflow
CR(3) <= get_ovf(RA_Data,RB_Data,Imm,Opcode);
END IF;

WAIT FOR 0 ns; -- force signals to be updated

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


34
IF (Phase = MemOp) THEN
IF (dlength = ’1’) THEN -- ldw
GPR(RT_addr) <= MemData;
ELSE -- ldb
GPR(RT_addr)( 7 DOWNTO 0) <= MemData(7 DOWNTO 0);
GPR(RT_addr)(31 DOWNTO 8) <= (OTHERS => ’0’);
END IF;
WAIT FOR Fetch_delay;
END IF;

IF (Phase = IOOp) THEN


IF (dlength = ’1’) THEN -- irw
GPR(RT_addr) <= IOData;
ELSE -- irb
GPR(RT_addr)( 7 DOWNTO 0) <= IOData(7 DOWNTO 0);
GPR(RT_addr)(31 DOWNTO 8) <= (OTHERS => ’0’);
END IF;
WAIT FOR Fetch_delay;
END IF;
END IF;
END PROCESS;

PROCESS -- output function

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


35
BEGIN
-- Instruction cycle
WAIT ON Phase;
IF (Phase = p_reset) THEN -- reset
MemRd <= ’0’; MemWr <= ’0’; MemEnable <= ’0’; MemLength <= ’0’;
MemData <= (OTHERS => ’Z’);
IORd <= ’0’; IOWr <= ’0’; IOEnable <= ’0’; IOLength <= ’0’;
IOData <= (OTHERS => ’Z’);

ELSIF (Phase = Fetch) THEN -- instruction fetch


MemAddr <= PC AFTER delay;
MemEnable <= ’1’ AFTER delay;
MemRd <= ’1’ AFTER Mdelay, ’0’ AFTER Pulse_Width;
MemLength <= ’1’ AFTER delay;
WAIT UNTIL MemRdy=’1’; -- wait instr. fetch completed
MemEnable <= ’0’ AFTER Fetch_delay;

ELSIF (Phase = Execute) THEN NULL; -- instruction execution


-- no output signals

ELSIF (Phase = MemOp) THEN


MemAddr <= tMemAddr(23 DOWNTO 0) AFTER delay;
MemEnable <= ’1’ AFTER delay;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


36
MemLength <= dlength AFTER delay;
IF ((To_Bitvector(Opcode) = "100000") OR
(To_Bitvector(Opcode) = "100001")) THEN -- ldb, ldw
MemRd <= ’1’ AFTER Mdelay, ’0’ AFTER Pulse_Width;
WAIT until MemRdy = ’1’;
MemEnable <= ’0’ AFTER Fetch_delay;
WAIT FOR Fetch_delay;
END IF;
IF ((To_Bitvector(Opcode) = "100010") OR
(To_Bitvector(Opcode) = "100011")) THEN -- stb, stw
MemWr <= ’1’ AFTER Mdelay, ’0’ AFTER Pulse_Width;
IF (dlength = ’1’) THEN -- stw
MemData <= tData AFTER delay;
ELSE -- stb
MemData(7 DOWNTO 0) <= tData(7 DOWNTO 0) AFTER delay;
END IF;
WAIT until MemRdy = ’1’;
MemEnable <= ’0’ AFTER delay;
MemData <= (OTHERS => ’Z’) AFTER delay;
WAIT FOR delay;
END IF;

ELSIF (Phase = IOOp) THEN

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


37
IOAddr <= PN AFTER delay;
IOEnable <= ’1’ AFTER delay;
IOLength <= dlength AFTER delay;
IF ((To_Bitvector(Opcode) = "100100") OR
(To_Bitvector(Opcode) = "100101")) THEN -- irb, irw
IORd <= ’1’ AFTER Mdelay, ’0’ AFTER Pulse_Width;
WAIT until IORdy = ’1’ ;
IOEnable <= ’0’ AFTER Fetch_delay;
WAIT FOR Fetch_delay;
END IF;
IF ((To_Bitvector(Opcode) = "100110") OR
(To_Bitvector(Opcode) = "100111")) THEN -- iwb, iww
IF (dlength = ’1’) THEN -- iww
IOData <= tData AFTER delay;
ELSE -- iwb
IOData(7 DOWNTO 0) <= tData(7 DOWNTO 0) AFTER delay;
END IF;
IOWr <= ’1’ AFTER Mdelay, ’0’ AFTER Pulse_Width;
WAIT until IORdy = ’1’;
IOEnable <= ’0’ AFTER delay;
IOData <= (OTHERS => ’Z’) AFTER delay;
WAIT FOR delay;
END IF;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


38
END IF;
END PROCESS;
END behavioral;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


39
µvhdl SPECIFICATION OF MEMORY CONTENTS

-- memory declaration
CONSTANT MaxMem: NATURAL:= 16#FFF#; -- 4Kbytes
TYPE MemArrayT IS ARRAY(0 to MaxMem-1) OF ByteT;
VARIABLE Mem : MemArrayT:=
(-- program
3=>"01100000", 2=>"00000000", 1=>"00000000", 0=>"00000000",
7=>"01000100", 6=>"00100000", 5=>"00000000", 4=>"00110010",
11=>"10000110", 10=>"10000001", 9=>"00000000", 8=>"00000000",
15=>"10000110", 14=>"10100001", 13=>"00000000", 12=>"00000100",
19=>"01000100", 18=>"01000000", 17=>"00000000", 16=>"00111111",
23=>"10001000", 22=>"01000001", 21=>"00000000", 20=>"00000000",
-- data
51=>"00110011", 50=>"00001111", 49=>"11110000", 48=>"11001100",
55=>"00110011", 54=>"00001111", 53=>"11110000", 52=>"11001100",
OTHERS => "00000000");
where the memory contents corresponds to the following instructions:
0x000000: xor R0,R0,R0 ; R0 = 0
0x000004: adi R1,R0,50 ; R1 = 50
0x000008: ldw R20,0(R1) ; R20= Mem(50,4)= Mem(48,4)
0x00000C: ldw R21,4(R1) ; R21= Mem(54,4)= Mem(52,4)
0x000010: adi R2,R0,63 ; R2 = 63
0x000014: stb R2,0(R1) ; Mem(50,1) = 63

0x000048: 0x330FF0CC
0x000052: 0x330FF0CC

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


40
IMPLEMENTATION OF XMC

• MEMORY SUBSYSTEM
• PROCESSOR
1. DATA SUBSYSTEM
2. CONTROL SUBSYSTEM

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


41
MEMORY SUBSYSTEM

Rd
222 x1 bits
Wr Controller MRdy
Enable

Controls

Address 22

Byte 3 Byte 2 Byte 1 Byte 0


2

8 8 8 8

Length Selector/Distributor

32

Data

Figure 15.10: IMPLEMENTATION OF THE MEMORY SUBSYSTEM.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


42
PROCESSOR

Condition signals
MemRdy
IORdy
Data Instr 32
signals ZE,NG,CY,OV 4

24
MemAddr
MemData 32 Data Control
subsystem subsystem
11
IOAddr
IOData 32

MemRd
MemWr
MemLength
MemEnable
IORd
IOWr
IOLength
IOEnable

Control signals Status


Clk
Reset

Figure 15.11: IMPLEMENTATION OF THE PROCESSOR.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


43
DATA SUBSYSTEM

Sin_Sout
Mem_ALU
MemData
0

Switch
MemData
DataB
1 0 1
Mux1 B MemAddr
AddrB WrIR
DataC Clk
DataA IR Reset
AddrC C A
WrC AddrA Instr

Extndr.
Register SE_ZE
file 0 1 1 0
PC_RA Mux2 Mux3 IR_RB

Clk Ain Bin


Reset A B

ALU
ALUOp WrCR
C
Cond
ALUdata Clk
Z N C V Reset
WrPC PCin
Clk ZE,NG,CY,OV
Reset PC
PCout

1 0 ALU_PC
Mux4

Figure 15.12: IMPLEMENTATION OF DATA SUBSYSTEM (I/O signals not shown).

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


44
ALU

ALUop Operation
0000 Zero 32
0001 A+B
0010 A-B
0011 -B
0100 A and B
0101 A or B
0110 A xor B
0111 not(B)
1000 unused
1001 B
1010 shiftl(A)
1011 shiftr(A)
1100 rotl(A)
1101 rotr(A)
1110 A+4
1111 unused

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


45
EVENT SEQUENCE FOR ALU INSTRUCTION

2
Mem_ALU

2 MemData
DataB
Mux1 MemAddr
AddrB
4 DataC 2
DataA IR
2 3 1
AddrC AddrA Instr
2 3
WrC 2
Register 2
file
2 Mux2 Mux3 2
PC_RA IR_RB
Clk

2
4 2
ALUOp
Cond WrCR
Clk
Z N C V

ZE,NG,CY,OV
PC

ALU_PC

Figure 15.13: SEQUENCE OF EVENTS IN DATA SUBSYSTEM FOR ALU INSTRUCTION.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


46
TIMING DIAGRAM FOR ALU INSTRUCTION

Clk

Instr Add Instruction

AddrA

AddrB

AddrC

ALUop

WrC

WrCR

DataA

DataB

DataC

Cond

1 2 3 4
instruction register ALUop register
decode read delay delay setup

Figure 15.14: TIMING DIAGRAM FOR ALU INSTRUCTION IN DATA SUBSYSTEM.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


47
CONTROL SUBSYSTEM

Instr MemRdy IORdy


OV,CY,ZE,NG

AddrA
AddrB
AddrC
State ALUOp
Combinational
reg. ...
logic
...
ALU_PC
Clk
Reset

Figure 15.15: CONTROL SUBSYSTEM.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


48
STATE DIAGRAM AND TIMING

Fetch
ALU_PC <- 1 ALU_Op <- 1110
Memop
MemRd <- 1, 0 Sin_Sout <- 1 Mem_ALU <-
MemLength <- 1, 0 WrIR <- 1, 0 WrC <-
MemEnable <- 1, 0 WrPC <- 1, 0
PC_RA <- 0
(Op < 100000) (Op >= 100000)
and (Op > 100111) and (Op <= 100111)

Execute
AddrA <- Instr(20 downto 16) IR_RB <- Mem_ALU <-
AddrB <- Instr(15 downto 11) ALUOp <- ALU_PC <-
AddrC <- Instr(25 downto 21) MemLength <-
WrPC <- MemRd <-
PC_RA <- WrCR <- MemWr <-
ZE_SE <- WrC <- MemEnable <-
Sin_Sout <-

Clk
Register
operations Fetch Execute Fetch

Memory
operations Fetch Execute Memop Fetch

Figure 15.16: STATE DIAGRAM AND TIMING FOR CONTROL SUBSYSTEM OF THE PROCESSOR.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


49
OPERATION OF THE COMPUTER AND CYCLE TIME

t6
Clk State Register

t0
NS= Execute
Control logic
t1 t1
t1
PC_RA=0 ALU_PC=1

Mux2 ALUOp Mux4

t2 PC t2 MemAddr

ALU Memory WrIR

t3 t4 MemData
WrPC=1 MemRdy=1
PC+4
Switch

t5
Instruction

Register PC Instruction Register


Clk t6

Figure 15.17: DEPENDENCIES FOR STATE FETCH.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


50
STATE EXECUTE

NS= Fetch or Memop t18


Clk State Register
t7 t7
IR

Decode logic Control logic


t9 t8
Instr. specific AddrA, AddrB, AddrC
control signals

t9 Zero/Sign Reg. File


Extender
t10 t10
t11 DataB PC DataA
t7
t9 Mux3 t9 Mux2

t13 t12

t9 ALU
ALUData t14

t9 Mux1
DataC t15

t17 Reg. File (t16)


Clk

Figure 15.18: DEPENDENCIES FOR STATE EXECUTE.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


51
STATE MEMOP

t25
Clk State Register
t15 t20 t18
NS= Fetch
Memory Control logic
t21 MemRdy t19 t19

WrC=1
Switch
t22

Mux1
t23 DataC

Clk
Reg. File (t24)
t25

Figure 15.19: DEPENDENCIES FOR STATE Memop.

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


52
EXAMPLE 15.1: OBTAIN MIN CYCLE PERIOD

Register Reg delay tR 2 ns (setup and propagation delay)


Register file RF delay tRF 4 ns
ALU ALU delay tALU 6 ns
Multiplexer Mux delay tmux 0.5 ns
Zero/sign ext. Ext delay tZSE 0.5 ns
Switch Switch delay tsw 0.5 ns
Control delay Ctrl delay tctl 0.5 ns
Decode delay Dec delay tdec 3 ns
Memory Mem delay tmem 8 ns (static memory)
CRITICAL PATHS ARE OBTAINED:
tf etch = tR + tctl + tmux + tmem + tsw
= 2 + 0.5 + 1 + 8 + 0.5 = 12ns

texec = tR + tctl + tRF + tmux + tALU + tmux + tRF


= 2 + 0.5 + 4 + 0.5 + 6 + 0.5 + 4 = 17.5ns

tmemop = tR + tctl + tmem + tsw + tmux + tRF


= 2 + 0.5 + 8 + 0.5 + 0.5 + 4 = 15ns
Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer
53
µvhdl DESCRIPTION OF IMPLEMENTATION

LIBRARY ieee; USE ieee.std_logic_1164.ALL; USE WORK.comp_pkg.ALL, WORK.ALL;

ARCHITECTURE structural OF Processor IS


SIGNAL Instr : WordT;
SIGNAL ZE, NG, CY, OV : STD_LOGIC;
SIGNAL AddrA, AddrB, AddrC : STD_LOGIC_VECTOR(4 DOWNTO 0);
SIGNAL ALUOp : STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL WrC, WrPC, WrCR, WrIR : STD_LOGIC;
SIGNAL Mem_ALU, PC_RA, IR_RB : STD_LOGIC;
SIGNAL ALU_PC, ZE_SE, SinSout: STD_LOGIC;

BEGIN
P1: ENTITY Data_Subsystem
PORT MAP (MemAddr, MemData, IOAddr, IOData,
Instr, ZE, NG, CY, OV, AddrA, AddrB, AddrC, ALUOp,
WrC, WrPC, WrCR, WrIR, Mem_ALU, PC_RA, IR_RB, ALU_PC,
ZE_SE, SinSout, Clk, Reset);

P2: ENTITY Ctrl_Subsystem


PORT MAP (Instr, ZE, NG, CY, OV, AddrA, AddrB, AddrC, ALUOp,
WrC, WrPC, WrCR, WrIR, Mem_ALU, PC_RA, IR_RB, ALU_PC,
ZE_SE, SinSout, MemRd, MemWr, MemLength, MemEnable,
MemRdy, IORd, IOWr, IOLength, IOEnable, IORdy, Status,
Clk, Reset);
END structural;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


54
µvhdl DESCRIPTION OF DATA SUBSYSTEM

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE WORK.comp_pkg.ALL, WORK.ALL;
ENTITY Data_Subsystem IS
PORT(MemAddr : OUT MAddrT ;
MemData : INOUT WordT ;
IOAddr : OUT IOAddrT ;
IOData : INOUT WordT ;
Instr : OUT WordT ;
ZE, NG, CY, OV : OUT STD_LOGIC ;
AddrA, AddrB, AddrC : IN STD_LOGIC_VECTOR(4 DOWNTO 0);
ALUOp : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
WrC, WrPC, WrCR, WrIR : IN STD_LOGIC ;
Mem_ALU, PC_RA, IR_RB : IN STD_LOGIC ;
ALU_PC, ZE_SE, Sin_Sout: IN STD_LOGIC ;
Clk, Reset : IN STD_LOGIC);
END Data_Subsystem;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


55
µvhdl DESCRIPTION OF DATA SUBSYSTEM (cont.)

ARCHITECTURE structural OF Data_Subsystem IS


SIGNAL DataA, DataB, DataC : WordT ;
SIGNAL Ain , Bin : WordT ;
SIGNAL ALUdata, IRdata : WordT ;
SIGNAL tMemdata : WordT ;
SIGNAL Cond, CRout : STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL IRreg, IRext : WordT ;
SIGNAL PCout : WordT:= (OTHERS => ’0’);

BEGIN
ALU1: ENTITY ALU
PORT MAP(Ain,Bin,ALUop,ALUdata,Cond);
GPR: ENTITY Reg_File
PORT MAP(AddrA,AddrB,AddrC,DataA,DataB,DataC,
WrC,Reset,Clk);
PC: ENTITY Reg
PORT MAP(ALUdata(23 DOWNTO 0),PCout(23 DOWNTO 0),
WrPC,Reset,Clk);
CR: ENTITY Reg
PORT MAP(Cond,CRout,WrCR,Reset,Clk);

ZE <= CRout(0); CY <= CRout(1);


NG <= CRout(2); OV <= CRout(3);

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


56

IR: ENTITY Reg


PORT MAP(tMemData,IRReg,WrIR,Reset,Clk);

Instr <= IRReg;

MX1: ENTITY Mux


PORT MAP(tMemData,ALUdata,Mem_ALU,DataC);
MX2: ENTITY Mux
PORT MAP(PCout,DataA,PC_RA,Ain);
ZSE: ENTITY Extender
PORT MAP(IRreg,ZE_SE,IRext);
MX3: ENTITY Mux
PORT MAP(IRext,DataB,IR_RB,Bin);
MX4: ENTITY Mux
PORT MAP(ALUdata(23 DOWNTO 0),PCout(23 DOWNTO 0),
ALU_PC,MemAddr);
SL : ENTITY Switch
PORT MAP(MemData,tMemData,DataB,Sin_Sout);
END structural;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


57
µvhdl DESCRIPTION OF REGISTER FILE

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.ALL;
USE WORK.comp_pkg.ALL;

ENTITY Reg_File IS
PORT(AddrA, AddrB, AddrC : IN STD_LOGIC_VECTOR(4 DOWNTO 0);
DataA, DataB : OUT WordT;
DataC : IN WordT;
WrC : IN STD_LOGIC ;
Reset, Clk : IN STD_LOGIC);
END Reg_File;

ARCHITECTURE behavioral OF Reg_File IS


TYPE RegFileT IS ARRAY(0 to 31) OF WordT;
SIGNAL GPR : RegFileT ;
BEGIN
PROCESS(AddrA,AddrB) -- output function
CONSTANT RF_delay : TIME := 4 ns;
BEGIN
DataA <= GPR(CONV_INTEGER(AddrA)) AFTER RF_delay;
DataB <= GPR(CONV_INTEGER(AddrB)) AFTER RF_delay;
END PROCESS;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


58

PROCESS(Reset,Clk) -- transition function


BEGIN
IF (Reset’EVENT and (Reset = ’1’)) THEN
FOR i IN 0 TO 31 LOOP
GPR(i) <= (OTHERS => ’0’);
END LOOP;
END IF;

IF (Clk’EVENT AND Clk = ’1’ AND WrC = ’1’) THEN


GPR(CONV_INTEGER(AddrC)) <= DataC;
END IF;
END PROCESS;
END behavioral;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


59
µvhdl DESCRIPTION OF ALU

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_signed.ALL;
USE WORK.comp_pkg.ALL;

ENTITY ALU IS
PORT(A, B: IN STD_LOGIC_VECTOR(31 DOWNTO 0);
Op : IN STD_LOGIC_VECTOR( 3 DOWNTO 0);
C : OUT STD_LOGIC_VECTOR(31 DOWNTO 0);
Cond: OUT STD_LOGIC_VECTOR( 3 DOWNTO 0));
END ALU;

ARCHITECTURE behavioral OF ALU IS


BEGIN
PROCESS(A,B,Op)
CONSTANT ALU_delay : TIME := 6 ns;
BEGIN
CASE Op IS
WHEN "0000" => C <= (OTHERS => ’0’) AFTER ALU_delay;
WHEN "0001" => C <= A + B AFTER ALU_delay;
WHEN "0010" => C <= A - B AFTER ALU_delay;
WHEN "0011" => C <= (OTHERS => ’0’) AFTER ALU_delay;
WHEN "0100" => C <= A and B AFTER ALU_delay;
WHEN "0101" => C <= A or B AFTER ALU_delay;
WHEN "0110" => C <= A xor B AFTER ALU_delay;
WHEN "0111" => C <= (OTHERS => ’0’) AFTER ALU_delay;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


60
WHEN "1000" => C <= A AFTER ALU_delay;
WHEN "1001" => C <= B AFTER ALU_delay;
WHEN "1010" => C <= A(30 DOWNTO 0) & ’0’ AFTER ALU_delay;
WHEN "1011" => C <= ’0’ & A(31 DOWNTO 1) AFTER ALU_delay;
WHEN "1100" => C <= A(30 DOWNTO 0) & A(31) AFTER ALU_delay;
WHEN "1101" => C <= A(0) & A(31 DOWNTO 1) AFTER ALU_delay;
WHEN "1110" => C <= A + 4 AFTER ALU_delay;
WHEN "1111" => C <= not(A) AFTER ALU_delay;
WHEN OTHERS => NULL;
END CASE;
Cond <= get_cc(A,B,Op) AFTER ALU_delay;
END PROCESS;
END behavioral;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


61
µvhdl DESCRIPTION OF REGISTERS

LIBRARY ieee; USE ieee.std_logic_1164.ALL;

ENTITY Reg IS
PORT(Data_in : IN STD_LOGIC_VECTOR;
Data_out: OUT STD_LOGIC_VECTOR;
Wr : IN STD_LOGIC ;
Reset : IN STD_LOGIC ;
Clk : IN STD_LOGIC);
END Reg;

ARCHITECTURE behavioral OF Reg IS


BEGIN
PROCESS(Wr,Reset,Clk)
CONSTANT Reg_delay: TIME := 2 ns;
VARIABLE BVZero: STD_LOGIC_VECTOR(Data_in’RANGE):= (OTHERS => ’0’);
BEGIN
IF (Reset = ’1’) THEN
Data_out <= BVZero AFTER Reg_delay;
END IF;

IF (Clk’EVENT AND Clk = ’1’ AND Wr = ’1’) THEN


Data_out <= Data_in AFTER Reg_delay;
END IF;
END PROCESS;
END behavioral;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


62
µvhdl DESCRIPTION OF OTHER MODULES: MUX

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY Mux IS
PORT(A_in,B_in: IN STD_LOGIC_VECTOR;
Sel : IN STD_LOGIC ;
Data_out : OUT STD_LOGIC_VECTOR);
END Mux;

ARCHITECTURE behavioral OF Mux IS


BEGIN
PROCESS(A_in, B_in, Sel)
CONSTANT Mux_delay: TIME := 500 ps;
BEGIN
IF (Sel = ’0’) THEN
Data_out <= A_in AFTER Mux_delay;
ELSE
Data_out <= B_in AFTER Mux_delay;
END IF;
END PROCESS;
END behavioral;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


63
µvhdl DESCRIPTION OF EXTENDER

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY Extender IS
PORT(X_in : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
ZE_SE : IN STD_LOGIC ;
X_out : OUT STD_LOGIC_VECTOR(31 DOWNTO 0));
END Extender;

ARCHITECTURE behavioral OF Extender IS


BEGIN
PROCESS(X_in, ZE_SE)
CONSTANT Ext_delay: TIME := 500 ps;
BEGIN
IF (ZE_SE = ’0’) THEN
X_out(31 DOWNTO 16) <= (OTHERS => ’0’) AFTER Ext_delay;
X_out(15 DOWNTO 0) <= X_in(15 DOWNTO 0) AFTER Ext_delay;
ELSE
X_out(31 DOWNTO 16) <= (OTHERS => X_in(15)) AFTER Ext_delay;
X_out(15 DOWNTO 0) <= X_in(15 DOWNTO 0) AFTER Ext_delay;
END IF;
END PROCESS;
END behavioral;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


64
µvhdl DESCRIPTION OF SWITCH

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY Switch IS
PORT(A : INOUT STD_LOGIC_VECTOR;
B_out: OUT STD_LOGIC_VECTOR;
C_in : IN STD_LOGIC_VECTOR;
Sel : IN STD_LOGIC );
END Switch;

ARCHITECTURE behavioral OF Switch IS


BEGIN
PROCESS(A, C_in, Sel)
CONSTANT Switch_delay: TIME := 500 ps;
CONSTANT dataZ: STD_LOGIC_VECTOR(A’RANGE):= (OTHERS => ’Z’);
BEGIN
IF (Sel = ’0’) THEN
B_out <= A AFTER Switch_delay;
A <= dataZ;
ELSE
A <= C_in AFTER Switch_delay;
END IF;
END PROCESS;
END behavioral;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


65
µvhdl DESCRIPTION OF CONTROL SYSTEM

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE WORK.comp_pkg.ALL;

ENTITY Ctrl_Subsystem IS
PORT(Instr : IN WordT ;
ZE, NG, CY, OV : IN STD_LOGIC ;
AddrA, AddrB, AddrC : OUT STD_LOGIC_VECTOR(4 DOWNTO 0);
ALUOp : OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
WrC, WrPC, WrCR, WrIR : OUT STD_LOGIC ;
Mem_ALU, PC_RA, IR_RB : OUT STD_LOGIC ;
ALU_PC, ZE_SE, Sin_Sout: OUT STD_LOGIC ;
MemRd,MemWr : OUT STD_LOGIC ;
MemLength : OUT STD_LOGIC ;
MemEnable : OUT STD_LOGIC ;
MemRdy : IN STD_LOGIC ;
IORd, IOWr : OUT STD_LOGIC ;
IOLength : OUT STD_LOGIC ;
IOEnable : OUT STD_LOGIC ;
IORdy : IN STD_LOGIC ;
Status : OUT StatusT ;
Clk, Reset : IN STD_LOGIC );
END Ctrl_Subsystem;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


66
µvhdl DESCRIPTION OF CONTROL SYSTEM (cont.)

LIBRARY ieee;
USE ieee.std_logic_signed.ALL;

ARCHITECTURE behavioral OF Ctrl_Subsystem IS


SIGNAL State: StatusT;
BEGIN
PROCESS -- transition function
ALIAS Opcode : STD_LOGIC_VECTOR(5 DOWNTO 0) IS Instr(31 DOWNTO 26);
CONSTANT Reset_delay: TIME:= 500 ps ;
CONSTANT Ctrl_delay : TIME:= 500 ps ;
BEGIN
WAIT ON Clk,Reset;
IF (Reset’EVENT AND Reset = ’1’) THEN
State <= p_reset AFTER Reset_delay;
Status <= p_reset AFTER Reset_delay;
WAIT UNTIL Clk = ’1’;
END IF;

IF (Clk’EVENT) AND (Clk = ’1’) THEN


CASE State IS
WHEN p_reset => Status <= fetch AFTER Ctrl_delay;
State <= fetch AFTER Ctrl_delay;
WHEN fetch => Status <= execute AFTER Ctrl_delay;
State <= execute AFTER Ctrl_delay;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


67

WHEN execute => CASE Opcode IS


WHEN "100000" | "100001" => State <= memop AFTER Ctrl_delay;
Status <= memop AFTER Ctrl_delay;
WHEN "100010" | "100011" => State <= memop AFTER Ctrl_delay;
Status <= memop AFTER Ctrl_delay;
WHEN OTHERS => State <= fetch AFTER Ctrl_delay;
Status <= fetch AFTER Ctrl_delay;
END CASE;
WHEN memop | ioop => Status <= fetch AFTER Ctrl_delay;
State <= fetch AFTER Ctrl_delay;
WHEN undef => NULL;
END CASE;
END IF;
END PROCESS;

PROCESS(State,Instr,MemRdy) -- output function


ALIAS Opcode : STD_LOGIC_VECTOR( 5 DOWNTO 0) IS Instr(31 DOWNTO 26);
ALIAS Imm : STD_LOGIC_VECTOR(15 DOWNTO 0) IS Instr(15 DOWNTO 0);
ALIAS D : STD_LOGIC_VECTOR(15 DOWNTO 0) IS Instr(15 DOWNTO 0);
ALIAS PN : STD_LOGIC_VECTOR(10 DOWNTO 0) IS Instr(10 DOWNTO 0);

CONSTANT Dec_delay : TIME:= 3 ns;


CONSTANT Ctrl_delay : TIME:= 500 ps;
CONSTANT MemRd_delay: TIME:= 2500 ps;
CONSTANT MemRd_pulse: TIME:= MemRd_delay + 3 ns ;
CONSTANT MemWr_delay: TIME:= 2500 ps;
CONSTANT MemWr_pulse: TIME:= MemWr_delay + 3 ns ;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


68
TYPE Ctrl_LineT IS
RECORD
MemOp, WrMem : STD_LOGIC;
RS_RB, IR_RB : STD_LOGIC;
WrC, WrPC, WrCR : STD_LOGIC;
ZE_SE : STD_LOGIC;
ALUop : STD_LOGIC_VECTOR(3 DOWNTO 0);
END RECORD;

VARIABLE Ctrl_Line : Ctrl_LineT;

TYPE Ctrl_TableT IS ARRAY(NATURAL RANGE 0 TO 63) OF Ctrl_LineT;

CONSTANT Ctrl_Table: Ctrl_TableT:=


-- Mem Wr RS IR Wr Wr Wr ZE ALU
-- Op Mem RB RB C PC CR SE op
(0 => (’0’, ’0’, ’1’, ’1’, ’0’, ’0’, ’0’, ’0’, "0000"), -- nop
2 => (’0’, ’0’, ’1’, ’1’, ’1’, ’0’, ’1’, ’0’, "1111"), -- not
4 => (’0’, ’0’, ’1’, ’1’, ’1’, ’0’, ’1’, ’0’, "1010"), -- lsh
6 => (’0’, ’0’, ’1’, ’1’, ’1’, ’0’, ’1’, ’0’, "1011"), -- rsh
8 => (’0’, ’0’, ’1’, ’1’, ’1’, ’0’, ’1’, ’0’, "1100"), -- lrt
10=> (’0’, ’0’, ’1’, ’1’, ’1’, ’0’, ’1’, ’0’, "1101"), -- rrt

16=> (’0’, ’0’, ’1’, ’1’, ’1’, ’0’, ’1’, ’0’, "0001"), -- add
17=> (’0’, ’0’, ’1’, ’0’, ’1’, ’0’, ’1’, ’1’, "0001"), -- adi
18=> (’0’, ’0’, ’1’, ’1’, ’1’, ’0’, ’1’, ’0’, "0010"), -- sub
19=> (’0’, ’0’, ’1’, ’0’, ’1’, ’0’, ’1’, ’1’, "0010"), -- sbi
20=> (’0’, ’0’, ’1’, ’1’, ’1’, ’0’, ’1’, ’0’, "0100"), -- and
21=> (’0’, ’0’, ’1’, ’0’, ’1’, ’0’, ’1’, ’0’, "0100"), -- ani

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


69

22=> (’0’, ’0’, ’1’, ’1’, ’1’, ’0’, ’1’, ’0’, "0101"), -- or
23=> (’0’, ’0’, ’1’, ’0’, ’1’, ’0’, ’1’, ’0’, "0101"), -- ori
24=> (’0’, ’0’, ’1’, ’1’, ’1’, ’0’, ’1’, ’0’, "0110"), -- xor
25=> (’0’, ’0’, ’1’, ’0’, ’1’, ’0’, ’1’, ’0’, "0110"), -- xri

32=> (’1’, ’0’, ’0’, ’0’, ’1’, ’0’, ’0’, ’1’, "0001"), -- ldb
33=> (’1’, ’0’, ’0’, ’0’, ’1’, ’0’, ’0’, ’1’, "0001"), -- ldw
34=> (’1’, ’1’, ’0’, ’0’, ’0’, ’0’, ’0’, ’1’, "0001"), -- stb
35=> (’1’, ’1’, ’0’, ’0’, ’0’, ’0’, ’0’, ’1’, "0001"), -- stw
36=> (’1’, ’0’, ’0’, ’1’, ’1’, ’0’, ’0’, ’0’, "1001"), -- irb
37=> (’1’, ’0’, ’0’, ’1’, ’1’, ’0’, ’0’, ’0’, "1001"), -- irw
38=> (’1’, ’1’, ’0’, ’1’, ’0’, ’0’, ’0’, ’0’, "1001"), -- iwb
39=> (’1’, ’1’, ’0’, ’1’, ’0’, ’0’, ’0’, ’0’, "1001"), -- iww

56=> (’0’, ’0’, ’1’, ’0’, ’0’, ’1’, ’0’, ’1’, "0001"), -- br
57=> (’0’, ’0’, ’1’, ’0’, ’0’, ’1’, ’0’, ’1’, "1000"), -- bri
48=> (’0’, ’0’, ’1’, ’0’, ’0’, ’1’, ’0’, ’1’, "0001"), -- brp
49=> (’0’, ’0’, ’1’, ’0’, ’0’, ’1’, ’0’, ’1’, "0001"), -- brn
50=> (’0’, ’0’, ’1’, ’0’, ’0’, ’1’, ’0’, ’1’, "0001"), -- bnz
51=> (’0’, ’0’, ’1’, ’0’, ’0’, ’1’, ’0’, ’1’, "0001"), -- brz
52=> (’0’, ’0’, ’1’, ’0’, ’0’, ’1’, ’0’, ’1’, "0001"), -- bnc
53=> (’0’, ’0’, ’1’, ’0’, ’0’, ’1’, ’0’, ’1’, "0001"), -- brc
54=> (’0’, ’0’, ’1’, ’0’, ’0’, ’1’, ’0’, ’1’, "0001"), -- bnv
55=> (’0’, ’0’, ’1’, ’0’, ’0’, ’1’, ’0’, ’1’, "0001"), -- brv
OTHERS => (’0’, ’0’, ’1’, ’1’, ’0’, ’0’, ’0’, ’1’, "0000")
);

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


70

BEGIN
IF (State’EVENT) THEN
CASE State IS
WHEN undef => NULL;
WHEN p_reset => ALUOp <= "0000";
MemRd <= ’0’; MemWr <= ’0’;
MemEnable <= ’0’; MemLength <= ’0’;
IORd <= ’0’; IOWr <= ’0’;
IOEnable <= ’0’; IOLength <= ’0’;
WHEN fetch =>
-- disable write signals from previous cycle
WrCR <= ’0’ AFTER Ctrl_delay;
WrC <= ’0’ AFTER Ctrl_delay;

-- fetch instruction
ALU_PC <= ’1’ AFTER Ctrl_delay;
MemLength<= ’1’ AFTER Ctrl_delay;
MemEnable<= ’1’ AFTER Ctrl_delay;
MemRd <= ’1’ AFTER MemRd_delay, ’0’ AFTER MemRd_pulse;
Sin_Sout <= ’0’ AFTER Ctrl_delay; -- switch in

-- increment PC
PC_RA <= ’0’ AFTER Ctrl_delay;
ALUop <= "1110" AFTER Ctrl_delay; -- PC + 4
WrIR <= ’1’ AFTER Ctrl_delay;
WrPC <= ’1’ AFTER Ctrl_delay;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


71

WHEN execute =>


-- disable signals from fetch cycle
WrIR <= ’0’ AFTER Ctrl_delay;
WrPC <= ’0’ AFTER Ctrl_delay;
MemEnable<= ’0’ AFTER Ctrl_delay;

-- other actions done by Instr’EVENT

WHEN memop | ioop =>


-- initiate memory access
ALU_PC <= ’0’ AFTER Ctrl_delay; -- address to memory
MemEnable<= ’1’ AFTER Ctrl_delay;
MemLength<= Opcode(0) AFTER Ctrl_delay; -- operand length
WrC <= Ctrl_Line.WrC AFTER Ctrl_delay;
IF (Ctrl_Line.WrMem = ’0’) THEN
MemRd <= ’1’ AFTER MemRd_delay, ’0’ AFTER MemRd_pulse;
Mem_ALU <= ’0’ AFTER Ctrl_delay;
ELSE
MemWr <= ’1’ AFTER MemWr_delay, ’0’ AFTER MemWr_pulse;
Sin_Sout <= ’1’ AFTER Ctrl_delay;
END IF;
END CASE;
END IF;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


72
IF (Instr’EVENT) THEN
-- decode opcode
Ctrl_Line:= Ctrl_Table(CONV_INTEGER(’0’ & Opcode));

-- decode registers
AddrA <= Instr(20 DOWNTO 16) AFTER Dec_delay;
IF (Ctrl_Line.RS_RB = ’0’) THEN
AddrB <= Instr(25 DOWNTO 21) AFTER Dec_delay;
ELSE
AddrB <= Instr(15 DOWNTO 11) AFTER Dec_delay;
END IF;
AddrC <= Instr(25 DOWNTO 21) AFTER Dec_delay;

-- decode control signals


PC_RA <= not(Ctrl_Line.WrPC) AFTER Ctrl_delay;
ZE_SE <= Ctrl_Line.ZE_SE AFTER Ctrl_delay;
IR_RB <= Ctrl_Line.IR_RB AFTER Ctrl_delay;
ALUOp <= Ctrl_Line.ALUop AFTER Ctrl_delay;
WrPC <= Ctrl_Line.WrPC AFTER Ctrl_delay;
WrCR <= Ctrl_Line.WrCR AFTER Ctrl_delay;

IF (Ctrl_Line.MemOp = ’0’) THEN


WrC <= Ctrl_Line.WrC AFTER Ctrl_delay;
Mem_ALU <= ’1’ AFTER Ctrl_delay;
END IF;
END IF;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer


73

IF (MemRdy’EVENT AND MemRdy=’1’) THEN


CASE State IS
WHEN memop => IF (Ctrl_Line.WrMem = ’1’) THEN
-- deactivate data bus
Sin_Sout <= ’0’ AFTER Ctrl_delay;
END IF;
WHEN OTHERS => NULL;
END CASE;
END IF;
END PROCESS;
END behavioral;

Introduction to Digital Systems 15 – Specification and Implementation of a Microcomputer

You might also like