0% found this document useful (0 votes)
26 views105 pages

Microprocessor Overview and Applications

Uploaded by

mbuja mbuja
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)
26 views105 pages

Microprocessor Overview and Applications

Uploaded by

mbuja mbuja
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/ 105

BY MR.

AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY


13/02/2019

MICROPROCESSOR
Microprocessor
It is a multipurpose, programmable, clock-driven, register-based electronic device that reads binary
instructions from memory, accepts binary data as input and processes data according to instructions
(program), and provides result as output.

It can also be defined as a programmable device that takes in numbers, performs on them arithmetic or
logical operations according to the program stored in memory and then produce other numbers as results.

Applications of Microprocessors
Instrumentation:
It is very useful in the field of instrumentation. Frequency counters, function generators, frequency
synthesizers, spectrum analyses and many other instruments are available, when microprocessors are used
as controller. It is also used in medical instrumentation.

Control
Microprocessor based controllers are available in home appliances, such as microwave oven, washing
machine etc., microprocessors are being used in controlling various parameters like speed, pressure,
temperature etc. These are used with the help of suitable transduction.

Communication
Microprocessors are being used in a wide range of communication equipments. In telephone industry, these
are used in digital telephone sets, telephone exchange and modem etc. The use of microprocessor in
television, satellite communication has made teleconferencing possible. Railway reservation and air
reservation system also uses this technology. LAN and WAN for communication of vertical information
through computer network.

Office Automation and Publication


Microprocessor based micro computer with software packages has changed the office environment.
Microprocessors based systems are being used for word processing, spread sheet operations, storage etc.
The microprocessor has revolutionized the publication technology.

Consumer
The use of microprocessor in toys, entertainment equipment and home applications is making them more
entertaining and full of features. The use of microprocessors is more widespread and popular. Now the
Microprocessors are used in:

1. Calculators
2. Accounting system
3. Games machine
4. Complex Industrial Controllers
5. Traffic light Control
6. Data acquisition systems
7. Multi user, multi-function environments
8. Military applications
1
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

Pag e |1
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

9. Radars
10. Washing machines
11. Satellites
12. Flights

Increase in application of microprocessors has been due to rapid advancement in electronics industry and
large scale integration of devices.

A microprocessor can function as:

• CPU of a computer called microcomputer


• Embedded in a large system
• Standalone unit controlling a process

Microprocessor communicates and operates in binary numbers 0 and 1 called bits

Microprocessor has a fixed set of instructions in binary pattern called machine language. These binary
instructions are given abbreviated names called mnemonics.

Hardware is the physical components of a microprocessor

A program is a set of instructions written for a microprocessor to perform a task and a group of programs is
called software.

In embedded systems, the microprocessor is part of the final product and is not available for programming
to the end user. A copying machine is a typical example of embedded system.
Microprocessors used in such systems are generally categorized as:
1. Microcontroller
2. General purpose microprocessor
Microprocessor recognizes and processes a group of bits called word (the number of digits that can be
processed at a time). Microprocessor is classified according to their word length. For example a processor
with 8-bit word is called an 8-bit microprocessor and that with 32-bit word is called a 32-bit
microprocessor.
Since microprocessor is programmable, it can be instructed to perform a given task within its capacity.

2
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

Pag e |2
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

The History of the Integrated circuits


Before the transistor, engineers had to use vacuum tubes. Vacuum tube (Fig. below) is an electronic device
that controls the flow of electrons in a vacuum. It is also called as electron tube or valve. John Ambrose
Fleming developed the first vacuum tube in 1904.

Just as the transistor, the vacuum tube can switch electricity on or off, or amplify a current. So why was the
vacuum tube replaced by the transistor? There are several reasons. Vacuum tubes:
1. were bulky, hence less suitable for portable products.
2. had higher operating voltages generally required.
3. had high power consumption; needs heater supply that generates waste heat and yields lower
efficiency, notably for small-signal circuits.
4. Glass tubes are fragile, compared to metal transistors.
5. Sometimes more prone to microphonics (transmittance of mechanical vibrations through an
electrical component) than transistors, depending upon circuit and device.
6. Cathode electron-emitting materials were used up in operation.
7. had high-impedance devices that needed impedance matching transformer for low-impedance loads,
like speakers; however, the magnetic cushion provided by an output transformer prevents the output
tubes from blowing up.
8. Sometimes had higher cost than equivalently powered transistors.
The vacuum tube looks and behaves very much like a light bulb; it generates a lot of heat and has a
tendency to burn out. Also, compared to the transistor it is slow, big and bulky.
When engineers tried to build complex circuits using the vacuum tube, they quickly became aware of its
limitations. The first digital computer ENIAC, for example, was a huge monster that weighed over thirty
tons, and consumed 200 kilowatts of electrical power. It had around 18,000 vacuum tubes that constantly
burned out, making it very unreliable. They required warming up before they could operate.
An integrated circuit is a thin slice of silicon or sometimes another material that has been specially
processed so that a tiny electric circuit is etched on its surface. The circuit can have many millions of
microscopic individual elements, including transistors, resistors, capacitors, and conductors, all electrically
connected in a certain way to perform some useful function.
The first integrated circuits were based on the idea that the same process used to make clusters of
transistors on silicon wafers might be used to make a functional circuit, such as an amplifier circuit or a
computer logic circuit. Slices of the semiconductor materials silicon and germanium were already being
printed with patterns, the exposed surfaces etched with chemicals, and then the pattern removed, leaving
dozens of individual transistors, ready to be sliced up and packed individually. But wires, a few resistors
3
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

Pag e |3
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

and capacitors might later connect those same transistors to make a circuit. Why not doing the whole thing
at one time on that slice of silicon?
The idea occurred to a number of inventors at the same time, but the first to accomplish it were Jack
Kilby of Texas Instruments and Robert Noyce of Fairchild Semiconductor Incorporated. The idea caught
on like wildfire because the integrated circuit had many of the advantages that had made the transistor
attractive earlier. These advantages included small size, high reliability, low cost, and small power
consumption. However, these circuits were difficult to make because if one component of the chip was
faulty, the whole chip was ruined.
As engineers got better and better at squeezing more and more transistors and other components onto a
single chip, the problems of actually making these chips increased. When the transistors were shrunk down
to microscopic size, even the smallest bit of dust could ruin the chip. That's why today, chips are made in
special "clean rooms" where workers wear the "bunny suits" that we often see on TV.
Compared to the original integrated circuit, which was a simple device with just a few components, the
number of components on today's' integrated circuits is amazing. In the 1960s, an engineer named Gordon
Moore predicted that the number of elements on a chip would double every year (later revised to every two
years) into the foreseeable future. "Moore's Law" has held true so far. By the beginning of the twenty-first
century, the Intel Pentium chip had over 100 million transistors on it, with the total number of components
including resistors, capacitors, and conductors being even larger.

Microprocessor History
In the beginning, there was Intel. Intel was and is a Company in America engaged in designing and
manufacturing products such as microprocessors, chipset, computers, stand-alone system-on-chip among
others and technologies such as the cloud. Intel invented the microprocessors or perhaps more accurately,
they invented the term “microprocessor”. An early 8-bit chip, the four-phase system AL1, had been
invented by Lee Boysel in 1969 as part of a multi-chip CPU. But it wasn’t called a microprocessor until a
court case in the 1990’s when it was demonstrated that AL1 could function as the core of a computer.
For all practical purposes, however, the PC age began with Intel's first microprocessor, which by itself
contained as much processing power as the most powerful computer that existed in the world at the time:
the ENIAC, which filled an entire room. The world's first commercially-viable microprocessor was dubbed
the Intel 4004. It was quickly succeeded less than a year later by the 8008, which was twice as powerful.

In 1978, Intel released the 16-bit 8086 processor. The 8088, also a 16-bit chip, followed less than a year
later. The 8088 incorporated technologies designed to make it backward-compatible with the 8-bit chips
that were still in wide use at the time. IBM chose the 8088 chip to power their original Personal Computer.

And so it was that IBM, Intel, and a little startup company called Microsoft brought computing to the
masses.

In the early 1990's, Intel released the i386 processor. The 386 was the first commercially available 32-bit
microprocessor. For the first time, it made multitasking (running more than one program at a time) possible
on desktop computers. The i486 added an onboard math co-processor, improved data transfer, and an
onboard memory cache, all of which were stunning advances in technology in that era.

4
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

Pag e |4
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

The Intel Pentium processor, released in 1993, was the first commercially available microprocessor capable
of executing two instructions for every clock cycle. Later releases in the Pentium line revolutionized
everything from the way data is moved about on the chips, to the way that multimedia content is handled.

Those improvements have since been eclipsed, however, by Intel's line of multi-core, 64-bit processors,
such as the popular Core™ series, which boast capabilities that were unheard of only a few years ago.

Many other manufacturing companies have also come up with advanced microprocessors

Evolution of Microprocessor:
Microprocessors were categorized into five generations: first, second, third, fourth, and fifth generations.
Their characteristics are described below:

First-generation
The microprocessors that were introduced in 1971 to 1972 were referred to as the first generation systems.
First-generation microprocessors processed their instructions serially they fetched the instruction, decoded
it, then executed it. When an instruction was completed, the microprocessor updated the instruction pointer
and fetched the next instruction, performing this sequential drill for each instruction in turn.

Second generation
By the late 1970s, enough transistors were available on the IC to usher in the second generation of
microprocessor sophistication: 16-bit arithmetic and pipelined instruction processing.

Motorola’s MC68000 microprocessor, introduced in 1979, is an example. Another example is Intel’s 8080.
This generation is defined by overlapped fetch, decode, and execute steps (Computer 1996). As the first
instruction is processed in the execution unit, the second instruction is decoded and the third instruction is
fetched.
The distinction between the first and second generation devices was primarily the use of newer
semiconductor technology to fabricate the chips. This new technology resulted in a five-fold increase in
instruction, execution, speed, and higher chip densities.

Third generation
The third generation, introduced in 1978, was represented by Intel’s 8086 and the Zilog Z8000, which were
16-bit processors with minicomputer-like performance. The third generation came about as IC transistor
counts approached 250,000.
Motorola’s MC68020, for example, incorporated an on-chip cache for the first time and the depth of the
pipeline increased to five or more stages. This generation of microprocessors was different from the
previous ones in that all major workstation manufacturers began developing their own RISC-based
microprocessor architectures (Computer, 1996).

Fourth generation
As the workstation companies converted from commercial microprocessors to in-house designs,
microprocessors entered their fourth generation with designs surpassing a million transistors. Leading-edge
microprocessors such as Intel’s 80960CA and Motorola’s 88100 could issue and retire more than one
instruction per clock cycle.
5
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

Pag e |5
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Fifth generation

Microprocessors in their fifth generation, employed decoupled super scalar processing, and their design
soon surpassed 10 million transistors. In this generation, PCs are a low-margin, high-volume-business
dominated by a single microprocessor.

6
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

Pag e |6
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Classification of Microprocessor:

The microprocessor is identified with the word size of data. For E.g. The ALU can perform a 4- bit data
operation at a time these microprocessor is called as 4-bit microprocessor.

4-bit Microprocessors
The first microprocessor was introduced in 1971 by Intel Corp. It was named Intel 4004 as it was a 4 bit
processor. It was a processor on a single chip. It could perform simple arithmetic and logic operations such
as addition, subtraction, Boolean AND and Boolean OR. It had a control unit capable of performing control
functions like fetching an instruction from memory, decoding it, and generating control pulses to execute it.
It was able to operate on 4 bits of data at a time. This first microprocessor was quite a success in industry.
Soon other microprocessors were also introduced. Intel introduced the enhanced version of 4004, the 4040.
Some other 4 bit processors are International’s PPS4 and Thoshiba’s T3472.

8-bit Microprocessors
The first 8 bit microprocessor which could perform arithmetic and logic operations on 8 bit words was
introduced in 1973 again by Intel. This was Intel 8008 and was later followed by an improved version, Intel
8088. Some other 8 bit processors are Zilog-80 and Motorola M6800.

16-bit Microprocessors
The 8-bit processors were followed by 16 bit processors. They are Intel 8086 and 80286.

32-bit Microprocessors
The 32 bit microprocessors were introduced by several companies but the most popular one is Intel 80386.

Pentium Series
Instead of 80586, Intel came out with a new processor namely Pentium processor. Its performance is closer
to RISC performance. Pentium was followed by Pentium Pro CPU. Pentium Pro allows allow multiple
CPUs in a single system in order to achieve multiprocessing. The MMX extension was added to Pentium
Pro and the result was Pentium II. The low cost version of Pentium II is Celeron.
The Pentium III provided high performance floating point operations for certain types of computations by
using the SIMD extensions to the instruction set. These new instructions make the Pentium III faster than
high-end RISC CPUs.
Interestingly Pentium IV could not execute code faster than the Pentium III when running at the same clock
frequency. So Pentium IV had to speed up by executing at a much higher clock frequency.

Organization of a Microprocessor based system


The figure below shows a simplified structure of a microprocessor based system. A microcomputer is an
example of a microprocessor based system. In the figure, three components are show
1. Microprocessor
2. I/O (Input/output)
3. Memory (read/write memory and read only memory)

7
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

Pag e |7
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Fig. Microprocessor –Based System with bus architecture.


- The components are organized around a common communication path called System Bus. The
Entire group of components is called a micro-computer.
- The components themselves are referred to as a subsystem.
- Microprocessor is one component of the microcomputer while Microcomputer is a complete
computer similar to any other computer, except the CPU functions of the microcomputer are
performed by the microprocessor.
- Peripheral is a term used for input/output devices. The functions of the various components of a
microprocessor-based system can be summarized as follows:

1. Microprocessor
i. Reads instructions from the memory.
ii. Communicates with all peripheral (memory and I/Os) using the system bus.
iii. Controls timing of information flow.
iv. Performs the computing task.
2. The Memory
i. Stores the binary information, called instruction and data.
ii. Provides instructions and data to the microprocessor on request.
iii. Stores the results and data for the microprocessor.
3. The Input device
i. Enters data and instructions under the control of a program.
4. The output device
i. Accepts data from the microprocessor as specified in a program.
5. The bus
i. Carries bits between the microprocessor and memory and I/Os.
Advantages
1. Computational/processing speed is high.
2. Intelligence has been brought to systems through microprocessors.
8
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

