Microprocessor
Microprocessor
A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Page 1 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
UNIT- I
Microprocessor
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, processes data according to those instructions and provide result s as output.
The microprocessor operates in binary 0 and 1 known as bits are represented in terms of
electrical voltages in the machine that means 0 represents low voltage level and 1
represents high voltage level.
Each microprocessor recognizes and processes a group of bits called the word and
microprocessors are classified according to their word length such as 8 bits microprocessor
with 8 bit word and 32 bit microprocessor with 32 bit word etc.
Terms used
1. CPU: - Central processing unit which consists of ALU and control unit.
2. Microprocessor: - Single chip containing all units of CPU.
3. Microcomputer: - Computer having microprocessor as CPU.
4. Microcontroller: single chip consisting of MPU, memory, I/O and
interfacing circuits.
5. MPU: - Microprocessing unit – complete processing unit with the
necessary control signals.
Page 2 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Instructions:
Each microprocessor is designed to execute a specific group of operations. This group of
operations is called an instruction set. This instruction set defines what the microprocessor can
and cannot.
A Microprocessor as a CPU:
Traditionally, the computer is represented with four components such as memory,
input, output and central processing unit (CPU) which consists of arithmetic logic unit (ALU)
and control unit(CU).
The CPU contains various registers to store data, the ALU to perform arithmetic and
logical operations, instruction decoders, counters and control lines.
The CPU reads instructions from memory and performs the tasks specified. It
communicates with input/output (I/O) devices either to accept or to send data, the I/O devices
is known as peripherals.
Later on around late 1960’s, traditional block diagram can be replaced with computer
having microprocessor as CPU which is known as microcomputer. Here CPU was designed using
integrated circuit technology (IC’s) which provided the possibility to build the CPU on a single
chip.
Page 3 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Page 4 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Microprocessor:
It is clock driven semiconductor device consisting of electronic logic circuits manufactured
by using either a large scale integration (LSI) or very large scale integration (VLSI) technique. It is
capable of performing various computing functions and making decisions to change the
sequence of program execution. It can be divided in to three segments.
A. Arithmetic/Logic unit: It performs arithmetic operations as addition and subtraction and
logic operations as AND, OR & XOR.
B. Register Array: The registers are primarily used to store data temporarily during the
execution of a program and are accessible to the user through instruction. The registers
can be identified by letters such as B, C, D, E, H and L.
C. Control Unit: It provides the necessary timing and control signals to all the operations in
the microcomputer. It controls the flow of data between the microprocessor and
memory & peripherals.
Memory:
Memory stores binary information such as instructions and data, and provides that
information to the up whenever necessary. To execute programs, the microprocessor reads
instructions and data from memory and performs the computing operations in its ALU. Results
are either transferred to the output section for display or stored in memory for later use.
Memory has two sections.
A. Read only Memory (ROM): Used to store programs that do not need alterations and can
only read.
B. Read/Write Memory (RAM): Also known as user memory which is used to store user
programs and data. The information stored in this memory can be easily read and
altered.
Input/Output:
It communicates with the outside world using two devices input and output which are
also Known as peripherals.
The input device such as keyboard, switches, and analog to digital converter transfer
binary information from outside world to the microprocessor.
The output devices transfer data from the microprocessor to the outside world. They
include the devices such as LED, CRT, digital to analog converter, printer etc.
System Bus:
It is a communication path between the microprocessor and peripherals; it is nothing
but a group of wires to carry bits.
Page 5 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Microprocessor instruction set and computer languages
Page 6 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
ASCII Code
Assembler
Page 7 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
High-Level Languages
Operating Systems
Page 8 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Large Computers
These are large, general purpose, multiuser, multitasking, computers designed to
perform such data processing tasks as complex scientific and engineering calculations and
handling of records for large corporations or government agencies. These computers can be
broadly classified into mainframes and supercomputers, and mainframes are further classified
according to their sizes. Typical examples are IBM System/390 series, Cray computers (Cray-2,
Y-MP), the Fujitsu GS8800, and the Hitachi MP5800. Mainframes are high-speed computers,
and their word length generally ranges from 32 to 64 bits. Supercomputers such as the Cray-2
and Y-MP are 64 bits high performance and high-speed computers.
Page 9 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Medium-size Computers
In the 1960s, these computers were designed to meet the instructional needs of small
colleges, the manufacturing problems of small factories and the data processing tasks of
medium-size business such as payroll and accounting. These are called mini-computers. These
machines were slower and smaller in memory capacity than mainframes.
Microcomputers
The 4-bit and 8-bit microprocessors became available in the mid-1970s, and initial
applications were primarily in the areas of machine control and instrumentation. As the price of
the microprocessors and memory began to decline, the applications mushroomed in almost all
areas, such as video games, word processing, and small-business applications. Early
microcomputers were designed around 8 bit microprocessors. Since then 16, 32, 64 bits
microprocessors, such as Intel 8086/88, Pentium I to IV, Motorola 68000, and the power PC
series have been introduced, and recent micro computers are designed around these
microprocessors. Present day micro computers can be classified in 4 groups: personal (or
business) computers (PC), work stations, single board, and single chip microcomputers
(microcontrollers).
Single-Board Microcomputers
Page 10 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Page 11 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
A 16-bit program counter
A 16-bit stack pointer
Six 8-bit registers arranged in pairs: BC, DE, HL
Requires +5V supply to operate at 3.2 MHZ single phase clock
It is used in washing machines, microwave ovens, mobile phones, etc.
Accumulator
It is an 8-bit register used to perform arithmetic, logical, I/O & LOAD/STORE operations.
It is connected to internal data bus & ALU.
Program counter
It is a 16-bit register used to store the memory address location of the next instruction
to be executed. Microprocessor increments the program whenever an instruction is being
executed, so that the program counter points to the memory address of the next instruction
that is going to be executed.
Page 12 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Stack pointer: It is also a 16-bit register works like stack, which is always
incremented/decremented by 2 during push & pop operations.
Temporary register:It is an 8-bit register, which holds the temporary data of arithmetic and
logical operations.
Flag register
It is an 8-bit register having five 1-bit flip-flops, which holds either 0 or 1 depending upon
the result stored in the accumulator.
These are the set of 5 flip-flops −
Sign (S)
Zero (Z)
Auxiliary Carry (AC)
Parity (P)
Carry (C)
Its bit position is shown in the following table −
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
Sign Flag (S): Sets or Resets based on the result stored in the accumulator. If the result
stored is positive, the flag resets else if the result stored is negative the flag is set.
Zero Flag (Z): Sets or Resets based on the result stored in the accumulator. If the result
stored is zero the flag is set else it is reset.
Auxiliary Carry Flag(AC) : This flag is set if there is a carry from low nibble(lowest 4 bits) to
high nibble(upper 4 bits) or a borrow from high nibble to low nibble, in the low order 8-bit
portion of an addition or subtraction operation.
Instruction Classification
An instruction is a binary pattern designed inside a microprocessor to perform a specific
function. The entire group of instructions, called the instruction set, determines what
functions the microprocessor can perform. These instructions can be classified into the
following five functional categories: data transfer (copy) operations, arithmetic operations,
logical operations, branching operations, and machine-control operations.
Types Examples
1. Between Registers. 1. Copy the contents of the register B into
Page 13 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
register D.
2. Specific data byte to a register or a memory 2. Load register B with the data byte 32H.
location.
3. Between a memory location and a register. 3. From a memory location 2000H to
register B.
4. Between an I/O device and the accumulator. 4.From an input keyboard to
the accumulator.
Arithmetic Operations
These instructions perform arithmetic operations such as addition, subtraction, increment, and
decrement.
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. No
two other 8-bit registers can be added directly (e.g., the contents of register B cannot be added
directly to the contents of the register C). The instruction DAD is an exception; it adds 16-bit
data directly in register pairs.
Subtraction - Any 8-bit number, or the contents of a register, or the contents of a memory
location can be subtracted from the contents of the accumulator and the results stored in the
accumulator. The subtraction is performed in 2's compliment, and the results if negative, are
expressed in 2's complement. No two other registers can be subtracted directly.
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.
Compare- Any 8-bit number, or the contents of a register, or a memory location can be
compared for equality, greater than, or less than, with the contents of the accumulator.
Complement - The contents of the accumulator can be complemented. All 0s are replaced by 1s
and all 1s are replaced by 0s.
Branching Operations - This group of instructions alters the sequence of program execution
either conditionally or unconditionally.
Page 14 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Jump - Conditional jumps are an important aspect of the decision-making process in the
programming. These instructions test for a certain conditions (e.g., Zero or Carry flag) and alter
the program sequence when the condition is met. In addition, the instruction set includes an
instruction called unconditional jump.
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.
In the 8085 microprocessor, byte and words are synonymous because it is an 8-bit
microprocessor. But, instructions are commonly referred to in terms of bytes rather than
words.
One-byte instructions
A one-byte instruction includes a opcode and a operand in the same byte.
Page 15 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
In the first instruction, operand and registers are specified. In the second instruction, the
operand B is specific and the accumulator is not there. Similarly, in the third instruction, the
accumulator is assume to be the implicit operand.
Two-byte instructions
In a two-byte instruction, the first byte specifies the operation code and second byte specifies
the operand.
Three-byte instructions
In a three-byte instruction, the first byte specifies the opcode, and the following two
bytes specify the 16-bit operand. The second byte is the low-order operand and the third byte
is the high-order operand. If a 16-bit numeral is present in the instruction then that instruction
will be of three-byte. For example, in LXI H,3500H and STA 2500H, etc.
Opcode Format
In the case of microprocessor, the instruction or operation are specified by using specific
bit pattern unique for each instruction. These bit patterns contain all the information about
operation, register used, memory to. The register and register pair are specified by using
certain combination of bits. These combinations of bits are in table below.
Page 16 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Data Format
In 8-bit processor systems, commonly used codes and data formats are,
1. ASCII Code- This is a 7-bit alphanumeric code that represents decimal numbers, English
alphabets and non-printable characters such as carriage return.
2. BCD Code- The term BCD stands for binary-coded decimal; it is used for decimal numbers.
The decimal numbering system has ten digits.
3. Signed Integer- A signed integer is either a positive number or a negative number. In a 8-
bit processor, the most significant digit, d7, is used for the sign; 0 represents the positive
sign and 1 represents the negative sign.
4. Unsigned Integer- A integer without a sign can be represented by all the 8 bits in a
Microprocessor register.
Data Storage:Memory
Memory is a storage of binary bits. Memory chips used in most systems are nothing but
8-bit registers stacked one above the other.
Flowchart
The steps listed in the problem analysis and the sequence can be represented in a block
diagram is called a flowchart.
Page 17 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
ADD B 80
OUT 01H D3
01
HLT 76
Let us assume that the read/write memory ranges from 2000H to 22FFH. The
microprocessor training kit has keypad to enter the hex code, in the memory. It provides a
special routine (monitor program) to enter a hex code byte by byte and execute the program.
Typical steps for storing hex code in the memory from address from address 2000H are as
follows:
Reset the microprocessor system by pressing the RESET key.
Enter into store mode by pressing SET key.
Enter the address of the memory 2000H, where the first hex code (starting address of the
program) is to be stored using hex keys.
Enter the hex code using hex keys.
Increment the memory address by 1 using INC key.
Repeat steps 4 and 5 until the last hex code.
Once the starting address is entered, the program can be executed by pressing EXECUTE
key. The EXECUTE key procedure loads the starting address of our program, 2000H into the
program counter and program control is transferred from monitor program to our program.
After this microprocessor reads one hex code at a time, and when it fetches the
complete instruction, it executes that instruction. Then it fetches the next instruction and this
process continues until the last instruction in the program is executed.
Page 18 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
LXI r.p., 16-bit data loads the specified register pair with data LXI H, 3050
STAX 16-bit address indirectly stores from the accumulator A STAX 2050
Page 19 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
OPCODE OPERAND EXPLANATION EXAMPLE
OUT 8-bit port address outputs contents of A to the specified port OUT 15
Page 20 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
OPCODE OPERAND EXPLANATION EXAMPLE
In the table,
R stands for register
M stands for memory
Mc stands for memory contents
r.p. stands for register pair
Page 21 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
OPCODE OPERAND DESTINATION EXAMPLE
ORA R A = A OR R ORA B
CMP M Compares Mc with A and triggers the flag register CMP 2050
CPI 8-bit data Compares 8-bit data with A and triggers the flag register CPI 50
Page 22 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
OPCODE OPERAND DESTINATION EXAMPLE
In the table,
R stands for register
M stands for memory
Mc stands for memory contents
1. Jump Instructions – The jump instruction transfers the program sequence to the memory address
given in the operand based on the specified flag. Jump instructions are 2 types: Unconditional Jump
Instructions and Conditional Jump Instructions.
(a) Unconditional Jump Instructions: Transfers the program sequence to the described
OPCODE OPERAND EXPLANATION EXAMPLE
memory address.
(b) Conditional Jump Instructions: Transfers the program sequence to the described memory
address only if the condition in satisfied.
OPCODE OPERAND EXPLANATION EXAMPLE
Page 23 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
OPCODE OPERAND EXPLANATION EXAMPLE
2. Call Instructions – The call instruction transfers the program sequence to the memory
address given in the operand. Before transferring, the address of the next instruction after CALL
is pushed onto the stack. Call instructions are 2 types: Unconditional Call Instructions and
Conditional Call Instructions.
(a) Unconditional Call Instructions: It transfers the program sequence to the memory address
given in the operand.
(b) Conditional Call Instructions: Only if the condition is satisfied, the instructions executes.
Page 24 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
OPCODE OPERAND EXPLANATION EXAMPLE
3. Return Instructions – The return instruction transfers the program sequence from the
subroutine to the calling program. Jump instructions are 2 types: Unconditional Jump
Instructions and Conditional Jump Instructions.
(b) Conditional Return Instruction: The program sequence is transferred unconditionally from
the subroutine to the calling program only is the condition is satisfied.
Page 25 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
OPCODE OPERAND EXPLANATION EXAMPLE
HLT - Halt
NOP - No Operation
Page 26 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
UNIT II
♦ Microprocessor-initiated operations
♦ Internal data operations
♦ Peripheral (or externally) initiated operations.
To perform these functions, the microprocessor requires a group of logic circuits and a
set of signals called control signals. However, early processors do not have the necessary
circuitry on one chip; the complete units are made up more than one chip. Therefore, the term
Micro Processing Unit (MPU) is 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).
The 8085/8080A MPU performs these functions using three sets of communication lines called
buses : The address bus, the data bus, and the control bus.
Page 27 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Internal Data Operations and the 8085/8080A Registers
The internal architecture of the 8085/8080A microprocessor determines how and what
operations can be performed with the data. These operations are,
1. Store 8-bits data.
2. Perform arithmetic and logical operations.
3. Test for conditions.
4. Sequence the execution of instructions.
5. Store data temporarily during execution in the defined R/W memory locations called the
stack.
To perform these operations, the microprocessor requires registers, an arithmetic logic unit
(ALU) and control logic, and internal buses (path for information flow).
1. RESET–
This RESET key is used to clear the program counter and update with 0000H memory
location. When this RESET pin is activated by any external key, then all the internal
operations are suspended for that time. After that the execution of the program can begin
at the zero memory address.
2. Interrupt–
8085 microprocessor chip have some pins for interrupt like TRAP, RST 5.5, RST 6.5 and RST
7.5. The microprocessor can be interrupted from the normal instructions and asked to
perform some other emergency operations, which are also known as Service routine. The
microprocessor resumes its operation after the completion Service routine.
3. READY–
The 8085 microprocessor has a pin called READY. If the signal at this READY pin is in low
state then the microprocessor enters into the Wait state. This signal is used mainly to
synchronize slower external devices with the microprocessor.
4. HOLD–
When the HOLD pin is activated by an external signal, the microprocessor relinquishes
control buses and allows the external peripheral to use them. For example, the HOLD signal
is used Direct memory access (DMA) data transfer.
MEMORY
Memory is an essential component of a microcomputer system. It stores binary
instructions and data for the microprocessor. There are two types of memory: Read/Write
Memory(R/WM) and Read-Only Memory (ROM).
1. Memory Organization (R/W Memory): To communicate with memory, the MPU should
be able to:
select the chip
Page 28 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Identify the register
Read from or Write into the register
Figure (a) shows memory chip of eight register with three address lines, one chip select (CS)
line,one read write (R/W) line, and eight I/O lines. The MPU uses the CS line to select the chip,
and the R/W line to control data flow.
Memory Map
Memory map is defined as the assignment of addresses to memory registers in various
memory chips in asystem. In a system based on the 8085/8080A microprocessor, the entire
memory map can range from 0000h to FFFFh (216= 65.536).
Example-1- Illustrate the memory map of the chip with 256 bytes of memory and hardware of
the chip select (CS) line in fig 2.
Page 29 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Memory classification
Memory is the most essential element of a computing system because without it computer
can’t perform simple tasks. Computer memory is of two basic type – Primary memory(RAM and
ROM) and Secondary memory(hard drive,CD,etc.). Random Access Memory (RAM) is primary-
volatile memory and Read Only Memory (ROM) is primary-non-volatile memory.Memory can
be classified into two groups as shown in fig.
It is also called as read write memory or the main memory or the primary memory.
The programs and data that the CPU requires during execution of a program are stored in this
memory.
It is a volatile memory as the data loses when the power is turned off.
RAM is further classified into two types- SRAM (Static Random Access
Memory) and DRAM (Dynamic Random Access Memory).
Page 30 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Page 31 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
There are two different methods by which I/O devices can be identified: Using 8-bit address,
and Using 16-bit address. These methods are described briefly in the following sections:
I/Oswith8-bitaddresses–
This is also known as peripheral-mapped I/O or I/O-mapped-I/O. In this type of I/O, MPU uses
eight address lines to identify an input or an output devices. This is an 8-bit numbering system
for I/Os used in conjunction with the input and output instructions. This is also known as I/O
space that is separate from the memory space which is 16-bit numbering system. The eight
address lines have 2^8 combinations which is total 256 addresses; therefore MPU can identify
256 input devices and 256 output devices with addresses ranging from 00H to FFH.
The input and output devices can be differentiated by using the control lines I/O Read
and I/O Write. MPU uses I/O Read control signal for input devices and I/O Write control signal
for output devices.
I/Oswith16-bitaddresses–
This is also known as Memory-mapped I/O. In this type of I/O, MPU uses sixteen address lines
to identify an input or an output devices; an I/O is connected as if it is a memory register. The
MPU uses same control signal (Memory Read and 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 (64K). The steps are summarized below:
1. The MPU places an 8-bit address ( or 16-bit address) on the address bus, which is decoded
by external decode logic.
2. The MPU sends a control signal (I/O Read or I/O Write) and enables the I/O device.
3. Data are transferred using the data bus.
Page 32 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
This microcomputer system has 8 data lines D0-D7 which are bidirectional and common
to all the devices.It generates four control signals: Memory Read, Memory Write, I/O Read and
I/O Write and they are connected to different peripheral devices. The MPU communicates with
only one peripheral at a time by enabling that peripheral through its control signal.
For example, sending a data to the output device, the MPU places the device address
(or output port number) on the address bus, data on the data bus and enables the output
device by using its control signal I/O Write. After that the output device display the result.
The term Micro Processing Unit (MPU) is similar to the term Central Processing Unit
(CPU) used in traditional computers. We define the MPU as a device or a group of devices (as a
unit) that can communicate with peripherals, provide timing signals, direct data flow, and
perform computing tasks as specified by the instructions in memory. The unit will have the
necessary lines for the address bus, the data bus, and the control signals, and would require
only a power supply and a crystal (or equivalent frequency - determining components) to be
completely functional.
Using this description, the 8085 microprocessor can almost qualify as an MPU, but with the
following two limitations.
1. The low-order address bus of the 8085 microprocessor is multiplexed (time shared) with the
data bus. The buses need to be de multiplexed.
2. Appropriate control signals need to be generated to interface memory and I/O with the
8085. (Intel has some specialized memory and I/O devices that do not require such control
signals).
Page 33 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
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 8085 is an enhanced version of predecessor, the 8080A; its instruction set is
upward-compatible with that of the 8080A, meaning that the 8085 instruction set includes all
the 8080A instructions plus some additional ones. Programs written for the 8080A will be
executed by the 8085, but the 8085 and the 8080A are not pin compatible.
Multiplexed Address / Data Bus
The signal lines AD7 to AD0 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 art 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.
Control and Status Signals
This group of signals includes two control signals (RD and WR), three status signals (IO/M, S 1 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 :
ALU - Address Latch Enable : This is a positive going pulse generated every time the 8085,
begins an operation (machine cycle); it indicates that the bits on AD 7 - AD0 are address bits.
This signal is used primarily to latch the low-order address from the multiplexed bus and
generate a separate set of eight address lines, A7 to A0.
RD - Read : This is a Read control signal (active low). This signal indicates that the selected
I/O or memory device is to be read and data are available on the data bus.
WR - Write : This is a Write control signal (active low). This signal indicates that the data on
the bus are to be written into a selected memory or I/O location.
IO/M: This is a status signal to differentiate between I/O and memory operations. When it is
high, it indicates and I/O Operation; when it is low, it indicates a memory operation. This
signal is combined with RD (Read) and WR (Write) to generate I/O and memory control
signals.
S1 and S0: There status signals, similar to IO/M, can identify various operations; but they are
rarely used in small systems.
X1, X2: A crystal (or RC, LC network) is connected at these two pins. The frequency is
internally divided by two; therefore, to operate a system at 3 MHz, the crystal should have
frequency of 6 MHz.
CLK (OUT) - Clock Output: This signal can be used as the system clock for other devices.
Page 34 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Interrupts and Externally Initiated
Signals
Line Location from which next instruction is picked up
HOLD (INPUT): HOLD indicates
that another device is
requesting for the use of the TRAP 0024
address and data bus.
HLDA (OUTPUT): HLDA is a
RST 5.5 002C
signal for HOLD
acknowledgement which
indicates that the HOLD RST 6.5 0034
request has been received.
After the removal of this
RST 7.5 003C
request the HLDA goes low.
INTR (Input): INTR is
an Interrupt Request Signal. Among interrupts it has the lowest priority. The INTR is
enabled or disabled by software.
INTA (Output): INTA is an interrupt acknowledgement sent by the microprocessor after
INTR is received.
RST 5.5, 6.5, 7.5 and TRAP (Inputs): These all are interrupts. When any interrupt is
recognized the next instruction is executed from a fixed location in the memory as given
below:
RST 7.5, RST 6.5 and RST 5.5 are the restart interrupts which cause an internal restart to be
automatically inserted.
The TRAP has the highest priority among interrupts. The order of priority of interrupts is as follows:
Page 35 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Reset Signals
RESET IN (Input): It resets the program counter (PC) to 0. It also resets interrupt enable
and HLDA flip-flops. The CPU is held in reset condition till RESET is not applied.
RESET OUT (Output): RESET OUT indicates that the CPU is being reset.
Clock Signals
X1, X2 (Input): X1 and X2 are terminals to be connected to an external crystal oscillator
which drives an internal circuitry of the microprocessor. It is used to produce a suitable clock
for the operation of microprocessor.
CLK (Output): CLK is a clock output for user, which can be used for other digital ICs. Its
frequency is same at which processor operates.
SID (Input): SID is data line for serial input. The data on this line is loaded into the seventh
bit of the accumulator when RIM instruction is executed.
SOD (Output): SOD is a data line for serial output. The seventh bit of the accumulator is
output on SOD line when SIM instruction is executed.
1. ALU
The ALU performs the actual numerical and logic operation such as ‘add’, ‘subtract’, ‘AND’,
Page 36 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
‘OR’ etc.
Uses data from memory and from Accumulator to perform arithmetic operation and always
stores result of operation in Accumulator.
The ALU consists of accumulator, flag register and temporary register.
a. Accumulator :-
The accumulator is an 8-bit register that is a part of 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.
b. Flag Register:-
8085 has 8-bit flag register. Flags are flip-flops which are used to indicate the status of
the accumulator and other register after the completion of operation. There are only 5
active flags.
S Z AC P CY
i. Sign flag(S):
Sign flag indicates whether the result of a mathematical or logical operation is negative
or positive. If the result is negative, this flag will be set (i.e. S=1) and if the result is positive, the
flag will be reset (i.e. S=0).
c. Temporary register
It is an 8-bit register, which holds the temporary data of arithmetic and logical operations.
Page 37 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
4. Register array
The register unit of 8085 consists of
Six general-purpose data registers B,C,D,E,H,L
Two internal registers W and Z
Two 16-bit address registers PC (program counter) and SP (stack pointer)
One increment/decrement counter register
One multiplexer (MUX)
The six general-purpose registers are used to store 8-bit data. They can be combined as
register pairs BC, DE, and HL to perform some 16-bit operations.
The two internal registers W and Z are used to hold 8-bit data during the execution of some
instructions, CALL and XCHG instructions.
SP is 16-bit registers used to point the address of data stored in the stack memory. It always
indicates the top of the stack.
PC is 16-bit register used to point the address of the next instruction to be fetched and
executed stored in the memory.
Page 38 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Page 39 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Memory interfacing
Memory is an integral part of a microprocessor system, and in this section, we will
discuss how to interface a memory device with the microprocessor. The Memory Interfacing in
8085 is used to access memory quite frequently to read instruction codes and data stored in
memory. This read/write operations are monitored by control signals. The microprocessor
activates these signals when it wants to read from and write into memory. In the last section
we have already seen the memory read and memory write machine cycles, and status of the
RD, WR and IO/M status signals for read/write operation. In the following section we will see
memory structure and its requirements, concepts in Memory Interfacing in 8085 and
interfacing examples.
Page 40 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Memory Structure and its Requirements: As mentioned earlier, read/write memories consist
of an array of registers, in which each register has unique address. The size of the memory is N
x M as shown in Fig. 1 where N is the number of registers and M is the word length, in number
of bits.
Fig 1
Page 41 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Page 42 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
UNIT III
–1 byte instruction
–E.g. MOV A, B
–2 byte instruction
–Loads the second byte ( 8 bit immediate data) into the register specified.
–R may be A, B, C, D, E, H & L
–Copy the contents of the specified register to memory. Here memory is the location specified
by contents of the HL register pair.
–E.g. MOV M, B
–E. g. MOV B, M
Write a program to load memory locations 7090 H and 7080 H with data 40H and 50H and
then swap these data.
Soln :
MVI H, 70H
MVI L, 90H
Page 43 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
MVI A, 40H
MOV M, A
MOV C, M
MVI L, 80H
MVI B, 50H
MOV M, B
MOV D, M
MOV M, C
MVI L, 90H
MOV M, D
HLT
–2 byte instruction.
–Loads the 8-bit data to the memory location whose address is specified by the contents of HL
pair.
–Loads the accumulator with the contents of memory location whose address is specified by 16
bit address.-A [4035H ]
8) IN 8-bit address
– 2-byte instruction
– Read data from the input port address specified in the second byte and loads data into the
accumulator.
– 2-byte instruction
Page 44 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
– Copies the contents of the accumulator to the output port address specified in the 2nd byte.
That means accumulator to output port: P A
Addressing modes:
Instructions are command to perform a certain task in microprocessor. The instruction
consists of op-code and data called operand. The operand may be the source only,
destination only or both of them. In these instructions, the source can be a register, a
memory or an input port. Similarly, destination can be a register, a memory location, or an
output port. The various format (way) of specifying the operands are called addressing mode.
So addressing mode specifies where the operands are located rather than their nature. The
8085 has 5 addressing mode:
HLT: Halt
Arithmetic Operations:
The 8085 microprocessor performs various arithmetic operations such as addition,
subtraction, increment and decrement. These arithmetic operations have the following
mnemonics.
Page 45 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
1. ADD R/M
1 byte add instruction, Adds the contents of register/memory to the contents of the accumulator
and stores the result in accumulator.– E. g. Add B; A [A] + [B]
3. SUB R/M
One byte subtract instruction, Subtracts the contents of specified register / m with the contents of
accumulator and stores the result in accumulator. E. g. SUB D ; A A-D
8085 performs addition with 8-bit binary numbers and stores the result in accumulator. If
the sum is greater than 8-bits (FFH), it sets the carry flag.
ADD C 101 0 0 1 01 0 1 4A
CY CY
Page 46 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
5)
Logic Operations:
A microprocessor is basically a programmable logic chip. It can perform all the logic
functions of the hardwired logic through its instruction set. The 8085 instruction set includes
such logic functions as AND, OR, XOR and NOT (Complement):
The following features hold true for all logic instructions:
1) The instructions implicitly assume that the accumulator is one of the operands.
2) All instructions reset (clear) carry flag except for complement where flag remain
unchanged.
3) They modify Z, P & S flags according to the data conditions of the result.
4) Place the result in the accumulator.
5) They do not affect the contents of the operand register.
3. ORA R/M
– Logically OR the contents of register/memory with the contents of accumulator, 1 byte
instruction and CY and AC is reset and other as per result.
5. XRA R/M
– Logically exclusive OR the contents of register memory with the contents of accumulator, 1
byte instruction and CY and AC is reset and other as per result.
Branching Operations:
The microprocessor is a sequential machine; it executes machine codes from one
memory location to the next. The branching instructions instruct the microprocessor to go to a
different memory location and the microprocessor continues executing machine codes from
that new location.
Page 47 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
The branching instructions are the most powerful instructions because they allow the
microprocessor to change the sequence of a program, either unconditionally or under certain
test conditions. The branching instruction code categorized in following three groups:
Jump instructions
Call and return instruction
Restart instruction
Jump Instructions:
The jump instructions specify the memory location explicitly. They are 3 byte
instructions, one byte for the operation code followed by a 16 bit (2 byte) memory address.
Jump instructions can be categorized into unconditional and conditional jump.
Unconditional Jump
8085 includes unconditional jump instruction to enable the programmer to set up
continuous loops without depending only type of conditions. E.g. JMP 16 bit address: loads
the program counter by 16 bit address and jumps to specified memory location.
E.g. JMP 4000H
Here, 40H is higher order address and 00H is lower order address. The lower order byte.
Conditional Jump
The conditional jump instructions allow the microprocessor to make decisions based on
certain conditions indicated by the flags. After logic and arithmetic operations, flags are ser or
reset to reflect the condition of data. These instructions check the flag conditions and make
decisions to change or not to change the sequence of program. The four flags namely carry,
zero, sign and parity used by the jump instruction.
Mnemonics Description
Page 48 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Call and return instructions: (Subroutine)
Call and return instructions are associated with subroutine technique. A subroutine is a
group of instructions that perform a subtask. A subroutine is written as a separate unit apart
from the main program and the microprocessor transfers the program execution sequence
from main program to subroutine whenever it is called to perform a task. After the completion
of subroutine task microprocessor returns to main program. The subroutine technique
eliminates the need to write a subtask repeatedly, thus it uses memory efficiently. Before
implementing the subroutine, the stack must be defined; the stack is used to store the memory
address of the instruction in the main program that follows the subroutines call.
To implement subroutine there are two instructions CALL and RET.
2. RET
Returns from the subroutine unconditionally.
1 byte instruction
Inserts the contents of stack pointer to program counter.
2007 MOV B, A
Page 49 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Program 8085 in Assembly language to add two 8-bit numbers and store 8-bit result in register
Program Logic
- Add two numbers
- Store result in register C
Algorithm
1. Get two numbers
2. Add them
3. Store result
4. Stop
MVI D, 2H
MVI E, 3H
MOV A, D
ADD E
MOV C, A
HLT
Page 50 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
FLOWCHART
DEBUGGING A PROGRAM
Debugging is the process of identifying and removing bug from software or program. It refers to
identification of errors in the program
logic, machine codes, and execution. It gives step by step information about the execution of
code to identify the fault in the program.
The debugging process is divided into two parts:
Static Debugging: It is similar to visual inspection of circuit board, it is done by a paper and
pencil to check the flowchart and machine codes. It is used to the understanding of code logic
and structure of program.
Dynamic Debugging: It involves observing the contents of register or output after execution of
each instruction (in single step technique) or a group of instructions (in breakpoint technique).
Page 51 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
PROGRAMMING TECHNIQUES WITH ADDITIONAL INSTRUCTIONS
PROGRAMMING TECHNIQUES: LOOPING, COUNTING AND INDEXING
The Programming Technique used to instruct the microprocessor to repeat task is called
looping. This process is accomplished by using jump instructions. A loop can be classified into
two groups:
Continuous loop- repeats a task continuously
Conditional loop-repeats a task until certain data condition are met
Continuous loop
A continuous loop is set up by using the unconditional jump Instruction shown in the flowchart.
A program with Continuous loop does not stop repeating the tasks until the system is reset.
Conditional Loop
A Conditional loop is setup by the conditional jump instructions. These instructions Check flags
(zero, carry, etc.) and repeat the specified task if the conditions are satisfied. These loops
usually include counting and indexing. Conditional loop is shown by the Flowchart as follow.
Page 52 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Page 53 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Increment / Decrement register pair by 1
INX R
-The contents of the designated register pair are incremented by 1 and the result is stored
in the same place.
Example: INX H
DCX R
-The contents of the designated register pair are decremented by 1 and the result is stored
in the same place.
Example: DCX H
Subtract memory
SUB M: The contents of the operand (memory) are subtracted to the contents of
the accumulator and the result is stored in the accumulator.
The operand is a memory location, its location is specified by the contents of the
HL registers.
All flags are modified to reflect the result of the Subtraction.
Page 54 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
1. Rotate accumulator left (RLC) –
In this instruction, each bit is shifted to the adjacent left position. Bit D7 becomes D0. Carry flag
CY is modified according to the bit D7.
Page 55 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
However, these procedures are invalid when logic 1 is rotated left from D7 to D0 or vice versa.
For example, if 80H is rotated left it becomes 01H.
DYNAMIC DEBUGGING
Checking for logical and syntax errors in the program is called as debugging.
TYPES:
1.STATIC
2.DYNAMIC
STATIC DEBUGGING:
Checking for errors in the program manually using paper and pencil is known as static
debugging.
DYNAMIC DEBUGGING:
Checking for errors in the program by observing the execution of instructions is called as
DynAMIC DEBUGGING.
SINGLE STEP:
Allows you to execute one instruction at a time and observe the results of each
instruction.
Page 56 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
A Single step facility is built with a hard wired logic circuit.
By pressing Single-step key in the microprocessor, able to observe addresses and codes
as they are executed.
Single-step technique will be able to spot
incorrect address
incorrect jump locations for loops
incorrect data or missing codes.
To effectively use this technique reduce the number of loops and delay counts to
minimum number.
Better to use this technique for short programs.
This technique helps to infer the flag status by observing the execution of jump instructions.
REGISTER EXAMINE:
Register Examine Key in the microprocessor allows to examine the contents of the
microprocessor register.
By pressing appropriate keys, the monitor program displays the contents of the
registers.
This technique is used in conjunction with either the single step or break point facilities.
After executing a block of instructions, we can examine the register contents of the
program at a critical juncture and compare the contents with the expected outcomes.
BREAK POINT:
Page 57 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
UNIT IV
COUNTERS AND TIME DELAYS
TIME DELAY
Procedure used to design a specific delay. A register is loaded with a number,
depending on the time delay required and then the register is decremented until it
reaches zero by setting up a loop with conditional jump instruction.
N10 = Equivalent decimal number of hexadecimal count loaded in the delay register
Page 58 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
TLA= Time to execute loop instruction=TL –(3T states* clock period)=1785-1.5=1783.5 μs
Page 59 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Flowchart for time delay with two loops
Write a Program to count continuously from FFH to 00H using register C with delay
count 8CH between each count and display the number at one of the output ports.
Page 60 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Page 61 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Page 62 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
The beginning of the stack is defined in the program by using the instruction LXI SP, 16
bit address. Once the stack location is defined, it loads 16 bit address in the stack pointer
register. Storing of data bytes for this operation takes place at the memory location that is one
less than the address e.g. LXI SP, 2099H
Here the storing of data bytes begins at 2098H and continuous in reverse order i.e
2097H. Therefore, the stack is initialized at the highest available memory location to prevent
the program from being destroyed by the stack information. The stack instructions are:
PUSH Rp/PSW (Store register pair on stack)
One byte instruction. Copies the contents of specified register pair or program
status word (accumulator and flag) on the stack. Stack pointer is decremented and content of
high order register is copied. Then it is again decremented and content of low order register is
copied.
One byte instruction. Copies the contents of the top two memory locations of the stack into
specified register pair or program status word. A content of memory location indicated by SP is
copied into low order register and SP is incremented by 1. Then the content of next memory
location is copied into high order register and SP is incremented by 1.
DI – disable interrupt
Page 63 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
EI – Enable interrupt
SIM – set interrupt mask
E.g.
LXI H, 9320H
LXI B, 4732H
LXI D, ABCDH
MVI A, 34H
PUSH H
PUSH B
PUSH D
PUSH PSW
POP H
POP B
POP D
POP PSW
HLT
Page 64 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Subroutines
– Rather than repeat the same instructions several times, they can be grouped into a
subroutine that is called from the different locations.
– The RET insutruction is used to return the execution to the calling routine.
– When CALL instruction is fetched, the MP knows that the next two Memory
location contains 16bit subroutine address in the memory.
The RET Instruction
Page 65 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
The CALL instruction places the return address at the two memory locations immediately
before where the Stack Pointer is pointing.
Set the SP correctly BEFORE using the CALL instruction. The RET instruction takes the contents
of the two memory locations at the top of the stack and uses these as the return address. Do
not modify the stack pointer in a subroutine.
Number of PUSH and POP instruction used in the subroutine must be same, otherwise, RET
instruction will pick wrong value of the return address from the stack and program will fail.
– Call by Reference:
The data is stored in one of the registers by the calling program and the subroutine uses the
value from the register. The register values get modified within the subroutine. Then these
modifications will be transferred back to the calling program upon returning from a
subroutine
– Call by Value:
The data is stored in one of the registers, but the subroutine first PUSHES register values in
the stack and after using the registers, it POPS the previous values of the registers from the
stack while exiting the subroutine.
i.e. the original values are restored before execution returns to the calling program.
– The calling program stores the data in the memory location and the subroutine retrieves
the data from the location and uses it.
– If not, the RET statement will pick up the wrong information from the top of the stack
and the program will fail.
– The same conditions used with conditional JUMP instructions can be used
Page 66 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Do not use a CALL statement to jump into different points of the same subroutine.
C003: MVIA FF
C005: OUT 00
C007: CALL 14 20
C00A: MVIA 11
C00C: OUT 00
C00E: CALL 14 20
C011: JMP 03 C0
C016: MVIC FF
C018: DCR C
C019: JNZ 18 C0
C01C: DCR B
C01D: JNZ 16 C0
C020: RET
Page 67 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
UNIT V
CONVERSIONS
Problem – Write an assembly language program for converting a 2 digit BCD number to its
binary equivalent using 8085 microprocessor.
Examples:
Input: 72H (0111 0010)2
Output: 48H (in hexadecimal) (0011 0000)2
((4x16) + (8x1)) =72
Algorithm:
Load the BCD number in the accumulator
Unpack the 2 digit BCD number into two separate digits. Let the left digit be BCD 1 and the right
one BCD2
Multiply BCD1 by 10 and add BCD2 to it
If the 2 digit BCD number is 72, then its binary equivalent will be 7 x OAH + 2 = 46H + 2 = 48H
Steps:
Load the BCD number from the memory location (201FH, arbitrary choice) into the
accumulator.
Temporarily store the accumulator’s value in B.
Obtain BCD2 by ANDing the accumulator with 0FH and store it in C.
Restore the original value of the accumulator by moving the value in B to A. AND the
accumulator with F0H.
If the value in the accumulator equals 0, then BCD2 is the final answer and store it in the
memory location, 2020H (arbitrary).
Else, shift the accumulator to right 4 times to obtain BCD1. Next step is to multiply BCD1 by
0A.
Multiplication: Move BCD1 to D and initialise E with 0AH as the counter. Clear the
accumulator to 0 and add D to it E number of times.
Finally, add C to the accumulator and store the result in 2020H
Page 68 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
2001H
2002H
2003H MOV B, A
2005H
2006H MOV C, A
2007H MOV A, B
2009H
200AH JZ SKIPMULTIPLY
200BH
200CH
200DH RRC
Page 69 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
200EH RRC
200FH RRC
2010H RRC
2011H MOV D, A
2012H XRA A
2014H
2016H DCR E
2018H
2019H
201CH
Page 70 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
201DH
201EH HLT
Binary-to-BCD conversion
The microprocessor processes data in binary form but data that is displayed is in BCD form.
Hence, we require to convert the binary data to BCD.
Problem Statement
A binary number is store dat location 800H. Convert the number into its BCD equivalent
and store it to the memory location 8050H.
Discussion
Here we are taking a number from the memory, and initializing it as a counter. Now in
each step of this counter we are incrementing the number by 1, and adjust the decimal value.
By this process we are finding the BCD value of binary number or hexadecimal number. We can
use INR instruction to increment the counter in this case but this instruction will not affect carry
flag, so for that reason we have used ADI 10H.
Page 71 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Program
F003 16, 00 MVI D,00H Clear D- reg for Most significant Byte
F007 C6, 01 LOOP ADI 01H Count the number one by one
Page 72 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
BCD ADDITION
Page 73 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Page 74 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Page 75 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
BCD SUBTRACTION
Page 76 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
MULTIPLICATION
Problem – Multiply two 8 bit numbers stored at address 2050 and 2051. Result is stored at
address 3050 and 3051. Starting address of program is taken as 2000.
Example –
Algorithm –
Program –
Page 77 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
2012 HLT
Example –
OUTPUT:
(2054H) = 04H
(2055H) = OEH
Page 78 of 79
STUDY MATERIAL FOR B.C.A
MICROPROCESSOR
SEMESTER - IV, ACADEMIC YEAR 2020-21
Algorithm –
Program –
MEMORY
ADDRESS MNEMONICS COMMENTS
Page 79 of 79