Microprocessors Notes Unit I & II
Microprocessors Notes Unit I & II
Microprocessors
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 data according to those instructions, and provides results as output.
The fact that the microprocessor is programmable means it can be instructed to perform
given tasks within its capability. For example, an instruction for adding two numbers may look
like a group of eight binary digits, such as 1000 0000, These instructions are simply a pattern
of Os and 1s. The user (programmer) selects instructions from the list and determines the
sequence of execution for a given task. These instructions are entered or stored in storage,
called memory, which can be read by the microprocessor,
The microprocessor design engineer selects combinations of bit patterns and gives a
specific meaning to each combination by using electronic logic circuits; this is called an
instruction. Instructions are made up of one word or several words. The set of instructions
designed into the machine makes up its machine language—a binary language, composed of
Os and |s—that is specific to each computer 8085 Machine Language
The 8085 is a microprocessor with 8-bit word length: its instruction set (or language)
is designed by using various combinations of these eight bits. The 8085 is an improved version
of the earlier processor 80804.
For example:
0011 1100 is an instruction that increments the number in the register called the accumulator
by one.
1000 0000 is an instruction that adds the number in the register called B to the number in the
accumulator, and keeps the sum in the accumulator.
For example, the binary code 0011 1100 of the 8085 microprocessor is represented by
the mnemonic INR A:
INR A INR. stands for increment, and A represents the accumulator. This symbol suggests
the operation of incrementing the accumulator contents by one.
Similarly, the binary code 1000 0000 (80), or 80H) is represented as ADD B ADD stands for
addition, and B represents the contents in register B. This symbol suggests the addition of the
contents in register B and the contents in the accumulator.
Machine language and assembly language are microprocessor-specifies and are both
considered low-level languages.
High-Level Languages
The hardware model in Figure 2.1(a) shows two major segments, One segment includes
the arithmetic/logic unit (ALU) and an 8-bit register called an accumulator, instruction decoder,
and flags. The second segment shows 68-bit and 16-bit registers. Both segments are connected
with various internal connections called an internal bus.
The arithmetic and logical operations are performed in the ALU. Results are stored in
the accumulator, and flip-flops, called flags, are set or reset to reflect the results (see Figure 2.
1a), There are three buses: a 16-bit unidirectional address bus, an 8-bil bidirectional data bus,
and a control bus.
8085 Programming Model
The programming model consists of some segments of the ALU and the registers. This
model does not reflect the physical structure of the 8085 but includes the information that is
critical in writing assembly language programs. The model includes six registers, one
accumulator, and one flag register, as shown in Figure 2.1(b). In addition, it has two 16-bit
registers: the stack pointer and the program counter. They are described briefly as follows.
REGISTERS
The 8085 has six general-purpose registers to store 8-bit data; these are identified as B,
C, D, E, H, and L, as shown in Figure 2.1(b). They can be combined as register pairs— BC,
DE, and HL—to perform some 16-bit operations. The programmer can use these registers to
store or copy data into the registers by using data copy instructions,
ACCUMULATOR
The accumulator is an 8-bit register that is part of the arithmetic/logic unit (ALU), This
register is used to store 8-bit data and to perform arithmetic and logical operations. The result
of an operation is stored in the accumulator. The accumulator is also identified as register A.
FLAGS
The ALU includes five flip-flops, which are set or reset after an operation according to
data conditions of the result in the accumulator and other registers. They are called Zero (Z),
Carry (CY), Sign (8), Parity (P), and Auxiliary Carry (AC) flags; they are listed in Table 2.1
and their bit positions in the flag register are shown in Figure 2.1(c). The most commonly used
flags are Zero, Carry, and Sign. The microprocessor uses these flags to test data conditions.
These flags have critical importance in the decision-making process of the microprocessor, The
conditions (set or reset) of the flags are tested through software instructions, For example, the
instruction JC (Jump On Carry) is implemented to change the sequence of a program when the
CY flag is set. The thorough understanding of flags is essential in writing assembly language
programs.
INSTRUCTION CLASSIFICATION
The 8085 instructions can be classified into the following five functional categories:
data transfer (copy) operations, arithmetic operations, logical operations, branching
operations, and machine-control operations.
This group of instructions copies data from a location called a source to another
location, called a destination, without modifying the contents of the source. In technical
manuals, the term data transfer is used for this copying function.
The various types of data transfer (copy) are listed below together with examples of each
type:
Types Examples
Between registers Copy the contents of register B into register
D.
Specific data byte to a register or a memory Load register B with the data byte 32H.
location
Between a memory location and a register From the memory location 2000H to
register B.
Between an I/O device and the accumulator. From an input keyboard to the accumulator.
ARITHMETIC OPERATIONS
Addition—Any 8-bit number, or the contents of a register, or the contents of a memory location
can be added to the contents of the accumulator and the sum is stored in the accumulator.
LOGICAL OPERATIONS
These instructions perform various logical operations with the contents of the accumulator,
Rotate—Each bit in the accumulator can be shifted either left or right to the next position,
BRANCHING OPERATIONS
This group of instructions alters the sequence of program execution either conditionally
or unconditionally.
Call, Return, and Restart—These instructions change the sequence of a program either by
calling a subroutine or returning from a subroutine. The conditional Call and Return
instructions also can test condition flags.
The 8085 instruction set is classified into the following three groups according to word
size or byte size.
In the 8085, “byte” and “word” are synonymous because it is an 8-bil microproces-
sor, However, instructions are commonly referred to in terms of bytes rather than words,
I. |-byte instructions
2. 2-byte instructions
3, 3-byte instructions
ONE-BYTE INSTRUCTIONS
A 1-byte instruction includes the opcode and the operand in the same byte. for example:
TWO-BYTE INSTRUCTIONS
In a 2-byte instruction, the first byte specifies the operation code and the second byte specifies
the operand. For example:
THREE-BYTE INSTRUCTIONS
In a 3-byte instruction, the first byte specifies the opcode, and the following two bytes specify
the 16-bit address, Note that the second byte is the low-order address and the third byte is the
high-order address. For example:
Data Format
In 8-bit processor systems, commonly used codes and data formats are ASCII, BCD, signed
integers, and unsigned integers. They are explained as follows.
ASCII Code—This is a 7-bit alphanumeric code that represents decimal numbers, English
alphabets, and nonprintable characters such as carriage return. Extended ASCII is an 8-bit code,
The additional numbers (beyond 7-bit ASCII code) represent graphical characters.
BCD Code—The term BCD stands for binary-coded decimal; it is used for decimal numbers,
The decimal numbering system has ten digits, 0 to 9. Therefore, we need only four bits to
represent ten digits from 0000 to1001.
Signed Integer—A signed integer is either a positive number or a negative number. In an 8-bit
processor, the most significant digit, D1, is used for the sign; 0 represents the positive sign and
1 represents the negative sign. The remaining seven bits, D6 – D0, represent the magnitude of
an integer.
Unsigned Integers—An integer without a sign can be represented by all the 8 bits in a
microprocessor register. Therefore, the largest number that can be processed at one time is
FFH.
PROBLEM STATEMENT
Write instructions to load the two hexadecimal numbers 32H and 48H in registers A and B,
respectively. Add the numbers, and display the sum at the LED output port PORT.
PROBLEM ANALYSIS
FLOWCHART
The steps listed in the problem analysis and the sequence can be represented in a block diagram,
called a flowchart. Figure 2.3 shows such a flowchart representing the above steps. This is a
simple flowchart, and the steps are self-explanatory.
ASSEMBLY LANGUAGE PROGRAM
To write an assembly language program, we need to translate the blocks shown in the flowchart
into 8085 operations and then, subsequently, into mnemonics. By examining the blocks, we
can classify them into three types of operations: Blocks | and 3 are copy operations; Block 2 is
an arithmetic operation, and Block 4 is a machine-control operation, To translate these steps
into assembly and machine languages, you should review the instruction set. The translation of
each block into mnemonics with comments is shown as follows:
To convert the mnemonics into Hex code, we need to look up the code in the 8085 instruction
set; this is called either manual or hand assembly,
STORING IN MEMORY AND CONVERTING FROM HEX CODE TO BINARY CODE
To store the program in R/W memory of a single-board microcomputer and display the output,
we need to know the memory addresses and the output port address. Let us assume that R/W
memory ranges from 2000H to 20FFH, and the system has an LED output port with the address
O1H,
To execute the program, we need to tell the microprocessor where the program begins by
entering the memory address 2000H. Now, we can push the Execute key (or the key with a
similar label) to begin the execution. As soon as the Execute function key is pushed, the
microprocessor loads 2000H in the program counter, and the program control is transferred
from the Monitor program to our program. The microprocessor begins to read one machine
code at a time, and when it fetches the complete instruction, it executes that instruction.
The 8085 microprocessor instruction set has 74 operation codes that result in 246
instructions, The set includes all the 8080A instructions plus two additional instructions (SIM
and RIM, related to serial 1/0). the frequently used instructions listed below,*
1. Data Transfer (Copy) Instructions. These instructions perform the following six operations.
• Microprocessor-initiated operations
• Internal operations
• Peripheral (or externally initiated) operations
the term micro processing unit (MPU) ts defined here as a group of devices that can perform
these functions with the necessary set of control signals. This term is similar to the term central
processing unit (CPU).
All these operations are part of the communication process between the MPU and peripheral
devices (including memory). To communicate with a peripheral (or a memory location), the
MPU needs to perform the following steps:
Step 1: Identify the peripheral or the memory location (with its address).
Step 2: Transfer binary information (data and instructions),
Step 3: Provide timing or synchronization signals.
The 8085 MPU performs these functions using three sets of communication lines
called buses: the address bus, the data bus, and the control bus
ADDRESS BUS
The address bus is a group of 16 lines generally identified as Ap to Ays. The address bus is
unidirectional: bits flow in one direction—from the MPU to peripheral devices. The MPU uses
the address bus to perform the first function: identifying a peripheral or a memory location
(Step 1).
DATA BUS
The data bus is a group of eight lines used for data flow (Figure 3.1).* These lines are
bidirectional—data flow in both directions between the MPU and memory and peripheral
devices. The MPU uses the data bus to perform the second function: transferring bi-
nary information
CONTROL BUS
The control bus is comprised of various single lines that carry synchronization signals, The
MPU uses such lines to perform the third function: providing timing signals (Step 3).
The term bus, in relation to the control signals, is somewhat confusing. These are not groups
of lines like address or data buses, but individual lines that provide a pulse to indicate an MPU
operation,
The internal architecture of the 8085 microprocessor determines how and what operations
can be performed with the data, These operations are:
External devices (or signals) can initiate the following operations, for which individual pins on
the microprocessor chip are assigned: Reset, Interrupt, Ready, Hold.
Reset: When the reset pin is activated by an external key (also called a reset key), all internal
operations are suspended and the program counter is cleared (it holds OOOOH), Now the
program execution can again begin at the zero memory address.
Interrupt: The microprocessor can be interrupted from the normal execution of instructions and
asked to execute some other instructions called a service routine (for example, emergency
procedures). The microprocessor resumes its operation after completing the service routine (see
Chapter 12),
Ready: The 8085 has a pin called READY. If the signal at this READY pin is low, the
microprocessor enters into a Wait state. This signal is used primarily to synchronize slower
peripherals with the microprocessor.
Hold: When the HOLD pin is activated by an external signal, the microprocessor relinquishes
control of buses and allows the external peripheral to use them, For example, the HOLD signal
is used in Direct Memory Access (DMA) data transfer ().These operations are listed here to
provide an overview of the capabilities of the 8085.
MEMORY
The R/W memory is made of registers, and each register has a group of flip-flops or field-effect
transistors that store bits of information; these flip-flops are called memory cells. The number
of bits stored in a register is called a memory word memory devices (chips) are available in
various word sizes, The user can use this memory to hold programs and store data, On the other
hand, the ROM stores information permanently in the form of diodes; the group of diodes can
be viewed as a register. In a memory chip, all registers are arranged in a sequence and identified
by binary numbers called memory addresses. To communicate with memory, the MPU should
be able to
The MPU uses its address bus to send the address of a memory register and uses the data bus
and control lines to read from or write into that register.
Input/output devices are the means through which the MPU communicates with “the outside
world.” The MPU accepts binary data as input from devices such as keyboards and A/D
converters and sends data to output devices such as LEDs or printers. There are two different
methods by which I/O devices can be identified: one uses an 8-bit address and the other uses a
16-bit address, These methods are described briefly in the following sections.
In this type of I/O, the MPU uses eight address lines to identify an input or an output de-
vice; this is known as peripheral-mapped I/O (also known as /O-mapped I/O), This is an
8-bit numbering system for I/Os used in conjunction with Input and Output instructions.
This is also known as I/O space, separate from memory space, which is a 16-bit number-
ing system. The eight address lines can have 256 (2° combinations) addresses: thus, the
MPU can identify 256 input devices and 256 output devices with addresses ranging from
00H to FFH.
The steps in communicating with an I/O device are similar to those in communicating with
memory and can be summarized as follows:
1. The MPU places an 8-bit address on the address bus, which is decoded by external de-
code logic
2, The MPU sends a control signal (1/O Read or I/O Write) and enables the I/O device,
In this type of I/O, the MPU uses 16 address lines to identify an I/O device; an I/O is connected
as if it is a memory register. This is known as memory-mapped I/O, The MPU uses the same
control signal (Memory Read or Memory Write) and instructions as those of memory. In some
microprocessors, such as the Motorola 6800, all I/Os have 16-bit addresses; I/Os and memory
share the same memory map (64<). In memory-mapped I/O, the MPU follows the same steps
as if it is accessing a memory register.
The 8085A (commonly known as the 8085) is an 8-bit general-purpose microprocessor capable
of addressing 64K of memory. The device has forty pins, requires a +5 V single power supply,
and can operate with a 3-MHz single-phase clock. The 8085A-2 version can operate at the
maximum frequency of 5 MHz. The 8085 is an enhanced version of its predecessor, the 8080A;
its instruction set is upward-compatible with that of the 8080A, meaning that the 8085
instruction set includes all the 8O080A instructions plus some additional ones.
Figure 4.1 shows the logic pinout of the 8085 microprocessor, All the signals can be classified
into six groups: (1) address bus, (2) data bus, (3) control and status signals, (4) power supply
and frequency signals, (5) externally initiated signals, and (6) serial I/O ports,
ADDRESS BUS
The 8085 has 16 signal lines (pins) that are used as the address bus; however, these lines are
split into two segments: A15—A8 and AD7-AD0. The eight signal lines, A15—A8, are
unidirectional and used for the most significant bits, called the high-order address, of a 16-bit
address. The signal lines AD7—AD0 are used for a dual purpose.
The signal lines AD1—AD8 are bidirectional: they serve a dual purpose. They are used as the
low-order address bus as well as the data bus. In executing an instruction, during the earlier
part of the cycle, these lines are used as the low-order address bus, During the later part of the
cycle, these lines are used as the data bus. (This is also known as multiplexing the bus.)
However, the low-order address bus can be separated from these signals by using a latch.
This group of signals includes two control signals (RD and WR), three status signals (IO/M,
S1, and S0) to identify the nature of the operation, and one special signal (ALE) to indicate the
beginning of the operation, These signals are as follows:
ALE—Address Latch Enable: This is a positive going pulse generated every time the 8085
begins an operation (machine cycle);
RD—Read: This is a Read control signal (active low).
WR—Write: This is a Write control signal (active low).
I0/M: This is a status signal used to differentiate between /O and memory operations.
S1 and S0: These status signals, similar to 1O/M, can identify various operations, but
they are rarely used in small systems.
AN 8085-BASED MICROCOMPUTER
A general microcomputer system was illustrated in Figure 3.15, in the last chapter, after our
discussion of the 8085 microprocessor and the interfacing devices, we can expand the system
to include more details, as shown in Figure 4.9. The system includes interfacing devices such
as buffers, decoders, and latches.
The 8085 MPU module (Figure 4.9) includes devices such as the 8085 microprocessor, an octal
latch, and logic gates, as shown previously in Figure 4.6, The octal latch demultiplexes the bus
AD7—AD0 using the signal ALE, and the logic gates generate the necessary control signals.
Figure 4.9 shows the demultiplexed address bus, the data bus, and the four active low control
signals: MEMR, MEMW, IOR, and LOW. In addition, to increase the driving capacity of the
buses, a unidirectional bus driver is used for the address bus and a bidirectional bus driver is
used for the data bus, Now we can examine various operations the 8085 microprocessor
performs in terms of machine cycles and T-states.
MEMORY INTERFACING
The primary function of memory interfacing is that the microprocessor should be able to read
from and write into a given register of a memory chip. Recall from Chapter 3 that to perform
these operations, the microprocessor should
Let us examine the timing diagram of the Memory Read operation (Figure 4.12) to understand
how the 8085 can read from memory. Figure 4,12 is the M, cycle of Figure 4.10 except that the
address bus is demultiplexed. We could also use the M, cycle to illustrate these interfacing
concepts.
1. The 8085 places a 16-bit address on the address bus, and with this address only one register
should be selected. For the memory chip in Figure 4.11 (a), only 11 address lines are required
to identify 2048 registers. Therefore, we can connect the low-order address lines Ajg-Ag of the
8085 address bus to the memory chip. The internal decoder of the memory chip will identify
and select the register for the EPROM, Figure 4.1 1(a).
2. The remaining 8085 address lines (Ajs-A,,) should be decoded to generate a Chip Select
(CS) signal unique to that combination of address logic (illustrated in Examples 4.3 and 4.4),
=a
3. The 8085 provides two signals—IO/M and RD—to indicate that it is a memory read
operation. The IO/M and RD can be combined to generate the MEMR (Memory Read) control
signal that can be used to enable the output buffer by connecting to the memory signal RD.
4, Figure 4.12 also shows that memory places the data byte from the addressed register during
T>, and that is read by the microprocessor before the end of T.
To write into a register, the microprocessor performs similar steps as it reads from a register.
Figure 4.13 shows the Memory Write cycle. In the Write operation, the 8085 places the address
and data and asserts the 1O/M signal. After allowing sufficient time for data to become stable,
it asserts the Write (WR) signal. The IO/M and WR signals can be combined to generate the
MEMW control signal that enables the input buffer of the memory chip and stores the byte in
the selected memory register.
Figure 4.18(a) shows the block diagram of the 8155 memory section, It has eight address lines,
one CE (Chip Enable) line, and five lines compatible with the control and status signals of the
8085: IO/M, ALE, RD, WR, and RESET. These control and status lines are not found in the
general-purpose memory devices shown in the previous section. These lines eliminate the need
for external demultiplexing of the bus AD7-AD0) and for generating separate control signals
for memory and I/O.
Figure 4,18(b) also shows the internal structure of the 8155 memory section. The memory
section includes 256 x 8 memory locations and an internal latch to demultiplex the bus lines
AD7-AD0. The memory section also requires a Chip Enable (CE) signal and the Memory Write
(MEMW) and Memory Read (MEMR) control signals, generated internally by combining the
IO/M, WR, and RD signals.
The approach to designing an interfacing circuit for an [/O device is determined primarily by
the instructions to be used for data transfer. An 1/O device can be interfaced with the 8085
microprocessor either as a peripheral [/O or as a memory-mapped I/O. In the peripheral I/O,
the instructions IN/OUT are used for data transfer, and the device is identified by an 8-bit
address. In the memory-mapped /O, memory-related instructions are used for data transfer, and
the device is identified by a 16-bit address. However, the basic concepts in interfacing 1/O
devices are similar in both methods.
The 8085 microprocessor has two instructions for data transfer between the processor and the
1/O device: IN and OUT. The instruction IN (Code DB) inputs data from an input device (such
as a keyboard) into the accumulator, and the instruction OUT (Code D3) sends the contents of
the accumulator to an output device such as an LED display. These are 2-byte instructions,
with the second byte specifying the address or the port number of an IO device. For example,
the OUT instruction is described as follows,
MEMORY-MAPPED I/O
In memory-mapped I/O, the input and output devices are assigned and identified by 16-bit
addresses. To transfer data between the MPU and I/O devices, memory-related instructions
(such as LDA, STA, ete.)* and memory control signals (MEMR and MEMW) are used. The
microprocessor communicates with an I/O device as if it were one of the memory locations.
The memory-mapped I/O technique is similar in many ways to the peripheral I/O technique,
To understand the similarities, it is necessary to review how a data byte is transferred from the
8085 microprocessor to a memory location or vice versa. For example, the following
instruction will transfer the contents of the accumulator to the memory location 8000H.
Memory Machine
Address Code Mnemonics Comments
2050 32 STA 8000H ;Store contents of accumulator in mem-
-ory location 8000H
2051 00
2052 80
(Note: It is assumed here that the instruction is stored in memory locations 2050H, 51H,
and 52H.)
The STA is a three-byte instruction; the first byte is the opcode, and the second and third bytes
specify the memory address. However, the 16-bit address 8000H is entered in the reverse order;
the low-order byte 00 is stored in location 2051, followed by the high-order address 80H (the
reason for the reversed order will be explained in Section 5.6). In this example, if an output
device, instead of a memory register, is connected al this address, the accumulator contents will
be transferred to the output device, This is called the memory-mapped I/O technique,
On the other hand, the instruction LDA (Load Accumulator Direct) transfers the data from a
memory location to the accumulator. The instruction LDA is a 3-byte instruction; the second
and third bytes specify the memory location. In the memory-mapped I/O technique, an input
device (keyboard) is connected instead of a memory, The input device will have the 16-bit
address specified by the LDA instruction. When the microprocessor executes the LDA
instruction, the accumulator receives data from the input device rather than from a memory
location. To use memory-related instructions for data transfer, the control signals Memory
Read (MEMR) and Memory Write (MEMW) should be connected to I/O devices instead of
IOR and IOW signals, and the 16-bit address bus (A15-A0) should be decoded.