Pag e |8
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

3. Automation of industrial processes and office automation have been realized.


4. Microprocessor is programmable and therefore there is flexibility in altering system
operations by changing the software alone.
5. Compact in size since less numbers of components used. There is also reduction in cost.
6. Operation and maintenance are easier.
7.
Disadvantages
1. They have limitations in terms of size of data.
2. The applications are limited by physical address space.
3. Analog signals cannot be processed directly and digitizing the analog signals introduces
error.
4. The speed of execution is slow when it comes to real time applications

A Computer System
A simple computer system comprises the basic components:
i. Process(Control Unit and the Arithmetic and Logic Unit)
ii. Main memory
iii. Input /Output unit
iv. Storage device

9
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

Pag e |9
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Fig. A computer System

Main Processor (or Central Processing Unit, CPU)


- This is the brain of the computer.
- There are different types of CPU from different companies
- Some examples include Intel, Motorola, AMD (Advanced Micro Devices), Cyrix etc.
- They operate at different speeds eg 166MHz, 233MHz, 450MHz, 733MHz etc
- The faster a CPU is, the faster it executes programs to accomplish tasks

The Central Processing Unit (CPU)


The CPU consists of:
1. A group of Registers (or Register Array)
These are high speed memory locations the temporarily store data and instructions during
processing.
The registers are identified by letter such as B, C, D, E, H, L, IX, and IY. These registers are
used to store data and addresses temporarily during the execution of a program.

2. Control Unit
- It is the device in charge of the operations of the computer and its peripheral
- The control unit provides the necessary timing and control signals to all the operations in the
microcomputer.
- It controls the flow of data between the microprocessor and memory and peripherals.
- It decodes (deciphers) decipher each instruction stored in it and then carries out the
instructions
- It also directs the movement of electronic signals between main memory and ALU.
- It also directs these electronic signals between the main memory and the input and output
devices.
For every instruction, the control unit carries out FOUR basic operations, known as the
machine cycle. In the machine cycle, the CPU:
i) Fetches an instruction
ii) Decodes the instruction
iii) Executes the instruction
iv) Stores the results
10
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 10
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

3. ALU (Arithmetic/Logic Unit)


- It performs such arithmetic operations as addition and subtraction, and such logic operations
as AND, OR, and XOR. Results are stored either in registers or in memory.
- The control unit issues out commands to the ALU, indicating where in the memory to get
data to be manipulated (processed) and how to interrelate the data.
- The data about to be processed is taken from the memory as directed by the control unit via
memory data register into the Accumulator. The ALU then performs the required operations
on data as directed by the control unit and then the results are stored in the accumulator.
They are later moved from the Accumulator and then stored in the main memory under
direction of the control unit and this process is called storing data.

4. Register Array
- This is yet another important component of the CPU though not shown in the block diagram
above.
- It consists of various registers identified by letter such as B, C, D, E, H, L, etc. These
registers are used to store data and addresses temporarily during the execution of a program.

5. Input Unit
- The input section transfers data and instructions in binary from the outside world to the
microprocessor.
- It includes such devices as a keyboard, switches, a scanner, and an analog-to-digital
converter.

6. Output Unit
- The output section transfers data from the microprocessor to such output devices as LED,
CRT, printer, magnetic tape, or another computer.

7. Main memory (Primary Memory)


- It stores such binary information as instructions and data, and provides that information to
the microprocessor.
- To execute programs, the microprocessor reads instructions and data from memory and
performs the computing operations in its ALU section.
- Results are either transferred to the output section for display or stored in memory for later
use.

8. System bus(not shown in the block diagram above)


- It is a communication path between the microprocessor and peripherals.
- The microprocessor communicates with only one peripheral at a time.
- The timing is provided by the control unit of the microprocessor.

MICROPROCESSOR INSTRUCTION SET AND COMPUTER LANGUAGES

11
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 11
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

- Word (or word length) is the number of bit the microprocessor recognizes and processes at a
time.
- Each machine has its own set of instructions based on the design of its CPU or its
microprocessor.
- To communicate with a computer, one must give instructions in binary language (machine
language). This is the natural dialect of a computer. It is machine oriented program i.e. the
language which machine can follow very easily.
- The program written in machine language is called Objet Program.
- In earlier computers all programs were written in machine language. The instructions were
written in binary (1’s and 0’s).

12
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 12
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Microprocessor versus Microcontroller

Microcontroller Microprocessor
1. CPU on a single chip 1. CPU and several supporting chips
2. Consist memory I/O ports 2. Memory, I/O Port to be connected externally

OR OR

13
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 13
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Microprocessor Microcontroller

It is the heart of the computer


System It is the heart of an embedded system.
system.

It contains CPU, general purpose registers, It contains the circuitry of microprocessor


Contains stack pointers, program counters, clock and has built-in ROM, RAM, I/O devices,
timing and interrupt circuits. timers and counters.

Data It has many instructions to move data It has one or two instructions to move data
memory between memory and CPU. between memory and CPU.

Circuit It is large. It is small.

Cost Cost of the entire system increases. Cost of the entire system is low.

Bit
It has one or two bit handling instructions. It has many bit handling instructions.
instructions

Register It has less number of registers; hence the It has more number of registers; hence the
numbers operations are memory based. programs are easier to write.

It is based on Von Neumann architecture, It is based on the Harvard architecture,


Storage where the program and data are stored in where the program memory and data
the same memory module. memory are stored in separate module.

Access time for memory and I/O devices Less access time for built-in memory and
Time
is more. I/O devices.

Hardware It requires more hardware. It requires less hardware.

14
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 14
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Another table of comparison is here:

15
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 15
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Microcomputer Block Diagram

- A microcomputer is a small, relatively inexpensive computer with a microprocessor as its


central processing unit (CPU).
- It includes a microprocessor, memory, and minimal input/output (I/O) circuitry mounted on
a single printed circuit board (motherboard).

Central Processing Unit:


The CPU as already been mentioned consists of ALU (Arithmetic and Logic Unit), register unit and control
unit.
The CPU fetches the stored instructions from the program memory, data word from data memory or from
an input device and after processing the data stores the result in data memory or sends it to an output device

a) ALU (Arithmetic and Logic Unit)


This unit performs computing functions on m-bit data where ‘m’ is the bit size of the processor.
These functions are arithmetic operations such as addition, subtraction and logical operation such as
AND, OR, XOR, rotate, compare etc. Results are stored either in registers or in memory or sent to
output devices.

b) Register Unit
It contains various 8-bit or 16-bit registers. These registers are used primarily to store data
temporarily during the execution of a program. Some of the registers are accessible to the user
through instructions. It means there contents can be read and/or changed through instructions. Some
of the registers are not accessible to user but they are used by the processor for the execution of an
instruction.
8085A microprocessor contains 8-bit registers such as Accumulator (Reg. A), B, C, D, E, H, L etc
and16-bit registers such as Program Counter (PC), Stack Pointer (SP).

16
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 16
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

c) Control Unit
It provides necessary timing & control signals required for the operation of microcomputer. It
controls the flow of data between the microprocessor and peripherals (input, output & memory).

The control unit gets a clock signal which determines the speed of the microprocessor. In all, the
CPU has the following basic functions:
a) It fetches an instructions word stored in memory.
b) It decodes the instruction to determine what the instruction is telling it to do.
c) It executes the instruction.
Executing the instruction may include same of the following major tasks:
1. Transfer of data from one register to another register in the CPU itself.
2. Transfer of data between a CPU register & specified memory location or input/output
device.
3. Performing arithmetic and logical operations on data from a specific memory location or a
designated CPU register.
4. Directing the CPU to change the sequence of fetching instructions, if processing the data
created a specific condition.
5. Performing housekeeping function within the CPU itself in order to establish desired
condition at certain registers.
d. It looks for control signal such as interrupts and provides appropriate responses.
e. It provides status, control, and timing signals that the memory and input/output section can use.

Memory
- It stores both the instructions to be executed (i.e. program) and the data involved. It usually
contains ROM (Read Only Memory) and RWM (Read Write Memory).
- The ROM can only read and cannot be written into and is non volatile that is, it retains its
contents when the power is turned off. A ROM is typically used to store instructions and
data that do not change. For example, it stores the monitor program of a microcomputer.
- One can either read from or write into a RWM in memory read operation or memory write
operation respectively. The RWM is volatile, that is it does not retain its contents when the
power is turned off.
- It is used to store user programs and data which are temporary might change during the
course of executing a program.
- During a memory read operation, the content of the addressed location is not destroyed.
- During a write operation, the original content of the addressed location is destroyed.

What then is the different Program Memory and Data Memory?


Program Memory (Rom)is used for permanent saving program being executed, while
Data Memory (Ram)is used for temporarily storing and keeping intermediate results and variables.
The microprocessor executes programs stored in program memory only.

17
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 17
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Memory sections often subdivided into units called pages. The entire memory section may involve
million of words, whereas a page contains between 256 & 4k warts. The computer may access a
memory location by first accessing a particular page and then accessing a location (or line number)
on that page.

The advantage of paging is that the computer can reach several locations on the same page with just
the address on the page. The process is like describing street address by first specifying a street and
then listing the house numbers. The control section transfers data to or from memory as follows:
1. The control section reads an address to the memory.
2. The control section sends a read and write signal to the memory to indicate, the direction
of the transform.
3. The control section waits until transfer has been completed. This delay precedes the ctual
data’s transfer in the input case and follows it in the output case.

Clock Generator:
Operations inside the microprocessor as well as in other parts of the microcomputer are usually
synchronous by nature. This is done so that events in different parts of the system can proceed in a
systematic fashion.

The clock needed to perform this synchronous operation is provided by the clock generator. The
clock generator generates the appropriate clock periods during which instruction executions are
carried out by the microprocessor.

Some of the microprocessors have an internal clock generator circuit to generate a clock signal.
These microprocessors require an external crystal or RC network to be connected at the appropriate
pins for deciding the operating frequency (e.g. 8085A). Some microprocessors require an external
clock generator (e.g. 8086). These microprocessors also provide an output clock signal which can
be used by other devices in the microcomputer system for their own timing and synchronizing.

Bus Structure in 8085


A bus is a group of conducting wires which carries information within the microprocessor. All the
peripherals are connected to microprocessor through a bus.
There are three buses in Microprocessor:
1. Address Bus
2. Data Bus
3. Control Bus

18
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 18
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Address Bus
It is a group of conducting wires which carries address only. The address bus is unidirectional
because data flow in one direction, from microprocessor to memory or from microprocessor to
Input/output devices. We can find that how much memory location it can use the formula 2^ N.
where N is the number of bits used for address lines.

Length of Address Bus of Intel8085 microprocessor is 16 Bit (That is, Four Hexadecimal Digits),
ranging from 0000 H to FFFF H, (H denotes Hexadecimal). The Intel 8085 microprocessor can
transfer maximum 16 bit address which means it can address 65, 536 different memory location.

The Length of the address bus determines the amount of memory a system can address. Such as a
system with a 32-bit address bus can address 2^32 memory locations. If each memory location
holds one byte, the addressable memory space is 4 GB. However, the actual amount of memory that
can be accessed is usually much less than this theoretical limit due to chipset and motherboard
limitations.

Question:
If a processor has 4 GB memory then how many address lines are required to access this memory?

19
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 19
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Answer:
4GB= 4 * 1GB
4 = 22
1GB = 230
4GB = 22 * 230 = 232
So, 32 address lines are required to access the 4 GB memory.

Data Bus
It is a group of conducting wires which carries Data only. Data bus is bidirectional because data
flow in both directions, from microprocessor to memory or Input/output devices and from memory
or Input/output devices to microprocessor.

Length of Data Bus of 8085 microprocessor is 8 Bit (That is, two Hexadecimal Digits), ranging
from 00 H to FF H (00000000H to 11111111H). H denotes Hexadecimal.
When it is write operation, the processor will put the data (to be written) on the data bus, when it is
read operation, the memory controller will get the data from specific memory block and put it into
the data bus.
The data bus also connects the I/O ports and CPU. The largest number that can appear on the data
bus is 11111111.
It has 8 parallel lines of data bus. So it can access up to 2^8 = 256 data bus lines.

Control Bus
The control bus is used for sending control signals to the memory and I/O devices. The CPU sends
control signal on the control bus to enable the outputs of addressed memory devices or I/O port
devices.
Some of the control bus signals are as follows:
1. Memory read
2. Memory write
3. I/O read
4. I/O write
5. Opcode fetch

MICROPROCESSOR INSTRUCTION SET AND COMPUTER LANGUAGES

- The word (or word length) is defined as the number of bits the microprocessor recognizes and
processes at time.
- Each machine has its own set of instructions based on the design of its CPU or of its
microprocessor.
- To communicate with the computer, one must give instructions in binary language (machine
language). This is the natural dialect of a computer. It is machine oriented program ie the language
which the machine can follow very easily. The program written in machine language is also known
as object program.
20
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 20
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

- In earlier computers, all programs were in machine language. Such programs contained very
detailed instructions for each calculation and for the usual clerical chores accompanying each task.
The instructions were written in binary i.e. each instructions consisted a string of characters
containg a particular combination of 1’s and 0’s
Example
Add and store of 2-number as in the table below
Instruction Number Operation Code (Opcode) Memory address (Operand)
1 0110B 10001110B
2 0111B 10001111B
3 1000B 01110001B
Table 2.0 (a) Exhibits addition and storing of results of two numbers

- It requires code for addition process as well as for the data to be added. The code required for
performing any operation on computer is called opcode (Operation Code) and the data/address on
which operation is performed is called operand.

- Writing of program in binary form is very tedious and confusing as it would be composed long
strings of 1s and 0s. This problem is partially overcome by writing programs and data in octal and
hexadecimal form. Table 2.0 (b) below shows equivalent binary, octal and hexadecimal codes of
instructions and memory used in table 2.0 (a)

Instruction Number Operation Code (Opcode) Memory address (Operand)


1 0110B = 06O = 06H 10001110B = 216O
2 0111B = 07O = 07H 10001111B= 217O
3 1000B = 10O = 08H 01110001B = 71H
Table 2.0 (b) Binary, Octal and Hexadecimal representation

