Professional Documents
Culture Documents
AUTHOR VETTED BY
DR. MK MUNJI DR. RL NYENGE
Copyright © 2020
All Rights Reserved.
INTRODUCTION
Welcome to this module. You probably have heard about the term microprocessor. You could
have formed and developed your own versions of what the term constitutes. In this module,
we will introduce you to the basic concepts in microprocessors and why you should study it.
This is an interactive instructional module that uses both action and collaborative learning
styles that provide you with diverse online learning experiences and effective learning
processes. The key purpose of this module is to expose you theoretically to the various types
of microprocessors in use, how they were developed, designed and applied to computers and
other microprocessor-based systems. This should hopefully equip you with the necessary
attitudes, knowledge and skills crucial in developing microprocessor systems to those who
would like to major in electronics.
Computing digital systems are designed to store, process, and communicate information in
digital form. They are found in a wide range of applications, including process control,
communication systems, digital instruments, and consumer products. A digital computer,
more commonly called simply a computer, is an example of a typical digital system.
The basic blocks of a computer are the central processing unit (CPU), the memory, and the
input/output (I/O). The CPU of a computer is basically the same as the brain of a human
being; so computer memory is conceptually similar to human memory. A question asked of a
human being is analogous to entering a program into a computer using an input device such
as a keyboard, and a person answering a question is similar in concept to outputting the
program result to a computer output device such as a printer. The main difference is that
human beings can think independently, whereas computers can only answer questions for
which they are programmed. Computer hardware includes such components as memory,
CPU, transistors, etc
We hope that you will find this module exciting, educative, and engaging. We also hope that
it stimulates your mind so that you can think of microprocessors in computing regardless of
your academic pursuits. After all, computing cuts across all fields of study and should be
exploited if motivation allows.
Week 10: 7 Intel 8086/8088 Assembly Language and Machine Language programming
This lesson is will discuss machine and assembly language programming in Intel 8086/8088
microprocessor, Instruction Cycle, machine cycle and Data flow, 8086/8088 instruction set
and assembly programming. The purpose of this lesson is to help learners design and write
assembly language programs for Intel 8086/8088 microprocessor
Troubleshooting
Twitter: @KUDigitalSchool
Facebook: @KUDSVOL
Table of Contents
Inside a microprocessor ..................................................................................................... 10
1.1Introduction ......................................................................................................................... 10
1.2 Lesson Learning Outcomes................................................................................................ 10
1.2.1 History of Microprocessors......................................................................................... 10
Table:1-1 Important Intel Microprocessors ......................................................................... 12
Lesson 2 ............................................................................................................................... 15
Microprocessor Architecture ............................................................................................ 15
2.1 Introduction ........................................................................................................................ 15
2.2 Lesson Learning Outcomes................................................................................................ 15
2.2.1 Von Neumann Architecture ........................................................................................ 15
2.2.2 Parallel processing schemes ........................................................................................ 19
Lesson 3 ............................................................................................................................... 24
Microprocessor Overview ................................................................................................. 24
3.1 Introduction ........................................................................................................................ 24
3.2 Lesson Learning Outcomes................................................................................................ 24
3.2.1 Difference between Microprocessor and Microcontroller .......................................... 24
3.2.2 Organization of a Microprocessor .............................................................................. 29
Lesson four ......................................................................................................................... 37
Microprocessor based systems .......................................................................................... 37
4.1 Introduction ........................................................................................................................ 37
4.2 Lesson Learning Outcomes................................................................................................ 37
4.2.1 Microprocessor based systems .................................................................................... 37
Lesson 5 ............................................................................................................................... 43
The 8085 Microprocessor Architecture ........................................................................... 43
5.1 Introduction ........................................................................................................................ 43
5.2 Lesson Learning Outcomes................................................................................................ 43
5.2.1 PIN arrangement of the 8085 microprocessor. ........................................................... 43
5.2.2 The Internal Organization the 8085 ............................................................................ 44
Lesson 6 ............................................................................................................................... 48
The 8085 Instructions ........................................................................................................ 48
6.1 Introduction ........................................................................................................................ 48
6.2 Lesson Learning Outcomes................................................................................................ 48
6.2.1 Addressing modes of the 8085 .................................................................................... 48
6.2.2 Classification of 8085 microprocessor Instructions .................................................... 49
Lesson 7 ............................................................................................................................... 53
The Stack and Subroutines ............................................................................................... 53
7.1 Introduction ................................................................................................................... 53
7.2 Lesson Learning Outcomes................................................................................................ 53
7.2.1 The Stack and Subroutines.......................................................................................... 53
7.2.2 Movement of data in stacks ........................................................................................ 55
Lesson 8 ............................................................................................................................... 58
Introduction to 8085 Programs......................................................................................... 58
8.1 Introduction ........................................................................................................................ 58
8.2 Lesson Learning Outcomes................................................................................................ 58
8.2.1 Write and Hand Assemble Programs .......................................................................... 58
Lesson 9 ............................................................................................................................... 62
Introduction to 8088/8086 ................................................................................................. 62
9.1 Introduction ........................................................................................................................ 62
9.2 Lesson Learning Outcomes................................................................................................ 62
9.2.1 Intel 8088/8086 Microprocessor Fundamentals.......................................................... 62
The 8086/8088 Instructions ............................................................................................... 74
10.1 Introduction ...................................................................................................................... 74
10.2 Lesson Learning Outcomes.............................................................................................. 74
10.2.1 Addressing modes of the 8086/8088......................................................................... 74
1. Purpose
This course is prepared for fourth year B.Sc. (TIT) students at Kenyatta University. The
course is based on the Intel 8088/8086 microprocessor, and prepares students to solve
practical problems using a microprocessor.
2. Description
Inside the microprocessor: Microprocessor architecture, microprocessor word lengths, types
of memory addressing, internal microprocessor buses, microprocessor registers and the
arithmetic and logic unit.
Microprocessor: Accumulator, status register, program counter, instruction register and
stack pointers.
Features of real microprocessors: data control logic, address control logic, data address
control bus buffers, microprocessor fetch-decode-execute cycle, instruction execution by
microprocessor and arithmetic operation by ALU.
Microprocessor systems: Basic units and application of 8088/8086 microprocessor.
4. Course Requirements
This is a blended learning course that will utilize the flex model. This means that learning
materials and instructions will be given online and the lessons will be self-guided with the
lecturer being available briefly for face to face sessions and support and also on-site (online)
most of the time. Your lecturer will be meeting you face to face to introduce a lesson and put
it into perspective and you will actively participate in your search for knowledge by
undertaking several online activities. This means that some of the 35 instructional hours of
the course will be delivered face to face while other lessons will be taught online through
various learner and lecturer activities. It is important for you to note that one instructional
hour is equivalent to two online hours. Three instructional hours will be needed per week.
Out of these, one will be used for face to face contact with your lecturer (also referred as e-
moderator in the online activities) while the other two instructional hours (translating to four
online hours) will be used for online activities otherwise referred to as e-tivities in the
lessons.
You will be required to participate and interact online with your peers and the e-moderator
who in this case is your lecturer. Guidelines for the online activities (which we shall keep
referring to as e-tivities) will be provided whenever there is an e-tivity. Please note that since
the online e-tivities are part of the learning process, they may be graded at the discretion of
your e-moderator. Such grading will however be communicated in the e-tivity guidelines and
feedback given as soon as possible after the e-tivity. The e-tivities will include but will not be
limited to online assessment quizzes, assignments and discussions. There are also assessment
questions that you can attempt at the end of every lesson to test your understanding of the
lesson. The answers to all the assessment questions are at the end of each lesson.
5. Assessment
The tools include online collaborative discussions forums that focus on team learning and
personal mastery and will therefore provide you with peer feedback, lecturer assessment and
self- reflection. You will also be required to do one major assignment that is meant to assess
the application of the skills and knowledge gained during the course. The project score in
combination with scores for e-tivities (where graded) will account for 30% of your final
examination score with the remaining 70% coming from a face to face sit-in final written
examination that will be guided by your university examination policy and procedures
1.1 Introduction
This lesson is recommended as the starting point for microprocessors and provides a
foundation on which the rest of the units build. The online lessons with readings, video
demonstrations, and activities introduce students to:
Computer's Central Processing Unit (CPU) built on a single Integrated Circuit (IC) is called
a microprocessor.
A digital computer with one microprocessor which acts as a CPU is called microcomputer.
The microprocessor contains millions of tiny components like transistors, registers, and
diodes that work together.
Fair child semiconductors (founded in 1957) invented the first Integrated Circuit in 1959 that
marked the microprocessor history. In 1968, Gordan Moore, Robert Noyce and Andrew
Grove resigned from the Fair child semiconductors and started their own company: Integrated
Electronics (Intel). In 1971, the first microprocessor Intel 4004 was invented. A
microprocessor is also known as a central processing unit in which numbers of peripherals’
are fabricated on a single chip. It has ALU (arithmetic and logic unit), a control unit,
registers, bus systems and a clock to perform computational tasks.
Generation of Microprocessor
1st Generation
This was the period during 1971 to 1973 of microprocessor’s history. In 1971, INTEL created
the first microprocessor 4004 that would run at a clock speed of 108 KHz.With only 4 bits as
the word size, the 4004 could only represent signed numbers in the range -8 to +7, which is
indeed very small. So, it was not really of practical use for arithmetic calculations. However,
it found applications in controlling devices.
2nd Generation
Intel 8008 was the next in the evolution, the first 8-bit microprocessor. This was in the year
1972. This was soon followed by Intel 8080, also an 8-bit microprocessor. Intel 8080 was the
first commercially popular 8bit microprocessor. With 8 bits as the word size, it could
represent signed numbers in the range of −128 to +127. This is also not a good enough range
for performing arithmetic calculations. Thus, the 8080 also was used only for control
applications.
Some other microprocessors like 6800 from Motorola, Z-80 from Zilog were also popular at
this time.
They were costly as they were based on NMOS technology fabrication and also for their
superfast speed.
3rd Generation
Around 1978, Intel released 8086, the first 16-bit microprocessor. With 16-bit word size, it
was possible to represent signed numbers in the range of −32,768 to +32,767, which is quite a
decent range for performing arithmetic calculations. As such, this processor became very
popular not only for control applications, but also for number crunching operations. Speeds
of those processors were four times better than the 2nd generation processors. Not to be
outdone, Motorola came out with 68000, their 16-bit processor. Zilog released Z-8000, again
a 16-bit processor. These are the most popular 16-bit processors.
4th Generation
In the early 80s, Intel released the 32-bit processor, the Intel 80386, by using HCMOS
fabrication. With 32-bit word size, it was possible to represent signed numbers in the range
±2×109, which is quite a large range for performing arithmetic calculations. If floating point
notation is used, it can represent much larger numbers. As such, this processor became very
popular as the CPU in computers for number crunching operations. At this time, Motorola
came out with 68020, their 32-bit processor. Intel released 80486, which was basically an
80386 processor with an 80387 numeric co-processor on a single chip. Motorola released
68030. In the early 90s, Intel released 80586 by the name Pentium processor. It is extremely
fast in performing arithmetic calculations and executing instructions. The Pentium 4 released
in 2000 has 42 Million transistors worked with a clock frequency of 1.5 GHz and is rated for
1500 MIPS (Million instructions per second).
5th Generation
From 1995 to until now this generation has been bringing out high-performance and high-
speed processors that make use of 64-bit processors. The present-day computers based on
microprocessors are already faster than the mini computers and sometimes the main frame
computers of yesteryear, and they are available at a small fraction of the cost of such main
frame computers.
Where,
Bus - Set of conductors intended to transmit data, address or control information to different
elements in a microprocessor. A microprocessor will have three types of buses, i.e., data bus,
address bus, and control bus.
IPC (Instructions Per Cycle) - It is a measure of how many instructions a CPU is capable of
executing in a single clock.
Clock Speed - It is the number of operations per second the processor can perform. It can be
expressed in megahertz (MHz) or gigahertz (GHz). It is also called the Clock Rate.
Word Length - The number of bits the processor can process at a time is called the word
length of the processor. 8-bit Microprocessor may process 8 -bit data at a time. The range of
word length is from 4 bits to 64 bits depending upon the type of the microcomputer.
Data Types - The microprocessor supports multiple data type formats like binary, ASCII,
signed and unsigned numbers.
Lesson 2
Microprocessor Architecture
2.1 Introduction
The microprocessor follows a sequence to execute the instruction: Fetch, Decode, and then
Execute.
Initially, the instructions are stored in the storage memory of the computer in sequential
order. The microprocessor fetches those instructions from the stored area (memory), then
decodes it and executes those instructions till STOP instruction is met. Then, it sends the
result in binary form to the output port. Between these processes, the register stores the
temporary data and ALU (Arithmetic and Logic Unit) performs the computing functions.
The phrase Von Neumann architecture derives from a paper written by computer scientist
John von Neumann in1945. This describes design architecture for an electronic digital
computer with subdivisions of a central arithmetic part, a central control part, a memory to
store both data and instructions, external storage, and input and output mechanisms. The
meaning of the phrase has evolved to mean a stored-program computer. A stored-program
digital computer is one that keeps its programmed instructions, as well as its data, in read-
write, random-access memory (RAM). So John Von Neumann introduced the idea of the
stored program. Previously data and programs were stored in separate memories. Von
Neumann realised that data and programs are indistinguishable and can, therefore, use the
same memory. On a large scale, the ability to treat instructions as data is what makes
assemblers, compilers and other automated programming tools possible. One can "write
programs which write programs". This led to the introduction of compilers which accepted
high level language source code as input and produced binary code as output.
The Von Neumann architecture uses a single processor which follows a linear sequence of
fetch-decode-execute. In order to do this, the processor has to use some special registers,
which are discrete memory locations with special purposes attached. These are:
These are
(i) PC Program Counter
(ii) CIR Current Instruction Register
(iii)MAR Memory Address Register
(iv) MDR Memory Data Register
(v) IR Index Register
(vi) Accumulator Holds results
(i) The program Counter: The program counter keeps track of where to find the next
instruction so that a copy of the instruction can be placed in the current instruction register.
Sometimes the program counter is called the Sequence Control Register (SCR) as it controls
the sequence in which instructions are execute
(ii) The current instruction register holds the instruction that is to be executed.
(iii) The memory address register is used to hold the memory address that contains either
the next piece of data or an instruction that is to be used.
(iv) The memory data register acts like a buffer and holds anything that is copied from the
memory ready for the processor to use it.
The central processor contains the arithmetic-logic unit (also known as the arithmetic unit)
and the control unit. The arithmetic-logic unit (ALU) is where data is processed. This
involves arithmetic and logical operations. Arithmetic operations are those that add and
subtract numbers, and so on. Logical operations involve comparing binary patterns and
making decisions.
The control unit fetches instructions from memory, decodes them and synchronizes the
operations before sending signals to other parts of the computer.
(v) The accumulator is in the arithmetic unit, the program counter and the instruction
registers are in the control unit and the memory data register and memory address register are
in the processor.
(vi) An index register is a microprocessor register used for modifying operand addresses
during the run of a program, typically for doing vector/array operations. Index registers are
used for a special kind of indirect addressing where an immediate constant (i.e. which is part
of the instruction itself) is added to the contents of the index register to form the address to
the actual operand or data.
A typical layout is shown in Fig. 2.1 which also shows the data path
The need for and the use of buses to convey data (Data, Address and Control Buses)
A bus is a set of parallel wires connecting two or more components of the computer.
The CPU is connected to main memory by three separate buses. When the CPU wishes to
access a particular memory location, it sends this address to memory on the address bus. The
data in that location is then returned to the CPU on the data bus. Control signals are sent
along the control bus.
The data, address and control buses connect the processor, memory and I/O controllers.
These are all system buses. Each bus is a shared transmission medium, so that only one
device can transmit along a bus at any one time.
Data and control signals travel in both directions between the processor, memory and I/O
controllers. Address, on the other hand, travel only one way along the address bus: the
processor sends the address of an instruction, or of data to be stored or retrieved, to memory
to an I/O controller.
The control bus is a bi-directional bus meaning that signals can be carried in both directions.
The data and address buses are shared by all components of the system. Control lines must
therefore be provided to ensure that access to and use of the data and address buses by the
different components of the system does not lead to conflict. The purpose of the control bus
is to transmit command, timing and specific status information between system components.
Timing signals indicate the validity of data and address information. Command signals
specify operations to be performed. Specific status signals indicate the state of a data transfer
request, or the status of request by a components to gain control of the system bus.
The data bus, typically consisting of 8, 16, or 32 separate lines provides a bi-directional path
for moving data and instructions between system components. The width of the data bus is a
key factor in determining overall system performance. For example, if the data bus is 8 bits
wide, and each instruction is 16 bits long, then the processor must access the main memory
twice during each instruction cycle.
Address bus: When the processor wishes to read a word (say 8, 16, or 32 bits) of data from
memory, it first puts the address of the desired word on the address bus. The width of the
address bus determines the maximum possible memory capacity of the system. For example,
if the address bus consisted of only 8 lines, then the maximum address it could transmit
would be (in binary) 11111111 or 255 – giving a maximum memory capacity of 256
(including address 0). A more realistic minimum bus width would be 20 lines, giving a
memory capacity of 220, i.e. 1Mb.
Second problem is both data and programs share the same memory space.
This is a problem because it is quite easy for a poorly written or faulty piece of code to write
data into an area holding other instructions, so trashing that program.
Another problem is that the rate at which data needs to be fetched and the rate at which
instructions need to be fetched are often very different. And yet they share the same
bottlenecked data bus. To solve the problem idea of the Harvard Architecture is considered
that to split the memory into two parts: One part for data and another part for programs. Each
part is accessed with a different bus. This means the CPU can be fetching both data and
instructions at the same time. There is also less chance of program corruption. This
architecture is sometimes used within the CPU to handle its caches, but it is less used with
RAM because of complexity and cost.
2.2.2 Parallel processing schemes
Von Neumann architecture is a sequential processing machine but if we could process more
than one piece of data at the same time? This would dramatically speed up the rate at which
processing could occur. This is the idea behind 'parallel processing'. Parallel processing is the
simultaneous processing of data. There are a number of ways to carry out parallel processing;
the table below shows each one of them and how they are applied in real life.
Parallel Processing Systems are designed to speed up the execution of programs by dividing
the program into multiple fragments and processing these fragments simultaneously.
Flynn's Classification
In 1966, Michael Flynn proposed a classification for computer architectures based on the
number of instruction steams and data streams (Flynn’s Taxonomy). Flynn uses the stream
concept for describing a machine's structure. A stream simply means a sequence of items
(data or instructions).
1. Pipelining
Using the Von Neumann architecture for a microprocessor illustrates that basically an
instruction can be in one of three phases. It could be being fetched (from memory), decoded
(by the control unit) or being executed (by the control unit). An alternative is to split the
processor up into three parts, each of which handles one of the three stages. This would result
in the situation shown in Fig. 2.2, which shows how this process, known as pipelining, works
with each single line is a pipeline: Fetch, Decode, Execute.
This helps with the speed of throughput unless the next instruction in the pipe is not the next
one that is needed. Suppose Instruction 2 is a jump to Instruction 10. Then Instructions 3, 4
and 5 need to be removed from the pipe and Instruction 10 needs to be loaded into the fetch
part of the pipe. Thus, the pipe will have to be cleared and the cycle restarted in this case. The
result is shown in Fig. 2.3
With an array processor, a single instruction is issued by a control unit and that instruction is
applied to a number of data sets at the same time. An array processor is a Single Instruction
Multiple Data computer or SIMD. You will find games consoles and graphics cards making
heavy use of array processors to shift those pixels about.
Limitations
This architecture relies on the fact that all data sets are acting on a single instruction.
However, if these data sets somehow rely on each other then you cannot apply parallel
processing. For example, if data A has to be processed before data B then you cannot do A
and B simultaneously. This dependency is what makes parallel processing difficult to
implement. And it is why sequential machines are still extremely common
A good example of this architecture is a supercomputer. For example the massively parallel
IBM Blue Gene supercomputer that has 4,098 processors, allowing for 560 Tera-Flops of
processing. This is applied to problems such as predicting climate change or running new
drug simulations. This is where larger problems that can be broken down into smaller chunks
and processed separately.
But even the humble CPU chip in your personal computers is likely to have multiple cores.
For example the Intel Core Duo has two CPUs (called 'cores') inside the chip, whilst the Quad
core has four. A multi-core computer is a 'Multiple Instruction Multiple Data' computer or
MIMD.
Math co-processor
So far, we have discussed parallel processing as a means of speeding up data processing. This
is fine but it does make an assumption that the Arithmetic Logic Unit (ALU) within the CPU
is perfect for handling all kinds of data. And this is not always true. There are two basic ways
of doing calculations within a CPU that is integer math which only deal with whole numbers
and floating point math which can deal with decimal or fractional numbers.
Large-number ranges are best handled as 'floating-point'. Handling floating point numbers
efficiently requires wide registers to deal with a calculation in one go. And the CPU architect
may not want to dedicate precious hardware space in his CPU for these wider registers So the
idea of a 'Math co-processor' came about. A co-processor is especially designed to carry out
floating point calculation extremely quickly. It co-exists with the CPU on the motherboard.
Whenever a floating point calculation needs to be done, the CPU hands the task over to the
co-processor then carries on with doing something else until the task is complete. The
advantage of having a co-processor is that calculation (and hence performance) is much
faster. The disadvantage is that it is more expensive, requires more motherboard space and
takes more power.
But if the computer is dedicated to handling heavy floating point work then it may be worth
it. For instance a computer within a signal processing card in a communication system may
include a math co-processor to process the incoming data as quickly as possible.
Lesson 3
Microprocessor Overview
3.1 Introduction
Microprocessor is a controlling unit of a micro-computer, fabricated on a small chip capable
of performing ALU (Arithmetic Logical Unit) operations and communicating with the other
devices connected to it.
Microprocessor consists of an ALU, register array, and a control unit. ALU performs
arithmetical and logical operations on the data received from the memory or an input device.
Register array consists of registers identified by letters like B, C, D, E, H, L and accumulator.
The control unit controls the flow of data and instructions within the compute
The term microprocessor came into existence in 1971, when the Intel Corporation developed
the first microprocessor (Intel-4004) which is a 4-bit microprocessor. The 4004 was not very
powerful; it was primarily used to perform simple mathematical operations in a calculator.
An 8-bit processor followed in 1972 and the development has progressed up to the present
64-bit microprocessors. The modern microprocessors can perform extremely sophisticated
operations, and take up much less space as well as delivering superior performance.
Microprocessor
Microprocessor (Fig 3.1 (a)) is an IC which has only the CPU inside them i.e. only the
processing powers such as Intel’s Pentium 1, 2, 3, 4, core 2 duo, i3, i5, i7 etc. A more formal
definition is: a microprocessor is a multipurpose, programmable, clock-driven, register-based
electronic device that reads binary instructions from a storage device called memory, accepts
binary data as input and processes the data according to those instructions, and provides
results as output. These microprocessors don’t have RAM, ROM, and other peripheral on the
chip. A system designer has to add them externally to make them functional.
Microprocessor Microcontroller
(a) (b)
A microprocessor is specified by its word size, e.g. 4-bit, 8-bit, 16-bit etc. The term word size
means the number of bits of data that can be processed by the microprocessor as a unit. It also
specifies the width of the data bus. Thus a 4-bit microprocessor has a word length of 4 bits
and so forth. Application of microprocessor includes:
Microcontroller
Microcontroller has a CPU, in addition to a fixed amount of RAM, ROM and other
peripherals all embedded on a single chip, as shown in Fig 6.1 (b). At times it is also termed
as a mini computer or a computer on a single chip. Unlike a general-purpose computer, which
also includes all of these components, a microcontroller is designed for a very specific task -
to control a particular system. Specific means applications where the relationship of input and
output is defined. Depending on the input, some processing needs to be done and output is
delivered.
The microprocessor follows a sequence: Fetch, Decode, and then Execute. Initially, the
instructions are stored in the memory in a sequential order. The microprocessor fetches those
instructions from the memory, then decodes it and executes those instructions till STOP
instruction is reached. Later, it sends the result in binary to the output port. Between these
processes, the register stores the temporarily data and ALU performs the computing
functions.
Instruction Set − It is the set of instructions that the microprocessor can understand.
Bandwidth − It is the number of bits processed in a single instruction.
Clock Speed − It determines the number of operations per second the processor can
perform. It is expressed in megahertz (MHz) or gigahertz (GHz).It is also known as
Clock Rate.
Word Length − It depends upon the width of internal data bus, registers, ALU, etc.
An 8-bit microprocessor can process 8-bit data at a time. The word length ranges from
4 bits to 64 bits depending upon the type of the microcomputer.
Data Types − The microprocessor has multiple data type formats like binary, BCD,
ASCII, signed and unsigned numbers.
Cost-effective − The microprocessor chips are available at low prices and results its
low cost.
Size − The microprocessor is of small size chip, hence is portable.
Low Power Consumption − Microprocessors are manufactured by using metaloxide
semiconductor technology, which has low power consumption.
Versatility − The microprocessors are versatile as we can use the same chip in a
number of applications by configuring the software program.
Reliability − The failure rate of an IC in microprocessors is very low, hence it is
reliable.
1. RISC Processor
RISC stands for Reduced Instruction Set Computer. It is designed to reduce the execution
time by simplifying the instruction set of the computer. Using RISC processors, each
instruction requires only one clock cycle to execute results in uniform execution time. This
reduces the efficiency as there are more lines of code, hence more RAM is needed to store the
instructions. The compiler also has to work more to convert high-level language instructions
into machine code.
Architecture of RISC
RISC microprocessor architecture uses highly-optimized set of instructions. It is used in
portable devices like Apple iPod due to its power efficiency.
Characteristics of RISC
2. CISC Processor
CISC stands for Complex Instruction Set Computer. It is designed to minimize the number
of instructions per program, ignoring the number of cycles per instruction. The emphasis is
on building complex instructions directly into the hardware.
The compiler has to do very little work to translate a high-level language into assembly level
language/machine code because the length of the code is relatively short, so very little RAM
is required to store the instructions.
IBM 370/168
VAX 11/780
Intel 80486
Architecture of CISC
Its architecture is designed to decrease the memory cost because more storage is needed in
larger programs resulting in higher memory cost. To resolve this, the number of instructions
per program can be reduced by embedding the number of operations in a single instruction.
Characteristics of CISC
oioihoihoihoihpoihoihoi
Variety of addressing modes.
Larger number of instructions.
Variable length of instruction formats.
Several cycles may be required to execute one instruction.
Instruction-decoding logic is complex.
One instruction is required to support multiple addressing modes.
3. Special Processors
These are the processors which are designed for some special purposes. Few of the special
processors are briefly discussed −
Coprocessor
Input/Output Processor
It is a specially designed microprocessor having a local memory of its own, which is used to
control I/O devices with minimum CPU involvement.
For example −
A transputer is a specially designed microprocessor with its own local memory and having
links to connect one transputer to another transputer for inter-processor communications. It
was first designed in 1980 by Inmos and is targeted to the utilization of VLSI technology.
A transputer can be used as a single processor system or can be connected to external links,
which reduces the construction cost and increases the performance.
For example − 16-bit T212, 32-bit T425, the floating point (T800, T805 & T9000)
processors.
This processor is specially designed to process the analog signals into a digital form. This is
done by sampling the voltage level at regular time intervals and converting the voltage at that
instant into a digital form. This process is performed by a circuit called an analogue to digital
converter, A to D converter or ADC.
Program Memory − It stores the programs that DSP will use to process data.
Data Memory − It stores the information to be processed.
Compute Engine − It performs the mathematical processing, accessing the program
from the program memory and the data from the data memory.
Input/Output − It connects to the outside world.
A computer, large or small, can be represented functionally (in a simplified form) by the
block diagram in Figure. 3.2. As shown, it comprises of three basic parts or sub-systems:
1. Microprocessor/processing unit
2. Storage/Memory
3. Input/output devices
Fig 3.2 Block diagram of microprocessor
Typical microprocessor architecture is shown in Figure 3.3. The various functional units are
as follows:
Fig 3.3 Microprocessor Architecture
Busses
Microcomputer, like all computers, manipulates binary information. The binary information
is represented by binary digits, called bits. µC operates on a group of bits which are referred
to as a word. The number of bits making-µP a word varies with the µP. Common word sizes
are: 4, 8, 12 and 16 bits (µPs with 32 bit-word have also of late entered the market). Another
binary terms that will be of interest in subsequent discussions are the byte and the nibble,
which represent a set of 8 bits and 4 bits, respectively.
Figure 3.3 shows busses interconnecting various blocks. These busses allow exchange of
words between the blocks. A bus has a wire or line for each bit and thus allows exchange of
all bits of a word in parallel. The processing of bits in the µP is also in parallel. The busses
can thus be viewed as data highways. The width of a bus is the number of signal lines that
constitute the bus.
The figure shows for simplicity three busses for distinct functions. Over the address bus, the
µP transmits the address of that I/O device or memory locations which it desires to access.
This address is received by all the devices connected to the processor, but only the device
which has been addressed responds. The data bus is used by the µP to send and receive data
to and from different devices (I/O and memory) including instructions stored in memory.
Obviously the address bus is unidirectional and the data bus is bi-directional. The control bus
is used for transmitting and receiving control signals between the µP and various devices in
the system.
Internal Registers
A number of registers are normally included in the microprocessor. These are used for
temporary storage of data, instructions and addresses during execution of a program. Those in
the Intel 8085 microprocessor are typical and are described below:
(i) Accumulator (Acc) or Result Register
This is an 8-bit register used in various arithmetic and logical operations. Out of the two
operands to be operated upon, one comes from accumulator (Acc), whilst the other one may
be in another internal register or may be brought in by the data bus from the main memory.
Upon completion of the arithmetic/logical operation, the result is placed in the accumulator
(replacing the earlier operand). Because of the later function, this register is also called as
result register.
Memories
As mentioned earlier, memories are required in a microprocessor for storing information
which may comprise of:
(a) the data to be used for computation,
(b) instructions and
(c) computational results.
A program starts as a set of instructions on a paper, and then this is transferred to a set of
cards with the instructions punched in code on them. These instructions also can be
transferred to magnetic tape, paper tape or directly into semiconductor memory which is the
eventual storage space for a program. The semiconductor memory chips are connected to the
µP through the address bus, data bus and control bus. (This is also the way that I/O devices
are connected to the µP). See Figure 3.4
Memory Classes
Memories may be broadly divided into two classes:
(a) Random Access Memory (RAM) or Read/Write Memory (RWM)
(b) Read only Memory (ROM)
A RAM can be of static or dynamic type. Dynamic RAMs have higher packing densities, are
faster and consume less power in the quiescent state. However, because of external refreshing
circuitry requirement, the dynamic RAMs are profitable only in large sizes.
Peripheral interfacing
Functions
When one or more I/O devices (peripherals) are to be connected to a microprocessor, an
interface network for each device, called peripheral interface, is required.
The interface incorporates commonly the following four functions:
(a) Buffering: Which is necessary to take care of incompatibility between the µP and the
peripheral.
(b) Address Decoding: Which is required to select one of the several peripherals connected in
the system.
(c) Command Decoding: Required for peripherals that perform actions other than of data
transfers.
(d) Timing and Control: All the above functions require timing and control.
Data Transfer
Data exchange or transfers which occur between a peripheral device and the µC fall into one
of the following two broad categories:
Programming Languages
Software Tools
(i) Assembler
It is a computer program that translates an AL program to ML program (also called object
code). A cross assembler is an assembler that is executed on a machine other than the one for
which it is producing the ML program. A self-assembler or resident assembler, on the other
hand, is meant to be run on the machine for which ML program is required to be produced.
(ii) Compiler
A compiler is a computer program that translates a HLL program to ML program (object
code). Like the assembler, the compiler can be a cross compiler or a self (resident) compiler.
(iii) Editor
During the process of program entry into the memory or debugging, it may be necessary to
make changes in the program text in order to correct any errors or modify the logic. An editor
helps the programmer to do this.
4.1 Introduction
Computer systems have undergone many changes recently. Machines that once filled large
areas have been reduced to small desktop computer systems because of the microprocessor
they possess computing power that was only dreamed of a few years ago. Million-dollar
mainframe computer systems, developed in the earlier are not as powerful as the Pentium
icore-based computers of today
1. Register Array:
Register array is group of registers. Register array contains general purpose registers and
special purpose registers. It is used for temporary storage of data.
Instruction decoding unit decodes the instruction. In order to execute (perform) the operation,
all data should be decoded. The processor cannot perform the execution, if data are not
decoded.
All the arithmetic and logic operations are performed with respect to ALU. The execution is
taken inside the ALU.
In order to perform all the operations, some predefined timing period is required. That is,
with respect to the time period, the processor will works. The control unit releases the control
signal. Control Signal provides control to both the processor and to the peripheral devices.
5. Flag Register:
Flag register is very near to ALU. “Flag register keeps the status of the last operation”. That
is, by the help of flag register, the processor can understand the status of the last operation.
Processor cannot access the data directly from the flag register.
In 8086 Processor, all the general purpose and special purpose registers except decoding
registers are 16 bit registers.
Instruction pointer will store the address of the next instruction to be executed. That is, the
address of the next instruction to be executed is stored in PC.
In 8086, PC is a 16 bit register. This means that, in 8086, 20 address lines are used. So the
8086 has 16-bit registers and 20 address lines.
6. System bus
System bus – 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.
Memory
Memory stores such binary information as instructions and data, and provides that
information to the processor whenever necessary. There are two types of memory; Read-Only
memory (ROM) and Read/Write memory (R/WM) or Random Access Memory (RAM).
ROM is used to store programs that do not need alterations. The RAM is used to store user
programs and data.
Memory Terminology
a) Memory Cell: A device or an electrical circuit used to store a single bit (0 or 1).
Examples of memory cells include flip-flop, a charged capacitor, and a single spot on
a magnetic tape or disk.
b) Bit: Abbreviation for binary digit, e.g. 1001 is a binary number with 4 bits.
c) Memory word: A group of bits (cells) in a memory that represents instructions or
data of some type.
d) Byte: A group of eight bits
e) Capacity: the total number of data units that can be stored. Consider the diagram of
Fig.6.3
Thus a 4K x 20 is (4 x 1024) words x 20, i.e. 4096 x 20, which means 4096 words each of 20
bits. A memory of 2M x 8 is actually (2 x 1048576) x 8 = 2097152 x 8 or 2097152 words
each of 8 bits.
Fig.4.3: A 2-address line memory registers with input and output buffers
Three address lines can be used to address 8 (23) memory locations as follows:
000 0
001 1
010 2
011 3
100 4
101 5
110 6
111 7
Fig. 6.5 shows a memory with 3 address lines; which can address 8 memory locations
(registers, Rn). The RD/ and the WR/ lines determine whether the memory performs a read or
a write operation, respectively.
The 8085 microprocessor has 16 address lines. If all these lines are connected to a single
memory device, it will decode these 16 address lines internally and produce different
addresses from 0000H to FFFFH so that each location in the memory will have a unique
address. The unique patterns from 00000000000000000 to 111111111111111111, represent
65536 different address combinations, or 64K memory locations.
Example 4.1
How many address lines are required to address a memory chip of 256 registers (Locations)?
Solution
2 x 256
By taking logs of both sides
x log 2 2 log 256
log 2 256
x 8
log 2 2
Example 4.2
Calculate the number of address lines required for an 8K-byte memory. How many data lines
does this memory have?
Solution
Memory locations = 8 x 1024 = 8192
Therefore 2 8192
x
5.1 Introduction
The 8085A (popularly known as 8085) is a conventional von Neumann design based on the
Intel 8080. It is designed by using nMOS technology, and includes on its chip most of the
logic circuitry for performing computing tasks and for communicating with peripherals. It has
an 8-bit data bus and a 16-bit address bus. The device has 40 pins, a +5V power supply, and
operates on a 3 to 5 MHz frequency single phase clock. The "5" in the model number came
from the fact that the 8085 requires only a +5-V power supply, rather than requiring the +5 V,
−5 V and +12 V supplies the 8080 needed.
The 8085A uses a multiplexed data bus. The address is split between the 8-bit address bus
and the 8-bit data bus. It is capable of decimal, binary, and double precision arithmetic. It has
a direct addressing capability to 64K bytes of memory.
Fig.5.1: (a) The 8085 Microprocessor pin-out diagram (b) the Intel 8085 chip
Fig. 5.1 shows the logic pin-out and chip of the 8085 microprocessor. To use the 8085 in a
microprocessor-based system, it is useful to know what each pin does. The pins in the 8085
microprocessor pin diagram can be grouped into 6 categories:
1. Power supply & frequency
2. Serial I/O ports
3. Externally initiated & acknowledgement signals
4. Data bus
5. Address bus
6. Control & Status bus
The functions of each pin in these broad categories will be left to the student as an e-tivity
exercise.
Temporary Register
This 8-bit register stores the operands of arithmetic-logic operations. For instance, during an
ADD C the contents of the C register are copied in the temporary register during one T state
and added during another T state. This register is one of the inputs of the ALU.
Fig.5.2: The 8085 Microprocessor: Functional Block Diagram
General Purpose Registers
The general purpose registers are used to store only the data that is used by the currently
running program or the results obtained from the currently running program. These general
purpose registers are user accessible by programs. Registers B, C, D, E, H and L are the
general purpose registers of 8085 as shown in Fig 5.3. They can be combined as register
pairs: BC, DE, and HL to perform some 16-bit operations. When used as a pair the C, E and
L registers contain the low-order byte. Among these pairs, HL has a special significance. A
few memory related instructions of 8085 (refer instruction set) use the HL pair as a memory
pointer. For example, the instruction “MOV A, M” transfers the content of memory location
pointed by the HL pair to accumulator. The HL pair is pre-loaded with the memory address in
which data is available.
Accumulator
It is an 8 bit register which stores the results of arithmetical and logical operations. It is also
used to receive data from input port to microprocessor and to send data to output port from
microprocessor. The accumulator, which is a part of the ALU, is referred to as register A in a
program. The result of an arithmetic operation is stored in the accumulator.
Flags
The ALU includes five flip-flops, which keep track of the changing conditions during a
microprocessor run. Each bit of the flag register is quite independent of each other, unlike in
all other registers, where each bit is just part of a single binary byte value and hence each bit
would have a numerical value. They are set or reset according to data conditions of the result
in the accumulator and other registers. They are called Zero (Z), carry (CY), Sign (S), Parity
(P), and Auxiliary carry (AC) flags. The bit positions reserved for these five flags, in the flag
register are shown in Fig.5.4.
S: S is set to 1 when the accumulator contents become negative during the execution
of some instructions, otherwise reset to zero. (Also, after an ALU operation, if the
most significant bit of the result is 1, then sign flag is set).
Z: The zero flag is set to 1, if the ALU or logic operation result in a zero and it is reset if
the result is non-zero.
AC: When an instruction causes a carry or carry is generated by digit D3 and passed on
to digit D4 the AC flag is set to 1, otherwise it remains reset to 0.This flag has
critical importance in the decision-making process of the microprocessor. This highly
specialized flag bit is tested by the DAA instruction to adjust the value of AL after a
BCD addition or subtraction. The auxiliary carry flag is, not free to the programmer.
P: Parity is logic 0 for odd parity and logic 1 for even parity. Parity is the count
of 1s in a number, and is expressed as even or odd. The flag is set to 1 if the result of
an arithmetic or logical operation has an even number of 1s. If it has an odd number
of 1s, the flag is reset to 0.
CY: When the result of an arithmetic operation results in a carry or a borrow out of the
higher order bit, the CY flag is set to 1, otherwise remains 0.
Instruction Register/Decoder
It is an 8-bit register which usually offers a temporary store for the current instruction of a
program. Latest instruction sent here from memory prior to execution. The content of the
register is decoded by the decoder circuitry, where the nature of the operation to be
performed is decided (interpreted). The internal machine command is interpreted to decide
the next course of action. Decoded instruction is then passed to next stage. In addition, there
are two temporary registers W and Z which are controlled internally and not available for
user access. These registers are used to hold 8-bit data during execution of some instructions.
6.1 Introduction
Efficient software development for the microprocessor requires a complete familiarity with
the addressing modes employed by each instruction. A set of instructions make a program,
whereby the instructions are commands to the microprocessor to perform an operation. The
addressing modes and instruction classification for the 8085 microprocessor will be
discussed.
Op Code (Operation Code) is the operation to be performed, while the operand is the data or
memory location. The operand can be specified in various ways, which may include:
8-bit or 16-bit data
An internal register
Memory location
8-bit (or 16-bit) address
The various formats for specifying operands are called the addressing modes. The 8085 has
five addressing modes which will be discussed in the following subsections:
Register Addressing
Data is provided through the registers.
Example 6.1
MOV Rd, Rs
MOV B, A; copy contents of A to B
ADD B; Add B to A
Indirect Addressing
Whenever an instruction uses the HL pointer, the addressing is called indirect addressing.
The address is stored in the HL register pair.
Example 6.2
MOV reg, M, where reg = A, B, C, D, E, H, or L and M = MHL. The instruction says to load
the specified register with the data addressed by HL. For example, MOV B, M; load register
B with the data found in the address in MHL.
Direct Addressing
This addressing mode is used to accept data from external devices and store it in the
accumulator or send the data stored in the accumulator to the outside device. In this
addressing mode, address of the operand is specified in the instruction itself.
Example 6.3
OUT 01H ; send from acc to port 01
IN 00H ; Accept from port 00 and load into acc
Immediate Addressing
Data is present in the instruction and is loaded to the destination provided. In this mode of
addressing, the data follows the op-code and is part of the instruction itself.
Example 6.4
MVI A, 09H, the 8-bit data 09H in the instruction is moved to register A.
Implied Addressing
The location of the data is contained within the op-code itself. For instance, RAL tells us to
rotate the accumulator bits left. The data is in the accumulator; this is why no operand is
needed with implied addressing.
6.2.2 Classification of 8085 microprocessor Instructions
An instruction is a binary pattern designed inside a microprocessor to perform a specific
function. The 8085 has 246 instructions with each instruction represented by an 8-bit binary
value, called Op-Code or Instruction Byte. The entire group of instructions is called an
instruction set. The instructions are classified according to what they do or according to their
word size. We discuss classification in the following subsections:
For example, the instruction LXI B 4000H will place the 16-bit number 4000 into the register
pair B, C. The upper two digits are placed in the 1st register of the pair and the lower two
digits in the 2nd.
Other instructions such as: MOV, MVI, LDA, and STA are illustrated by example 6.5.
Examples 6.5
MOV A,B
MOV is the mnemonic for move. It tells the computer to move data from one register to
another. The operation is nondestructive, meaning that the data in B is copied but not erased.
Arithmetic Instructions
These instructions perform mathematical operations like add, subtract, increment, and
decrement.
Addition (ADD, ADI): Any 8-bit number, the contents of a register, or the contents of a
memory location can be added to the contents of the accumulator and the result is stored in
the accumulator. No two other 8-bit registers can be added directly.
Example 6.6
Suppose register A = 04H and register B = 02H, what are the contents of the accumulator
after the execution of ADD B
Solution This instruction adds the contents of B to the contents of the accumulator and stores
the answer in the accumulator, therefore A = 06H
Examples 6.7
ADD B or ADD M; Add register or memory to accumulator
The contents of register or memory are added to the contents of accumulator.
The result is stored in accumulator.
If the operand is a memory location, its address is specified by H-L pair.
All flags are modified to reflect the result of the addition.
Example 6.8
ADD B means to add contents of the register B to the accumulator. If A = 04H and B = 02H,
then the execution of ADD B results in A = 06H
Logical Instructions
These instructions perform logical operations on the contents of the accumulator. Some of the
logical operations are:
AND
OR
Source: Accumulator and An 8-bit number, or the contents of a register, or the contents of a
memory location
Destination: Accumulator
Example 6.9
ANA B or ANA M; Logical AND register or memory with accumulator
The contents of the accumulator are logically ANDed with the contents of register or
memory.
The result is placed in the accumulator.
If the operand is a memory location, its address is specified by the contents of H-L
pair.
S, Z, P are modified to reflect the result of the operation.
CY is reset and AC is set.
ANA B means to AND the contents of the accumulator with the contents of the register B.
Example 6.10
Suppose the two registers contain: A = 1100 1100 and B = 1111 0001, what are the contents
of A after the execution of the instruction ANA B?
Branching Instructions
The branching instruction alters the normal sequential flow either unconditionally or
conditionally.
(a) Unconditional branch; Go to a new location irrespective of the outcome of an
operation.
JMP Address; Jump to the address specified (Go to).
CALL Address; Jump to the address specified but treat it as a subroutine.
RET; Return from a subroutine.
The addresses supplied to all branch operations must be 16-bits.
(b) Conditional branch; Go to a new location if a specified condition is met.
Examples 6.11
The following are some conditional instructions
JZ Address; (Jump on Zero): Go to address specified if the Zero flag is set.
JC Address; (Jump on Carry): Go to the address specified if the Carry flag is set.
JP Address; (Jump on Plus): Go to the address specified if the Sign flag is not set
Example 6.12
This example demonstrates an unconditional instruction
JMP 3000H tells the microprocessor to get the next instruction from memory location
30000H. Suppose this instruction is stored at 2005H; at the end of the fetch cycle, the
program counter contains 2006H, i.e. PC = 2006H
2005H JMP 3000H
3000H
During the execution cycle, the JMP 3000H loads the program counter with PC = 3000H. At
the beginning of the next fetch cycle, the next instructions comes from 3000H (and not
2006H)
Example 6.13
Op Code Operand Hex Code Comment
MOV C, A 4FH Copy contents of A into C
ADD B 80H Add contents of B to the
contents of A
In the first instruction, both operand register are specified while in the second, the operand B
is specified and the accumulator is assumed.
Two-byte Instruction
The first byte specifies the opcode while the second byte specifies the operand.
Example 6.14
Op Code Operand Hex Code Comments
MVI A, 32H 3E Load an 8-bit byte into A
32 Two memory locations required
Three-byte Instructions
The first byte specifies the opcode, and the next two bytes specify the 16-bit address.
Example 6.15
Op Code Operand Hex Code Comment
LDA 2050H 3A load contents of memory location
50 2050H into A
20
These instructions would require three memory locations each to store the binary codes.
Lesson 7
The Stack and Subroutines
7.1 Introduction
The stack holds data temporarily and stores the return addresses used by subroutines. The
stack memory is a last-in, first-out (LIFO) memory, which describes the way that data are
stored and removed from the stack. Data are placed onto the stack with a PUSH instruction
and removed with a POP instruction. The CALL instruction also uses the stack to hold the
return address for subroutines and a RET (return) instruction to remove the return address
from the stack.
Example 7.1
Where will the storing of data start when stack pointer is loaded with memory address
2500H, using the instruction: LXI SP, 2500H?
Solution
The storing of data bytes begins at 24FFH and continues in decreasing order as shown in
Fig. 7.1 As a general practice, the stack is initialized at the highest available memory
location.
Stack Instructions
The instructions that read and write into the stack are called stack instructions. They include
PUSH and POP which are important instructions that store and retrieve data from the LIFO
stack memory. Data can be stored (written) on the stack using the instruction PUSH, while
the instruction POP transfers (reads) data from the stack.
Example 7.2
Suppose SP = 2500 H and HL = 5678H, illustrate the state of the stack after the execution of
PUSH H
Solution 56 H will be loaded to memory location 24FF H and 78 H will be loaded to 24FE H
memory location as shown in Fig. 9.2. At the end of this instruction the stack pointer, SP
contains 24FE H.
Subroutine
A subroutine is a group of instructions that will be used repeatedly in different locations of a
program to perform a function that occurs in the main program. Rather than repeat the same
instructions several times, they can be grouped into a subroutine that is called from the
different locations. In Assembly language, a subroutine can exist anywhere in the code.
However, it is customary to place subroutines separately from the main program.
Subroutine Instructions
The 8085 microprocessor has two instructions to implement subroutines: CALL (call a
subroutine), and RET (return to main program from subroutine). The CALL is in the main
program, and RET at the end of a subroutine. The address of the subroutine program is
specified with the CALL instruction. When a CALL<address> instruction is executed, the
contents of the program counter (PC) are pushed onto the stack. Then the starting address of
the subroutine is loaded into the program counter. The next instruction fetched is the first
instruction of the subroutine. On completion of the subroutine, a RET instruction POPs the
return address off the stack into the program counter and returns control to the instruction that
immediately follows the CALL in a program when a RET instruction executes. Although the
CALL instruction is a branching instruction, it differs from the jump instruction in that a
CALL saves a return address on the stack. A few examples follow:
This is the format for unconditional call instruction which is of three bytes.
Example 7.3 will be used to illustrate how the stack and the related instructions work.
Example 7.3
Study the following program and explain how it works
Address Instruction
2000H LXI SP, 2100H
2001H
2002H
2003H CALL 8050H
2004H
2005H
2006H MVI A,0EH
.
.
200AH HLT
.
.
8050
.
.
8059 RET
Solution The LXI loads the stack pointer with 2100H. During the execution of CALL 8050H,
the address of the next instruction is saved in the stack. This address (2006H) is pushed into
the stack as shown in Fig 9.3(a)
(a) (b)
Fig. 7.3: (a) Saving a return address during a subroutine call (b) Popping the return address
during a RET
The program counter is then loaded with 8050H, the starting address of the subroutine. When
the subroutine is completed, the RET instruction takes the processor back to the main
program as follows:
i) The low byte is popped from the stack into the lower half of the program
counter; then the high byte is popped from the stack into the upper half of the
program counter (Fig. 9.3b).
ii) After the second increment, the stack pointer is back at 2100H. The process is
summarized in Fig. 9.4
CALL 8050H
8050H
RET
Note: The stack operation is automatic during a CALL or a RET instruction. All we have to
do is to initialize the setting of the stack pointer; this is the purpose of LXI SP,dble
instruction. It sets the upper boundary of the stack. The CALL automatically pushes the
return address onto the stack, and RET automatically POPs this return address off the stack.
Lesson 8
8.1 Introduction
Microprocessors recognize and operate on unique mnemonics developed for a given
processor. A program called an assembler translates the mnemonics into the corresponding
binary machine codes of the processor. In this chapter, we put into practice what we have
learnt in the previous chapters so that we write simple 8085-based assembly language
programs.
Example 8.1
Find the Hex code for the following instructions, identify the opcodes, operands, and show
the order of entering the codes in memory.
a) STA 2050H b) JNZ 2070H
Solution
a) Hex code = 32 50 20. Opcode = STA, Operand = 2050H
Hex code = C2 70 20. Opcode = JNZ, Operand = 2070H
Example 8.2
Store the number D5H in register B
Solution
Mnemonics M/C code Operands Comments
MVI B, D5H 06 B, D5H move D5 into reg B
D5
HLT 76 Halt the process
Example 8.3
Write a program to load two hexadecimal numbers 32H and 48H in registers A and B,
respectively. Add the numbers, and display the sum at the LED output port PORT1.
Solution
Problem analysis
1. Load the numbers in the registers
2. Add the numbers
3. Display the sum at the output port PORT1
Fig.8.1: Flow chart for adding two numbers (b) common flow chart symbols
The translation of each block in the flow chart into mnemonics is as follows:
Block1 MVI A, 32H Load register A with 32H
MVI B, 48H Load register B with 48H
Block 2 ADD B Add two bytes and save sum in A
Block 3 OUT 01H Display accumulator contents at port 01H
Block 4 HALT End
Hand Assembling
To convert the mnemonics of example 10.3 into hex code, we need to look up the code in the
8085 instruction set; this is called manual or hand assembly. To hand-assemble means to
translate a source program into machine-language program by hand rather than machine.
Example 8.4
Hand-assemble the following program starting from 2000H
MVI A, 49H
MVI B, 4AH
MVI C, 4BH
STA 6285H
HLT
Solution
Address Hex code Mnemonics
2000H 3EH MVI A, 49H
2001H 49H
2002H 06H MVI B, 4AH
2003H 4AH
2004H 0EH MVI C, 4BH
2005H 4BH
2006H 32H STA 6285H
2007H 85H
2008H 62H
2009H 76H HLT
Example 8.5
Load the hexadecimal 9BH and A7H into registers D and E, respectively, and add the
numbers. If the sum is greater than FFH, display 01H at output PORT0; otherwise, display
the sum. You are given that the R/W memory begins at 2000H
Solution
The problem can be divided into the following steps (Algorithm):
i) Load the numbers in the registers
ii) Add the numbers
iii) If sum > FFH display 01, otherwise display the sum
iv) End
These steps can be converted into a flow chart, as shown in Fig. 10.2
Fig. 8.2: A flow chart to test the carry flag
Memory locations 2007H and 2008H have been left blank because the exact location of the
transfer is not known; what is known is that two bytes should be reserved for the 16-bit
address. After completing the straight line sequence, we know the memory address of the
label DSPLAY, as 200BH. This address is placed in the reversed order, i.e.
2007 0B Low-order
2008 20 High-order
Lesson 9
Introduction to 8088/8086
9.1 Introduction
Whenever an instruction calls for an arithmetic or logical function, the EU passes the data to
Arithmetic and Logic Unit together with a command telling the ALU what to do with the
data. The EU then accepts the resulting data from the ALU and sees to it that it is stored into
correct location (register or memory), as designated by the instruction.
System Bus
The System Bus is a series of conductive traces of signal lines on the system board, which is
used to communicate between 8086/8088 (cpu) and all other devices.
In order to build a complete computer, there are a number of other hardware devices (chips in
the computer. Some of them are:
To read from memory, for example, the Bus Interface Unit puts the correct memory address
onto the Address Bus and puts the command to read from memory onto the Control Bus. All
devices connected to the bus see this address and command simultaneously, but only the
memory-control circuitry respond to it. The memory-control circuitry is then responsible for
decoding the address, retrieving the data from the appropriate memory chips, and placing the
data onto the Data Bus for retrieval by the BIU.
To write to memory, the BIU puts the memory address onto the Address Bus, the byte of data
onto the Data Bus, and a command to write data onto memory of the control bus. The
memory-control circuitry decodes the command and the address, retrieves the data from the
Data Bus, and stores it into the correct memory chips. All other circuitry simply ignores the
command.
System bus
Communication with the many special-purpose microprocessors attached to the System Bus
is accomplished through I/O ports. I/O ports are used for the transfer of data between the
8086/8088 processor and the other support hardware within the system. The In and OUT
instructions tell the processor to input or output data through the I/O ports.
When executing an IN instruction, the BIU puts the I/O port address onto the Address Bus
and puts the command to input data onto the Control Bus. The circuitry on some peripheral
device attached to the bus recognizes the red command and decodes the I/O port as the
address of some register within the peripheral device. It then retrieves the data from the
register and places it onto the Data Bus from which it is retrieved by the BIU and fed to the
Execution Unit within the processor.
To execute an OUT instruction, the BIU puts the command to output data onto the Control
Bus, and I/O address onto the Address Bus, and the data to be output onto the Data Bus. The
circuitry of a peripheral device is then responsible for recognizing the output command and
the I/O address and for retrieving the data from the data bus.
1. Storage Elements
Bits: The smallest storage element on any computer is the bit, which can have a value
of 0 or 1.
Nibbles: A nibble is a sequence of 4 bits.
e.g.
1 1 0 1
bit 3 bit 0
e.g.
1 0 1 0 1 1 0 1
bit 7 bit 0
Words: in 8086/8088, a word consists of 16 bits that can be viewed as:
1) A horizontal sequence of 16 bits or.
e.g.
1 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1
bit 15 bit 0
1 0 1 0 1 1 0 1
bit 15 bit 8
1 0 1 0 1 1 0 1
bit 7 bit 0
Note: in memory, the least significant bye (bits 0-7) is stored in lower numbered
memory location, and the most significant byte (bits 8-15) is stored in the next
higher numbered location.
Note: in memory, its 0-7 bits would come first; bits 8-15 would be in the next higher
numbered byte and so on.
Quadword: A quadword is 2 double words, hence 4 words or 8 bytes.
Tenbytes: A tenbyte is a sequence of 10 bytes.
2. Memory
Computer memory consists of an ordered sequence of storage units (8-bits called bytes), each
with its own address.
8086/8088’s memory is bytes-addressable, which means that each byte has its own
address, e.g. if A is the address of a word (16 bits), then A is actually the address of
the first byte (bits 0-7) of the word, A+1 is the address of the second byte (bits 8-15)
of the word, and A+2 is the address of the next word.
Memory address space: (MAS): 220= 1,048,576= 1M(bytes) (address space: 0—220- 1,
i.e.00000-fffff: in hexadecimal)
Map of the memory address space (MAS)
The whole MAS is organized by a 216 * 24 matrix: there are 216 paragraphs, each of
which with 16 (24) bytes.
Paragraph numbers:
0000 0001
0002
FFFE
FFFF
…
Figure 1: Map of the memory address space (MAS) of the 8086/8088.
Hexadecimal number system
The hexadecimal number system uses sixteen characters to represent umbers:0
through 9 and A through F; A is worth ten, B is worth eleven, …, and F is fifteen. In
assembly program, the hexadecimal will be indicated by the letter h.
Example: 7Fh is the number 127(7*16+15*1) and its equivalent binary number is
01111111b.
The conversion between binary and hexadecimal is simple. To covert from
hexadecimal to binary: just represent each hexadecimal digit by four binary digits:
Example: 74Dh = 011101001101b
To convert from binary to hexadecimal: break the binary number into groups of four
digits, and convert each group into one hexadecimal digit:
Example: 101001001110b = A4Fh
Character representation
Each character is represented by a byte or two hexadecimal digits according to ASCII
code.
41h A
42h B
. .
. .
5Ah Z
61h a
62h b
. .
. .
7Ah z
30h 0
. .
. .
39h 9
In assembly the ASCII representation of character can be defined by enclosing the
characters in paired single (‘) or double (“) quotes.
Example: ‘A’ ‘e’ “9”
Note ‘A’ = 41h, ‘a’ = 61h and “9” = 39h
Segment-relative addresses.
1) There are 16 bits in a segment register. The content of the segment register
represents the paragraph number of the paragraph at which it begins.
2) All memory address are formed by segment-relative format which is computed
as follows:
Absolute address=(segment register)*16 + offset (16-bit) denoted by segment
register: where the offset can be content of a register (16-bit) and a 16-bit
value. e.g. where CS is the code segment register, IP is the instruction pointer
register
CS: 1110000000000000
CS*16: 11100000000000000000 (Beginning of code segment)
IP: 0000000000001101 (offset)
--------------------------------------------------------------------------
CS : IP = 11100000000000001101 (Actual location (absolute
address) in memory)
3. Program stack
A program stack is a region of memory (RAM), which is defined by the assembly program.
The program stack is implemented by setting the SS (stack segment) register and by
initializing the SP (stack pointer) register to the byte immediately above the top of the sack
segment. Data is moved onto the stack in word- sized units by an operation called a push and
retrieved from the stack in word-sized units by an operation called pop in the reversed order
(last in- first out).
A Push operation decrements the SP register twice (-2) and put the word at SS : SP. A Pop
operation retrieves the word at SS: SP and increments the SP register twice (+2)
Figure 2: Stack operations
Example: A program stack is to use 100h bytes and SS= 58A1h, A = 1234h and B = 5678h.
Figure 3 shows the “empty” stock, where the initial value of SP register = 100h and the
stack starts at address of 58A10h and ends at address of 58B0Fh (100 bytes). Figure 4
shows the stack after two Push operations: Push A and Push B, and Figure 5 shows the
stack after two Pushes and one Pop operation (Pop B).
1. Data registers
There are four 16-bit data registers that are used to store data.
1) Accumulator: AX (used for arithmetic and logic instruction).
2) Base register: BX (stored data)
3) Count register: CX (is altered by the loop instruction).
4) Data register: DX (used for multiply and divide instructions).
An “X” register can be subdivided into a high part (H, 8-15 bits) and a low part (L, 0-7bits).
AX Register: Accumulator register consists of two 8-bit registers AL and AH, which
can be combined together and used as a 16- bit register AX. AL in this case contains
the low-order byte of the word, and AH contains the high-order byte. Accumulator
can be used for I/O operations, rotate and string manipulation.
BX Register: This register is mainly used as a base register. It holds the starting base
location of a memory region within a data segment. It is used as offset storage for
forming physical address in case of certain addressing mode.
CX Register: It is used as default counter - count register in case of string and loop
instructions.
DX Register: Data register can be used as a port number in I/O operations and
implicit operand or destination in case of few instructions. In integer 32-bit multiply
and divide instruction the DX register contains high-order word of the initial or
resulting number.
AX AH AL
BX BH BL
CH CL
CX
DH DL
DX
15 8 7 0
2. Segment registers
The 8086/8088 has four separate “work area” for the parts of an assembly language program:
data, instruction, stack and extra data. Each area is called a segment and has a register to
associate with called segment register. Each segment can be up to 65,536 bytes, and two
segments my overlap.
1) Data segment register (DS): indicates the beginning of the data segment.
2) Code segment register (CS): indicates the beginning of the code segment.
3) Stack segment register (SS): the stack is a part of memory. The stack is only word-
addressable.
4) Extra data segment register (ES): points to the beginning of the extra data
The pointers IP, BP, SP usually contain offsets within the code, data and stack segments
respectively
A stack is a pile or list of items that can be accessed one at a time and from only one end,
usually the items are removed from the top and added to the top. Thus, the stack is also called
last-in first-out (LIFO) list. In8086/8088, the stack is implemented by a segment of the
memory; each item is a 16-bit word (2 bytes). There are two registers associated with stack:
SS and SP.
Index registers
There are two index registers:
(a) Source index register (SI)
(b) Destination index register (DI)
There is no significance to the words source and destination, and SI and DI can be used
interchangeably. Index registers are used in the same way subscripts that are used in high-
level language. That enables us to access the elements in an array or table.
Destination Index (DI) and/or Source Index (SI) is a 16-bit register. DI/SI is used for
indexed, based indexed and register indirect addressing, as well as a destination data addresses
in string manipulation instructions.
5. Status register
In 8086/8088 the status register is called the flag register. The flag register contains
information about the most recently executed instruction. There are 16 bits in register. But
only bits 0, 2, 4 and 6-11 are used
Flags Register determines the current state of the processor. They are modified automatically
by CPU after mathematical operations, this allows to determine the type of the result, and to
73
determine conditions to transfer control to other parts of the program. The 8086 flag register
as shown in the fig 1.5. 8086 has 9 active flags and they are divided into two categories:
1. Conditional Flags
2. Control Flags
Conditional Flags
Carry Flag (CY): This flag indicates an overflow condition for unsigned
integer arithmetic. It is also used in multiple-precision arithmetic.
Auxiliary Flag (AC): If an operation performed in ALU generates a
carry/barrow from lower nibble (i.e. D0 – D3) to upper nibble (i.e. D4 – D7),
the AC flag is set i.e. carry given by D3 bit to D4 is AC flag. This is not a
general-purpose flag; it is used internally by the Processor to perform
Binary to BCD conversion.
Parity Flag (PF): This flag is used to indicate the parity of result. If lower
order 8-bits of the result contains even number of 1’s, the Parity Flag is set
and for odd number of 1’s, the Parity flag is reset.
Zero Flag (ZF): It is set; if the result of arithmetic or logical operation is
zero else it is reset.
Sign Flag (SF): In sign magnitude format the sign of number is indicated
by MSB bit. If the result of operation is negative, sign flag is set.
Control Flags
Control flags are set or reset deliberately to control the operations of the
execution unit. Control flags are as follows:
Trap Flag (TF): It is used for single step control. It allows user to execute
one instruction of a program at a time for debugging. When trap flag is set,
program can be run in single step mode.
Interrupt Flag (IF): It is an interrupt enable/disable flag. If it is set, the
maskable interrupt of 8086 is enabled and if it is reset, the interrupt is
disabled. It can be set by executing instruction sit and can be cleared by
executing CLI instruction.
Direction Flag (DF): It is used in string operation. If it is set, string bytes are
accessed from higher memory address to lower memory address. When it is reset,
the string bytes are accessed from lower memory address to higher memory
address.
74
Lesson 10
The 8086/8088 Instructions
10.1 Introduction
Efficient software development for the microprocessor requires a complete familiarity with
the addressing modes employed by each instruction. A set of instructions make a program,
whereby the instructions are commands to the microprocessor to perform an operation. The
addressing modes and instruction classification for the 8086/8088 microprocessor will be
discussed.
The op-code register direction bit (D) and data size bit (W) in byte 1 are defined by Intel as
follows:
Op code occupies six bits and it defines the operation to be carried out by the
instruction.
Register Direction bit (D) occupies one bit. It defines whether the register operand in
byte 2 is the source or destination operand.
o D = 1 specifies that the register operand is the destination operand; on the
other hand,
o D = 0 indicates that the register is a source operand.
75
Data size bit (W) defines whether the operation to be performed is on 8- or 16- bit
data.
o W = 0 indicates 8-bit operation.
o W = 1 specifies 16-bit operation.
The second byte of the instruction usually identifies whether one of the operands is in
the memory or the registers; this byte contains three fields.
o The Mode (MOD) field,
o The register (REG) field,
o The Register/Memory (R/M) field.
The addressing modes for sequential control transfer instructions are explained as follows:
1. IMMEDIATE
In this type of addressing, immediate data is a part of instruction, and appears in the form of
successive byte or bytes.
In the above examples, the source operand is in immediate mode and the destination operand
is in register mode.
2. DIRECT
In the direct addressing mode, a 16-bit memory address (offset) is directly specified in the
instruction as a part of it.
The instruction Opcode is followed by an affective address, this effective address is directly
used as the 16 bit offset of the storage location of the operand from the location specified by
the current value in the selected segment register.
The Execution Unit (EU) has direct access to all registers and data for register and immediate
operands. However the EU cannot directly access the memory operands. It must use the BIU,
in order to access memory operands. In the direct addressing mode, the 16 bit effective
address (EA) is taken directly from the displacement field of the instruction.
3. REGISTER:
In register addressing mode, the data is stored in a register and it is referred using the
particular register. All the registers, except IP, may be used in this mode.
77
The operand to be accessed is specified as residing in an internal register of 8086. Fig. below
shows internal registers, anyone can be used as a source or destination operand, however only
the data registers can be accessed as either a byte or word.
4. REGISTER INDIRECT
Sometimes, the address of the memory location, which contains data or operand, is
determined in an indirect way, using the offset registers. This mode of addressing is known as
register indirect mode. In this addressing mode, the offset address of data is in either BX or
SI or DI registers. The default segment is either DS or ES. The data is supposed to be
available at the address pointed to by the content of any of the above registers in the default
data segment.
Here, data is present in a memory location in DS whose offset address is in BX. The effective
address of the data is given as 10H*DS+ [BX]. The EA is specified in either pointer (BX)
register or an index (SI or DI) register. The 20 bit physical address is computed using DS and
EA.
78
5. INDEXED
In this addressing mode, offset of the operand is stored in one of the index registers. DS and
ES are the default segments for index registers SI and DI respectively. This mode is a special
case of the above discussed register indirect addressing mode.
Here, data is available at an offset address stored in SI in DS. The effective address, in this
case, is computed as 10H*DS+ [SI].
6. REGISTER RELATIVE:
In this addressing mode, the data is available at an effective address formed by adding an 8-
bit or 16-bit displacement with the content of any one of the registers BX, BP, SI and DI in
the default (either DS or ES) segment. The example given before explains this mode.
7. BASED INDEXED:
The effective address of data is formed, in this addressing mode, by adding content of a base
register (any one of BX or BP) to the content of an index register (any one of SI or DI). The
default segment register may be ES or DS.
Here, BX is the base register and SI is the index register. The effective address is computed
as 10H*DS+ [BX] + [SI].
The effective address is formed by adding an 8-bit or 16-bit displacement with the sum of
contents of any one of the bases registers (BX or BP) and any one of the index registers, in a
default segment.
If the location to which the control is to be transferred lies in a different segment other than
the current one, the mode is called inter-segment mode. If the destination location lies in the
same segment, the mode is called intra-segment.
In this mode, the address to which the control is to be transferred lies in the same segment in
which the control transfers instruction lies and appears directly in the instruction as an
immediate displacement value. In this addressing mode, the displacement is computed
relative to the content of the instruction pointer IP.
The effective address to which the control will be transferred is given by the sum of 8 or 16
bit displacement and current content of IP. In case of jump instruction, if the signed
displacement (d) is of 8 bits (i.e. –128 <d</d16 bits (i.e. –32768<+32768), it is termed as
long jump.
80
In this mode, the displacement to which the control is to be transferred is in the same segment
in which the control transfer instruction lies, but it is passed to the instruction indirectly.
Here, the branch address is found as the content of a register or a memory location. This
addressing mode may be used in unconditional branch instructions.
3. INTER-SEGMENT DIRECT MODE: In this mode, the address to which the control is
to be transferred is in a different segment. This addressing mode provides a means of
branching from one code segment to another code segment. Here, the CS and IP of the
destination address are specified directly in the instruction.
4. INTER-SEGMENT INDIRECT MODE: In this mode, the address to which the control
is to be transferred lies in a different segment and it is passed to the instruction indirectly, i.e.
contents of a memory block containing four bytes, i.e. IP (LSB), IP (MSB), CS (LSB) and CS
(MSB) sequentially. The starting address of the memory block may be referred using any of
the addressing modes, except immediate mode.
These instructions are used to transfer the data from the source operand to the destination
operand. Following are the list of instructions under this group −
MOV − Used to copy the byte or word from the provided source to the provided
destination.
PPUSH − Used to put a word at the top of the stack.
POP − Used to get a word from the top of the stack to the provided location.
PUSHA − Used to put all the registers into the stack.
POPA − Used to get words from the stack to all registers.
XCHG − Used to exchange the data from two locations.
81
IN − Used to read a byte or word from the provided port to the accumulator.
OUT − Used to send out a byte or word from the accumulator to the provided port.
LEA − Used to load the address of operand into the provided register.
LDS − Used to load DS register and other provided register from the memory
LES − Used to load ES register and other provided register from the memory.
LAHF − Used to load AH with the low byte of the flag register.
SAHF − Used to store AH register to low byte of the flag register.
PUSHF − Used to copy the flag register at the top of the stack.
POPF − Used to copy a word at the top of the stack to the flag register.
DIV − Used to divide the unsigned word by byte or unsigned double word by word.
IDIV − Used to divide the signed word by byte or signed double word by word.
82
These instructions are used to perform operations where data bits are involved, i.e. operations
like logical, shift, etc.
SHL/SAL − Used to shift bits of a byte/word towards left and put zero(S) in LSBs.
SHR − Used to shift bits of a byte/word towards the right and put zero(S) in MSBs.
SAR − Used to shift bits of a byte/word towards the right and copy the old MSB into
the new MSB.
ROL − Used to rotate bits of byte/word towards the left, i.e. MSB to LSB and to
Carry Flag [CF].
ROR − Used to rotate bits of byte/word towards the right, i.e. LSB to MSB and to
Carry Flag [CF].
RCR − Used to rotate bits of byte/word towards the right, i.e. LSB to CF and CF to
MSB.
RCL − Used to rotate bits of byte/word towards the left, i.e. MSB to CF and CF to
LSB.
4. String Instructions
String is a group of bytes/words and their memory is always allocated in a sequential order.
These instructions are used to transfer/branch the instructions during an execution. It includes
the following instructions −
CALL − Used to call a procedure and save their return address to the stack.
RET − Used to return from the procedure to the main program.
JMP − Used to jump to the provided address to proceed to the next instruction.
These instructions are used to control the processor action by setting/resetting the flag values.
These instructions are used to execute the given instructions for number of times. Following
is the list of instructions under this group −
LOOP − Used to loop a group of instructions until the condition satisfies, i.e., CX = 0
LOOPE/LOOPZ − Used to loop a group of instructions till it satisfies ZF = 1 & CX
=0
LOOPNE/LOOPNZ − Used to loop a group of instructions till it satisfies ZF = 0 &
CX = 0
JCXZ − Used to jump to the provided address if CX = 0
8. Interrupt Instructions
These instructions are used to call the interrupt during program execution.
INT − Used to interrupt the program during execution and calling service specified.
INTO − Used to interrupt the program during execution if OF = 1
IRET − Used to return from interrupt service to the main program