- It is evidence from table 2.0 (b) that the machine language programs can be written either in Binary
(represented by B) or in Octal (represented by O), or in Hexadecimal (represented by H) forms.
- Because it is difficult for most people to write programs in sets of 0s and 1s, computer
manufacturers have devised English-like words to represent the binary instructions of a machine.
Programmers can write programs, called assembly language programs, using these words.
- Each manufacturer of a microprocessor has devised a symbolic code for each instruction, called a
mnemonic.
- Mnemonic – a combination of letters to suggest the operation of an instruction
- Example of assembly language program is
Mnemonic Meaning
ADD addition
SUB subtraction
MOV movement
21
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 21
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

- It is much easier to remember ADD than 0111B that stands for additions. So, to help the
programmer, a number of mnemonics has been composed. The word mnemonics pronounce as
nemonik refers to an aid to remember. The programmer understands these mnemonics but not by
the computer (microprocessor). Therefore, the mnemonics must be translated into a form that the
microprocessor can understand.
- There are two methods of converting mnemonics in binary form that microprocessor can
understand. They are:
• Hand assembly
• Machine assembly
- Instruction is a binary pattern entered through an input device into memory to command the
microprocessor to perform specified function.
- Programs written in assembly language are specific to a given machine and therefore they are not
transferable from one machine to another.
- To circumvent this limitation, such general- purpose languages as BASIC, FORTRAN. PASCAL,
C, AND C++ have been devised; a program written in any of languages can be machine –
independent. These languages are called high-level languages.
- Machine language and assembly language are microprocessor specific and are both considered low-
level language.
Machine language is a computer programming language consisting of binary or hexadecimal
instructions which a computer can respond to directly. It is in binary, and the assembly language is
in English-like word; however, the microprocessor understands only the binary. These English-like
words are translated binary codes using a program called assembler.
- Assembler – is a computer program that translates an assembly language program from mnemonic
to the binary machine code of a computer.
- Interpreter – a program that translates the English-like statements of a high-level language into the
machine language of a computer. An interpreter translates one statement at a time from a source
code to an object code.
- Monitor program – a program that interprets the input from a keyboard and converts the input into
its binary equivalent.
- Compiler - a program that converts instructions into a machine-code or lower-level form so that
they can be read and executed by a computer. The compiler translates the whole program at a
go.
- Source code is a program written either in mnemonics or an assembly language or high-level
language (before it is assembled or compiled).
- The block diagram shows translation of High level Language Program to Machine Language

Compiler
Source Code or Object Code
22
Interpreter
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 22
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

ASCII Code
A computer is a binary machine. To communicate with computer in alphabetic letter in alphabet letters and
decimal numbers, translation codes are necessary.

The commonly used code is known as ASCII – American Standard Code for Information Interchange. It is
a 7-bit code with 128(27) combinations, and each combination from 00H to 7FH is assigned to a letter, a
decimal number, a symbol, or a machine command. For example 30H to 39H represent 0 – 9 decimal 30H
to 39H represent 0 to 9 decimal digits, 41H to 5AH represent capital letters A through Z, 20H to 2FH
represent various symbols, and initial codes 00H to 1FH represent such machine commands as carriage
return and line feed.

In microcomputer systems, keyboards (Called ASCII keyboards), video screens, and printers are typical
examples of devices that use ASCII codes. When “9” is pressed on an ASCII keyboard, the computer
receives 39H in binary, called an ASCII character, and the system program translate ASCII characters into
appropriate binary numbers.

However, recent computers use many more characters than the original 128 combinations; this is called
Extended ASCII. It is an 8-bit code that provides 256(28) combinations; the additional 128 combination are
assigned to various graphic characters.

Operating System
The interaction between the hardware and the software is managed by a set of programs called operating
system of a computer. It oversees all operations of the computer.

Characteristics of Operating System


Here is a list of some of the most prominent characteristic features of Operating Systems −
 Memory Management − Keeps track of the primary memory, i.e. what part of it is in use by
whom, what part is not in use, etc. and allocates the memory when a process or program requests
it.
 Processor Management − Allocates the processor (CPU) to a process and deal locates the
processor when it is no longer required.
 Device Management − Keeps track of all the devices. This is also called I/O controller that
decides which process gets the device, when, and for how much time.
 File Management − Allocates and de-allocates the resources and decides who gets the resources. It
manages the sharing of internal memory among multiple applications

23
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 23
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

 Security − Prevents unauthorized access to programs and data by means of passwords and other
similar techniques.
 Job Accounting − Keeps track of time and resources used by various jobs and/or users.
 Control Over System Performance − Records delays between the request for a service and from
the system.
 Interaction with the Operators − Interaction may take place via the console of the computer in
the form of instructions. The Operating System acknowledges the same, does the corresponding
action, and informs the operation by a display screen.
 Error-detecting Aids − Production of dumps, traces, error messages, and other debugging and
error-detecting methods.

 Coordination Between Other Software and Users − Coordination and assignment of compilers,
interpreters, assemblers, and other software to the various users of the computer systems.

24
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 24
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Utility programs
- Commonly referred to as just "utilities," are software programs that add functionality to your
computer or help your computer perform better. These include antivirus protection, backup, disk
repair, file management, memory management, password protection, and networking programs and
file compression. Utilities can also be applications such as screensavers, font and icon tools, and
desktop enhancements.
- Some utility programs help keep your computer free from unwanted software such as viruses or
spyware, while others add functionality that allows you to customize your desktop and user
interface.
- Utility is a program that performs a very specific task, usually related to managing system
resources. It is program that performs a specific task related to the management of computer
functions, resources, or files, as password protection, memory management, virus protection, and
file compression.
- In general, programs that help make your computer better are considered utilities.

- Operating systems contain a number of utilities for managing disk drives, printers, and
other devices.
Utilities differ from applications mostly in terms of size, complexity and function.
- Utilities are sometimes installed as memory-resident programs.

Application Programs
- This is a program is a comprehensive, self-contained program that performs a particular function
directly for the user. Among many others, application programs include:
 Email
 Web browsers
 Games
 Word processors
 Enterprise software
 Accounting software
 Graphics software
 Media players
 Database management
- Because every program has a particular application for the end user, the term "application" is used.
For instance, a word processor can help the user create an article, whereas a game application can
be used for entertainment.
- An application program is also known as an application or application software.

Components of a computer
- The two major components of a computer can be summarized by the following illustration.

25
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 25
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

THE MICROPROCESSOR
- This is a multipurpose, programmable, clock driven, register based electronic device that reads
binary information from a storage device called memory, accepts binary data as input and processes
data according to those instruction and provides results as output.

There are different types of CPU from different companies.

- These include but not limited to:


Intel 80386, 80486, Pentium, Pentium with MMX, Pentium II, Pentium III, Celeron, Pentium
IV, Pentium Dual Core, Centrino, Coppermine, core-i3,core-i7 etc
Motorola 68000, PowerPC
AMD Athlon, Duron, Thunderbird
etc

- They operates at different speeds e.g. 166MHz, 233MHz, 450MHz, 733MHz, 850MHz, GHz, 2.4
GHz , 3GHz etc .
- The faster a CPU is, the faster it executes programs to accomplish tasks.

The Architecture
- The word "architecture" typically refers to building design and construction. In the computing
world, "architecture" also refers to design, but in this case describes the design of computer
systems.

26
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 26
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

- The internal logic design of the microprocessor called its "Architecture", determine how and what
various operations are performed by the microprocessor.

Types of Microprocessor Architecture


There are different types of architectural designs of CPU. Among the designs are:
1. The CISC (Complex instruction set computing)
- It was first developed by Intel.
- It contains large number of complex instructions.
- In this instructions are not register based.
- Instructions cannot be completed in one machine cycle.
- Data transfer is from memory to memory.
- Micro programmed control unit is found in CISC.
- Also they have variable instruction formats.

2. RISC (Reduced instruction set computing)


It reduces the operational time by shortening the clock cycle per instruction.
- It is a type of microprocessor that has a limited number of instructions.
- They can execute their instructions very fast because instructions are very small and simple.
- RISC chips require fewer transistors which make them cheaper to design and produce.
- In RISC, the instruction set contains simple and basic instructions from which more
complex instruction can be produced.
- Most instructions complete in one cycle, which allows the processor to handle many
instructions at same time.
- In this instructions are register based and data transfer takes place from register to register.
3. Von-Neumann architecture
The von Neumann Architecture is named after the mathematician and early computer scientist John
von Neumann.Von Neumann Architecture or Princeton Architecture is a Computer Architecture,
where the Program i.e. the Instructions and the Data are stored in a single memory.

Since the Instruction Memory and the Data Memory are the same, the Processor or CPU cannot
access both Instructions and Data at the same time as they use a single bus.

27
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 27
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

The Von Neumann architecture developed for the ENIAC (Electronic Numerical Integrator And
Computer) uses the same memory and data paths for both program and data storage. ENIAC
was the world's first general-purpose computer. ENIAC was designed and built for the United
States Army to calculate artillery firing tables.

Figure 1.5: Von Neumann Microcontroller Architecture


This type of architecture has severe limitations to the performance of the system as it creates a
bottleneck while accessing the memory.
4. Harvard Microcontroller Architecture
Harvard Architecture, in contrast to Von Neumann Architecture, uses separate memory for
Instruction (Program) and Data. Since the Instruction Memory and Data Memory are separate in a
Harvard Architecture, their signal paths i.e. buses are also different and hence, the CPU can access
both Instructions and Data at the same time.

Both the concepts are similar except the way they access memories. The idea behind the Harvard
architecture is to split the memory into two parts – one for data and another for programs.

Real world computer designs are actually based on modified Harvard architecture and are
commonly used in microcontrollers and DSP (Digital Signal Processing).
Almost all Microcontrollers, including 8051 Microcontroller implement Harvard Architecture.

28
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 28
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Figure 1.6: Von Harvard Microcontroller Architecture

Harvard architecture is more complicated but separate pipelines remove the bottleneck that Von
Neumann creates.

The Intel 8085


Our focus here is mainly on the Intel 8085. It is a good starting point. It has basic fetching, registers, few
ALUs and memory access just enough to demystify the microprocessor internal arrangement and
operations

The Intel 8085 ("eighty-eighty-five") is an 8-bitmicroprocessor produced by Intel and introduced in 1976. It
is an 8-bit microprocessor with 16-bit address width capable of addressing 64kB of memory, with 40 pins
and formed with 6500 transistors. It requires a +5 volt power supply and operates with a 3 MHz frequency

It is an easy to use and still widely used system. It has simple architecture and have adequate instruction set
that enable students to learn necessary programming concept easily.

29
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 29
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

It is a software-binary compatible with the more-famous Intel 8080 with only two minor instructions added
to support its added interrupt and serial input/output features. However, it requires less support circuitry,
allowing simpler and less expensive microcomputer systems to be built. The Intel 8085 is a
conventional von Neumann design based on the Intel 8080.

Fig. Intel 8085

Fig. Microprocessor simplified block diagram

30
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 30
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Intel 8085 is majorly divided into three units:


1. Processing Unit
2. Instruction Unit
3. Storage and Interface Unit

Processing Unit
The processing unit consists of:
i. Arithmetic and Logic Unit
ii. Accumulator
iii. Status Flags
iv. Temporary Register

31
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 31
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Instruction Unit
This unit consists of:
i. Instruction Register
ii. Instruction Decoder
iii. Timing and Control Unit

Storage and Interface Unit


This unit consists of:
i. General Purpose Registers
ii. Stack Pointer
iii. Program Counter
iv. Increment/Decrement Register
v. Address Latch
vi. Address/Data Latch
Three Other Units
i. Interrupt Controller
ii. Serial I/Controller
iii. Power Supply

Processing Unit
The control unit (CU)
The control unit works by receiving input information that it converts into control signals. It directs the
operation of the processor.

It tells the computer’s memory, arithmetic/logic unit and input/output devices how to respond to program
instructions.

Functions of control unit can be categorized into following 5 categories

1. Fetching instructions one by one from primary memory and gather required data and operands to
perform those instructions.
2. Sending instructions to ALU to perform additions, multiplication etc.
32
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 32
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

3. Receiving and sending results of operations of ALU to primary memory


4. Fetching programs from input and secondary memory and bringing them to primary memory
5. Sending results from ALU stored in primary memory to output
The following presentation represents a three-stage illustration of instructions execution from a program
during processing.

However six steps could be involved in execution an instruction by CPU though not each of them are
required for any instructions

Step 1: Fetch instruction


Execution cycle starts with fetching instruction from main memory. The instruction at the current program
counter (PC) will be fetched and will be stored in instruction register (IR).

Step 2: Decode instruction


During this cycle the encoded instruction present in the IR (instruction register) is interpreted by the
decoder.

Step 3: Perform ALU operation


ALU (Arithmetic Logic Unit) is where two operands in the instruction will be operated on given operator in
the instructions. Such as, if the instruction was to add two numbers, then here the addition will happen.
ALU take two values and output the result of the operation.

33
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 33
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Step 4: Access memory


There are only two kinds of instructions that access memory: LOAD and STORE. LOAD copies a value
from memory to a register and STORE copies a register value to memory. Any other instruction skips this
step.

Step 5: Update Register File


In this step, the output/result of the ALU is written back to the register file to update the register file. The
result could also be due to a LOAD from memory. Some instructions don't have results to store. For
example, BRANCH and JUMP instructions do not have any results to store.

Step 6: Update the PC (Program Counter)


Ultimately, at the end of the execution of the current instruction, we need to update the program counter
(PC) to the address of the next instruction, so that we can go back to step 1 where the CPU will fetch
instruction. However, the program counter might need to be set to other memory address than the next one
if the instruction was BRANCH or JUMP

Arithmetic Logic Unit


Various circuits are required to process data or perform arithmetical operations which are connected to
microprocessor's ALU. Accumulator and Data Buffer store data temporarily. These data are processed as
per control instructions to solve problems. Such problems are
- Performing arithmetic operations like +, -, *, on the data available in
accumulator and temporary/general purpose registers.
- Performs logical operations like NOT, AND, OR, X-OR, complemented.
- There can be more than one integrated ALU to speed up arithmetical and logical operations
Organization of ALU

34
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 34
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Registers
- The CPU consists of a number of registers. These registers can be found in processing unit,
Instruction unit or storage and interface Unit.

- These are high speed storage locations that temporarily store data and instructions during
processing. They may store a program instruction while it is being decoded, store data while it is
being processed by the ALU, or store the results of a calculation.

- Register are used to quickly accept, store, and transfer data and instructions that are being used
immediately by the CPU, there are various types of Registers that are used for various purpose.

- These Registers are used for performing the various operations. While we are working on the
system, these Registers are used by the CPU for performing operations. When we gives some input
to the system then the input will be stored into the registers and the system will gives us the results
after processing , the result will also be from the registers.

35
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 35
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Registers Performance:-
i Fetching: The Fetch Operation is used for taking the instructions that are given by the user and
the Instructions that are stored into the Main Memory will be fetch using the registers.

ii Decoding: The Decode Operation is used for interpreting the Instructions meaning the
Instructions are decoded i.e the CPU will find out which Operation is to be performed on the
Instructions.

iii Executing: Execution operation is performed by the CPU and Results produced by the CPU are
then stored into the Memory and after that they are displayed on the user Screen.

Classification of Registers
There are eight addressable 8-bit registers in Intel 8085 microprocessor: A, B, C, D, E, H, L, F, and two 16-
bit registers PC and SP. These registers can be classified as:
1. General Purpose Registers
2. Temporary Registers : a) Temporary data register b) W and Z registers
3. Special Purpose Registers : a) Accumulator b) Flag registers c)
Instruction register
4. Sixteen bit Registers : a) Program Counter (PC) b) Stack Pointer (SP)

1. General Purpose Registers:


- The B, C, D, E, H, and L are 8-bit general purpose registers that can be used as a separate 8-bit
registers or as 16-bit register pairs, BC, DE, and HL. When used in register pair mode, the high
order byte resides in the first register (i.e. in B when BC is used as a register pair) and the low order
byte in the second (i.e. in C when BC is used as a register pair).
2. Temporary Registers
- It is an 8-bit register which is used to hold the data on which the accumulator is computing
operation. It is also called an operand register because it provides operands to ALU. It provides
operands to ALU. ALU can store immediate result in temporary register. It is not accessible by
user.

The two types are:


a. Temporary Data Register
The ALU has two inputs. One input is supplied by the accumulator and other from temporary data
register. The programmer cannot access this temporary data register. However, it is internally used
for execution of most of the arithmetic and logical instructions.
For example: ADD B is the instruction in the arithmetic group of instructions which adds the
contents of register A and register B and stores result in register A. The addition operation is
performed by ALU. The ALU takes inputs from register A and temporary data register. The
contents of register B are transferred to temporary data register for applying second input to the
ALU.
36
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 36
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

b. W and Z registers: W and Z registers are temporary registers. These registers are used to hold 8-bit
data during execution of some instructions. These registers are not available for programmer,
since 8085Microprocessor Architecture uses them internally.
Use of W and Z registers:
The CALL instruction is used to transfer program control to a subprogram or subroutine. This
instruction pushes the current PC contents onto the stack and loads the given address into the PC.
The given address is temporarily stored in the W and Z registers and placed on the bus for the fetch
cycle. Thus the program, control is transferred to the address given in the instruction. XCHG
instruction exchanges the contents of H with D and L with E, at the time of exchange W and Z
registers are used for temporary storage of data.
3. Special Purpose Registers:
i. Register A (Accumulator)
This Register is used for storing not only the results produced by the system but also contains one
of the operands during data processing.
When the CPU generates some results after the processing, all the results are stored into the A
register. In summary
- It is an 8-bitregister.
- It the main register of microprocessor.
- It is also called register ‘A’.
- It is used in the arithmetic and logic operations.
- It always contains one of the operands on which arithmetic/logic has to
be performed.
- After the arithmetic/logic operation, the contents of accumulator are replaced by the result.
ii. Flag Register
Flags are nothing but a group of individual Flip-flops. The flags will show either a logical (0 or 1)
(i.e.) a set or reset depending on the data conditions in accumulator or various other registers. It
alerts the processor that some event has taken place i.e they are used to check the status of
Accumulator after the operation is performed.

For example, if zero value is put into an arithmetic register (accumulator) as a result of an
arithmetic operation or a comparison, then the zero flag will be raised by the CPU. Thus, the
subsequent instruction can check this flag and when a zero flag is "ON" it can take an appropriate
route in the algorithm.

The figure below illustrates flag/status registers used by the Intel 8085 Microprocessor

37
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 37
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Fig: Status Flags

The Intel 8085 processors have a set of 5 flags.


 Carry flag
 Parity flag
 Auxiliary carry flag
 Zero flag
 Sign flag

Consider two binary numbers.


For example:
1100 0000
1000 0000
When we add the above two numbers, a carry is generated in the most significant bit. The number
in the extreme right is least significant bit, while the number in extreme left is most significant bit.
So a ninth bit is generated due to the carry. So how is it to accommodate 9th bit in an 8 bit register?

For this purpose the Carry flag is used.


I. Carry flag
The carry flag is set whenever a carry is generated and reset whenever there is no carry.

38
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 38
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

II. Auxiliary carry flag


But there is an auxiliary carry flag? What is the difference between the carry flag and auxiliary
carry flag?
Let’s discuss with an example. Consider the two numbers given below
0000 0100, 0000 0101
When we add both the numbers a carry is generated in the third bit from the least significant bit.
This sets the auxiliary carry flag. When there is no carry, the auxiliary carry flag is reset.
So whenever there is a carry in the most significant bit Carry flag is set. While an auxiliary carry
flag is set only when a carry is generated in bits other than the most significant bit.

In summery

- It is used in BCD operations.


- If there is carry in BCD addition, auxiliary carry is set(1).
- If there is no carry, auxiliary carry is reset(0).

III. Parity Flag (P)


Parity checks whether it’s even or add parity. This flag returns a 0 if it is odd parity and returns
a 1 if it is an even parity. That is if after any arithmetic or logical operation the result has even
parity, an even number of 1 bits, the parity register becomes set i.e. 1, otherwise it becomes reset
i.e. 0.
1-accumulator has even number of 1 bits
0-accumulator has odd parity
Sometimes they are also called parity bit which is used to check errors while data transmission is
carried out.

IV. Zero (Z)


Zero flag shows whether the output of the operation is 0 or not
- It tells whether the result stored in accumulator is zero or not after the
operation is performed.
39
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 39
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

- If result is zero, zero flag is set(1).


- If result is not zero, zero flag is reset(0).
V. Sign(S)
Sign flag shows whether the output of operation has positive sign or negative sign. A value 0 is
returned for positive sign and 1 is returned for negative sign. That is;
- It tells the sign of result stored in accumulator after the operation is performed.
- If result is –ve, sign flag is set(1).
- If result is +ve, sign flag is reset(0).

4. Instruction Register
An instruction fetched from the memory is temporarily stored in instruction register (IR) prior to its
decoding.
In a typical processor operation, the processor first fetches the opcode of instruction from memory
(i.e. it places an address on the address bus and memory responds by placing the data stored at the
specified address on the data bus).

The CPU stores this opcode in the instruction register. This opcode is further sent to the instruction
decoder to select one of the 256 alternatives.

In a nutshell
It is used to hold the current instruction which the microprocessor is about to execute. That
is, it is used to store the opcode of the current instruction that is being fetched from the
memory before execution.
5. Sixteen Bit Registers
a. Program counters (PC)
- It is a 16 bit register used as memory pointer. It stores the memory address of the next
instruction to be executed. So we can say that this register is used to sequencing the
program. Generally the memory has 16 bit addresses so that it has 16 bit memory. The
program counter is set to 0000H.
- Program Counter acts as a pointer to the next instruction. How processor increments
program counter depends on the nature of the instruction; for one byte instruction it
increments program counter by one, for two byte instruction it increments program counter
by two and for three byte .instruction it increments program counter by three such that
program counter always points to the address of the next instruction.
- In case Of JUMP and CALL instructions, address followed by JUMP and CALL
instructions is placed in the program counter. The processor then fetches the next instruction
from the new address specified by JUMP or CALL instruction.
In a nutshell

40
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 40
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

- The program counter (PC), commonly called the instruction pointer (IP) in Intel x86
microprocessors, and sometimes called the instruction address register, or just part of the
instruction sequencer in some computers.
- It is a 16-bitregister.
- It is used to hold the address of next instruction to be executed.
- The microprocessor increments the value of Program Counter after the
execution of the current instruction, so that, it always points to the next
instruction.

41
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 41
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

b. Stack Pointer (SP)


- A stack pointer is a small register that stores the address of the last program request in
a stack.
- A stack is a specialized buffer which stores data from the top down
- It is also a 16 bit register used as memory pointer.
- The stack is a reserved area of the memory in the RAM where temporary information may
be stored. It is a small register that stores the address of the last program request in a stack.
- When data item is "pulled" or "popped" from the top of a stack, the item is copied from the
address of the stack pointer, and the stack pointer decrements to the next available item at
the top of the stack.
- Given that the stack grows backwards into memory, it is customary to place the bottom of
the stack at the end of memory to keep it as far away from user programs as possible. In the
8085, the stack is defined by setting the SP (Stack Pointer) register.

Stack example

Instruction Decoder
- As mentioned earlier, the processor first fetches the opcode of instruction from memory and
stores this opcode in the instruction register. It is then sent to the instruction decoder.
- Instruction decoder identifies the instructions. It takes the information from instruction
register and decodes the instruction to be performed. The instruction decoder decodes it and
accordingly gives the timing and control signals which control the register, the data buffers,
ALU and external peripheral signals depending on the nature of the instruction.

In a nutshell
- Instruction decoder decodes information present in the instruction register for further
processing.
- It generates various machine cycles depending upon the instruction.
- The machine cycles are then given to the Timing and Control Unit.
42
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 42
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Address Buffer
This is an 8-bit unidirectional buffer. It is used to drive external high order address bus (A15-A8). It is
also used to tri-state the high order address bus under certain conditions such as reset, hold, halt, and when
address lines are not in use.
Address/Data Buffer
- This is an 8-bit bi-directional buffer
- It is used to drive multiplexed address/data bus, i.e. low order addresses bus (A7-A0) and
data bus (D7-D0). It is also used to tri-state the multiplexed address/data bus under certain
conditions such as reset, hold, and halt and when the bus is not in use.
- The contents of the stack pointer and program counter are loaded into the address buffer
and address data buffer. The address and data buffers are used to drive external address and
data buses respectively. As the memory and I/O chips are connected to these buses, the
CPU can exchange desired data to the memory and I/O chips.
- The address-data buffer is not only connected to the external data bus but also to the internal
data bus which consists of 8-bits. The address data buffer can both send and receive data
from internal data bus.

Incrementer/DecrementerAddress Latch
- This is 16-bit register used to increment or decrement the content of the PC or SP as a part
of execution of instruction related to them.
- It is actually a function performed by the ALU. The Incrementer is used to increment the PC
value, after Intel8085 has fetched a byte of the instruction. This way, the PC will be pointing
to the next instruction by the time the current instruction is fully fetched.
- It is also used for the incrementing of the SP value after a byte is popped out of the stack
top.
- The decrementer is used for decrementing the SP value before a byte is pushed above the
stack top. It
Interrupt Control
- Interrupts are used to disrupt the normal sequence of main program execution to draw
CPU’s attention to an external event e.g. a request from an I/O device. When the CPU
receives an interrupt, it temporarily suspends the execution of the current program, attends
to the interrupting device or event, and then returns to continue with the main program
execution.
- The interrupt control block has five interrupt inputs RST 5.5, RST 6.5, RST 7.5, TRAP and
INTR and one acknowledge signal INTA.
Serial I/O Control
- There are two pins in this unit. This unit is used for serial data communication.
- In situations like, data transmission over long distance and communication with cassette
tapes or a CRT terminal, it is necessary to transmit data bit by bit to reduce the cost of
cabling.

43
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 43
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

In serial communication one bit is transferred at a time over a single line. The Intel 8085’s
-
serial I/O control provides two lines, SOD and SID for serial communication.
- The serial output data (SOD) line is used to send data serially and serial input data (SID)
line is used to receive data serially.
Timing and Control Circuitry
- It provides timing and control signal to the microprocessor to perform the various
operations. It has three control signals. It controls all external and internal circuits.

- It operates with reference to clock signal. It synchronizes all the data transfers.
The three control signal:

1. ALE-Arithmetic Latch Enable. This provides control signals to synchronize the


components of microprocessor.
2. RD- This is active low used for reading operation.
3. WR-This is active low used for writing operation.

- There are three status signal used in microprocessor S0, S1 and IO/M. It changes its status
according the input provided to these pins.

- The control circuitry in the Intel 8085 Microprocessor Architecture is responsible for all the
operations. It includes an oscillator and a control-sequencer that produces the control
signals needed for internal and external control.

- The 8085 timing and control unit generates control signals that can be used to select
appropriate external devices and functions to perform READ and WRITE operations and
also to select memory or I/O port.

Index Register
- It is a register common in 8-bit processors but is not specifically incorporated in the Intel
8085 CPU
- It is also known as base register. The Index register is an internal register within the
microprocessor unit whose contents is modified (subtracted from or added to) during the
execution of an instruction to determine the memory location which will be accessed by the
CPU.
- The byte that is added to or subtracted from the Index register contents is called the
Displacement.

Memory Address Register (MAR)


- It is also a register common in 8-bit processors but is not specifically incorporated in the
Intel 8085 CPU
- Memory Address Register (MAR) stores the address information to be communicated to the
outside world. It stores the address to access memory. The information is stored temporarily.
- This is sometimes called a storage address register or an address latching register.

44
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 44
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

- Therefore there are TWO sources of address for the microprocessor address information, the
PC and the MAR.
- The PC is used for the opcode address while the MAR is used for data/operand address. A
multiplexer is used to switch to either the PC or the MAR onto the address bus, depending
on whether the CPU is in opcode fetch cycle or memory read/write cycle.

Memory Buffer Register (MBR) or Memory Data Register (MDR)


- Memory buffer register (MBR) or memory data register (MDR) is the register in a
computer's processor, or central processing unit that stores the data being transferred to and
from the immediate access storage. It stores information that is being sent to, or received
from, the memory along the bidirectional data bus i.e., it holds the contents of data or
instruction read from, or written in memory

Program Status Word(PSW)


The content of Accumulator and Status Flags clubbed together is known as Program Status
Word(PSW).
It is a 16-bitword.

Fig 2.4 Program status word

Index Register
This is a hardware element which holds a number that can be added to (or, in some cases, subtracted from)
the address portion of a computer instruction to form an effective address. It is also known as base
register. An index register in a computer's CPU is a processor register used for modifying operand
addresses during the run of a program.

PIN DIAGRAM AND PIN DESCRIPTION OF INTEL 8085

The 8085 microprocessor is a clock-driven semiconductor device consisting of electronic logic circuits
manufactured by using either a large-scale integration (LSI) or very-large-scale integration (VLSI)
technique. It is capable of performing various computing functions and making decisions to change the
sequence of program execution. It has all the circuitry that makes up a CPU (hence it is a CPU on a single
chip). 8085 microprocessor is a 40 pin IC, DIP package.

45
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 45
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

46
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 46
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

47
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 47
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

48
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 48
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

49
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 49
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

50
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 50
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

51
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 51
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

52
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 52
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

53
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 53
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

54
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 54
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

FUNCTION PERFORMED BY MICROPROCESSOR


All function performed by a microprocessor can by classified in three general categories:-
i. Microprocessor initiated operations.
ii. Internal data operations.
iii. Peripheral (or externally) initiated operations.

1. Microprocessor-Initiated Operations
Generally, microprocessor performs primarily four operations.
a) Memory Read: Reads data from memory.
b) Memory Write: Writes data into memory.
c) I/O read: Accepts data from input devices.
d) I/O Write: Sends data to output devices.
All these operations are part of the communication process between the microprocessor and peripheral
devices (including memory).

To communicate with a peripheral (or a memory location), the microprocessor needs to perform the
following steps:
Step 1: Identify the peripheral or the memory location (with its address).
Step 2: Transfer data
Step 3: Provide timing or synchronization signals.
The 8085 performs these functions using three sets of communication lines called buses: The address bus,
the data bus, and the control bus.

To communication with a memory, for example to read instruction from memory location:-
1- Microprocessor places address on address bus.
2- The address on the bus is decoded.
3- The memory location is identified.
4- The microprocessor sends a pulse called memory read as control signal.
5- The pulse activates the memory chip.
6- The contents of the memory location are placed on the data bus as in the figure below.

55
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 55
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

2. Internal Data Operations:-


The internal architecture of the Intel 8085determines how and what operations can be performed with the
data.These operations are:-
i. Store 8-bit data.
ii. Performs arithmetic and logical operations.
iii. Test for conditions.
iv. Sequence the execution of instructions.
v. Store data temporarily during execution in the
Stack Pointer.
3. Peripheral or Externally Initiated Operations
External devices (or signals) can initiate the following operation for which individual pins on
microprocessor chip are assigned: Reset, Interrupt, Ready, Hold.
a. Reset: when reset is activated all internal operations are suspended and the program counter is
cleared.
b. Interrupt: the microprocessor can be interrupted from normal execution
and asked to execute other instructions called "service routine" (emergency).Microprocessor
resumes its operation after that.
c. Ready: Intel 8085 has pin called ready. If the signal is low microprocessor enters into wait state.
This signal used to synchronize slower peripherals with microprocessor.
d. Hold: when hold pin activated by external signal microprocessor
relinquishes control buses and allows the external peripheral to use the.
For example: Hold signal is used in direct memory access data transfer.

56
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 56
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

OPERATION OF MACHINE CYCLES


Machine Cycle and Instruction Cycle
During normal operation, the microprocessor sequentially fetches and executes one instruction after
another. Timing is provided by the clock. One clock period is called a timing state, or T-state

A T-State is the time period of the one complete cycle of the internal clock signal of the processor.
The time taken to execute a machine cycle is expressed in terms of T-states. In Intel 8085, if the external
clock frequency applied through X1 & X2 pins are 6 MHz; then the internal clock frequency is 3 MHz
.Therefore, one T-State equals to T = 1/F = 1/3MHz = 0.333μs.

T-States
This is one clock period

Machine Cycle
Time required by the microprocessor to complete an operation of accessing memory or input/output
devices. Machine cycle is comprised of some member of T-states.

It is the time required by the microprocessor to complete an operation of accessing memory or


input/output devices is called machine cycle

The five major types of machine cycles a microprocessor can undergo are will be handled later.

Instruction Cycle
This comprise of one or more number of machine cycles. That is the number of timing T-states needed
to fetch and execute an instruction is called Instruction cycle.

The instruction cycle can also be referred to as the fetching and execution of a single instruction. The three-
stage or four steps which the CPU carries each instruction i.e fetch, decode, execute, and store.

Every instruction in the computer is executed by means of machine cycle

57
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 57
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

A machine cycle is a complete fetch-execute operation. Fetch cycle takes 4T-states and execution cycle
takes 3T-states.

Time Delay
The procedure used to design a specific delay is similar to that used to set up a counter. A register is loaded
with a number, depending on the time delay required, and then the register is decremented until it reaches
zero by setting up a loop with a conditional Jump instruction. The loop causes the delay, depending upon
the clock period of the system.

Time Delay Using One Register


A count is loaded in a register and the loop is executed until the count reaches zero. An example of set of
instructions necessary to set up the loop is given below with an 8085-based microcomputer with 2 MHz
clock frequency:

To calculate the time delay in a loop, we must account for the T-states required for each instruction and for
the number of times the instructions are executed in the loop. In above example, register C is loaded with
the count FFH (25510) by the instruction MVI, which is executed once and takes seven Tstates. The next
two instructions, DCR and JNZ, form a loop with a total of 14 (4+10) T-states.
58
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 58
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

The loop is repeated 255 times until register C = 0.


Now, the time delay in the loop TL with 2 MHz clock frequency is calculated as:
TL = (T x Loop T-states x N10)
Where, TL= Time Delay in the Loop
T = System Clock Period
N10= Equivalent Decimal Number of the Hexadecimal Count Loaded in the Delay Register.

Note: The T-states for JNZ instruction are shown as 10/7. This is why the 8085 microprocessor requires
10 T-states to execute a conditional Jump instruction when it jumps or changes the sequence of the
program and 7 T-states when the program falls through the loop (goes to the instruction following the
JNZ). This difference can be accounted for the delay calculation by subtraction the execution time of three
states. Therefore, adjusted loop delay is:

Now the total delay must take into account the execution time of the instructions outside the loop. In the
above example, we have only one instruction (MVI C) outside the loop. Therefore, the total delay is:
Total Delay = Time to Execute Instructions Outside Loop + Time to Execute Loop Instructions

Time Delay Using Register Pair


The time delay can be considerably increased by setting a loop and using a register pair with a 16-bit
number (maximum FFFFH). The 16-bit number is decremented by using the instruction DCX. However,
the instruction DCX does not set the Zero Flag and without the test flags, Jump instructions cannot check
desired data conditions. Additional techniques, therefore, must be used to set the Zero Flag.

The following set of instructions uses a register pair to set up a time delay.

Delay Calculation:
59
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 59
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

The loop includes four instructions: DCX, MOV, ORA and JNZ and takes 24 clock periods for execution.
The loop is repeated 2384H times, which is converted to decimal as:

Time Delay Using a Loop within a Loop Technique


A time delay similar to that of a register pair can also be achieved by using two loops; one loop inside the
other loop as shown in example below.

Delay Calculation:

Let’s further understand the process of delay calculation in 8085 using yet another example. We need to
calculate the exact duration in microseconds or milliseconds which would be provided by given delay
routine.

Assume that 8085 is running at 2MHz frequency so


1 clock duration (T) = 1/f = 0.5usec

1 MVI B, 10H 7 T-States


2 LOOP2 MVI C, FFH 7 T-States
3 LOOP1 DCR C 4 T-States
4 JNZ LOOP1 10/7T-States
5 DCR B 4 T-States
6 JNZ LOOP2 10/7-States
60
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 60
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Now start calculation

NOTE: Always remember to start from inner most loops and then move towards outer loop.

In this program, for sake of simplicity, I have also associated line numbers

Steps:
1. 1st innermost loop is at line no. 3 and 4. Now line 3 and 4 is going to get repeated for FFH or 256
times i.e. (10+4) T-states would be repeated for256 times. But since, in the last iteration, JNZ
condition fails and JZ instruction gets executed. JNZ instruction takes 10 T-states whereas JZ takes 7
T-states. So for 14 T-states are processed for 254 iterations, but in 255th iteration, it took only 11 T-
states, so while calculating:
(255 x 14) - 3 = 3567 T-states
2. Now, these 3567 T-states, along with (7+4+10) T-states are placed in another outer loop, which is
going to rotate for 10H times or 16 times. Don't forget to subtract 3 for the same reason mentioned in
point 1.
( (3567 + 7 + 4 + 10) x 16) - 3 = 57405 T-states
3. Now, combine this value to the T-state of 1st instruction of delay routine
(57405+7) = 57412 T-state
4. Since 1 clock duration = 1 T-state = 0.5usec, so
(57412 x 0.5usec) = 28.706 msec
This given routine is going to generate delay of 28.706 msec. This same process is applied to calculate the
execution time of any 8085 microprocessor program such that user can calculate how responsive system
might be, if the system is running using given program and said specification.

Determine the execution time or the following program segment using Intel 8085 microprocessor with a
system clock frequency of 3 MHZ

Instruction T-States
MVI A, 30H 7
MVI B, 20H 7
ADD B 4
STA 8054 13
HLT 4

Solution
Te = nTc

Where
Te = total execution time
Tc= the period time
n= total number of T-states for the program without loop
61
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 61
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

1
Tc =
f
But f = 3x106 Hz
Tc =1/3x106 Hz
= 0.33333µs
MVI A, 30H 7 X 0.33333µs = 2.333 x10-6
MVI B, 20H 7 X 0.33333µs = 2.333 x10-6
ADD B 4 X 0.33333µs = 1.33 x10-6
STA 8054 13 X 0.33333µs = 4.33 x10-6
HLT 4 X 0.33333µs = 1.33 x10-6
Total 11.65µs

Types of Machine cycles


There are FIVE major types of machine cycles in the Intel 8085 CPU can undergo.
i. Opcode FETCH(4T-states)
ii. Memory READ (3T-states)
iii. Memory WRITE (3T-states)
iv. I/O READ (3T-states)
v. I/O WRITE (3T-states)

Other machine cycles may include


i. Interrupt Acknowledge
ii. Bus Idle

The first machine instruction cycle is always an opcode fetch, and the 8-bit obtained during an opcode
fetch are always interpreted as the opcode of an instruction.

The number of machine cycles required to execute an instruction depends on that particular instruction.

Instruction Format

An instruction is a command to the microprocessor to perform a given task on a specified data.

Each instruction has two parts: one is task to be performed, called the operation code (opcode), and the
second is the data to be operated on, called the operand.
An operand can be:
• A datum
• A register
• A memory location

Fig. Instruction Format


62
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 62
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Instruction Set
This is a complete set of all the instructions in machine code that can be recognized and executed by a
Central Processing unit.

These instructions can be classified into five functional categories:


1. Data Transfer group
2. Arithmetic group
3. Logic group
4. Branch group
5. Control

Some important aspects of the instruction set are noted below:


1. Data Transfer group: This group comprises instructions that move data between internal registers,
between internal register and external memory location and I/O transfer.
Examples
MOV Move
MVI Move Immediate
LDA Load Accumulator Directly from Memory
STA Store Accumulator Directly in Memory
LHLD Load H & L Registers Directly from Memory
SHLD Store H & L Registers Directly in Memory
An 'X' in the name of a data transfer instruction implies that it deals with a register
pair (16-bits);
LXI Load Register Pair with Immediate data
LDAX Load Accumulator from Address in Register Pair
STAX Store Accumulator in Address in Register Pair
XCHG Exchange H & L with D & E
XTHL Exchange Top of Stack with H & L

2. Arithmetic group: Instructions meant for arithmetic operations that add, subtract, increment or
decrement data in a register are put in this group.
Examples
ADD Add to Accumulator
ADI Add Immediate Data to Accumulator
ADC Add to Accumulator Using Carry Flag
ACI Add immediate data to Accumulator Using Carry
SUB Subtract from Accumulator
SUI Subtract Immediate Data from Accumulator
SBB Subtract from Accumulator Using Borrow (Carry) Flag
SBI Subtract Immediate from Accumulator Using Borrow (Carry)
Flag.
INR Increment Specified Byte by One
DCR Decrement Specified Byte by One
INX Increment Register Pair by One
DCX Decrement Register Pair by One
63
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 63
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

DAD Double Register Add; Add Content of Register


Pair to H & L Register Pair

3. Logic group: This group performs logical (Boolean) operations on data in registers and memory and
on conditional flags. The logical AND, OR, and Exclusive OR instructions enables you to set
specific bits in the accumulator ON or OFF.
Examples
ANA Logical AND with Accumulator
ANI Logical AND with Accumulator Using Immediate Data
ORA Logical OR with Accumulator
OR Logical OR with Accumulator Using Immediate Data
XRA Exclusive Logical OR with Accumulator
XRI Exclusive OR Using Immediate Data

The Compare instructions compare the content of an 8-bit value with the contents of the
accumulator;
CMP Compare
CPI Compare Using Immediate Data

The rotate instructions shift the contents of the accumulator one bit position to the left or right:
RLC Rotate Accumulator Left
RRC Rotate Accumulator Right
RAL Rotate Left through Carry
RAR Rotate Right through Carry

Complement and carry flag instructions:


CMA Complement Accumulator
CMC Complement Carry Flag
STC Set Carry Flag

4. Branch group: The branching instructions alter normal sequential program flow, either unconditionally
or conditionally. The unconditional branching instructions are as follows:
JMP Jump
CALL Call
RET Return
Conditional branching instructions examine the status of one of four condition flags to determine whether
the specified branch is to be executed. The conditions that may be specified are as follows:
NZ Not Zero (Z = 0)
Z Zero (Z = 1)
NC No Carry (C = 0)
C Carry (C = 1)
PO Parity Odd (P = 0)
PE Parity Even (P = 1)
P Plus (S = 0)
64
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 64
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

M Minus (S = 1)
Thus, the conditional branching instructions are specified as follows:

Jumps Calls Returns


JC CC RC (Carry)
JNC CNC RNC (No Carry)
JZ CZ RZ (Zero)
JNZ CNZ RNZ (Not Zero)
JP CP RP (Plus)
JM CM RM (Minus)
JPE CPE RPE (Parity Even)
JP0 CPO RPO (Parity Odd)
Two other instructions can affect a branch by replacing the contents or the program counter:
PCHL Move H & L to Program Counter
RST Special Restart Instruction Used with Interrupts
5. Control Instructions
Examples of some of the control instructions are:
I - Enable Interrupt System
DI - Disable Interrupt System
HLT - Halt
NOP - No Operation

Other Instructions are:


Stack Instructions
The following instructions affect the Stack and/or Stack Pointer
PUSH Push Two bytes of Data onto the Stack
POP Pop Two Bytes of Data off the Stack
XTHL Exchange Top of Stack with H & L
SPHL Move content of H & L to Stack Pointer

I/0 instructions
IN Initiate Input Operation
OUT Initiate Output Operation

The operand (or data) can be specified in various ways. It may include 8-bit (or 16-bit) data, an internal
register, a memory location, or 8-bit (or 16-bit) address.

Instruction word size


The Intel 8085 instruction set is classified into the following three groups according to word size:
1. One-word or 1-byte instructions
2. Two-word or 2-byte instructions
3. Three-word or 3-byte instructions

65
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 65
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

In the Intel 8085, "byte" and "word" are synonymous because it is an 8-bit microprocessor. This is not
always true with other microprocessors.
However, instructions are commonly referred to in terms of bytes rather than words.

66
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 66
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

One-Byte Instructions
A 1-byte instruction includes the opcode and operand in the same byte. Operand(s) are internal registers
and are coded into the instruction. For example:

Mnemonic- MOV B, A
Opcode- MOV
Operand- B, A

Mnemonic- ADD B
Opcode- ADD
Operand- B

Mnemonic- CMA
Opcode- CMA
Operand- NA

Other examples of 1 byte instructions are given in the table below

These instructions are 1-byte instructions performing three different tasks.


In the first instruction, both operand registers are specified. In the second instruction, the operand B is
specified and the accumulator is assumed.
67
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 67
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Similarly, in the third instruction, the accumulator is assumed to be the implicit operand. These instructions
are stored in 8-bit binary format in memory; each requires one memory location.

The length of these instructions is 8-bit; each requires one memory location. The mnemonic is always
followed by a letter (or two letters) representing the registers (such as A, B, C, D, E, H, L and SP).

Two-Byte Instructions
In a two-byte instruction, the first byte specifies the operation code and the second byte specifies the
operand. Source operand is a data byte immediately following the opcode. For example:
Instructions require two memory locations to store in the memory.

Assume that the data byte is 32H. The assembly language instruction is written as

Mnemonic- MVI A, 32H


Opcode- MVI
Operand- A, 32H

Mnemonic- MVI B, F2H


Opcode- MVI
Operand- B, F2H

Note – This type of instructions needs two bytes to store the binary codes. The mnemonic is always
followed by 8-bit (byte)

The instruction would require two memory locations to store in memory.


MVI r, data
r  data

Three-Byte Instructions
68
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 68
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

The1st byte specifies opcode and 2nd & 3rd bytes specifies 16-bit address
2nd byte holds the low order address.
3rd byte holds the high order address.
Instructions require three memory locations to store single byte in the memory.

Note that the second byte is the low-order address and the third byte is the high-order address.
Opcode + data byte + data byte

Mnemonic- LDA 2050H


Opcode- LDA
Operand- 2050H

Mnemonic- JMP 2085H


Opcode- JMP
Operand- 2085H

This instruction would require three memory locations to store in memory.


Three byte instructions - opcode + data byte + data byte
LXI rp, data16
rp is one of the pairs of registers BC, DE, HL used as 16-bit registers. The two data bytes are 16-bit data in
L H order of significance.

Note – These instructions would require three memory locations to store the binary codes. The mnemonic
is always followed by 16-bit (or adr).

INSTRUCTION SET 8085


These instructions can be classified into five functional categories:
1. Control Instructions
2. Logical Instructions
3. Branching Instructions
4. Arithmetic Instructions
5. Data Transfer Instructions

Control Instructions
69
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 69
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Opcode Operand Explanation of Description


Instruction

NOP none No operation No operation is performed. The instruction is fetched and


decoded. However no operation is executed.
Example: NOP

HLT none Halt and enter The CPU finishes executing the current instruction and halts any
wait state further execution. An interrupt or reset is necessary to exit from
the halt state.
Example: HLT

DI none Disable The interrupt enable flip-flop is reset and all the interrupts
interrupts except the TRAP are disabled. No flags are affected.
Example: DI

EI none Enable The interrupt enable flip-flop is set and all interrupts are
interrupts enabled. No flags are affected. After a system reset or the
acknowledgement of an interrupt, the interrupt enable flip-flop
is reset, thus disabling the interrupts. This instruction is
necessary to re-enable the interrupts (except TRAP).
Example: EI

RIM none Read interrupt This is a multipurpose instruction used to read the status of
mask interrupts 7.5, 6.5, 5.5 and read serial data input bit. The
instruction loads eight bits in the accumulator with the
following interpretations.
Example: RIM

SIM none Set interrupt This is a multipurpose instruction and used to implement the
mask 8085 interrupts 7.5, 6.5, 5.5, and serial data output. The
instruction interprets the accumulator contents as follows.
Example: SIM

70
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 70
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Logical Instructions
Opcode Operand Explanation of Description
Instruction

CMP R Compare register The contents of the operand (register or memory) are M
M or memory with compared with the contents of the accumulator. Both
accumulator contents are preserved. The result of the comparison is shown
by setting the flags of the PSW as follows:
if (A) < (reg/mem): carry flag is set
if (A) = (reg/mem): zero flag is set
if (A) > (reg/mem): carry and zero flags are reset
Example: CMP B or CMP M

CPI 8-bit Compare The second byte (8-bit data) is compared with the contents of
data immediate with the accumulator. The values being compared remain
accumulator unchanged. The result of the comparison is shown by setting
the flags of the PSW as follows:
if (A) < data: carry flag is set
if (A) = data: zero flag is set
if (A) > data: carry and zero flags are reset
Example: CPI 89H

ANA R Logical AND The contents of the accumulator are logically ANDed with M
M register or the contents of the operand (register or memory), and the
memory with result is placed in the accumulator. If the operand is a
accumulator memory location, its address is specified by the contents of
HL registers. S, Z, P are modified to reflect the result of the
operation. CY is reset. AC is set.
Example: ANA B or ANA M

ANI 8-bit Logical AND The contents of the accumulator are logically ANDed with
data immediate with the
accumulator 8-bit data (operand) and the result is placed in the
accumulator. S, Z, P are modified to reflect the result of the
operation. CY is reset. AC is set.
Example: ANI 86H

XRA R Exclusive OR The contents of the accumulator are Exclusive ORed with M
M register or the contents of the operand (register or memory), and the
memory with result is placed in the accumulator. If the operand is a
accumulator memory location, its address is specified by the contents of
HL registers. S, Z, P are modified to reflect the result of the
operation. CY and AC are reset.
Example: XRA B or XRA M

71
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 71
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

XRI 8-bit Exclusive OR The contents of the accumulator are Exclusive ORed with the
data immediate with 8-bit data (operand) and the result is placed in the
accumulator accumulator. S, Z, P are modified to reflect the result of the
operation. CY and AC are reset.
Example: XRI 86H

ORA R Logical OR The contents of the accumulator are logically ORed with M
M register or the contents of the operand (register or memory), and the
memory with result is placed in the accumulator. If the operand is a
accumulator memory location, its address is specified by the contents of
HL registers. S, Z, P are modified to reflect the result of the
operation. CY and AC are reset.
Example: ORA B or ORA M

ORI 8-bit Logical OR The contents of the accumulator are logically ORed with the
data immediate with 8-bit data (operand) and the result is placed in the
accumulator accumulator. S, Z, P are modified to reflect the result of the
operation. CY and AC are reset.
Example: ORI 86H

RLC none Rotate Each binary bit of the accumulator is rotated left by one
accumulator left position. Bit D7 is placed in the position of D0 as well as in
the Carry flag. CY is modified according to bit D7. S, Z, P,
AC are not affected.
Example: RLC

RRC none Rotate Each binary bit of the accumulator is rotated right by one
accumulator right position. Bit D0 is placed in the position of D7 as well as in
the Carry flag. CY is modified according to bit D0. S, Z, P,
AC are not affected.
Example: RRC

RAL none Rotate Each binary bit of the accumulator is rotated left by one
accumulator left position through the Carry flag. Bit D7 is placed in the Carry
through carry flag, and the Carry flag is placed in the least significant
position D0. CY is modified according to bit D7. S, Z, P, AC
are not affected.
Example: RAL

RAR none Rotate Each binary bit of the accumulator is rotated right by one
accumulator right position through the Carry flag. Bit D0 is placed in the Carry
through carry flag, and the Carry flag is placed in the most significant
position D7. CY is modified according to bit D0. S, Z, P, AC
are not affected.

72
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 72
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Example: RAR

CMA none Complement The contents of the accumulator are complemented. No flags
accumulator are affected.
Example: CMA

CMC none Complement carry The Carry flag is complemented. No other flags are affected.
Example: CMC

STC none Set Carry Set Carry


Example: STC

Branching Instructions
Opcode Operand Explanation of Description
Instruction

JMP 16-bit Jump The program sequence is


address unconditionally transferred to the memory location
specified by the 16-bit address
given in the operand.
Example: JMP 2034H or JMP
XYZ

Flag 16-bit Jump The program sequence is


Opcode Description address conditionally transferred to the memory location
Status
specified by the 16-bit address
JC Jump on Carry CY = 1 given in the operand based on the
Jump on no specified flag of the PSW as
JNC CY = 0
Carry described below.
Jump on Example: JZ 2034H or JZ XYZ
JP S=0
positive
JM Jump on minus S=1
JZ Jump on zero Z=1
JNZ Jump on no zero Z = 0
Jump on parity
JPE P=1
even
Jump on parity
JPO P=0
odd

16-bit Unconditional The program sequence is


Opcode Description Flag
address subroutine call transferred to the memory location
73
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 73
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Status specified by the 16-bit address


given in the operand. Before the
CC Call on Carry CY = 1 transfer, the address of the next
Call on no instruction after CALL (the
CNC CY = 0
Carry contents of the program counter)
CP Call on positive S = 0 is pushed onto the stack.
Example: CALL 2034H or CALL
CM Call on minus S=1 XYZ
CZ Call on zero Z=1
CNZ Call on no zero Z=0
Call on parity
CPE P=1
even
Call on parity
CPO P=0
odd

RET none Return from The program sequence is


subroutine transferred from the subroutine to
unconditionally the calling program. The two
bytes from the top of the stack are
copied into the program counter,
and program execution begins at
the new address.
Example: RET

Flag none Return from The program sequence is


Opcode Description subroutine transferred from the subroutine to
Status
conditionally the calling program based on the
RC Return on Carry CY = 1 specified flag of the PSW as
Return on no described below. The two bytes
RNC CY = 0
Carry from the top of the stack are
Return on copied into the program counter,
RP S=0 and program execution begins at
positive
the new address.
RM Return on minus S = 1 Example: RZ
RZ Return on zero Z=1
Return on no
RNZ Z=0
zero
Return on parity
RPE P=1
even
Return on parity
RPO P=0
odd

74
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 74
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

PCHL none Load program The contents of registers H and L


counter with HL are copied into the program
contents counter. The contents of H are
placed as the high-order byte and
the contents of L as the low-order
byte.
Example: PCHL

RST 0-7 Restart The RST instruction is equivalent


to a 1-byte call instruction to one
of eight memory locations
depending upon the number. The
instructions are generally used in
conjunction with interrupts and
inserted using external hardware.
However these can be used as
software instructions in a program
to transfer program execution to
one of the eight locations. The
addresses are:
Restart
Instruction
Address
RST 0 0000H
RST1 0008H
RST 2 0010H
RST 3 0018H
RST 4 0020H
RST 5 0028H
RST 6 0030H
RST 7 0038H
The 8085 has four additional
interrupts and these interrupts
generate RST instructions
internally and thus do not require
any external hardware. These
instructions and their Restart
addresses are:
Restart
Interrupt
Address

75
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 75
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

TRAP 0024H
RST 5.5 002CH
RST 6.5 0034H
RST 7.5 003CH

Arithmetic Instructions
Opcode Operand Explanation of Description
Instruction

ADD R Add register or The contents of the operand (register or memory) are added
M memory, to to the contents of the accumulator and the result is stored in
accumulator the accumulator. If the operand is a memory location, its
location is specified by the contents of the HL registers. All
flags are modified to reflect the result of the addition.
Example: ADD B or ADD M

ADC R Add register to The contents of the operand (register or memory) and M the
M accumulator with Carry flag are added to the contents of the accumulator and
carry the result is stored in the accumulator. If the operand is a
memory location, its location is specified by the contents of
the HL registers. All flags are modified to reflect the result
of the addition.
Example: ADC B or ADC M

ADI 8-bit data Add immediate to The 8-bit data (operand) is added to the contents of the
accumulator accumulator and the result is stored in the accumulator. All
flags are modified to reflect the result of the addition.
Example: ADI 45H

ACI 8-bit data Add immediate to The 8-bit data (operand) and the Carry flag are added to the
accumulator with contents of the accumulator and the result is stored in the
carry accumulator. All flags are modified to reflect the result of
the addition.
Example: ACI 45H

LXI Reg. pair, Load register pair The instruction loads 16-bit data in the register pair
16-bit data immediate designated in the operand.
Example: LXI H, 2034H or LXI H, XYZ

DAD Reg. pair Add register pair The 16-bit contents of the specified register pair are added
to H and L to the contents of the HL register and the sum is stored in
76
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 76
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

registers the HL register. The contents of the source register pair are
not altered. If the result is larger than 16 bits, the CY flag is
set. No other flags are affected.
Example: DAD H

SUB R Subtract register The contents of the operand (register or memory ) are
M or memory from subtracted from the contents of the accumulator, and the
accumulator result is stored in the accumulator. If the operand is a
memory location, its location is specified by the contents of
the HL registers. All flags are modified to reflect the result
of the subtraction.
Example: SUB B or SUB M

SBB R Subtract source The contents of the operand (register or memory ) and M
M and borrow from the Borrow flag are subtracted from the contents of the
accumulator accumulator and the result is placed in the accumulator. If
the operand is a memory location, its location is specified
by the contents of the HL registers. All flags are modified
to reflect the result of the subtraction.
Example: SBB B or SBB M

SUI 8-bit data Subtract The 8-bit data (operand) is subtracted from the contents of
immediate from the accumulator and the result is stored in the accumulator.
accumulator All flags are modified to reflect the result of the subtraction.
Example: SUI 45H

SBI 8-bit data Subtract The contents of register H are exchanged with the contents
immediate from of register D, and the contents of register L are exchanged
accumulator with with the contents of register E.
borrow Example: XCHG

INR R Increment register The contents of the designated register or memory) are
M or memory by 1 incremented by 1 and the result is stored in the same place.
If the operand is a memory location, its location is specified
by the contents of the HL registers.
Example: INR B or INR M

INX R Increment register The contents of the designated register pair are incremented
pair by 1 by 1 and the result is stored in the same place.
Example: INX H

DCR R Decrement The contents of the designated register or memory are M


M register or decremented by 1 and the result is stored in the same place.
memory by 1 If the operand is a memory location, its location is specified

77
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 77
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

by the contents of the HL registers.


Example: DCR B or DCR M

DCX R Decrement The contents of the designated register pair are decremented
register pair by 1 by 1 and the result is stored in the same place.
Example: DCX H

DAA none Decimal adjust The contents of the accumulator are changed from a binary
accumulator value to two 4-bit binary coded decimal (BCD) digits. This
is the only instruction that uses the auxiliary flag to perform
the binary to BCD conversion, and the conversion
procedure is described below. S, Z, AC, P, CY flags are
altered to reflect the results of the operation.
If the value of the low-order 4-bits in the accumulator is
greater than 9 or if AC flag is set, the instruction adds 6 to
the low-order four bits.
If the value of the high-order 4-bits in the accumulator is
greater than 9 or if the Carry flag is set, the instruction adds
6 to the high-order four bits.
Example: DAA

Data Transfer Instructions


Opcode Operand Explanation of Description
Instruction

MOV Rd, Rs Copy from This instruction copies the contents of the source register
M, Rs source(Rs) to into the destination register; the contents of the source
Rd, M destination(Rd) register are not altered. If one of the operands is a
memory location, its location is specified by the contents
of the HL registers.
Example: MOV B, C or MOV B, M

MVI Rd, data Move immediate 8- The 8-bit data is stored in the destination register or
M, data bit memory. If the operand is a memory location, its location
is specified by the contents of the HL registers.
Example: MVI B, 57H or MVI M, 57H

LDA 16-bit Load accumulator The contents of a memory location, specified by a 16-bit
address address in the operand, are copied to the accumulator.
The contents of the source are not altered.
Example: LDA 2034H

LDAX B/D Reg. Load accumulator The contents of the designated register pair point to a

78
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 78
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

pair indirect memory location. This instruction copies the contents of


that memory location into the accumulator. The contents
of either the register pair or the memory location are not
altered.
Example: LDAX B

LXI Reg. pair, Load register pair The instruction loads 16-bit data in the register pair
16-bit data immediate designated in the operand.
Example: LXI H, 2034H or LXI H, XYZ

LHLD 16-bit Load H and L The instruction copies the contents of the memory
address registers direct location pointed out by the 16-bit address into register
L and copies the contents of the next memory location
into register H. The contents of source memory
locations are not altered.
Example: LHLD 2040H

STA 16-bit 16-bit address The contents of the accumulator are copied into the
address memory location specified by the operand. This is a 3-
byte instruction, the second byte specifies the low-order
address and the third byte specifies the high-order
address.
Example: STA 4350H

STAX Reg. pair Store accumulator The contents of the accumulator are copied into the
indirect memory location specified by the contents of the operand
(register pair). The contents of the accumulator are not
altered.
Example: STAX B

SHLD 16-bit Store H and L The contents of register L are stored into the memory
address registers direct location specified by the 16-bit address in the operand
and the contents of H register are stored into the next
memory location by incrementing the operand. The
contents of registers HL are not altered. This is a 3-byte
instruction, the second byte specifies the low-order
address and the third byte specifies the high-order
address.
Example: SHLD 2470H

XCHG none Exchange H and L The contents of register H are exchanged with the
with D and E contents of register D, and the contents of register L are
exchanged with the contents of register E.
Example: XCHG

79
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 79
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

SPHL none Copy H and L The instruction loads the contents of the H and L
registers to the stack registers into
pointer the stack pointer register, the contents of the H register
provide the high-order address and the contents of the L
register provide the low-order address. The contents of
the H
and L registers are not altered.
Example: SPHL

XTHL none Exchange H and L The contents of the L register are exchanged with the
with top of stack stack location pointed out by the contents of the stack
pointer register. The contents of the H register are
exchanged with the next stack location (SP+1); however,
the contents of the stack pointer register are not altered.
Example: XTHL

PUSH Reg. pair Push register pair The contents of the register pair designated in the
onto stack operand are copied onto the stack in the following
sequence. The stack pointer register is decremented and
the contents of the high order register (B, D, H, A) are
copied into that location. The stack pointer register is
decremented again and the contents of the low-order
register (C, E, L, flags) are copied to that location.
Example: PUSH B or PUSH A

POP Reg. pair Pop off stack to The contents of the memory location pointed out by the
register pair stack pointer register are copied to the low-order register
(C, E, L, status flags) of the operand. The stack pointer is
incremented by 1 and the contents of that memory
location are copied to the high-order register (B, D, H, A)
of the operand. The stack pointer register is again
incremented by 1.
Example: POP H or POP A

OUT 8-bit port Output data from The contents of the accumulator are copied into the I/O
address accumulator to a port port specified by the operand.
with 8-bit address Example: OUT F8H

IN 8-bit port Input data to The contents of the input port designated in the operand
address accumulator from a are read and loaded into the accumulator.
port with 8-bit Example: IN 8CH
address

80
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 80
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

ADDRESSING MODES OF 8085

It is define as the way in which data is addressed in the operand part of the instruction. It
indicates to the CPU from where to finds or get data and where to store results
When a CPU executes an instruction, it needs to know where to get data and where to store results.
Such information is specified in the operand fields of the instruction.

To perform any operation, we have to give the corresponding instructions to the microprocessor. In each
instruction, programmer has to specify three things:
1. Operation to be performed.
2. Address of source of data.
3. Address of destination of result.
The term addressing mode refers to the way in which the operand of the instruction is specified.
The Intel 8085 has the following 5 different types of addressing.
1. Immediate Addressing
2. Direct Addressing
3. Register Addressing
4. Register Indirect Addressing
5. Implied Addressing

1. Immediate Addressing
In immediate addressing mode the:
- Data is specified in the operand part of instruction immediately.
- Data is stored along with the instruction and it is directly transferred to the register.
Example
MVI B, 3EH - Move the data 3EH given in the instruction to B register
MVI is the operation (task)
B is the destination
3EH is the immediate data (source)

MVI A, 05 H Move 05 H in accumulator.


MVI is the operation.
05 H is the immediate data (source).
A is the destination.

Mores examples:
MVI B, 45H (move the data 45H immediately to register B)
LXI H 3050H (load the register H-L pair with the operand 3050H immediately)
JMP address (jump to the operand address immediately)

ADI DATA ; Add immediate the data to the contents of the accumulator.
MVI 08H ; Move the data 08 H immediately to the accumulator
SUI 05H ; Subtract immediately the data 05H from the accumulator
MVI A 0FH; Load OFH to register Accumulator
81
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 81
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

LXI D FFF0H; load FFF0H to the D-E register pair.


Here F0H – Lower byte and FFH – Higher byte.
After the execution of the above instructions,
(A) = 0FH and (D)(E)=FFF0H.

2. Direct Addressing
In direct addressing mode:
- The data to be operated on is available inside a memory location and that memory
location is directly specified as an operand. The operand is directly available in the
instruction itself.
- That is, the data is stored in the memory and the exact memory location is specified in the
instruction. The memory address is specified as the lower order in byte3, and the higher
order in byte 2 of the address.
- In this addressing mode, the program instructions and data can be stored in different
memory.
Example
LDA 1050H - Load the data available in memory location 1050H in to accumulator; SHLD 3000H 19
LD is the operation (Task)
A is the destination
1050H is the address of source (i.e. memory address where the data is located)

LDA 2500 H Load the contents of memory location 2500 H into accumulator.
LD is the operation (Task)
A is the destination
2500 H is the address of source (i.e. memory address where the data is located)

LDA 2050 (load the contents of memory location into accumulator A)


LHLD address (load contents of 16-bit memory location into D-E register pair)
IN 35 (read the data from port whose address is 01)
STA 8000H; Store the contents of the Accumulator in the location 8000H
IN 01H; Read the data from port whose address is 01H.

82
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 82
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Other examples

3. Register Addressing
In register addressing mode:
- The instruction specifies the name of the register in which the data is available. That is,
in this addressing mode data is specified through register in operand part of instruction.
- The data to be operated is available inside the register(s) and register(s) is(are) operands.
Therefore the operation is performed within various registers of the microprocessor.
- Operands are the names of internal register. The processor gets data from the register
specified by instruction.

Example
MOV A, B - Move the content of B register to A register; SPHL; ADD C.
MOV is the operation
B is the source
A is the destination
Other examples
MOV A, B (move the contents of register B to register A)
ADD B (add contents of registers A and B and store the result in register A)
INR A (increment the contents of register A by one)
SUB D; subtract the contents of D register from Accumulator.
ADD B, C; Add the contents of C register to the contents of B register.

MOV B, D; move the contents of register D to register B.


INX H; Increment the contents of H-L register pair.

Originally,
(B) = 0FH and (D) = 1FH
and (H) = 0FH and (L) = 1AH

After the execution of above instructions,


(B) = 1FH, (D) = 1FH and,
(H)(L) = 0F1BH

83
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 83
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

4. Register Indirect Addressing


In register indirect addressing mode,
- The instruction specifies the name of the register in which the address of the data is
available. Here the data will be in memory and the address will be in the register pair.
- That is, the data to be operated on is available inside a memory location and that memory
location is indirectly specified b a register pair.
- the address of the operand is given in an indirect way with the help of a register pair
- The data is stored in memory and the address of memory location is stored in a
register pair (H-L, B-C, or D-E). The first register of the register pairs (H, B and D),
contains the higher order byte and the second register contains the low order byte.
Example
MOV A, M (Move data from memory location specified by H-L pair to accumulator.)
MOV is the operation (task)
M is the memory location specified by H-L register pair.
A is the destination

LDAX B (move contains of B-C register to the accumulator)


LXIH 9570H : Load immediate the H-L pair with the address of the location 9570H

Other examples

5. Implied Addressing
84
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 84
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

In implied addressing mode,


- The instruction itself specifies the data to be operated.
- The operand is hidden and the data to be operated on is available in the instruction itself.
- The operand is supposed to be present generally in accumulator
Example
CMA - Complement the content of accumulator. This finds the 1’s complement of the content of
accumulator A and stores the results in the A
CMA is the operation
A is the source
A is the destination

RRC (rotate accumulator A right by one bit)


RLC (rotate accumulator A left by one bit)
CMC; Complement carry
RLC; Rotate Accumulator left by one bit
RRC; Rotate Accumulator right by one bit
STC; Set carry.

Other examples

85
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 85
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING

THE MEANING OF INSTRUCTIONS

86
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 86
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

High-Level Languages
The solution to many of the difficulties associated with assembly language programs is to use, instead,
"high-level" or procedure-oriented" languages. Such languages allow you to describe tasks in forms that
are problem oriented rather than computer oriented. Each statement in a high-level language performs a
recognizable function; it will generally correspond to many assembly language instructions. A program
called a compiler translates the high-level language source program into object or machine language
instructions.
87
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 87
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Many different high-level languages exist for different types of tasks. If, for example, you can express what
you want the computer to do in algebraic notation, you can write your program in FORTRAN (Formula
Translation Language), the oldest and most widely used of the high-level languages. Now, if you want to
add two numbers, you just tell the computer:
SUM = NUMB1+NUMB2

That is a lot simpler (and a lot shorter) than either the equivalent machine language program or the
equivalent assembly language program. Other high-level languages include COBOL (for business
applications).ALGOL (another algebraic language), PL/I (a combination of FORTRAN, ALGOL, and
COBOL), and APL and BASIC (languages that are popular for time-sharing systems).

The general advantages and disadvantages of high-level languages are:


Advantages:
• More convenient descriptions of tasks
• More efficient program writing
• Easier documentation
• Standard syntax
•Independence of the structure of a particular computer
•Portability
•Availability of library and other programs
Disadvantages:
•Special rules
• Extensive hardware and software support required
•Orientation of common languages to algebraic or business problems
•Inefficient programs
•Difficulty of optimizing code to meet time and memory requirements
• Inability to use special features of a computer conveniently

In a nutshell
Instruction consists of a mnemonic and one or two operands (data).
Machine Language: Consist of 0s and1s.
Assembly Languages: Uses short form notations, called, mnemonics, to write a program .The Mnemonics
are like MOV , ADD , SUB, etc.
High level languages: It uses English like sentences with proper syntax to write a program.
Assembler translates Assembly language program into machine code.
Compilers like Pascal, Basic, C etc translate the HLL program into machine code. The programmer does
not have to be concerned with internal details of the CPU.

88
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 88
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

INSTRUCTION CODE MNEMONICS

THE ASSEMBLER PROGRAM


An assembly language is a low-level programming language for microprocessors and other
programmable devices. It is not just a single language, but rather a group of languages. An assembly
language implements a symbolic representation of the machine code needed to program a given CPU
architecture. Assembly language is also known as assembly code
Advantages of Assembly Language
1. Programs written in machine language are replaceable by mnemonics which are easier to remember.
2. Memory Efficient.
3. It is not required to keep track of memory locations.
4. Faster in speed.
5. Easy to make insertions and deletions.
6. Hardware Oriented.
7. Requires fewer instructions to accomplish the same result.
Disadvantages of Assembly Language
1. Long programs written in such languages cannot be executed on small sized computers.
2. It takes lot of time to code or write the program, as it is more complex in nature.
89
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 89
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

3. Difficult to remember the syntax.


4. Lack of portability of program between computers of different makes.
5. No SDKs (System Development Kit).

Flowcharts
What is a Flowchart?
Flowchart is a graphical representation of an algorithm. Programmers often use it as a program-planning
tool to solve a problem. It makes use of symbols which are connected among them to indicate the flow of
information and processing.
The process of drawing a flowchart for an algorithm is known as “flowcharting”.

The following are basic Symbols used in flowchart designs


1. Terminal: This is an oval symbol indicating Start, Stop and Halt in a program’s logic flow. A
pause/halt is generally used in program logic under some error conditions. Terminal is the first and last
symbols in the flowchart.

2. Input/output: This is depicted by parallelogram, denoting any function of input/output type. Program
instructions that take input from input devices and display output on output devices are indicated with
parallelogram in a flowchart.

3. Processing: This is represented by box, depicting arithmetic instructions. All arithmetic processes
such as adding, subtracting, multiplication and division are indicated by action or process symbol.

4. Decision This is represented by a diamond symbol depicting, a decision point. Decision based
operations such as yes/no question or true/false are indicated by diamond in a flowchart.

90
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 90
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

5. Connectors: Whenever flowchart becomes complex or it spreads over more than one page, it is useful
to use connectors to avoid any confusions. It is represented by a circle.

6. Flow lines: Flow lines indicate the exact sequence in which instructions are executed. Arrows
represent the direction of flow of control and relationship among different symbols of flowchart.
Example of a flow chart

91
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 91
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

92
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 92
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

93
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 93
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

94
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 94
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Assembler instructions
The assembly text is usually divided into fields, separated by spaces and tabs. A format for a typical line
from assembly language program can be given as

Label : Mnemonic Operand1, Operand2 ; Comment. The fields, as shown in Table 2-1.

95
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 95
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

The operation code field is the only field which can never be empty; it always contains either an instruction
mnemonic or directive to the assembler, called a pseudo-instruction, pseudo-operation, or pseudo-op.

The address field may contain an address or data, or it may be blank.

The comment and label fields are optional. A programmer will assign a label to a statement or add a
comment as a personal convenience, e.g., to make the program easier to read.

LABELS
The label field is the first field in an assembly language instruction; it may be blank. If a label is present,
the assembler assigns to the label the value of the address for the memory location into which the first
object program byte for that instruction is loaded. You may subsequently use the label as an address or as
data in another instruction's operand field. The assembler will replace the label with the assigned value
when creating an object program.

Labels are most frequently used in Jump, Call or Branch instructions. These instructions place a new value
in the Program Counter and so alter the normal sequential execution of instructions. JUMP 15016 means
"place the value 15016 in the Program Counter". The next instruction to be executed will be the one in
memory location 15016- The instruction JUMP START means "place the value assigned to the label
START in the Program Counter". The next instruction to be executed will be the one in the memory
location to which the label START has been assigned. Table 2-3 contains an example.

96
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 96
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

When the machine language version of this program is executed, the instruction JUMP START causes the
address of the instruction labeled START to be placed in the Program Counter. The instruction with the
label START will be executed next.
Why use a label?
Here are some reasons:
1) A label makes a program location easier to find and remember.
2) The label can be moved to correct a program. You do not have to change any subsequent label
references; the assembler will make all the necessary changes.
3) The assembler or loader can relocate the whole program by adding a constant (are location
constant) to each address in which a label was used. Thus we can move the program to allow for the
insertion of other programs or simply to rearrange memory.
4) The program is easier to use as a library program, i.e., it is easier for someone else to take your
program and add it to some totally different program.
5) You co not have to figure out memory addresses. Figuring out memory addresses is particularly
difficult with microprocessors which have instructions that vary in length. It makes sense to assign
a label to any instruction which you might want to use as destination or otherwise identify.

Assembler operation codes (mnemonics)


The main task of the assembler is the translation of mnemonic operation codes into their binary
equivalents. The assembler performs this task using a fixed table much as you would if you were doing the
assembly by hand.

The assembler must, however, do more than just translate the operation codes. It must also somehow
determine how many operands the instruction requires and what type they are. This may be rather complex
—some instructions (like a Halt) have no operands, others (like an Addition or a Jump instruction) have
one, while still others (like a transfer between registers or a multiple-bit shift) require two. Some
instructions
may even allow alternatives, e.g., some computers have instructions (like Shift or Clear) which can either
apply to the Accumulator or to a memory location. We will not discuss how the assembler makes these
distinctions; we will just note that it must do so.

97
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 97
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

98
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 98
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

PSEUDO-OPERATIONS
Some assembly language instructions are not directly translated into machine language instructions.
These instructions are directives to the assembler; they assign the program to certain areas in memory,
define symbols, designate areas of RAM for temporary data storage, place tables or other fixed data in
memory, and perform other housekeeping functions.

To use these directives or pseudo-operations a programmer places the pseudo-operation's mnemonic in the
operation code field, and an address or data in the address field, if the specified pseudo-operation requires
it.
The most common pseudo-operations are:
DATA
EQUATE or DEFINE
ORIGIN
RESERVE
Different assemblers use different names for these operations but the purposes are the same. Housekeeping
pseudo-operations include:
END
LIST
NAME
PAGE
SPACE
TITLE

THE DATA PSEUDO-OPERATION


The DATA pseudo-operation allows the programmer to enter data into program memory. This data may
include:
• Lookup tables
• Code conversion tables
• Messages
• Synchronization patterns
• Thresholds
• Names
• Coefficients for equations
• Commands
• Conversion factors
• Weighting factors
• Characteristic times or frequencies
• Subroutine addresses
• Key identifications
• Test patterns
• Character generation patterns
• Identification patterns
• Tax tables
• Standard forms
• Masking patterns
99
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 99
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

The DATA pseudo-operation treats the data as a permanent part of the program. The format of a DATA
pseudo-operation is usually quite simple. An instruction like:
DZCON DATA 12
will place the number 1 2 in the next available memory location and assign that location the name DZCON.
Usually every DATA pseudo-operation has a label, unless it is one of a series of DATA pseudo-operations.
The data and label may take any form that the assembler permits.

Most assemblers allow more elaborate DATA instructions which handle a large amount of data at one time,
e.g.,
EMESS DATA 'ERROR'
SQRS DATA 1,4.9.16,25
A single instruction may fill many words of program memory, limited only by the length of a line. Note
that if you cannot get all the data on one line, you can always follow one
DATA instruction with another, e.g.
MESSG DATA 'NOW IS THE'
DATA TIME FOR ALL'
DATA 'GOOD MEN'
DATA TO COME TO THE'
DATA 'AID OF THEIR'
DATA 'COUNTRY'
Microprocessor assemblers typically have some variations of standard DATA pseudo-operations. DEFINE
BYTE OR FORM CONSTANT BYTE handles 8-bit numbers; DEFINE WORD OR FORM CONSTANT
WORD handles 16-bit numbers or addresses. Other special pseudo-operations may handle character-coded
data.

THE EQUATE (or EQUALS) PSEUDO-OPERATION


The EQUATE pseudo-operation allows the programmer to DEFINING
equate labels and names with addresses or data. These pseudo- NAMES
operation is almost always given the mnemonic EQU. The
names may refer to device addresses, numeric data, starting addresses, fixed addresses,
etc.
The EQUATE pseudo-operation assigns the numeric value in its operand field to
the label in its label field. Here are two examples:
TTY LAST EQU
EQU 5 5000
Most assemblers will allow you to define one label in terms of another, e.g.
LAST ST1 EQU
EQU FINAL START+1

The label in the operand field must, of course, have been previously defined. Often, the operand field may
contain more complex expressions, as we shall see later. Double name assignments (two names for the
same data or address) may be useful in patching together programs which use different names for the same
variable (or different spellings of what was supposed to be the same name).
Note that an EQU pseudo-operation does not result in the assembler placing anything into memory. It
simply places an additional name in a table (called a symbol table) which the assembler maintains.
100
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 100
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

ADDRESSES AND THE OPERAND FIELD

Most assemblers allow the programmer a lot of freedom in describing the contents of the Operand Address
field. But remember, the assembler has built-in names for registers and instructions and may have other
built-in names.
Some common options for the operand field are:
1) Decimal numbers
Most assemblers assume all numbers to be decimal unless they are marked otherwise. So
ADD 100
means "add the contents of memory location 100 decimal to the contents of the accumulator".
2) Other number systems
Most assemblers will also accept binary, octal, or hexadecimal entries. But you must identify these
number systems in some way, e.g., by preceding or following the number with an identifying
character or letter. Here are some common identifiers:
B for binary
0, Q, or C for octal (we avoid O because of the confusion with zero).
H for hexadecimal (or standard BCD)
D for decimal. D may be omitted, it is the default case.
Assemblers generally require hexadecimal numbers to start with a digit (e.g., 0A36 instead
of A36) in order to distinguish between numbers and names or labels. It is good practice to enter
numbers in the base in which their meaning is the clearest — i.e., decimal constants in decimal;
addresses and BCD numbers in hexadecimal; masking patterns or bit outputs in binary if they are
short, and in hexadecimal if they are long.
3) Symbolic names
Names can appear in the operand field; they will be treated as the data which they represent. But
remember. there is a difference between data and addresses. The sequence
FIVE EQU 5
ADD FIVE
will add the contents of memory location 5 (not necessarily the number 5) to the contents of the
accumulator.

4) The current value of the location counter (usually referred to as * or $).


This is useful mainly in Jump instructions; for example:
JUMP $+6
causes a Jump to the memory location six words beyond the word which contains the
first byte of the JUMP instruction:

101
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 101
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Most microprocessors have many two and three-word instructions. Thus you will have difficulty
determining exactly how far apart two assembly language statements are. Therefore, using offsets
from the Location Counter frequently results in errors which you can avoid if you use labels.
5) Character codes
Most assemblers allow text to be entered as ASCII strings. Such strings may be surrounded either
with single or double quotation
marks; strings may also use a beginning or ending symbol such as A or C. A few assemblers also
permit EBCDIC strings.
We recommend that you use character strings for all text. It improves the clarity and readability of
the program.

6) Combination of 1 through 5 with arithmetic, logical, or special operators.


Almost all assemblers allow simple arithmetic combinations such as START+1. Some assemblers
also permit multiplication, division, logical functions, shifts, etc. These are referred to as
expressions. Note that the assembler evaluates expressions at assembly time. Even though an
expression in the operand field may involve multiplication, you may not be able to use
multiplication in the logic of your own program — unless you write a subroutine for that specific
purpose.

Assemblers vary in what expressions they accept and how they interpret them. Complex
expressions make a program difficult to read and understand. We have made some
recommendations during this section but will repeat them and add others here. In general, the user
should emphasize clarity and simplicity. There is
no payoff for being an expert in the intricacies of the assemblers or in having the most complex
expression on the block. We suggest the following approach:

1. Use the clearest number system or character code for data.


2. Masks and BCD numbers in decimal, ASCII characters in octal, or ordinary numerical
constants in hexadecimal serve no purpose and therefore should not be used.
3. Remember to distinguish data and addresses.
4. Don't use offsets from the Location Counter.
5. Keep expressions simple and obvious. Don't rely on obscure features of the assembler.

102
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 102
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

CONDITIONAL ASSEMBLY
Some assemblers allow you to include or exclude parts of the source program, depending
on conditions existing at assembly time. This is called conditional assembly; it gives the assembler
some of the flexibility of a compiler. Most microcomputer assemblers have limited capabilities for
conditional assembly. A usual form is:
IF COND
.
CONDITIONAL PROGRAM
.
.
.
ENDIF
If the expression COND is true at assembly time, the instructions between IF and ENDIF(two pseudo-
operations) are included in the program.

Typical uses of conditional assembly are:


1. To include or exclude extra variables.
2. To place diagnostics in test runs.
3. To allow data of various bit lengths.
Unfortunately, conditional assembly tends to clutter programs and make them difficult
to read. Use conditional assembly only if it is necessary.

MACROS
You will often find that particular sequences of instructions occur many times in a source program.
Repeated instruction sequences may reflect the needs of your program logic, or they may be compensating
for deficiencies in your microprocessor's instruction set .You can avoid repeatedly writing out the same
instruction sequence by using a macro.

Macros allow you to assign a name to an instruction sequence. You then use the macro name in your
source program instead of the repeated instruction sequence. The assembler will replace the macro name
with the appropriate sequence of instructions. This may be illustrated as follows:

103
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 103
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Macros are not the same as subroutines. A subroutine occurs once in a program, and program execution
branches to the subroutine. A macro is expanded to an actual instruction sequence each time the macro
occurs; thus a macro does not cause any branching.

Macros have the following advantages:


1. Shorter source programs.
2. Better program documentation.
3. Use of debugged instruction sequences — once the macro has been debugged,
you are sure of an error free instruction sequence every time you use the macro.
4. Easier changes. Change the macro definition and the assembler makes the change
for you every time the macro is used.
5. Inclusion of commands, keywords, or other computer instructions in the basic instructionset.
You use the macro as an extension of your instruction set.
104
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 104
BY MR. AKETCH – A TVET TRAINER - KENYA COAST NATIONAL POLY
13/02/2019

Disadvantages of macros are:


1. Repetition of the same instruction sequences.
2. A single macro may create a lot of instructions.
3. Lack of standardization.
4. Possible effects on registers and flags that may not be clearly stated. One problem is that variables
used in a macro are only known within it (i.e., they are local rather than global). This can often
create a great deal of confusion without any gain in return. You should be aware of this problem
when using macros.

COMMENTS
All assemblers allow you to place comments in a source program. Comments have no effect on the object
code, but they help you to read, understand, and document the program. Good commenting is an essential
part of writing assembly language programs; without comments programs are very difficult to understand.

Use comments to tell what the program is doing, not what instructions do.
Comments should say things like "IS TEMPERATURE ABOVE LIMIT?", "LINE FEEDTO TTY", OR
"EXAMINE LOAD SWITCH".

LOADERS
The loader is the program which actually takes the output (object code) from the assembler and places it in
memory. Loaders range from the very simple to the very complex.

105
BY M R. AKE TCH – A TVE T TRAINER - KENYA CO AST NATIO NAL POLY 13/ 02/2019

P a g e | 105

You might also like