Microprosessor Notes
Microprosessor Notes
T)
SEMESTER - II (CBCS)
MICROPROCESSOR
ARCHITECTURE
SUBJECT CODE: USIT202
© UNIVERSITY OF MUMBAI
: Aarti Sahitya
Assistant Professor,
K J Somaiya Institute of Engineering and
Information Technology, Sion, Mumbai.
Published by : Director,
Institute of Distance and Open Learning,
University of Mumbai,
Vidyanagari,Mumbai - 400 098.
Printed by :
ii
CONTENTS
Chapter No. Title Page No.
Unit 1
Unit 2
Unit 3
Unit 4
Unit 5
iii
F.Y.B.SC (I.T)
SEMESTER - II (CBCS)
Microprocessor Architecture
SYLLABUS
iv
IV Code Conversion, BCD Arithmetic, and 16-Bit Data Operations:
BCD-to-Binary Conversion, Binary-to-BCD Conversion, BCD-to-
Seven-Segment-LED Code Conversion, Binary-to-ASCII and ASCII-
to-Binary Code Conversion, BCD Addition, BCD Subtraction,
Introduction To Advanced Instructions and Applications,
Multiplication, Subtraction With Carry.
Software Development System and Assemblers: 12
Microprocessors-Based Software Development system, Operating
System and Programming Tools, Assemblers and Cross-Assemblers,
Writing Program Using Cross Assemblers.
Interrupts:
The 8085 Interrupt, 8085 Vectored Interrupts, Restart as S/W
Instructions, Additional I/O Concepts and processes.
V The Pentium and Pentium Pro microprocessors: Introduction,
Special Pentium registers, Memory management, Pentium instructions,
Pentium Pro microprocessor, Special Pentium Pro features.
Core 2 and later Microprocessors: Introduction, Pentium II software 12
changes, Pentium IV and Core 2, i3, i5 and i7.
SUN SPARC Microprocessor: Architecture, Register file, data types
and instruction format
v
UNIT 1
1
MICROPROCESSOR, MICROCOMPUTERS,
AND ASSEMBLY LANGUAGE
Unit Structure
1.0 Objectives
1.1 Introduction
1.2 Microprocessor
1.2.1 A Programmable Machine
1.2.2 Advances in Semiconductor Technology
1.2.3 Organization of a Microprocessor-based system
1.2.4 How does the Microprocessor work?
1.3 Microprocessor Instruction Set and Computer Languages
1.3.1 Machine Language
1.3.1.1 8085 Machine language
1.3.2 Assembly language
1.3.2.1 8085 Assembly language
1.3.2.2 Writing and executing an assembly language program
1.3.3 High-level language
1.3.4 Operating systems
1.4 From Large Computers to Single-Chip Microcontrollers
1.4.1 Large computers
1.4.2 Medium-size computers
1.4.3 Microcomputers
1.5 Application:
1.5.1 System hardware
1.5.2 System software
1
MICROPROCESSOR ARCHITECTURE
1.6 Summary
1.7 List of references
1.8 Unit End Exercise
1.0 Objectives
x Define microprocessor
x Classification of computers
1.1 Introduction
x Today microprocessor systems are used in every sphere of life with day to
day demand increasing for faster and better systems.
2
Chapter 1: Microprocessor, Microcomputers, and Assembly Language
1.2 Microprocessor
x In early 1960s, the processor was built using separate elements and in the
1970s all of the components that make up the processor are fabricated on a
single chip i.e. silicon chip.
x So this reduces the size of the processor and increases the computation speed.
x The data the microprocessor takes in for manipulation comes from the input
devices. These devices writes data from the outside world to the
microprocessor.
3
MICROPROCESSOR ARCHITECTURE
x Memory is the location where instructions and programs are stored. Each
location is capable of storing only one bit. So several bit locations are
combined to create registers and several registers are combined to create a
memory. Each location in memory is identified by address and capable of
storing group of bits.
4
Chapter 1: Microprocessor, Microcomputers, and Assembly Language
x The microprocessor processes on binary digits (called bits) i.e. 0 and 1 only.
x Several digits i.e. bits are combined to create words and this forms the basis
of microprocessor classification based on word length.
x So for example each line is an 8 bit register that stores a 8 bit word and several
registers are combined one below the another to create a memory cell.
x The user enters data into memory through input devices like keyboard and
simple switch.
x The microprocessor reads the instruction from the memory and processes the
data according to those instructions.
x The results are viewed on output device like seven segment LEDs and printer.
5
MICROPROCESSOR ARCHITECTURE
x The invention of transistors further brought down the size of the system
Historical Perspective:
x The world’s first recognized microprocessor is Intel4004 a 4-bit
microprocessor–programmable controller on a chip.
x There were just 45 instructions for 4004 and widely used in video games and
small-scale microprocessor control system.
x In 1970 due to the increase in computational demand, Intel built the 8008
which is extended 8-bit version of the 4004 microprocessor.
x As people begin to use, Intel recognized the limitations and came up with the
powerful 8 bit microprocessor 8080 in 1973.
x Table 1.1 lists several of these early microprocessors and their manufacturers.
6
Chapter 1: Microprocessor, Microcomputers, and Assembly Language
x With fifty years since the invention of the 4004, Intel has made the processors
that are designed with 15 million transistors that can address 1TB of memory
and can operate at 400 Mhz to 1.5 GHz frequency.
7
MICROPROCESSOR ARCHITECTURE
8
Chapter 1: Microprocessor, Microcomputers, and Assembly Language
x The instructions are sequentially stored in the memory one after another.
x The series is continued until each and every instructions are done.
x The microprocessor uses system bus to fetch the address, data and binary
instructions to and from the memory.
x However each microprocessor has its own binary words creating the
instruction set and the interpretation of the words which is designed based on
the microprocessor.
9
MICROPROCESSOR ARCHITECTURE
x The word length (expressed in bytes – 8 bits) is defined as the number of bits
the microprocessor recognizes and processes in a given time
x So high level languages are used which contains English like statements and
are machine independent.
x If a machine language has ‘n’ bits then the language has 2n words.
x For example a machine with a word length of eight bits can have 256 (2 8)
combinations of eight bits – thus a language have 256 words.
x The design engineer selects only certain combination of bit pattern and not
all and then gives a specific interpretation to each combination known as
instruction.
x For example, the combination 0000 1100 (Hex Code – 0C) is interpreted as
Increment the value of Register C by 1.
x It is tedious and error-inducive for people to write instructions in binary
language so writing in hexadecimal makes it less error-prone.
10
Chapter 1: Microprocessor, Microcomputers, and Assembly Language
x But just reading a set of hexadecimal code makes it difficult for the user to
interpret the meaning of the program.
x This code known as mnemonics are short English words which are machine
dependent.
x Using the same example from before, 0000 1100 is 0C in hex and the
mnemonic is INR C.
x For example, an 8-bit microprocessor for Motorola i.e. 6800 and Intel i.e.
8085s instruction sets are different from each other.
x The first procedure is called either manual or hand assembly. The steps are
¾ From the instruction set given by the manufacturer, write the
instructions in assembly language.
¾ Find the corresponding hexadecimal code for each instruction.
¾ Enter the hex code in the memory step by step in the kit using the
hexadecimal keyboard.
¾ Press the Exec key to execute the code and check for presence of errors.
11
MICROPROCESSOR ARCHITECTURE
¾ Correct errors if any and view the result in seven segment LED Display.
x They have English like statements with proper syntax and semantic.
x The machine does not understand high level language and so tools like
compiler and interpreter convert them into machine language for processing.
x The operating system controls the overall operation and manages the
interaction between the computer hardware and software.
12
Chapter 1: Microprocessor, Microcomputers, and Assembly Language
x The operating system boots when the system is switched on identifying the
hardware and handles the application programs running in the background.
x Several operating systems have evolved over the years from control monitor
program to graphical user interface operating system.
13
MICROPROCESSOR ARCHITECTURE
x They are capable of solving complex and scientific calculations and handles
huge volumes of data and handles hundreds of user.
Mainframe Supercomputer
x To meet the needs of small factories and data processing tasks the medium-
size or mini computers are introduced.
14
Chapter 1: Microprocessor, Microcomputers, and Assembly Language
1.4.3 Microcomputers
x It contains microprocessor as its central processor along with memory and
minimal input/output devices
15
MICROPROCESSOR ARCHITECTURE
16
Chapter 1: Microprocessor, Microcomputers, and Assembly Language
executes them. It reads temperature from LCD and turn on/off fan or
heater depending on the set point value
¾ Memory – The ROM provides instructions to monitor the system and
R/W memory temporary stores the temperature value.
¾ Input Device – The temperature sensor is the main input device which
measures the temperature in signals and for the microprocessor to
process the signal A/D (Analog to Digital) Convertor is used. Devices
cannot be directly connected to processor and therefore connected via
input ports.
¾ Output Device – LCD panel, fan and heater forms the output device of
this application. Just as input device cannot be directly connected, the
output devices are also connected via ports.
1.5 Summary
x The microprocessor along with memory and I/O devices carry out various
functionalities.
x Different computer languages are available but the processor understands the
machine language and users program in assembly or high level language
List of References
17
MICROPROCESSOR ARCHITECTURE
x https://www.tutorialspoint.com/microprocessor/microprocessor_overview.h
tm
18
UNIT 1
2
MICROPROCESSOR ARCHITECTURE AND
MICROCOMPUTER SYSTEMS
Unit Structure
2.0 Objectives
2.1 Introduction
2.2 Microprocessor Architecture and its Operation
2.2.1 Microprocessor-Initiated Operations
2.2.2 Internal Operations
2.2.3 Peripheral Operations
2.3 Memory
2.3.1 Flip-flop or Latch as Storage Element
2.3.2 Memory Map and Address
2.3.3 Word Size of Memory
2.3.4 Instruction Fetch from Memory
2.3.5 Classification of Memory
2.4 I/O Devices
2.4.1 Peripheral-mapped I/O
2.4.2 Memory-mapped I/O
2.5 Microcomputer System Illustration
2.6 Logic Devices
2.6.1 Tri-state Device
2.6.2 Decoder
2.6.3 Encoder
2.6.4 D Flip-flop
2.7 Application: MCTS
2.8 Summary
2.9 List of references
2.10 Unit End Exercise
19
MICROPROCESSOR ARCHITECTURE
2.0 Objectives
2.1 Introduction
x User can write programs using the instruction set of the microprocessor.
20
Chapter 2: Microprocessor Architecture and Microcomputer Systems
21
MICROPROCESSOR ARCHITECTURE
FLAG REGISTER
ACCUMULATOR (A REGISTER) D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
B C
D E
H L
STACK POINTER (SP)
PROGRAM COUNTER (PC)
ADDRESS BUS DATA BUS
x The first instruction is written at address 2000H and this value is loaded in
program counter and execution begins.
x Then program counter is incremented to next address which is 2002H and the
instructions increments the value in C register.
22
Chapter 2: Microprocessor Architecture and Microcomputer Systems
2.3 Memory
x The microprocessor reads data and programs (here instructions) from the
memory and stores results to the memory.
x The microcomputer system has two types of memory – Read Only Memory
and Read/Write Memory
x The Read Only Memory is non-volatile that stores system level programs
available to system all time.
x The Read/Write memory holds program and data which can be read and
written by the programmer and are volatile in nature.
23
MICROPROCESSOR ARCHITECTURE
x So a basic feature of memory that stores the binary bits is the flip-flop or
latch.
x The latch includes one input line, one output line, and an enable input that
allows the latch to be triggered.
x For securing and controlling the data in and out of latch, we use tristate
buffers at input and output line.
x The input buffer in controlled by the active low control signal write (ܹܴ തതതതതሻ
തതതതሻ
and the output buffer is controlled by the active low control signal read (ܴܦ
x This latch is called as a memory cell capable of storing a binary bit or digit.
x For example four latches have been connected to create a memory register
identified as 1 x 4 where 1 represents count of memory register and 4
represents the number of bits the individual register can hold.
24
Chapter 2: Microprocessor Architecture and Microcomputer Systems
y The Enable signal (EN) enables the register and the write or read operation
can be performed in the register by enabling the input or output buffer
respectively with the control signal.
y We can now expand the diagram by adding several memory registers to create
a memory chip.
y Using interfacing logic with help of decoder, we can select individual
registers and perform write or read operation by enabling the input or output
buffer respectively.
y Let’s construct as 4 x 4 memory i.e. 4 registers each capable of storing a 4 bit
word.
y When count of registers increases then the enable signal is replaced by
address lines for register selection.
y Two address line A1-A0 are connected to decoder for selecting the register.
y Four combinations (00, 01, 10 and 11) will select the register (0, 1, 2 and 3).
25
MICROPROCESSOR ARCHITECTURE
y We shall further expand with eight registers on one chip each capable of
storing 8 bits/1 byte of data.
y For this we will require three address lines A2 – A0 which provides eight
combinations (000, 001, 010, 011, 100, 101, 110, 111) for register select.
y And if we have 16 registers, we need four address lines and this calculation
goes on.
No. of Size of memory
address lines
1 2
2 4
3 8
4 16
5 32
6 64
7 128
8 256
9 512
10 1024 ≈ 1K
11 2048 ≈ 2K
12 4096 ≈ 4K
13 8192 ≈ 8K
14 16384 ≈ 16K
15 32768 ≈ 32K
16 65536 ≈ 64K
Table 2.1 – Memory size and address line relationship
26
Chapter 2: Microprocessor Architecture and Microcomputer Systems
27
MICROPROCESSOR ARCHITECTURE
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
x The above table is called the memory map which is the pictorial
representation of the address range.
x We shall now see a memory organization of 256 registers with 8 data lines
i.e. this memory called as 256 x 8 memory organization.
x 256 = 28. So 8 address lines (A7—A0) are used for selecting memory register
and remaining 8 address lines (A15—A8) are used for chip select (ܵܥ തതതതሻ logic
and two control signals Write (ܹܴതതതതത ) and Read (ܴܦ
തതതത) for data storage and
retrieval respectively.
x For register select the address line are connected to internal decoder and for
chip select the address line are connected to NAND gate via invertors.
x So when the NAND gate output is low the memory chip is selected.
28
Chapter 2: Microprocessor Architecture and Microcomputer Systems
A1 A1 A1 A1 A1 A1 A A A A A A A A A A
5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
x We shall now see a memory organization of 8192 registers with 8 data lines
i.e. this is referred as a memory size of 8192 x 8.
x 8192 = 213. So 8 address lines (A12—A0) are used for selecting memory
register and remaining 3 address lines (A15—A13) are used for chip select
തതതതሻ logic and two control signals Write (ܹܴ
(ܵܥ തതതതത ) and Read (ܴܦ
തതതത) for data
storage and retrieval respectively with same logic applied for interfacing.
29
MICROPROCESSOR ARCHITECTURE
A1 A1 A1 A1 A1 A1 A A A A A A A A A A
5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
x We can construct any memory based on above logic and calculate the address
range on the memory chip.
x For example, a memory chip of size 512 x 4 means 512 registers individually
which stores 4 bits and total memory chip size calculated as 512 x 4 = 2048
bits.
x This is done by sending the address of the specific memory register via the
address bus and enable the data flow depending on the control signal issued.
x For example the memory address 2000H contains the instruction MOV E, A
30
Chapter 2: Microprocessor Architecture and Microcomputer Systems
Memory
Main Secondary
Masked Flash
Static Dynamic PROM EPROM EEPROM
ROM memory
31
MICROPROCESSOR ARCHITECTURE
x The Read Only Memory (ROM) is non-volatile memory which stores system
level programs that PC want at all times.
Masked ROM are hard-wired and bit masking is done by metallization
process usually by the manufacturers.
Programmable ROM (PROM) is diode-based and programmed using
special devices that burn the fuses for storage of the appropriate bit
pattern.
Erasable PROM (EPROM) can be programmed as it stores bits by
charging and erasing the floating gate. Erasing is done using UV rays
and hence entire memory content will be erased and can be
reprogrammed again.
Electrically Erasable PROM (EEPROM) – Similar to EPROM with
difference that erasing is done under software control at register level
instead of entire chip.
Flash Memory are advanced level with erasing done at sector level or
entirely and can be reprogrammed million times.
32
Chapter 2: Microprocessor Architecture and Microcomputer Systems
33
MICROPROCESSOR ARCHITECTURE
x As name indicate these devices have a three output states – Logic 0, Logic 1
and high impedance state
x This state is to effectively remove the device influence from rest of the circuit.
x Tristate devices have enable line to confirm whether device works in normal
state or high impedance state
x Tristate buffer and tristate invertor are commonly used interfacing devices.
x When enable is high these device act as normal device and when enable line
is low, the device enters into high impedance state.
2.6.2 Decoder
y Decoder is a logic circuit that converts binary information from n input to 2n
output.
y So in high performance memory system decoders can minimize the effect of
memory selection.
y Each combination of input lines helps to select a single unique memory
register.
y Example 2:4 Decoder, 3:8 Decoder and so on.
34
Chapter 2: Microprocessor Architecture and Microcomputer Systems
2.6.3 Encoder
x Encoder is opposite of decoder where it provides output for each input
signal
2.6.4 D Flip-Flop
x It is most essential device while interfacing the output devices
x The MPU holds data in the data bus only for few microseconds and it is very
important to latch the data before it is lost
Figure 2.17 – D FF
35
MICROPROCESSOR ARCHITECTURE
y The application discussed in the last chapter is now expanded with interfacing
devices included.
y Decoder is required to interface each device
y The input device in this case temperature sensor are interfaced using buffer
y The output devices in this case fan, heater and LCD are interfaced using the
latch
2.8 Summary
y The microprocessor performs basic four operations such as Memory Read
തതതതതതതതതത, Memory Write (ܹܯܧܯሻ
(ܴܯܧܯሻ തതതതതതതതതതത, I/O Read (ܴܱܫሻ
തതതതതതത, I/O Write (ܹܱܫሻ
തതതതതതതത.
y The address bus, data bus and control bus govern the entire communication
between MPU, memory and peripherals
y The architecture of 8085 is robust to handle different kinds of operation.
y Memory is integral part of MPU and different types of memories help in
execution of different activities of the microprocessor all identified by 16 bit
address.
y I/O devices are interfaced either by 8 bit address or 16 bit address.
y To interconnect peripherals and MPU several interfacing devices are used to
ease the operation
36
Chapter 2: Microprocessor Architecture and Microcomputer Systems
x https://www.tutorialsmate.com/2020/04/types-of-computer-memory.html
37
UNIT 1
3
8085 MICROPROCESSOR ARCHITECTURE
AND MEMORY INTERFACING
Unit Structure
3.0 Objectives
3.1 Introduction
3.2 8085 Microprocessor Unit
3.2.1 8085 Microprocessor
3.2.2 Microprocessor communication and bus system
3.2.3 Demultiplexing the address-data bus
3.2.4 Generating Control Signals
3.2.5 The 8085 Microprocessor Architecture
3.3 8085 based Microcomputer Illustration
3.3.1 The 8085 Machine Cycle
3.3.2 Opcode Fetch Cycle
3.3.3 Memory Read Machine Cycle
3.3.4 Memory Write Machine Cycle
3.3.5 How to Recognize Machine Cycle
3.4 Memory Interfacing
3.4.1 Memory structure and its requirements
3.4.2 Basic concepts in memory interfacing
3.4.3 Address Decoding and Memory Address
3.4.3.1 Read Only Memory Chip
3.4.3.2 Read/Write Memory Chip
3.5 Interfacing 8155 Memory Segment
3.6 Designing Memory for MCTS Project
38
Chapter 3: 8085 Microprocessor Architecture and Memory Interfacing
3.0 Objectives
3.0 Introduction
x The 8085 microprocessor is enhanced version of its predecessor 8080A.
x Introduced in the year 1976, the 8085 is the predominantly and widely
accepted 8 bit microprocessor.
x It works on single +5V power supply and operates on 3MHz clock frequency.
x It has 16 address lines with which it can address 64K memory and 8 data
lines.
39
MICROPROCESSOR ARCHITECTURE
x Address bus
o There are 16 address lines which are unidirectional
o The first eight pins A15 - A8 carry the high order address i.e. the most
significant bits and the remaining eight pins A7 - A0 are combined with
data bus which holds the low order address i.e. the least significant bits
and data.
40
Chapter 3: 8085 Microprocessor Architecture and Memory Interfacing
41
MICROPROCESSOR ARCHITECTURE
x First step involves the microprocessor placing the 16-bit address on the
program counter.
x The data in the memory location identified by the address in now on placed
on the data bus.
x The data bus carries it to instruction decoder where the action is taken
according to the instruction.
42
Chapter 3: 8085 Microprocessor Architecture and Memory Interfacing
x The low order address lines are multiplexed with data bus as AD7– AD0.
x The high order address is available for three clock period and low order is
available for only one clock period and hence will be lost
x When ALE is high, the latch is enabled and the bus contains address which
is stored in latch and when ALE is low the latch is disabled and the bus now
contains data which is directly used.
43
MICROPROCESSOR ARCHITECTURE
x The signals can be generated using negative NAND gates or a 3:8 decoder.
44
Chapter 3: 8085 Microprocessor Architecture and Memory Interfacing
x Register Group
o A pair of temporary register W and Z not available to the programmer
but used by the microprocessor during the stack operations.
o Six general purpose 8-bit register B, C, D, E, H and L to store data.
o They are combined to form register pairs BC, DE and HL to store 16-
bit data.
o A 16-bit program counter (PC) to hold the address of the instruction to
be executed and which keeps incrementing to fetch the next instruction
till the end of program.
o A 16-bit stack pointer register used as pointer to stack location where
data is stored temporarily.
45
MICROPROCESSOR ARCHITECTURE
x The time taken for the complete execution of single instruction is the
instruction cycle.
x The time taken for the complete execution of one operation such as accessing
memory or peripheral is the machine cycle.
x The 8085 one instruction cycle can have one to six machine cycle and each
machine cycle has three to six T-states.
46
Chapter 3: 8085 Microprocessor Architecture and Memory Interfacing
x So the first machine cycle of any instruction is opcode fetch cycle which has
four T-states.
x It uses the first three states T1 —T3, to fetch the code and T4 to decode and
execute the opcode.
x The multiplexed bus AD7– AD0 hold low order address during T1 which is
indicated by ALE signal going high and between T2- T3 holds the data
indicated as ALE goes low.
x ഥ , S1
Opcode fetch is a memory operation and indicated by status signals IO/ܯ
and S0 = 011.
x തതതതሻgoes low
When opcode (data) is placed in the data bus the read signal (ܴܦ
to enable the operation.
x The high order address and multiplexed address data bus logic remains same
as opcode fetch cycle.is available for three T-states.
x ഥ , S1 and S0 = 010.
Memory read operation is indicated by status signals IO/ܯ
When data is placed in the data bus from memory location the read signal
തതതതሻgoes low to enable the operation.
(ܴܦ
47
MICROPROCESSOR ARCHITECTURE
x The high order address and multiplexed address data bus logic remains same
as opcode fetch cycle.is available for three T-states.
x ഥ , S1 and S0 = 001.
Memory write operation is indicated by status signals IO/ܯ
x When data is placed in the memory location from the data bus now instead
തതതതത ሻ goes low to enable the operation
of read, the write signal (ܹܴ
x It is a two byte instruction and it requires two machine cycle to execute the
instruction.
x The first machine cycle is opcode fetch which requires four T-states and
second machine cycle is memory read which requires three T-states and so a
total of seven T-states.
Memory Address Mnemonic Hex / Machine Code
2000 MVI B, 43H 06 (0000 0110)
2001 43 (0100 0011)
48
Chapter 3: 8085 Microprocessor Architecture and Memory Interfacing
x In the first machine cycle the microprocessor decodes the opcode as seen in
the opcode fetch machine cycle and in the second machine cycle the memory
places the data byte on the data bus which is then stored in register B at the
end of T3.
x The execution time of the instruction is calculated as
o Let us assume the Clock frequency f = 2 MHz
x It is a three byte instruction but it requires four machine cycle to execute the
instruction.
49
MICROPROCESSOR ARCHITECTURE
x The first machine cycle is opcode fetch which requires four T-states and
second and the third machine cycle is memory read with three T-states each
followed by final cycle of memory write with three T-states making it a total
of thirteen T-states.
x In the opcode fetch cycle, the microprocessor places the address 2050H in
address bus and opcode 32H in data bus.
x In the first memory read cycle the microprocessor reads the address 2051H
and the data bus reads the low order byte 00H.
x In the second memory read machine cycle the microprocessor reads the
address 2052H and the data bus reads the high order byte 80H.
x In the last cycle the address 8000H is placed in the address bus and the byte
available in the accumulator is stored in this location via the data bus.
50
Chapter 3: 8085 Microprocessor Architecture and Memory Interfacing
51
MICROPROCESSOR ARCHITECTURE
x The memory read and write cycle explained earlier illustrates the interfacing
concept.
x A unique pulse identifies the address and this pulse can be generated using
NAND gate and 3:8 Decoder.
x The output of NAND gate selects the chip when address A15- A12 will be
high.
x The same result can be obtained 3:8 decoder which can decode 8 devices
based on the address bits A14- A12.
x The address lines A11—A0 are connected to memory chip to select register.
x The address lines A14—A12 are connected as inputs to 3:8 decoder which
തതതത ) and A15 is connected to enable pin of
when asserted low selects the chip (ܧܥ
the decoder.
x So the value A15—A12 = 0000 enables the decoder to assert output through
O0 .
52
Chapter 3: 8085 Microprocessor Architecture and Memory Interfacing
x The address lines A10—A0 are connected to memory chip to select register.
x The address lines A13—A11 are connected as inputs to 3:8 decoder which
തതതത ) and remaining address lines A15 and
when asserted low selects the chip (ܧܥ
ഥ is connected to enable pin of the decoder
A14 along with IO/ܯ
x So the value A15—A11 = 10001 enables the decoder to assert output through
O1.
53
MICROPROCESSOR ARCHITECTURE
x Both the memory chips used all address lines for decoding and this is
known as absolute decoding.
x The 256 x 8 memory is identified with 8 address lines A7-A0 and the
remaining address lines A15-A11 are connected to decoder with A15-A14
connected to enable pin and A13-A11 connected to input of the decoder and
output O4 of the decoder is asserted low to enable the chip. So A15-A11 =
00100 enables the decoder.
54
Chapter 3: 8085 Microprocessor Architecture and Memory Interfacing
x This interfacing technique where all address lines are not used for decoding
is called as partial decoding and advantageous as cost saving technique.
x The address range for the above memory is called foldback or mirror
memory.
x The primary address range is 2000H -20FFH and foldback memory range is
2100H – 27FFH.
55
MICROPROCESSOR ARCHITECTURE
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
56
Chapter 3: 8085 Microprocessor Architecture and Memory Interfacing
0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 2000H
0 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 27FFH
0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 2800H
0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 2FFFH
x The primary address range is 2000H -27FFH and foldback memory range is
2800H – 2FFFH.
3.7.1 Testing
x Testing is simply done by randomly choosing a memory location and writing
the data byte at that location with help of keyboard and then reading the
content of the same memory location and displaying the result in display.
x If the content matches then memory is available and we can repeat this test
at different memory locations.
3.7.2 Troubleshooting
x The best way to perform troubleshooting is visual inspection.
x We check wires, pin connections which is easy but logic level of buses
checking is difficult as it is dynamic.
x Signal injection is useful technique where signal is injected at input and check
output as per expected outcome
57
MICROPROCESSOR ARCHITECTURE
x The infinite loop loads value AAH in accumulator and then stores the value
in the memory location 2000H and this process is repeated infinitely.
x The monitor program reads hex keyboard and check for closure.
x It then display the key pressed at display and simultaneously stores binary
equivalent memory.
3.9 Summary
x The 8085 microprocessor is dual inline package with 40 pins with each pin
having a unique functionality.
x The architecture of 8085 has functional groups that helps to carry the
operation with ease.
58
Chapter 3: 8085 Microprocessor Architecture and Memory Interfacing
x In interfacing the memory, if all address lines are used then it represents
absolute decoding and if few address lines are used its partial decoding and
this reduces hardware and generates foldback mirror which provides multiple
addresses.
x https://tutorialspoint.com
x https://www.brighthubengineering.com
x https://www.javatpoint.com
1. ഥ (iv)
State the functions of the following pins: (i) X1 (ii) HLDA (iii) IO/ܯ
തതതതതതത
( ܣܶܰܫv) READY
2. Illustrate the steps and timing of data flow for the instruction MOV D, M
stored in memory location 2000H.
3. Illustrate the steps and timing of data flow for the instruction LDA 4050H
stored in memory location 3000H.
4. How to interface the EPROM. What is the address decoding technique &
state the memory address range?
5. How to test and troubleshoot memory interfacing circuit?
59
UNIT-2
4
I/O INTERFACING
Unit Structure
4.0 Objectives
4.1 Introduction
4.2 Basic Interfacing Concepts
4.2.1 Peripheral I/O Instructions
4.2.2 I/O Execution
4.2.3 Device Selection And Data Transfer
4.2.4 Absolute vs Partial Decoding
4.2.5 Input Interfacing
4.2.6 Interfacing I/Os Using Decoders
4.3 Interfacing Output Displays
4.3.1 Illustration: LED Display for Binary Data
4.3.2 Illustration: Seven- Segment LED Display as an Output Device
4.4 INTERFACING INPUT DEVICES
4.4.1 Illustration: Data Input from DIP Switches
4.5 Memory –Mapped I /O
4.5.1 Execution of Memory- Related Data Transfer Instructions
4.5.2 Illustration: Safety Control System Using Memory-Mapped
I/O Technique
4.5.3 Comparison of Memory-Mapped I/O and Peripheral I/O
4.6 Testing And Troubleshooting I/O Interfacing Circuits
4.6.1 Diagnostic Routine And Machine Cycles
4.7 Summary
60
Chapter 4: I/O Interfacing
4.0 Objectives
x Illustrate the 8085 bus contents and control signals when OUT and IN
instructions are executed.
x Illustrate 8085 bus contents and control signal when memory- related
instructions (LDA, STA, etc) are executed.
4.1 Introduction
61
MICROPROCESSOR ARCHITECTURE
62
Chapter 4: I/O Interfacing
Typically, to display the accumulator at an output device (such as LEDs) with the
address, for example, 01H, the instruction will be written and stored in memory as
follows:
(Note: The memory locations 2050H are chosen here arbitrarily for the illustration.)
If the output port with the address 01H is designed as an LED display, the
instruction OUT will display the contents of the accumulator at the port. The second
byte of this OUT instruction can be any of the 256 combinations of eight bits, from
00H to FFH. Therefore, the 8085 can communicate with 256 different output ports
with device addresses ranging from 00H to FFH. Similarly, the instruction IN can
be used to accept data from 256 different input ports. Now the question remains:
How does one assign a device address or a port number to an I/O device from
among 256 combinations? The decision is arbitrary and somewhat dependent on
available logic chips. To understand a device address, it is necessary to examine
how the microprocessor executes IN/OUT instructions.
63
MICROPROCESSOR ARCHITECTURE
When the 8085 decodes the machine code D3, it finds out that the instruction is a
2- byte instruction and that it must read the second byte.
In the second machine cycle, M2 (Memory Read), the 8085 places the next address,
2051 H, on the address bus and gets the device address 01H via the data bus.
On the low –order (AD7 - AD0 ) as well as high-order (A15 - A8 ) address bus.
The IO/Ṁ signal goes high to indicate that it is an I/O operation. At T2, the
accumulator contents are placed on the data bus (AD7 - AD0), followed by the
control signal WR
By ANDing the IO/Ṁ and ܹܴ signals, the ܹܱܫsignal can be generated to enable
an output device.
Figure 4.1 shows the execution timing of the OUT instruction. The information
necessary for interfacing an output device is available during T2 and T3 of the M3
cycle. The data byte to be displayed is on data bus, 8- bit device address is available
on the low- order as well as high-order address bus, and availability of the data byte
is indicated by the ܹܴ control signal. The availability of the device address on both
segments of the address bus is redundant information; in peripherals I/O, only one
segment of the address bus (low or high) is sufficient for interfacing. The data byte
remains on the data bus only for two T- states, then the processor goes on to execute
the next instruction. Therefore, the data byte must be latched now, before it is lost,
using the device address and control signal
64
Chapter 4: I/O Interfacing
In Instruction
The 8085 instruction set includes the instruction IN to read (copy) data from input
devices such as switches, keyboard, and A/D data convertors. This is a two- byte
instruction that reads an input device and places the data in the accumulator. The
first byte is the opcode, and the second byte specifies the port address. Thus, the
addresses for input devices can range from 00H to FFH . The instruction is
described as
IN 8- bit :- This is a two- byte instruction with the hexadecimal opcode DB, and
the second byte is the port address of an input device.
This instruction reads (copies) data from an input device and places the data byte
in the accumulator.
To read switch positions, for example, from an input port with the address 84H, the
instructions will be written and stored in memory as follows :
When the microprocessor is asked to execute this instruction, it will first read the
machine codes (or bytes) stored at locations 2065H and 2066H, then read the switch
positions at port 84H by enabling the interfacing device of the port. The data byte
indicating switch positions from the input port will be placed in the accumulator.
Figure shows the timing of the IN instruction; M1 and M2 cycles are identical to
that of the OUT instruction.
In the M3 cycle, the 8085 microprocessor places the address of the input port (84H)
on the low- order address bus AD7 –AD0 as well as on the high- order address bus
A15 – A8 and asserts the ܴ ܦsignal, which is used to generate the I/O Read (IOR)
signal.
The ܴܱܫenables the input port, and the data from input port are placed on the data
bus and transferred into the accumulator.
65
MICROPROCESSOR ARCHITECTURE
Machine cycles M3 (Figure 4.2 ) is similar to the M3 cycle of the OUT instruction;
the only differences are (1) the control signal is ܴܦinstead of ܹܴ and (2) data flow
from an input port to the accumulator rather than from the accumulator to an output
port.
66
Chapter 4: I/O Interfacing
The block diagram (Figure 4.3 ) illustrate these steps for interfacing an I/O device.
Figure 4.4 shows a practical decoding circuit for the output device with address
01H. Address lines A7 – A0 are connected to 8- input NAND gate that functions as
a decoder. Lines A0 is connected directly, and lines A7 – A1 are connected through
the inverters. When the address bus carries address 01H, gate G1 generates a low
pulse; otherwise, the output remains high. Gate G2 and the control signal ܹܱܫto
generate an I/O select pulse when both input signals are low.
67
MICROPROCESSOR ARCHITECTURE
Meanwhile the contents of the accumulator are placed on the data bus and are
available on the data bus for a few microseconds and, therefore, must be latched
for display. The I/O select pulse clocks the data into the latch for display by the
LEDs.
As a result, the device has multiple addresses (similar to fold back memory
addresses).
68
Chapter 4: I/O Interfacing
The address lines are decoded by using an 8- input NAND gate. When address lines
A7 – A0 are high(FFH), the output of the NAND gate goes low and is combined
with control signal ܴܱܫin gate G2. When the MPU executes the instruction (IN
FFH), gate G2 generates the device select pulse that is used to enable the tri- state
buffer. Data from the key are put on the data bus D7 – D0 and loaded into the
accumulator. The circuit for the input port in figure differs from the output port in
figure as follows:
69
MICROPROCESSOR ARCHITECTURE
Figure 4.7 illustrate another scheme of address decoding. In this circuit, a 3- to- 8
decoder and a 4- input NAND gate are used to decode the address bus; the decoding
of the address bus is the first step in interfacing I/O devices.
The address lines A2, A1 and A0 are used as input to the decoder, and the remaining
address lines A7 – A3 are used to enable the decoder. The address lines A7 is directly
connected to E3 (active high Enable line), and the address lines A6 – A3 are
connected to E1 and E2 (active low enable line) using the NAND gate. The decoder
has eight output lines; thus, we can use this circuit to generate eight device address
pulses for eight different addresses.
The second step is to combine the decoded address with an appropriate control
signal to generate the I/O select pulse. Figure shows that the output O0 of the
decoder is logically ANDed in a negative AND gate with the ܹܱܫcontrol signal.
The output of the gate is the I/O select pulse for an output port. The third step is to
use this pulse to enable the output port. Figure shows that the I/O select pulse
enables the LED latch with the output port address F8H, as shown below (A7 – A0
is the de multiplexed low- order bus).
Similarly, the output O2 of the decoder is combined with I/O Read (IOR) signal,
and the I/O select pulse is used to enable the input buffer with the address FAH.
70
Chapter 4: I/O Interfacing
This section concerns the analysis and design of practical circuits for data display.
The section includes two different types of circuits. The first illustrates the simple
display of binary data with LEDs, and the second illustrate the interfacing of seven-
segment LEDs.
Circuit Analysis
Address bus A7 – A0 is decoded by using an 8- input NAND gate. The output of
the NAND gate goes low only when the address lines carry the address FFH. The
output of the NAND gate is combined with the microprocessor control signal ܹܱܫ
in a NOR gate (connected as negative AND).The output of NOR gate 74LS02 goes
to generate an I/O select pulse when both inputs are low (or both signals are
asserted). Meanwhile, the contents of accumulator have been put on the data bus.
The I/O select pulse is used as a clock pulse to activate the D- type latch, and the
data are latched and displayed.
Figure 4.8 :- Interfacing LED Output Port Using the 7475 D-Latch (a) and
Using the 74LS373 Octal D-Type Latch (b)
71
MICROPROCESSOR ARCHITECTURE
In this circuit, the LED cathodes are connected to the Q output of the latch. The
anodes are connected to +5V through resistors to limit the current flow through the
diodes. When the data line (for example D0 ) has 1, the output Q is 0 and the
corresponding LED is turned on. If the LED anode were connected to Q, its cathode
would be connected to the ground .In this configuration, the D flip-flop would not
be able to supply the necessary ground. In this configuration, the D flip-flop would
not be able to supply the necessary current to the LED.
Figure 4.8 uses the 74LS373 octal latch an interfacing device, and both circuit(a)
an (b) are functionally similar. The 74LS373 includes D-latches(flip-flops)
followed by tri-state buffers. This device has two control signals: Enable (G) to
clock data in the flip-flops and Output Control (OC) to enable the buffers. In this
circuit, the 74LS373 is used as a latch; therefore the tri- state buffers are enabled
by grounding the OC signal.
Program
Address Machine Mnemonics Comments
(LO) Code
00 3E MVI A, ; Load accumulator with data
DATA
01 DATA*
02 D3 OUT FFH ; Output accumulator contents
to port FFH
03 FF
04 76 HLT ; End of program
Program Dscription
Instruction MVI loads the accumulator with the data you enter, and instruction
OUT FFH identifies the LED port as the output device and displays the data.
2. Given ܹܴ and IO/ M signals from the 8085, generate the ܹܱܫcontrol signal.
72
Chapter 4: I/O Interfacing
3. Explain the binary codes required to display 0 to F Hex digits at the seven-
segment LED.
4. Write instructions to display digit 7 at the port.
Hardware Description
The design problem specifies two MSI chips – decoder (74LS138) and the latch
74LS373 – and a common- anode seven-segment LED. The decoder and the latch
have been described in previous sections; the seven-segment LED and its binary
code requirement are discussed below.
73
MICROPROCESSOR ARCHITECTURE
connected to DP; otherwise it is left open. The binary code required to display a
digit is determined by the type of the seven-segment LED ( common cathode or
common anode ), the connections of the data lines, and the logic required to light
the segment. For example, to display digit 7 at the LED in Figure 4.10, the
requirements are as follows :
Data D7 D6 D5 D4 D3 D2 D1 D0
Lines =78H
Bits X 1 1 1 1 0 0 0
Segments NC G F E D C B A
The code for each digit can be determined by examining the connections of the data
lines to the segments and the logic requirements.
74
Chapter 4: I/O Interfacing
This can be accomplished by using A2, A1 and A0 as input lines to the decoder. A3
can be connected to active low enable E1, and the remaining address lines can be
connected to E2 through the 4- input NAND gate. Figure shows an output port with
the address F5H. The output O5 of the decoder is logically ANDed with the control
signal ܹܱܫusing the NOR gate (74LS02). The output of the NOR gate is the I/O
select pulse that is used to enable the latch (74LS373). The control signal is ܹܱܫ
is generated by logically ANDing IO / M and ܹܴ signals in the negative NAND
gate (physically OR gate 74LS32).
Instructions: The following instructions are necessary to display digit 7 at the
output port:
MVI A, 78H ; Load seven- segment code in the accumulator
OUT F5H ; Display digit 7 at port F5H
HLT; End
The first instruction loads 78H in the accumulator; 78H is binary code necessary to
display digit 7 at the common- anode seven- segment LED. The second instruction
sends the contents of the accumulator (78H) to the output port F5H. When the 8085
executes the OUT instruction, the digit 7 is displayed at the port as follows:
1. In the third machine cycle M3 of the OUT instruction (refer the figure), the
port address F5H is placed on the address bus A7 – A0 (it is also duplicated
on the high- order bus A15 – A8, but we have used the low- order bus for
interfacing in this example).
2. The address F5H is decoded by the decoding logic (decoder and 4- input
NAND gate), and the output O5 of the decoder is asserted.
3. During T2 of the M3 cycle (see Figure ), the 8085 places the data byte 78H
from the accumulator on the data bus and asserts the ܹܴ signal.
4. In the Figure 4.10, when the ܹܱܫsignal is asserted, the output of the NOR
gate 74LS02 goes high and enables the latch 74LS 373.
The data byte (78H), which is already on the data bus at th input of the latch, is
passed on the output of the latch and displayed by the seven-segment LED.
However, the byte is latched when the ܹܴ signal is de-asserted during T3.
Current Requirements: The circuit in Figure uses a common- anode seven-
segment LED. Each segment requires 10 to 15 mA of current (ID max = 19 mA) for
appropriate illumination. The latch can sink 24mA when the output is low and can
supply approximately 2.6 mA when the output is high. In this circuit, common-
75
MICROPROCESSOR ARCHITECTURE
anode LED segments are turned on by zeros on the output of the latch. If common-
cathode seven segment LED were used in this circuit, the output of the latch would
have to be high to drive the segments. The current supplied would be about 2.6mA,
which is insufficient to make the segments visible.
76
Chapter 4: I/O Interfacing
A7 A6 A5 A4 A3 A2 A1 A0
1 0 0 0 0 1 0 0 = 84H
Enables lines Don’t Care Input
The control signal I/O Read ( IOR) is generated by ANDing the IO / M (through
an inverter) and ܴ ܦin a negative NAND gate, and the I/O select pulse is generated
by ANDing the output of the decoder and the control signal ܴܱܫ. When the address
is 84H and the control signal ܴܱܫis asserted, the I/O select pulse enables the tri-
state buffer and the logic levels of the switches are placed on the data bus.
The 8085, then, begins to read switch positions during T3 (Figure) and places the
reading in the accumulator. When a switch is closed, it has logic 0, and when it is
open, it is tied to +5V, representing logic 1.
Figure 4.11 shows that the switches S7 –S3 are open and S2 – S0 are closed; thus,
the input reading will be F8H.
A7 A6 A5 A4 A3 A2 A1 A0
1 0 0 0 0 1 0 0 = 84H
0 1 =8CH
1 0 =94H
1 1 =9CH
77
MICROPROCESSOR ARCHITECTURE
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 etc ) and memory control signals ()ܴܯܧܯ
and ) ܹܯܧܯ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.
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 ). In this example, if an output device, instead of a memory
register, is connected at 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 ()ܴܯܧܯ
78
Chapter 4: I/O Interfacing
and Memory Write (MEMW) should be connected to I/O devices instead of ܴܱܫ
and ܹܱܫsignals, and the 16- bit address bus (A15 – A0 ) should be decoded. The
hardware details will be described in section).
On the other hand, in executing the OUT instruction (Figure), the 8- bit device
address is repeated on the low- order address bus (A0 – A7) as well as on the high-
order bus, and the ܹܱܫcontrol signal is used. To identify an output device, either
the low-order or the high-order bus can be decoded. In the case of the STA
instruction, the entire bus must be decoded.
79
MICROPROCESSOR ARCHITECTURE
Device selection and data transfer in memory-mapped I/O require three steps that
are similar to those required in peripheral I/O:
1. Decode the address bus to generate the device address pulse.
2. AND the control signal with the device address pulse to generate the device
select (I / O select) pulse.
3. Use the device select pulse to enable the I/O port.
To interface a memory- mapped input port, we can use the instruction LDA 16- bit,
which reads data from an input port with the 16-bit address and places the data in
the accumulator.
The instruction has four machine cycles; only the fourth machine cycle differs from
M4 in Figure 4.12. The control signal will be ܴܦrather than ܴ, the data flow from
the input port to microprocessor.
For example, switch S7 controls the cooling system, and switch S0 controls the exit
gate. All switch inputs are tied high; therefore, when switch is open (off), it has
+5V and when a switch is closed (on), it has logic 0.
80
Chapter 4: I/O Interfacing
The circuit includes 3 – to-8 decoder, one 8- input NAND gate, and one 4-input
NAND gate to decode the address bus. The output O0 of decoder is combined with
control signal ܹܯܧܯto generate the device select pulse that enables the octal
latch. The output O1 is combined with the control signal ( )ܴܯܧܯto enable the
input port. The eight switches are interfaced using a tri-state buffer 74LS244, and
the solid state relays controlling various processes are interfaced using an octal
latch (74LS373) with tri-state output.
1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0
To 8- input NAND gate to Enable E2 To 4-input NAND To Decoder =FFF8
gate to Enable E1 Enable Input H
E3
81
MICROPROCESSOR ARCHITECTURE
A1 A1 A1 A1 A1 A1 A A A A A A A3 A A A
5 4 3 2 1 0 9 8 7 6 5 4 2 1 0
1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1
To 8- input NAND gate to Enable E2 To 4-input NAND To Decoder =FFF9
gate to Enable E1 Enable Input H
E3
82
Chapter 4: I/O Interfacing
4. Data transfer Between any register and I/O Only between I/O and
the accumulator
5. Maximum number The memory map (64K) is The I/O map is
of I/Os possible shared between I/Os and independent of the
system memory memory map; 256 input
devices and 256 output
devices can be
connected.
6. Execution speed 13 T-states (STA, LDA) 10 T-states
7 T-states (MOV M, R)
7. Hardware More hardware is needed to Less hardware is needed
requirements decode 16-bit address to decode 8-bit address
8. Other features Arithmetic or logical Not available
operations can be directly
performed with I/O data
83
MICROPROCESSOR ARCHITECTURE
This loop has 27 T- states and eight operations (machine cycles ). To execute the
loop once, the microprocessor asserts the ܴ ܦsignal seven times ( the Opcode Fetch
is also a loop is executed in 8.9μs, and the ܹܴ signal is repeated every 8.9μs that
can be observed on a scope. If we sync the scope on the ܹܴܹܴ pulse from the
8085, we can check the output on a scope. If we sync the scope on the ܹܴ pulse
from the 8085, we can check the output of the decoder, ܹܱܫ, and IOSEL signals;
some of these signals of a working circuit are shown in Figure 4.14
When the 8085 asserts the ܹܴ signal, the port address F5H must be on the address
bus A7- A0, and the output O5 of the decoder in figure must be low. Similarly, the
ܹܱܫmust be low and the IOSEL (the output of the 74LS02) must be high. Now if
we check the data bus in relation to ܹܴ signal, one line at a time, we must read the
data byte 78H.If the circuit is not properly functioning, we can check various
signals in reference to the ܹܴ signal as suggested below:
84
Chapter 4: I/O Interfacing
2. If ܹܱܫis high, check the input to the OR gate 74LS32 . Both should be low.
3. If O5 of the decoder is high, check all the output lines O0 to O7 of the decoder.
If all of them are high, that means the decoder is not enabled. If one of the
outputs of the decoder is low, it suggests that the input address lines are
improperly connected.
4. If the decoder is not enabled, check the address lines A4 – A7 ; all of them
must be high and the address line A3 must be low.
5. Another possibility is that the port is enabled, but the seven-segment display
is wrong .
The problem must be with data lines. Try different codes to display other digits. If
two data lines are interchanged, you may be able to isolate these two data lines.
The final step is to check all the data lines.
4.7 Summary
In this chapter, we examined the machine cycles of the OUT and IN instructions
and derived the basic concepts in interfacing peripheral-mapped I/Os. Similarly,
we examined the machine cycles of memory-related data transfer instructions and
derived the basic concepts in interfacing memory-mapped I/Os. These concepts
were illustrated with various examples of interfacing I/O devices.
Peripheral-Mapped I/O
The OUT is a two-byte instruction. It copies (transfers or sends) data from the
accumulator to the addressed port.
When the 8085 executes the OUT instruction, in the third machine cycle, it places
the output port address on the low-order bus, duplicates the same port address on
the high-order bus, places the contents of the accumulator on the data bus, and
asserts the control signal ܹܴ
A latch is commonly used to interface output devices.
The IN instruction is a two-byte instruction. It copies ( transfer or reads) data from
an input port and places the data into the accumulator.
When the 8085 executes the IN instruction, in the third machine cycle, it places the
input port address on the low-order bus, as well as on the high-order bus, asserts
the control signal ܴܦ, and transfers data from the port to the accumulator.
A tri-state buffer is commonly used to interface input devices.
85
MICROPROCESSOR ARCHITECTURE
Memory-Mapped I/O
Memory-related instructions are used to transfer data.
To interface I/O devices, the entire bus must be decoded to generate the device
address pulse, which must be combined with the control signal (( )ܴܯܧܯor
MEMW) to generate the I/O select pulse. This pulse is used to enable the I/O device
and transfer the data.
86
Unit-2
5
INTRODUCTION TO 8085 ASSEMBLY
LANGUAGE PROGRAMMING
Unit Structure
5.0 Objectives
5.1 Introduction
5.2 The 8085 Programming Model
5.2.1 Programming Registers
5.3 Instruction Classification
5.3.1 The 8085 Instruction Set
5.4 Instruction and Data Format
5.4.1 Instruction Word Size
5.4.2 Opcode Formats
5.4.3 Data Format
5.5 How to Write Assemble, and Execute a Simple Program
5.5.1 Illustrate Program: Adding Two Hexadecimal Numbers
5.5.2 How Does a Microprocessor Differentiate Between
Data and instruction Code?
5.6 Overview of the 8085 Instruction Set
5.7 Summary
5.0 Objectives
x Define the term flag and explain how the flags are affected
x Explain the terms operation code (opcode) and operand, and illustrate these
terms by writing instructions.
87
MICROPROCESSOR ARCHITECTURE
x Classify the instructions in terms of their word size and specify the number
of memory registers required to store the instructions in memory
x Translate the flowchart into mnemonics and convert the mnemonics into Hex
code for a given programming problem.
5.1 Introduction
88
Chapter 5: Introduction to 8085 Assembly Language Programming
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
(b)
Figure 5.1: 8085 Programming Model (a) and Flag Register (b)
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 5.1. 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 a 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 (S), Parity (P),and Auxiliary (AC) flags;
they are listed in Table 5.1 and their bit positions in the flag register are shown in
89
MICROPROCESSOR ARCHITECTURE
Figure 5.1(a) . The most commonly used flags are Zero, Carry and Sign. The
microprocessor uses these flags to test data conditions.
For example, after an addition of two numbers, if sum in the accumulator is larger
than eight bits, the flip- flop used to indicate a carry – called the Carry flag (CY) is
set to one.
When an arithmetic operation results in zero, the flip- flop called the Zero (Z) flag
is set to one. Figure 5.1(a) shows an 8-bit register, called the flag register, adjacent
to the accumulator. However, it is not used as a register; five bit positions out of
eight are used to store the outputs the five flip-flops. The flags are stored in the 8-
bit register so that the programmer can examine these flags (data conditions ) by
accessing the register through an instruction.
These flags have critical importance in the decision- making process of
microprocessor. The conditions (set or reset) of the flag 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.
90
Chapter 5: Introduction to 8085 Assembly Language Programming
The microprocessor uses this register to sequence the execution of the instructions.
The function of the program counter is to point to the memory address from which
the next byte is to be fetched. When a byte (machine code) is being fetched, the
program counter is incremented by one to point to the next memory location.
91
MICROPROCESSOR ARCHITECTURE
Types Examples
Between a memory location and a From the memory location 2000H to
register register B
Between an I/O device and the From an input keyboard to the
accumulator accumulator
Arithmetic Operations
These instructions perform arithmetic operation such as addition, subtraction,
increment, and decrement.
The instruction DAD is exception; it adds 16- bit data directly in register
pairs.
Logical Operations
These instructions perform various logical operations with the contents of the
accumulator.
92
Chapter 5: Introduction to 8085 Assembly Language Programming
2. Rotate: - Each bit in the accumulator can be shifted either left or right to the
next position.
3. Compare: - Any 8-bit number, or the contents of a register, or memory
location can be compared for equality, greater than, or less than, with the
contents of the accumulator.
4. Complement: - The contents of the accumulator can be complemented; all
0s are replaced by 1s and all 1s are replaced by 0s.
Branching Opertions
This group of instructions alters the sequence of program execution either
conditionally or unconditionally.
1. Jump:- Conditional jumps are an important aspects of the decision-making
process in programming. These instructions test for a certain condition (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.
2. 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.
93
MICROPROCESSOR ARCHITECTURE
called the operation code (opcode) and the second is the data to be operated on,
called the operand. The operand (or data) can be specified in various ways. It may
include 8-bit (or 16- bit) data, an internal register, a memory location, or 8- bit (or
16- bit) address. In some instructions, the operand is implicit.
The 8085 instruction set is classified into the following three groups according to
word size:
1. One-word or 1-byte instructions.
2. Two-word or 2-byte instructions
3. Three-word or 3-byte instructions
In the 8085, “byte” and “word” are synonymous because it is an 8-bit
microprocessor. However, instructions are commonly referred to in terms of bytes
rather than words.
These instructions are 1-byte instructions performing three different tasks. In the
first instruction, both operand registers are specified.
Two-Byte Instructions
In a 2-byte instruction, the first specifies the operation code and thee second byte
specifies the operand. For example:
94
Chapter 5: Introduction to 8085 Assembly Language Programming
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:
These commands are in many ways similar to our everyday conversation. For
example, while eating in a restaurant, we may make the following requests and
orders:
1. Pass (the ) butter
2. Pass (the ) bowl.
3. (Let us) eat.
4. I will have combination 17 ( on the menu).
5. I will have what Susie ordered.
The first request specifies the exact item; it is similar to the instruction for loading
a specific data byte in a register.
95
MICROPROCESSOR ARCHITECTURE
The second request mentions the bowl rather than the contents, even though one is
interested in the contents of the bowl. It is similar to the instruction MOV C,A
where registers (bowls) are specified rather than data.
The third suggestion (let us eat) assumes that one knows what to eat. It is similar
to the instruction Complement, which implicitly assumes that the operand is
accumulator.
In the fourth sentence, the location of the item on menu is specified and not the
actual item. It is similar to the instruction: transfer the data byte from the location
2050H.
The last order (what Susie ordered) is specified indirectly. It is similar to an
instruction that specifies a memory location through the contents of a register pair.
These various ways of specifying data are called the addressing modes. Although
microprocessor instructions require one or more words to specify the operands, the
notations and conventions used in specifying the operands have very little to do
with the operation of the microprocessor.
The mnemonic letters used to specify a command are chosen by the manufacturer.
When an instruction is stored in memory, it is stored in binary code, the only code
the microprocessor is capable of reading and understanding. The conventions used
in specifying the instructions are valuable in terms of keeping uniformity in
different programs and in writing assemblers. The important point to remember is
that the microprocessor neither reads nor understands mnemonics or hexadecimal
numbers.
96
Chapter 5: Introduction to 8085 Assembly Language Programming
Notations Meaning
= 010 = D register
=011 = E register
= 100 = H register
= 101 = L register
nnn Restart number 000 to 111
97
MICROPROCESSOR ARCHITECTURE
For all data transfer instructions except MOV instruction format the opcode is,
0 0 d d d Io Io Io
Destination register Information operation
98
Chapter 5: Introduction to 8085 Assembly Language Programming
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 to 1001. The remaining numbers,
1010 (A) to 1111(F), are considered invalid. An 8- bit register in thev8085 can
accommodate two BCD numbers.
Unsigned Integers- An integer without a sign can be represented by all the 8 bit in
a microprocessor register. Therefore, the largest number that can be processed at
one time is FFH. However, this does not imply that the 8085 microprocessor is
limited to handling only 8- bit numbers.
Numbers larger than 8 bits (such as 16-bit or 24-bit numbers) are processed by
dividing them in groups of 8 bits.
99
MICROPROCESSOR ARCHITECTURE
Now let us examine how the microprocessor interrupts any number. Let us assume
that after performing some operations the result in the accumulator is 0100 0001
(41H) . This number can have many interpretations:
(1) It is an unsigned number equivalent to 65 in decimal.
(2) It is BCD number representing 41 decimal
(3) It is the ASCII capital letter “A” or
(4) It is group of 8 bits where bits D6 and D0 turn on and the remaining bits turn
off output devices.
The processor processes binary bits; it is up to the user to interpret the result. In our
example, the number 41H can be displayed on a screen as an ASCII “A” or 41
BCD.
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
PORT1.
Problem Analysis
Even though this is a simple problem, it is necessary to divide the problem into
small steps to examine the process of writing programs. The wording of the
problem provides sufficient clues for the necessary steps. They are as follows:
1. Load the numbers in the registers.
2. Add the numbers.
3. Display the sum at the output port PORT1.
100
Chapter 5: Introduction to 8085 Assembly Language Programming
Flowchart
The steps listed in the problem analysis and the sequence can be represented in a
block diagram, called a flowchart. Figure shows such a flowchart representing the
above steps. This is a simple flowchart, and the steps are self-explanatory.
Start
Load 1 Hex
Numbers
Add Numbers
Display Sum
End
101
MICROPROCESSOR ARCHITECTURE
The translation of each block into mnemonics with comments is shown as follows:
Let us assume that R/W memory ranges from 2000H to 20FFH, and the system has
an LED output port with the address 01H. Now, to enter the program:
1. Reset the system by pushing the RESET key.
2. Enter the first memory address using the Hex keys where the program should
be stored.
Let us assume it is 2000H.
3. Enter each machine code by pushing Hex keys. For example, to enter the first
machine code, push the 3, E, and STORE keys. (The STORE key may be
labelled differently in different systems.) When you push the STORE key,
the program will store the machine code in memory location 2000H and
upgrade the memory address to 2001H.
4. Repeat Step 3 until the last machine code, 76H.
5. Reset the system.
102
Chapter 5: Introduction to 8085 Assembly Language Programming
Now the question is : How does the Hex code get converted into binary code?
The answer lies with the Monitor program stored in Read- Only memory (or
EPROM) of the microcomputer system. An important function of the Monitor
program is to check the keys and convert Hex code into binary code. The entire
process of manual assembly is shown in Figure
In this illustrate example, the program will be stored in memory as follows:
This program has eight machine codes and will require eight memory locations to
store the program. The critical concept that needs to be emphasized here is that the
microprocessor can understand and execute only the binary instructions (or data )
everything else (mnemonics, Hex code, comments) is for the convenience of
human being.
103
MICROPROCESSOR ARCHITECTURE
The microprocessor begins to read one machine code at a time, and when it fetches
the complete instruction, it executes that instruction. For example, it will fetch the
machine codes stored in memory locations 2000H and 2001H and execute the
instruction MVI A, 32H; thus it will load 32H in register A. The ADD instruction
will add the two numbers, and the OUT instruction will display the answer 7A (32H
+48H= 7A) at the LED port. It continues to execute instructions until it fetches the
HLT instruction.
104
Chapter 5: Introduction to 8085 Assembly Language Programming
continues in a sequence, one code after another (one memory location after another)
at the speed of its clock until the system is turned off ( or the clock stops) . If an
unconditional loop is set up in a program, the execution will continue until the
system is either reset or turned off.
Now a puzzling questions is : How does the microprocessor differentiate between
a code and data when both are binary numbers ?
The answer lies in the fact that the microprocessor interprets the first byte it fetches
as an opcode.
When the 8085 is reset, its program counter is cleared to 0000H and it fetches the
first code from the location 0000H
In the example of the previous section, we tell the processor that our program
begins at location 2000H. The first code it fetches is 3EH. When it decodes that
code, it knows that it is a two- byte instruction. Therefore, it assumes that the
second code, 32H, is a data byte. If we forgot to enter 32H and enter the next code,
06H, instead, the 8085 will load 06H in the accumulator, interpret the next code,
48H, as an opcode, and continue the execution in sequence. As a consequence, we
may encounter a totally unexpected result.
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 an RIM, related to serial I/O) .
The following notations are used in the description of the instructions.
R= 8085 8- bit register (A, B, C, D, E, H, L)
M=Memory register (location)
Rs= Register Source (A, B, C, D, E, H, L)
Rd= Register Destination (A, B, C, D, E, H, L)
Rp= Register Pair (BC, DE, HL, SP)
( ) = Contents of
105
MICROPROCESSOR ARCHITECTURE
2. Arithmetic instructions:
Add
Subtract
Increment (Add 1)
Decrement (Subtract 1)
106
Chapter 5: Introduction to 8085 Assembly Language Programming
Mnemonics Tasks
DCR R Decrement the contents of a register
INX Rp Increment the contents of a register pair
DCX Rp Decrement the contents of a register pair
ADD M Add the contents of a memory location to the contents of the
accumulator
SUB M Subtract the contents of a memory location from the contents
of the accumulator.
INR M Increment the contents of a memory location.
DCR M Decrement the contents of a memory location.
3. Logical instructions:
AND
OR
X-OR
Compare
Rotate
Table 5.10: Logical instructions
Mnemonics Tasks
ANA R/M Logically AND the contents of register/memory with the
contents of the accumulator.
ANI 8-bit Logically AND the 8-bit data with the contents of the
accumulator.
ORA 8-bit Logically OR the contents of register/memory with the
contents of the accumulator.
ORI 8-bit Logically OR the 8-bit data with the contents of the
accumulator.
XRA 8-bit Exclusive-OR the contents of register/memory with the
contents of the accumulator.
XRI 8-bit Exclusive-OR the 8-bit data with the contents of the
accumulator.
CMA Complement the contents of the accumulator.
RLC Rotate each bit in the accumulator to left position.
RAL Rotate each bit in the accumulator including the carry to the
left position.
RRC Rotate each bit in the accumulator including the carry to the
right position.
107
MICROPROCESSOR ARCHITECTURE
Mnemonics Tasks
RAR Rotate each bit in the accumulator including the carry to the
right position.
CMP R/M Compare the contents of register/ memory with the contents
of the accumulator for less than, equal to, or more than.
CPI 8-bit Compare 8-bit data with the contents of the accumulator for
less than, equal to, or more than.
4. Branch Instructions:
108
Chapter 5: Introduction to 8085 Assembly Language Programming
5.7 Summary
This chapter described the data manipulation functions of the 8085 microprocessor,
provided an overview of the instruction set, and illustrated the execution of
instructions in relation to the system’s clock. The important concepts in this chapter
can be summarized as follows.
The 8085 microprocessor operations are classified into five major groups: data
transfer (copy), arithmetic, logic, branch, and machine control.
An instruction has two parts: opcode (operation to be performed) and operand (data
to be operated on).
The operand can be data (8-bit or 16- bit), address, or register, or it can be implicit.
The method of specifying an operand (directly, indirectly, etc.) is called the
addressing mode.
The instruction set is classified in three groups according to the word size : 1,2,3-
byte instructions.
To write an assembly language program, divide the given problem into small steps
in terms of the microprocessor operations, translate these steps into assembly
language instructions, and then translate them into the 8085 machine code.
4. Find the Hex machine code for the following instructions from the instruction
set, and identify the number of bytes of each instruction.
MVI B, 4FH ; Load the first byte
MVI C,78H; Load the second byte
MOV A,C ; Get ready for addition
ADD B; Add two bytes
OUT 07H ; Display the result at port 7
HLT : End the program
109
MICROPROCESSOR ARCHITECTURE
6. Write logical steps to add the following two Hex numbers. Both the numbers
should be saved for future use. Save the sum in the accumulator.
Numbers: A2H and 18H
7. Data byte 28H is stored in register B and data byte 97H is stored in the
accumulator. Show the contents of register B, C, and the accumulator after
the execution of the following two instructions:
MOV A,B
MOV C,A
110
Unit-2
6
INTRODUCTION TO 8085 INSTRUCTIONS
Unit Structure
6.0 Objectives
6.1 Introduction
6.2 Data Transfer (Copy) Opertions
6.2.1 Addressing Modes
6.2.2 Illustrative Program: Data Transfer – From Register to Output Port
6.2.3 Illustrative Program: Data Transfer to Control Output Devices
6.3 Arithmetic Operations
6.3.1 Addition
6.3.2 Illustrate Program: Arithmetic Operations –Addition and Increment
6.3.3 Subtraction
6.3.4 Illustrative Program: Subtraction of Two Unsigned Numbers
6.4 Logic Operations
6.4.1 Logic and
6.4.2 Illustrative Program: Data Masking with Logic And
6.4.3 Or, Exclusive-Or and Not
6.4.4 Setting and Resetting Specific Bits
6.4.5 Illustrative Program : Oring Data from Two Input Ports
6.5 Branch Operations
6.5.1 Unconditional Jump
6.5.2. Illustrative Program: Unconditional Jump to Set Up
A Continuous Loop
6.5.3 Conditional Jumps
6.5.4 Illustrative Program: Testing of the Carry Flag
6.6 Writing Assembly Language Programs
111
MICROPROCESSOR ARCHITECTURE
6.0 Objectives
x Explain the functions of data transfer (copy) instructions and how the
contents of the source register and destination register are affected.
x Explain the functions of the machine control instructions HLT and NOP
x Explain the arithmetic instructions, and recognize the flags that are set or
reset for given data conditions.
6.1 Introduction
112
Chapter 6: Introduction to 8085 Instructions
The simple illustrative programs given in this chapter can be entered and executed
on the single-board microcomputers used commonly in laboratories.
One of the primary functions of the microprocessor is copying data, from a register
( or I/O or memory) called the source, to another ( or I/O or memory) called the
destination. The copying function is frequently labelled as the data transfer
function.
The term copy is equally valid for input /output functions because the contents of
the source are not altered. However, the term data transfer is used so commonly to
indicate the data copy function, these terms are used interchangeably when the
meaning is not ambiguous.
Instructions
The data transfer instructions copy data from a source into a destination without
modifying the contents of the source. The previous contents of the destination are
replaced by the contents of the source.
In the 8085 processor, data transfer instructions do not affect the flags.
113
MICROPROCESSOR ARCHITECTURE
Example 6.1:- Load the accumulator A with data byte 82H ( H as Hexadecimal
number) and save the data in register B.
114
Chapter 6: Introduction to 8085 Instructions
The first instruction is a 2-byte instruction that loads the accumulator with the data
byte 82H, and the second instruction MOV B, A copies the contents of the
accumulator in register B without changing the contents of the accumulator.
Example 6.2 :- Write instructions to read eight ON/OFF switches connected to the
input port with the address 00H, and turn on the devices connected to the output
port with the address 01H, as shown in Figure 6.1
Figure 6.1: Reading Data at Input Port and Sending Data to Output Port
Solution: - The input has eight switches that are connected to the data bus through
the tri-state buffer. Any one of the switches can be connected to +5V (logic 1) or
to ground (logic 0), and each switch controls the corresponding device at the output
port. The microprocessor needs to read the bit pattern on the switches and send the
same bit pattern to the output port to turn on the corresponding devices.
Instructions: IN 00H
OUT 01H
HLT
When the microprocessor executes the instruction IN 00H, it enables the tri-state
buffer. The bit pattern 4FH formed by the switch positions is placed on the data bus
and transferred to the accumulator. This is called reading an input port.
115
MICROPROCESSOR ARCHITECTURE
When the microprocessor executes the next instruction, OUT 01H, it places the
contents of the accumulator on the data bus and enables the output port 01H.The
output port latches the bit pattern and turns ON/ OFF the devices connected to port
according to the pattern. In the Figure 6.1, the bit pattern 4FH will turn on the
devices connected to the output port data lines D6, D3, D2, D1, and D0 . The space
heater and four light bulbs. To turn off some of the devices and turn off some of
the devices and turn on the other devices, the bit pattern can be modified by
changing the switch positions.
For example, to turn on the radio and the coffeepot and turn off all other devices,
the switches S4 and S5 should be on the others should be off. The microprocessor
will read the bit pattern 0011 0000, and this bit pattern will turn on the radio and
the coffeepot and turn off other devices.
The preceding explanation raises two questions:
1. What are second bytes in the instructions IN and OUT?
2. How are they determined?
In answer to the first question, the second bytes are I/O port addresses. Each I/O
port is identified with a number or an address similar to the postal address of a
house. The second byte has eight bits, meaning 256 (28) combinations; thus 256
input ports and 256 output ports with the addresses from 00H to FFH can be
connected to the system.
The answer to the second question depends on the logic circuit used to connect and
identify a port by the system designer.
The various formats of specifying the operands are called the addressing modes.
1. Immediate Addressing – MVI R, Data
2. Register Addressing - MOV Rd, Rs
3. Direct Addressing - IN / OUT Port#
116
Chapter 6: Introduction to 8085 Instructions
For example, in the case of the MVI opcode, the letter I suggests that the second
byte is data and not a register. What is important is to become familiar with the
instructions.
Problem Statement
Load the hexadecimal number 37H in register B, and display the number at the
output port labelled PORT1.
Problem Analysis
Even though this is a very simple problem it is necessary to break the problem into
small steps and outline the thinking process in terms of the tasks.
STEPS
Questions to be asked
Is there an instruction to load the register B? YES - MVI B.
Is there an instruction to send the data from register B to the output port? No
Review the instruction OUT. This instruction sends data from the accumulator to
an output port.
The solution appears to be as follows: Copy the number from register B into
accumulator A.
Is there an instruction to copy data from one register to another register ? YES –
MOV Rd, Rs.
Flowchart
The thinking process described here and the steps necessary to write the program
can be represented in a pictorial format, called a flowchart. Figure 6.2 describes
the preceding steps in a flowchart.
Flowcharting is an art. The flowchart in Figure 6.2 does not include all the steps
described earlier. Although the number of steps that should be represented in a
flowchart is ambiguous, not all of them should be included. It should represent a
logical approach and sequence of steps in solving the problem.
117
MICROPROCESSOR ARCHITECTURE
Start
Enter Number in
a Register
Output
Number
Stop
Symbol commonly used in flowcharting are shown in Figure 6.3. Two types of
symbols – rectangles and ovals – are already illustrated in Figure 6.2 .
118
Chapter 6: Introduction to 8085 Instructions
The diamond is used with Jump instructions for decision making and the double-
sided rectangle is used for subroutine.
The flowchart in Figure 6.2 includes what steps to do and in what sequence. As a
rule, a general flowchart does not include how to perform these steps or what
registers are being used.
Now, to translate the assembly language program into machine language, look up
the hexadecimal machine codes for each instruction in the 8085 instruction set and
write each machine code in the sequence, as follows :
This program has six machine codes and will require six bytes of memory to enter
the program into your system. If your single-board microprocessor has R/W
memory starting at the address 2000H, this program can be entered in the memory
119
MICROPROCESSOR ARCHITECTURE
Program Format
Memory Machine Instruction Operand Comments
Address Code Opcode
(Hex) (Hex)
XX00 06 MVI B, 37H Load register B with data
37H
XX01 37
XX02 78 MOV A, B Copy(B) into (A)
XX03 D3 OUT PORT1 Display accumulator
XX04 PORT1 contents (37H) at Port1
XX05 76 HLT End of the program
This program has five columns: Memory Address, Machine Code, Opcode,
Operand and Comments.
Memory Address These are 16-bit addresses of the user (R/W) memory in the
system. Where the machine code of the program is stored. The beginning address
is shown as XX00; the symbol XX represents the page number of the available
R/W memory in the microcomputer, and 00 represents the line number.
Machine Code
If the system has R/W memory with the starting address at 2000H and the output
port address 01H, the program will be stored as follows :
120
Chapter 6: Introduction to 8085 Instructions
Opcode (Operation Code) :- An instruction is divided into two parts : Opcode and
Operand . Opcodes indicate the type of operation or function that will be performed
by the machine code.
Operand: - The operand part of an instruction specifies the item to be processed;
it can be 8- bit or 16-bit data, a register, or a memory address.
An instruction, called mnemonic is formed by combining an opcode and an
operand.
The mnemonics are used to write programs in the 8085 assembly language; and
then mnemonics in these programs are translated manually into the binary machine
code by looking up in the instruction set.
Comments The comments are written as a part of the proper documentation of a
program to explain or elaborate the purpose of the instruction used.
These are separated by a semicolon (;) from an instruction on same line.
If the program is properly entered and executed, the data byte 37H will be
displayed.
121
MICROPROCESSOR ARCHITECTURE
After you have executed this program, you can find the answer in the accumulator
by pushing the Examine Register Key
The program also can be executed by entering the machine code 76 in location
2003H, thus eliminating the OUT instruction.
Problem Statement
A microcomputer is designed to control various appliances and lights in your
house. The system has an output port with the address 01H, and various units are
connected to the D7 to D0 as shown in Figure 6.4. On a cool morning you want to
turn on the radio, the coffeepot, and space heater. Write appropriate instructions for
the microcomputer.
Assume the R/W memory in your system begins at 3000H.
Problem Analysis
The output port in Figure 6.4 is a latch (D flip-flop) .When data bits are sent to the
output port they are latched by the D flip-flop. A data bit at logic 1 supply
approximately 5V as output and can turn on solid-state relays.
To turn on the radio, the coffeepot and the space heater set D6, D5, and D4 at logic
1, and the other bits at logic 0.
D7 D6 D5 D4 D3 D2 D1 D0
0 1 1 1 0 0 0 0 = 70H
The output port requires 70H, and it can be sent to the port by loading the
accumulator with 70H.
122
Chapter 6: Introduction to 8085 Instructions
Program Output
The program simulates controlling of the devices connected to the output port by
displaying 70H on a seven-segment LED display. If your system has individual
123
MICROPROCESSOR ARCHITECTURE
The arithmetic operations Add and Subtract are performed in relation to the
contents of the accumulator. However, the Increment or Decrement operations can
be performed in any register.
Instructions
These arithmetic instructions (except INR and DCR)
1. Assume implicitly that the accumulator is one of the operands.
2. Modify all the flags according to the data conditions of the result.
3. Place the result in the accumulator.
4. Do not affect the contents of the operand register.
124
Chapter 6: Introduction to 8085 Instructions
6.3.1 Addition
The 8085 performs addition with 8-bit binary numbers and stores the sum in the
accumulator. If the sum is larger than eight bits (FFH), it sets the Carry flag.
Addition can be performed either by adding the contents of a source register (B, C,
D, E, H, L, or memory) to the contents of the accumulator (ADD) or by adding the
second byte directly to the contents of the accumulator (ADI).
Example 6.3 :- The contents of the accumulator are 93H and the contents of
register C are B7H. Add both contents.
Instruction :- ADD C
CY D7 D6 D5 D4 D3 D2 D1 D0
(A) 93= 1 0 0 1 0 0 1 1
+
(C) B7= 1 0 1 1 0 1 1 1
Carry 1 1 1 1 1 1
SUM(A) 14A 1 0 1 0 0 1 0 1 0
When the 8085 adds 93H and B7H, the sum is 14AH; it is larger than eight bits, .
Therefore, the accumulator will have 4AH in binary, and the CY flag will be set.
The result in the accumulator (4AH) is not 0, and bit D7 is not 1; therefore the Zero
and the Sign flags will be reset.
Example 6.4:- Add the number 35H directly to the sum in the previous example
when the CY flag is set.
SUM(A) 7FH 0 0 1 1 1 1 1 1 1
The addition of 4AH and 35H does not generate a carry and will reset the previous
carry flag.
125
MICROPROCESSOR ARCHITECTURE
Therefore, in adding numbers, it is necessary to count how many times the CY flag
is set by using some other programming techniques.
Example 6.5:- Assume the accumulator holds the data byte FFH. Illustrate the
difference in the flags set by adding 01H and by incrementing the accumulator
contents.
126
Chapter 6: Introduction to 8085 Instructions
Carry Flag Set to 1 because the answer is larger than eight bits; there is a carry
generated out of the last bit D7. During the addition bits D0 through D6 may generate
carries but these carries do not affect the CY flag.
Misconception #1:- Bit D0 in the result (4AH) corresponds to the bit position of
the Carry flag D0 in the flag register, therefore, the Carry flag is reset.
Misconception #2 :- In the addition process, bits D0 of 93H and B7H generate a
carry (or other bit additions generate carries ); therefore the Carry flag is set.
Zero Flag:- Reset to 0 because the answer is not zero. The Zero flag is set only
when all eight bits in the result are 0.
Misconception #3 :- Bit D6 in the result (4AH) is 1, and it corresponds to bit D6
(zero flag position) in the fag register. Therefore, the Z flag is set.
Sign Flag :- Reset to 0 because D7 in the result is 0. The position of the sign flag
in the flag register is also D7 . But it is just a coincidence. The microprocessor
designer could have chosen bit D6 for the Sign flag and bit D7 for the Zero flag in
the flag register. The Sign flag is relevant only when we are using signed numbers.
Misconception #4 :- If the Sign flag is set, the result must be negative.
Program
The illustrative program for arithmetic operations using addition and increment is
presented as figure 6.5 to show the register contents during some of the steps.
127
MICROPROCESSOR ARCHITECTURE
Program Description
1. The first machine cycle codes load 8BH in register D and 6FH in register C .
These are data copy instructions, so no flags are affected and they remain in
the previous state.
The status of the flags is shown X to indicate no change in their status.
2. Instruction INR C adds 1 to 6FH and changes the contents of C to 70H . The
result is nonzero and bit D7 is zero; therefore, the S and Z flags are reset. The
CY flag is not affected by the INR instruction,
3. To add ( C ) to (D), the contents of the registers must be transferred to the
accumulator because the 8085 cannot add two registers directly. The
instruction MOV A, C copies 70Hfrom C register into the accumulator
without affecting (C).
4. Instruction ADD D, adds (D) to (A) stores the sum in A, and sets the Sign
flag as shown below:
(A) : 70H = 0 1 1 1 0 0 0 0
+
(D) : 8BH = 1 0 0 0 1 0 1 1
(A) : FBH = 1 1 1 1 1 0 1 1
128
Chapter 6: Introduction to 8085 Instructions
Program Output
It will display FBH at the output port. If the output port is not available, the program
can be executed by entering the NOP instructions in place of the OUT instruction
and the answer FBH can be verified by examining the accumulator A. Similarly the
contents of registers C and D and the flags can be verified.
By examining the contents of the registers, following points can be confirmed:
1. The sum is stored in Accumulator
2. The contents of the source registers are not changed.
3. The Sign (S) flag is set.
Even though the Sign(S) flag is set, this is not a negative sum. The microprocessor
sets the Sign flag whenever an operation results in D7 =1. The microprocessor
cannot recognize whether FBH is a sum, a negative number, or a bit pattern.
In this example, the addition is not concerned with the signed numbers. With the
signed numbers, bit D7 is reserved for a sign programmer and no number larger
than +12710 can be entered.
6.3.3 Subtraction
The 8085 performs subtraction by using the method of 2’s complement.
The subtraction can be performed by using either the instruction SUB to subtract
the contents of a source register or the instruction SUI to subtract an 8- bit number
from the contents of the accumulator.
The 8085 performs the following steps internally to execute the instruction SUB
( or SUI)
Step1: Converts subtrahend (the number to be subtracted) into its 1’s complement.
Step 2 : Adds 1 to 1’s complement to obtain 2’s complement of the subtrahend.
Step3: Add 2’s complement to the minuend (the contents of the accumulator)
Step 4: Complement the Carry flag
Example 6.6
Register B has 65H and the accumulator has 97H. Subtract the contents of register
B from the contents of the accumulator.
Instruction: SUB B
Subtrahend (B) : 65H = 0110 0101
129
MICROPROCESSOR ARCHITECTURE
Step1:
1’s complement of 65H= 1001 1010
Step2:
+
Add 01 to obtain 0000 0001
2’s complement of 65H= 1001 1011
Step 3:
Add 97H to 2’s complement of 65H= 1001 0111
2’s complement of 65H= 1001 1011
Carry 1 1 111
CY 1 0011 0010
CY 0 0011 0010
Problem Statement
Write a program to do the following:
1. Load the number 30H in register B and 39H in register C.
2. Subtract 39H from 30H
3. Display the answer at PORT1
Program
The illustrative program for subtraction of two unsigned numbers is presented as
Figure 6.6 to show the register contents during the steps.
130
Chapter 6: Introduction to 8085 Instructions
Program Description
1. Register B and C are loaded with 30H and 39H, respectively. The instruction
MOV A, B copies 30H into the accumulator. The contents of a register can
be subtracted only from the contents of the accumulator and not from any
other register.
Step1:
39H = 0 0 1 1 1 001
1’s complement of 39H= 1 1 0 0 0 110
Step2:
+
Add 01 to obtain 0 0 0 0 0 001
2’s complement of 39H= 1 1 0 0 0 111
Step 3:
Add 30H to 2’s complement of 39H= 0011 0000
2’s complement of 39H= 1 1 0 0 0 111
______________________________________________________
CY=0 1 1 1 1 0 1 1 1
131
MICROPROCESSOR ARCHITECTURE
3. The number F7H is a 2’s complement of the magnitude (39H – 30H) = 09H.
Program Output
In this program, the unsigned numbers were used to perform the subtraction.
The 8085instruction set includes logic functions such as AND, OR, Ex OR, and
NOT (complement) . The opcodes of these operations as follows :
All logic operations are performed in relation to the contents of the accumulator.
Instructions
1. Implicitly assume that the accumulator is one of the operands.
2. Reset (clear) the CY flag .The instruction CMA is an exception; it does not
affect any flags.
3. Modify the Z, P, and S flags according to the data conditions of the result.
4. Place the result in the accumulator.
5. Do not affect the contents of the operand register.
132
Chapter 6: Introduction to 8085 Instructions
133
MICROPROCESSOR ARCHITECTURE
Figure 6.7(b) shows that each bit of register b is independently ANDed with each
bit of the accumulator, thus simulating eight 2- input AND gates.
Problem Statement
To conserve energy and to avoid an electrical overload on a hot afternoon,
implement the following procedures to control the appliances throughout the
house(figure 6.8) . Assume that the control switches are located in the kitchen, and
they are available to anyone in the house. Write the instruction to
1. Turn on the air conditioner if switch S7 of the input port 00H is on.
2. Ignore all other switches of the input port even if someone attempts to turn
on other appliances.
Problem Analysis
In this problem we are interested in only one switch positions, S7, which is
connected to data line D7. Assume that various persons in the family have turned
on the switches of the air conditioner (S7 ), the radio (S4), and the lights ( S3, S2, S1,
S0 ).
134
Chapter 6: Introduction to 8085 Instructions
If the microprocessor reads the input port (IN 00H), the accumulator will have data
byte 9FH .This can be simulated by using the instruction MVI A, 9FH .However,
if we are interested in knowing only whether switch S7 is on, we can mask bits D6
through D0 by ANDing the input data with a byte that has 0 in bit positions D6
through D0 and 1 in the position D7 .
D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 0 0 0 0 0 = 80H
After bits D6 through D0 have been masked, the remaining byte can be sent to the
output port to simulate turning on the air conditioner.
Program
Memory Machine Instruction Comments
Address Code Opcode Operand
HI-LO
XX00 3E MVI A, Data This instruction simulates
01 9F the instruction IN 00H
02 E6 ANI 80H Mask all the bits except D7
03 80
04 D3 OUT 01H Turn on the air conditioner
05 01 if S7 is on.
06 76 HLT End of program
Program Output
The instruction ANI 80H ANDs the accumulator data as follows:
The ANDing operation always reset the CY flag. The result (80H) will be placed
in accumulator and then sent to output port, and the logic 1 of data bit D7 turns on
the air conditioner.
135
MICROPROCESSOR ARCHITECTURE
Example 6.7:- Assume register B holds 93H and the accumulator holds 15H.
Illustrate the results of the instruction ORA B, XRA B, and CMA.
The result 97H will be placed in the accumulator, the CY flag will be reset, and the
other flags will be modified to reflect the data conditions in the accumulator.
The result 86H will be placed in the accumulator and flags will be modified as
shown.
The result EAH will be placed in the accumulator and no flags will be modified.
136
Chapter 6: Introduction to 8085 Instructions
At the various times, we may want to set or reset a specific bit without affecting
the other bits. OR logic can used to set the bit, and AND logic can be used to reset
the bit.
Example 6.8 :- In Figure 6.8, keep the radio on (D4) continuously without affecting
functions of other appliances, even if someone turns off the switch S4 .
Solution:- To keep the radio on without affecting the other appliances, the bit D4
should be set by ORing the reading of the input port with the data byte 10H as
follows :
IN 00H (A)= D7 D6 D5 D4 D3 D2 D1 D0
ORI = 0 0 0 1 0 0 0 0
10H
__________________________
__________________________
(A) D7 D6 D5 1 D3 D2 D1 D0
The instruction IN reads the switch positions shown as D7 – D0 and the instruction
ORI sets the bit D4 without affecting any other bits.
137
MICROPROCESSOR ARCHITECTURE
Example 6.9:- In the Figure 6.8, assume it is winter and turn off the air conditioner
without affecting the other appliances.
Solution :- To turn off the air conditioner, reset bit D7 by ANDing the reading of
the input port with the data byte 7FH as follows :
IN 00H (A)= D7 D6 D5 D4 D3 D2 D1 D0
ANI 7FH = 0 1 1 1 1 1 1 1
__________________________
__________________________
(A) 0 D6 D5 D4 D3 D2 D1 D0
The ANI instruction resets bit D7 without affecting the other bits.
Problem Statement
An additional input port with eight switches and the address 01H (Figure 6.9) is
connected to the microcomputer shown in the Figure 6.8 to control the same
appliances and lights from the bedroom as well as from the kitchen. Write
instructions to turn on the devices from any of the input ports.
138
Chapter 6: Introduction to 8085 Instructions
Problem Analysis
To turn on the appliances from any one of the input ports, the microprocessor needs
to read the switches at both ports and logically OR the switch positions.
Assume that the switch positions in one input port correspond to the data byte 91H
and the switch positions in the second port correspond to the data byte A8H. The
person in the bedroom wants to turn on the air conditioner, the radio, and the
bedroom light; and the person in the kitchen wants to turn on the air conditioner,
the coffeepot, and the kitchen light. By ORing these two data bytes the
microprocessor can turn on the necessary appliances.
To test this program, we must simulate the reading of the input port by loading the
data into register – for example, into B and C.
Program
Memory Machine Instruction Comments
Address Code Opcode Operand
HI-LO
XX00 06 MVI B, 91H This instruction simulates
01 91 reading input port 01H
02 0E MVI C, A8H This instruction simulates
03 A8 reading input port 00H
04 78 MOV A, B It is necessary to transfer data
byte fro B to A to OR with C.
Band C cannot be ORed
directly.
05 B1 ORA C Combine the switch positions
from register B and C in the
accumulator.
06 D3 OUT PORT! Turn on appliances and light
07 PORT1
08 76 HLT End of program
PROGRAM OUTPUT
By logically ORing the data bytes in registers B and C
139
MICROPROCESSOR ARCHITECTURE
The branch instructions are most powerful instructions because they allow the
microprocessor to change the sequence of a program, either unconditionally or
under certain test conditions. These instructions are key to the flexibility and
versatility of a computer.
Branch instructions instruct the microprocessor to go to a different memory
location, and the microprocessor continues executing machine codes from that new
location.
The address of the new memory location is either specified explicitly or supplied
by the microprocessor or by extra hardware. They are classified in three categories:
1. Jump instructions
2. Call and Return instructions
3. Restart 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 memory address.
Jump instructions are classified into two categories Unconditional Jump and
Conditional Jump.
Instruction
Opcode Operand Description
JMP 16-bit Jump
It is 3-byte instruction
The second and third bytes specify the 16-bit memory
address.
Second byte low-order and third-byte high- order memory
address.
For example, to instruct the microprocessor to go the memory location 2000H, the
mnemonics and the machine code entered will be as follows:
140
Chapter 6: Introduction to 8085 Instructions
The 16 –bit memory address of the jump location is entered in the reverse order,
the low-order byte(00H) first, followed by the high-order byte(20H)
Problem Statement
Modify the program in Example6.2 to read the switch positions continuously and
turn on the appliances accordingly.
Problem Analysis
One of the major drawbacks of the program in Example 6.2 is that the program
reads switch positions once and then stops. Therefore, if you want to turn on/off
different appliances, you have to reset the system and start all over again. This is
impractical in real-life situations. However, the unconditional Jump instruction, in
place of the HLT instruction, will allow the microcomputer to monitor the switch
positions continuously.
Memory Machine Label Mnemonics Comments
Address Code
2000 DB START IN 00H Read input switches
2001 00
2002 D3 OUT 01H Turn on devices according to
2003 01 switch position
2004 C3 JMP START Go back to beginning and
2005 00 read the switches again
2006 20
Program Format
The program includes one more column called label . The memory location 2000H
is defined with the label START ; therefore, the operand of the jump instruction
can be specified by the label START. The program sets up the endless loop, and
the microprocessor monitors the input port continuously. The output will reflect
any change in the switch positions.
141
MICROPROCESSOR ARCHITECTURE
Flags
The 8085 flag register has five flags, one of which (Auxiliary Carry) is used
internally.
Two Jump instructions are associated with each flag. The sequence of a program
can be changed either because the condition is present or because the condition is
absent.
For example, while adding the numbers we can change the program sequence either
because the carry is present (JC= Jump on Carry) or because carry is absent
(JNC=Jump On No Carry).
Instructions
All conditional Jump instructions in 8085 are 3-byte instructions; the second byte
specifies the low-order (line number) memory address, and the third byte specifies
the high-order (page number) memory address.
The following instructions transfer the program sequence to the memory location
specified under the given conditions.
Opcode Operand Description
JC 16-bit Jump on Carry (if result generate carry and CY=1)
JNC 16-bit Jump on No Carry ( CY=0)
JZ 16-bit Jump on Zero (if result is zero and Z=1)
JNZ 16-bit Jump on No Zero( Z=0)
JP 16-bit Jump On Plus (if D7 = 0 and S=0)
JM 16-bit Jump On Minus (if D7= 0 and S=0)
JPE 16-bit Jump On Even Parity (P=1)
JPO 16-bit Jump On Odd Parity (P=0)
142
Chapter 6: Introduction to 8085 Instructions
All the Jump instructions are listed here. Zero and Carry flags and related Jump
instructions are used frequently.
Problem Statement
Load the hexadecimal number 9BH and A7H in register D and E, respectively, and
add the numbers. If the sum is greater than FFH, display 01H at output PORT0;
otherwise, display the sum.
Figure 6.10: Flowchart And Assembly Language Program to Test Carry Flag
143
MICROPROCESSOR ARCHITECTURE
While translating into machine code, we leave memory locations 2007H and 2008H
blank because the exact locations 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 i.e.
200BH. This address must be placed in the reversed order as shown:
2007 0B Low- order: Line Number
2008 20 High-order : Page Number
144
Chapter 6: Introduction to 8085 Instructions
The flowchart will be as be as in Figure 6.11, and it shows that the program
sequence is changed if there is a Carry. This flowchart has two end points : thus it
will require a few more instructions than that of the Figure 6.10.In this particular
example, it is unimportant whether to use instruction JC or JNC, but in most cases
the choice is made by the logic of a problem.
145
MICROPROCESSOR ARCHITECTURE
Problem Statement
A microcomputer is designed to monitor various processes on the floor of a
manufacturing plant, presented schematically in Figure 6.12.It has two input ports
with the addresses F1H and F2H and output port with address F3H.
Input port F1H has six switches, five of which D4 –D0 control the conveyer belts
through the output port F3H.
Switch S7, corresponding to the data line D7, is reserved to indicate an emergency
on the floor. Input port F2H is controlled by the foreman, and its switch S7’ is used
to indicate an emergency. Output line D6 of port F3H is connected to the emergency
alarm.
146
Chapter 6: Introduction to 8085 Instructions
Write a program to
1. Turn on the five conveyer belts according to the ON/ OFF positions of the
switches S4 – S0 at port F1H.
2. Turn off the conveyer belts and turn on the emergency alarm only when both
switches –S7 from port F1H and S7’ from the port F2H – are triggered.
3. Monitor the switches continuously.
Problem Analysis
To perform the task specified in the problem, the microprocessor needs to
1. Read the switch positions.
2. Check whether switches S7 and S7’ from the ports F1H and F2H are on.
3. Turn on the emergency signal if both switches are on, and turn off all the
conveyer belts.
4. Turn on the conveyer belts according to the switch positions S0 through S4 at
input port F1H if both the switches, S7 and S7’ are not on simultaneously.
5. Continue checking the switch positions.
The five steps listed above can be translated into a flowchart and an assembly
language program as shown in the Figure 6.13
147
MICROPROCESSOR ARCHITECTURE
6.6.3 Documentation
A program is similar to a circuit diagram. Its purpose is to communicate to others
what the program does and how it does it. Appropriate comments are critical for
conveying the logic behind a program. The program as a whole should be self-
documented.
Program Execution
The above machine codes can be loaded in R/W memory, starting with memory
address 2000H.The execution of the program can be done in two ways. The first is
to execute the entire code by pressing the Execute key, and second is to use the
148
Chapter 6: Introduction to 8085 Instructions
Single-Step key executes one instruction at a time, and by examining Register key
and flags as each instruction is being executed.
6.8 Summary
The instructions from 8085 instruction set include Data transfer instructions such
as MOV, MVI, IN, OUT instruction. These instructions copy the contents of the
source into the destination without affecting the source register.
Arithmetic Instructions such as ADD, ADI, SUB, SUI, INR, DCR and Logic
Instructions such as ANA, ANI, ORA, ORI, XRA, XRI, CMA. The results of
arithmetic and logic operations are usually placed in the accumulator.
The conditional Jump instructions are executed according to the flags set after an
operation.
149
MICROPROCESSOR ARCHITECTURE
Q2) Write instructions to load the hexadecimal number 65H in register C, and
92H in the accumulator A. Display the number 65 at PORT0 and 92H in
PORT1.
Q4) Write a program using the ADI instruction to add the two hexadecimal
numbers 3AH and 48H and to display the answer at an output port.
150
UNIT 3
7
PROGRAMMING TECHNIQUES WITH
ADDITIONAL INSTRUCTIONS
Unit Structure
7.1 Objectives
7.2 Introduction
7.3 Looping, Counting And Indexing
7.4 Additional Data Transfer And 16-Bit Arithmetic Instructions&Arithmetic
Instruction Related To Memory.
7.5 Logic Operations: Rotate,Logics Operations: Compare, Dynamic
Debugging.
7.1 Objectives
7.2 Introduction
151
MICROPROCESSOR ARCHITECTURE
5. The mnemonic for a particular instruction consists of letters and suggest the
operation to be performed by that instruction.
6. The mnemonic for a particular instruction consists of letters and suggest the
operation to be performed by that instruction.
16.1 Data Transfer Group - This group of instructions copies data from a
location
152
Chapter 7: Programming Techniques w-ith Additional Instructions
153
MICROPROCESSOR ARCHITECTURE
The program listed above will continuously add data FF h in memory location
starting at 4500H.
First Instruction- LXI H will load the address 4500 H address in H & L
Second Instruction- MVI C will load data 14h in Register C
Third Instruction- Will Copy data FFH in M(H & L) Register continuously with
labelled loop UP
Fourth instruction- Increment Memory location.
Fifth Instruction- will decrement the counter register over here is C
Sixth Instruction- Will continuously Jump if no zero.
Seventh Instruction- Will Halt the program
Example 2 Write a program on Bubble Sort
Instruction
Start: LXI B, OFF5H
MVI D, 00H
MVI C,04H
Check: Mov A,M
INX H
CMP M
JC Nxtbt
DCX H
MOV M,A
DCX H
MOV B,M
INX H
MVI D,01H
Nxtbt: DCR C
JNZ Check
Mov A,D
RRC
JC Start
HLT
154
Chapter 7: Programming Techniques w-ith Additional Instructions
The above program will compare two numbers and sort the number in ascending
order
Example 3 To find the largest number in an array of data using 8085 instruction set
Algorithm
1. Load the address of the first element of the array in HL pair
2. Move the count to B register
3. Increment the pointer
4. Get the first data in A register
5. Decrement the counter
6. Increment the pointer
7. Compare the content of memory addressed by HL pair with that of A register
8. If carry=0, go to step 10 or if carry=1 go to step 9
9. Move the content of memory addressed by HL to A register
10. Decrement the counter
11. Check for Zero of the counter. If ZF=0, go to step 6, or if ZF=1 go to next
step
12. Store the largest data in memory
13. Terminate the Program
Instruction Explanation
LXI H,4200 Set pointer for array
MOV B,M Load the Count
LOOP: INX H Increment the Memory location
CMP M If A register > M go to Head
JNC AHEAD Jump to AHEAD label if carry=0
MOV A,M Set new value as largest
AHEAD:DCR B Decrement the B counter
JNZ LOOP Repeat comparisons till count=0
STA 4300 Store the largest value at 4300
HLT Terminate the program
155
MICROPROCESSOR ARCHITECTURE
Input 05(4200)
0A(4201)
F1(4202)
1F(4203)
26(4204)
FE(4205)
Output FE(4300)
Example 5 To find the smallest number in an array of data using 8085 instruction
set
Algorithm
1. Load the address of the first element of the array in HL pair
2. Move the counttoB–reg.
3. Incrementthe pointer
4. Getthe firstdata inA –reg.
5. Decrementthe count.
6. Incrementthepointer
7. Compare the contentofmemory addressed by HLpairwiththatofA -reg.
8. Ifcarry = 1,go tostep10orifCarry = 0goto step9
9. Move the contentofmemory addressedby HLtoA –reg.
10. Decrementthecount
11. CheckforZero ofthe count. IfZF=0,goto step6,orifZF= 1go to next step.
12. Storethe smallestdata inmemory.
13. Terminatetheprogram.
Program
LXIMOV H,4200B,M Set pointer for array Loadthe Count
INX H
MOV A,M Set1stelementaslargestdata
DCR B Decrement the count
LOOP: INX H
CMP M IfA-reg < Mgo toAHEAD
JC AHEAD Jump if carry=1 to AHEAD Label
156
Chapter 7: Programming Techniques w-ith Additional Instructions
Output: 0A(4300)
Example 6 To write a program to arrange anarray of descending order
Algorithm
1. Initialize HL pairas memory pointer
2. Get the countat4200intoC–register
3. Copy it in D–register(for bubble sort(N-1)times required)
4. Get the first value in A –register
5. Compare it with the value at next location.
6. If they are out of order, exchange the contents of A–register and Memory
7. Decrement D–register content by 1
8. Repeat steps 5 and 7 till the value in D-register become zero
9. Decrement C –register content by 1
10. Repeat steps 3 to 9 till the value in C –register becomes zero
LXIMOVD H,4200C,M
REPEAT: CR C
MOV D,C
LXI H,4201
LOOP: MOV A,M
INX H
CMP M
JNC SKIP
157
MICROPROCESSOR ARCHITECTURE
MOV B,M
MOV M,A
DCX H
MOV M,B
INX H
SKIP: DCR D
JNZ LOOP
DCR C
JNZ REPEAT
HLT
1. Load Register Pair Immediate- LXI Reg pair, 16-bit data. The instruction
loads 16 bit data in the register pair designated in the operand. Eg LXI
H,2034H.
2. Load H and L registers direct-LHLD 16-bit address. The instruction copies
the contents of the memory location pointed out by the 16-bit address in to
register L and Copies the contents of the next memory location in to register
H. The contents of source memory locations are not altered. Eg LHLD 2040
H.
3. Mov R.M-R.M copies data byte from memory to register. Memory location,
its location is specified by the contents of the HL registers. Eg MOV B,M.
158
Chapter 7: Programming Techniques w-ith Additional Instructions
4. LDAX B/D Register pair- The contents of the designated register pair point
to a memory location. This location in to the accumulator. The contents of
either the register pair or the memory location are not altered. Eg LDAX B
5. Load Accumulator- LDA 16-bit address , the contents of a memory location,
specified by a 16-bit address in the operand, are copied to the accumulator.
The contents of the source are not altered. Eg LDA 2034H
6. MOV M,R-This instruction copies the contents of the source. The source
register are not altered. As one of the operands is a memory location, its
location is specified by the contents of the HL registers. Eg MOV M,B
7. STA 16-bit address- The contents of the accumulator are copied in to the
memory location specified by the operand. This is a 3-byte instruction, the
second byte specifies the low-order address and the third byte. Eg MOV M,B
8. Store Accumulator Indirect- STAX register pair the contents of the
accumulator are copied in to the memory location specified by the contents
of the operand(register pair). The contents of the accumulator are not altered.
Eg STAX B
9. Store H and L registers indirect- SHLD 16-bit address, the contents of register
L are stored in to the memory location specified by the 16-bit address in the
operand and the contents of the H register are stored in to the next memory
location by incrementing the operand. The contents of register HL are not
altered. This is a 3 byte instruction, the second byte specifies the low-order
address and the third byte specifies the high-order address. Eg SHLD 2470H
10. Increment 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.
Eg INX H
11. Decrement register pair by 1- DCX R, the contents of the designated register
pair are decremented by 1 and the result is stored in the same place.
Eg DCX H
12. Add memory(ADD M)- The contents of the operand (memory) are added 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 addition.
13. Substract Memory (SUB M)- The contents of the operand (memory) are
substracted 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 substraction.
159
MICROPROCESSOR ARCHITECTURE
Algorithm
1. Start the program by loading the first data into Accumulator.
2. Move the data to a register (B register).
3. Get the second data and load into Accumulator.
4. Add the two register contents.
5. Check for carry.
6. Store the value of sum and carry in memory location.
7. Terminate the program.
Program
Input: 80(4150)
80(4251)
Output: 00(4152)
01(4153)
160
Chapter 7: Programming Techniques w-ith Additional Instructions
Algorithm
1. Start the program by loading the first data into Accumulator.
2. Move the data to a register(B register).
3. Get the second data and load in to Accumulator.
4. Subtract the two register contents.
5. Check for carry.
6. If carry is present take 2’s complement of Accumulator.
7. Store the value of borrow in memory location.
8. Store the difference value (present in Accumulator) to a memory
9. location and terminate the program.
Program
MVI C, 00 Initialize C to 00
LDA 4150 Loadthe value to Acc.
MOV B,A Move the contentof Acc to Bregister.
LDA 4151 Loadthe value to Acc.
SUB B
JNC LOOP Jumpon no carry.
CMA Complement Accumulator contents.
INR A Increment value in Accumulator.
INR C Increment value in register C
LOOP:STA 4152 Storethe value of A-reg to memory address.
MOV A, C Move contents of register C to Accumulator.
STA 4153 Storethe value of Accumulator memory address.
HLT Terminate the program.
Input: 06(4150)
02(4251)
Output:04(4152)
01(4153)
161
MICROPROCESSOR ARCHITECTURE
PROGRAM:
MVI D,00 InitializeregisterDto00
MVI A, 00 InitializeAccumulatorcontentto00
LXI H,4150
MOV B,M Get the first number in B-reg
INX H
MOV C, M Get the second number in C-reg.
LOOP: ADD B Add content of A- reg to register B.
JNC NEXT Jump on no carry to NEXT.
INR D Increment content of register D
NEXT: DCR C Decrement content of register C.
JNZ LOOP Jump on no zero to address
STA 4152 Store the result in Memory
MOV A, D
STA 4153 Store the MSB of result in Memory
HLT Terminate the program.
162
Chapter 7: Programming Techniques w-ith Additional Instructions
PROGRAM:
LXI H,4150
MOV B,M Getthedividendin B– reg.
MVI C, 00 ClearC –regforqoutient
INX H
MOV A, M Getthe divisorin A –reg.
NEXT: CMP B CompareA -regwithregisterB.
JC LOOP Jumponcarry toLOOP
SUB B SubtractA–regfromB-reg.
INR C IncrementcontentofregisterC.
JMP NEXT JumptoNEXT
LOOP: STA 4152 Storethe remainderinMemory
MOV A, C
STA 4153 Storethe quotientinmemory
HLT Terminatetheprogram.
Input: FF(4150)
FF(4251)
163
MICROPROCESSOR ARCHITECTURE
164
Chapter 7: Programming Techniques w-ith Additional Instructions
165
MICROPROCESSOR ARCHITECTURE
Miscellaneous Questions
Q1. Write down some arithmetic Instruction with illustrative program
Q2. Write Logical instructions with program
Q3. Describe the concept about dynamic debugging
Q4. Describe the types of dynamic debugging
166
UNIT 3
8
COUNTER & TIME DELAYS
Unit Structure
8.1 Objectives
8.2 Introduction
8.3 Counters and Time Delays, Illustrative Program: Hexadecimal Counter
8.4 Illustrative Program: zero-to-nine (Modulo Ten) Counter
8.5 Generating Pulse Waveforms
8.6 Debugging Counter and Time-Delay Programs
8.1 Objectives
8.2 Introduction
2. When the delay subroutine is executed, the microprocessor does not execute
other tasks. For the delay we are using the instruction execution times,
executing some instructions in a loop, the delay is generated.
3. So in this chapter we are going to study more about counters, time delays and
various other programs of 8085 for hexadecimal counter, modulo ten counter,
pulse wave form.
167
MICROPROCESSOR ARCHITECTURE
4. Time Delays- The procedure used to design a specific delay is similar to that
used to set up a counter. A register is loaded with a number, depending on
the time delay is required, and then the register is decremented until it
reaches zero by setting up a loop with a conditional jump instruction. The
loop causes the delay, depending upon the clock period of the system
168
Chapter 8: Counter & Time Delays
10 Using One Register- A Count is loaded in a register, and we can use a loop
to produce a certain amount of time delay in a program.
The first instruction initializes the loop counter and is executed only once
requiring only 7T-States
The following two instructions form a loop that requires 14T States to
execute and is repeated 255 times until C becomes 0.
10.2 We need to keep in mind though that in the last iteration of the loop,
the JNZ instruction will fail and require only 7T States rather than the
10.
10.3 Therefore,we must deduct 3 T states from the total delay to get an
accurate delay calculation. To calculate the delay, we use the following
formula
Tdelay= TO + TL
169
MICROPROCESSOR ARCHITECTURE
10.4 Using a single register, one can repeat a loop for a maximum count of
255 times.
10.5 It is possible to increase this count by using a register pair for the loop
counter instead of the single register.
10.5 A minor problem arises in how to test for the final count since DCX
and INX do not modify the flags.
10.6 However, if the loop is looking for when the count becomes zero, we
can use a small trick by oring the two registers in the pair and then
checking the zero flag
170
Chapter 8: Counter & Time Delays
12.1 Instead (or in conjunction with) Register Pairs, anested loop structure
can be used to increase thetotal delay produced.
MVI B, 10H 7 T-States
LOOP2 MVI C, FFH 7 T-States
LOOP1 DCR C 4 T-States
JNZ LOOP1 10 T-States
DCR B 4 T-States
JNZ LOOP2 10 T-States
12.2 The Calculation remains the same except that the formula must be
applied recursively to each loop, Start with the inner loop, then plug
that delay in the calculation of the outer loop.
12.3 Delay of inner loop
TO1=7 T States (MVI C, FFH)
TL1=(255*14)-3= 3567 T States(14 T States for the DCR C and JNZ
instructions repeated 255 times (FF16=25510 ) minus 3 for the final JNZ)
TLoop1= 7+3567=3574 T States
Delay of the outer loop
TO2=7 T States
(MVI B, 10H)
171
MICROPROCESSOR ARCHITECTURE
13. Increasing the Time Delay- The Delay can be further increased by using
register pairs for each of the loop counters in the nested loops set up. It can
also be increased by adding dummy instructions(like NOP) in the body of the
Loop.
172
Chapter 8: Counter & Time Delays
14.1 This Problem has two parts, the first is to set up a continuous down-
counter and the second is to design a given delay between two counts.
The hexadecimal counter is set up by loading a register with an
appropriate starting number and decrementing it until it becomes zero.
After zero count, the register goes back to FF because decrementing
zero results in a (-1), which is FF in 2’s Complement. The 1 ms delay
between each count is set up by using delay techniques.
173
MICROPROCESSOR ARCHITECTURE
Time Delay Calculation - Delay loop includes two instructions: DCR C andJNZ
with 14 T-states. Therefore the time delay TL inthe loop (without accounting for
the fact that JNZrequires 7 T-States in the last cycle, because countwill remain
same even if the calculations take intoaccount the difference of 3 T-States) is:
174
Chapter 8: Counter & Time Delays
Time Delay Calculation- The major delay between two counts is provided by the
16-bit number in the delay register HL(inner loop in flow chart). This delay is set
up by using a register pair.
175
MICROPROCESSOR ARCHITECTURE
A2C2H would provide approx 1 sec delay between two counts. To achieve higher
accuracy in the delay, the instructions outside the loop must be accounted for delay
calculation. (will be 41665).
A10101010
After RLC 0 1 0 1 0 1 0 1
A AND 01H 0 0 0 0 0 0 0 1
COUNT= 52.410 = 34H
176
Chapter 8: Counter & Time Delays
Miscellaneous Questions
Q1. Write in short about Counter & Time Delays in 8085
Q2. Write a program for hexadecimal counter
Q3. How to calculate time delay for a particular program
Q4. Write a Program for Modulo ten counter
Q5. How to write a program for generating pulse wave form
Q6. Write the steps for debugging counter and Timer delay programs
177
UNIT 3
9
STACKS AND SUB-ROUTINES
Unit Structure
9.1 Objectives
9.2 Introduction
9.3 Stack, Subroutine, Restart, Conditional Call, Return Instructions
9.4 Advanced Subroutine concepts
9.1 Objectives
9.2 Introduction
178
Chapter 9: Stacks and Sub-Routines
5. Given that the stack grows backwards into memory, it is customary to place
the bottom of the stack at the end of memory to keep it as far away from user
programs as possible.In the 8085, the stack is defined by setting the SP (Stack
Pointer) register.
This sets the Stack Pointer to location FFFFH (end of memory for the 8085).
6. Saving Information on the Stack
1. Information is saved on the stack by Pushing it on.
2. It is retrieved from the stack by Poping it off.
3. The 8085 provides two instructions: PUSH and POP for storing
information on the stack and retrieving it back.
4. Both PUSH and POP work with register pairs ONLY.
179
MICROPROCESSOR ARCHITECTURE
Increment SP
Copy the contents of the memory location pointed to by the SP to register D
Increment SP
180
Chapter 9: Stacks and Sub-Routines
181
MICROPROCESSOR ARCHITECTURE
2. MP reads the subroutine address from the next two memory location
and stores the higher order 8 bit of the address in the W register and
stores the lower order 8 bit of the address in the Z register.
182
Chapter 9: Stacks and Sub-Routines
Fig. 7 - Program
183
MICROPROCESSOR ARCHITECTURE
Program Execution
5. CALL Execution
Instruction requires five machine cycles and eighteen Tstates:Call instruction
is fetched, 16-bit address is read during M2 and M3 and stored temporarily
in W/Zregisters. In next two cycles content of program counter are stored on
the stack (address from where microprocessor continue it execution of
program after completion of the subroutine)
184
Chapter 9: Stacks and Sub-Routines
6. RET Execution
Program execution sequence is transferred to the memory location 2043H
location.M1 is normal fetch cycle during M2 contents of stack pointer are
placed on address bus so 43H data is fetched and stored on Z register and SP
is upgraded.Similarly for M3. Program sequence is transfered to2043H by
placing contents of memory and stack
185
MICROPROCESSOR ARCHITECTURE
2.2 Executed the same way as call instructions, the 8085 stores the
contents of the program counter(the address of the next
instruction) on the top of the stack and transfers the program to
the restart location.
3. The conditional Call and Return instructions are based on four data
conditions(flags): Carry, Sign and Parity. In case of a conditional call
the program is transferred to the subroutine if condition is met. In case
of a conditional return instruction, the sequence returns to the main
program if the condition is met.
186
Chapter 9: Stacks and Sub-Routines
5. Nesting Subroutines
187
MICROPROCESSOR ARCHITECTURE
6. Write a program to provide the given on /off time to three traffic lights
(Green, Yellow and Red) and two pedestrian signs(Walk and Don’t Walk).
The signal lights and signs are turned on /off by the data bits of an output port
188
Chapter 9: Stacks and Sub-Routines
189
MICROPROCESSOR ARCHITECTURE
Miscellaneous Questions
Q1. Explain the concept of Stack, subroutines, Return, Restart and conditional
Call
Q2. Explain about nesting of subroutines
References
To refer opcodes for program in simulator use the link Here
https://electricalvoice.com/opcodes-8085-microprocessor/
190
UNIT 4
10
CODE CONVERSION WITH BCD
Unit Structure
10.0 Objectives
10.1 Introduction
10.2 BCD –TO- Binary Conversion
10.2.1 Illustrative Program: 2- Digit BCD – to- Binary Conversion
10.3 Binary –TO-BCD Conversion
10.3.1 Illustrative Program: Binary – To-Unpacked-BCD Conversion
10.4 BCD-TO-Seven-Segment-LED Code Conversion
10.4.1IllustrativeProgram:BCD-TO-Common-Cathode-LEDCode
Conversion
10.5 Binary –TO-ASCII AND ASCII–TO-Binary Code Conversion
10.5.1 Illustrative Program: Binary-To-ASCII Hex Code Conversion
10.5.2 Illustrative Program: ASCII Hex-to-Binary Conversion
10.6 Summary
Questions and Programming Assignments
10.0 Objectives
Write programs and subroutine to
x Convert a packed BCD number (0-99) into its binary equivalent.
x Convert a binary digit ( 0 to F) into its ASCII Hex code and vice versa.
x Select an appropriate seven-segment code for a given binary number using
the table look-up technique.
x Convert a binary digit ( 0 to F) into its ASCII Hex code and vice versa.
x Decimal- adjust 8-bit BCD addition and subtraction.
x Perform such arithmetic operation as multiplication and subtraction using 16-
bit data related instructions.
x Demonstrate uses of instructions such as DAD, PCHL, XTHL, and XCHG.
191
MICROPROCESSOR ARCHITECTURE
10.1 Introduction
In microprocessor applications, various number systems and codes are used to input
data or to display results. The ASCII (American Standard Code for Information
Interchange) keyboard is a commonly used input device for disk- based
microcomputer systems. Similarly, alphanumeric characters (letters and numbers)
are displayed on a CRT( cathode ray tube) terminal using the ASCII code. However
, inside the microprocessor , data processing is usually performed in binary. In some
instances, arithmetic operations are performed in BCD numbers. Therefore, data
must be converted from one code to another code. The programming techniques
used for code conversion fall into four general categories.
1. Conversion based on position of a digit in a number (BCD to binary and vice
versa) .
2. Conversion based on hardware consideration (binary to seven-segment code
using table look-up procedure).
3. Conversion based on sequential order of digits (binary to ASCII and vice
versa).
4. Decimal adjustment in BCD arithmetic operations. (This is an adjustment
rather than a code conversion).
This chapter discusses these techniques with various examples as
subroutines. The subroutines are written to demonstrate industrial practices
in writing software, and can be verified on single- board microcomputers. In
addition, instructions related to 16- bit data operations are introduced and
illustrated.
In most microprocessor –based products, data are entered and displayed in decimal
numbers.
For example, in an instruction laboratory , readings such as voltage and current are
maintained in decimal numbers, and data are entered through a decimal keyboard.
The system-monitor program of the instrument converts each key into equivalent
4- bit binary number and stores two BCD number in an 8-bit register or a memory
location. These numbers are called packed BCD. Even if data are entered in
decimal digits, it is inefficient to process data in BCD numbers because , in each 4-
bit combination, digit A though F are unused. Therefore, BCD numbers are
generally converted into binary numbers for data processing.
192
Chapter 10: Code Conversion with BCD
The conversion of a BCD number into its binary equivalent employs the principle
of positional weighting in a given number.
The digit 7 represents 70, based on its second position from the right. Therefore ,
converting 72BCD into its binary equivalent requires multiplying the second digit by
10 and adding the first digit.
Converting a 2- digit BCD number into its binary equivalent requires the following
steps:
1. Separate an 8- bit packed BCD number into two 4- bit unpacked BCD digits:
BCD1 and BCD2
2. Convert each digit into its binary value according to its position.
3. Add both binary numbers to obtain the binary equivalent of the BCD number.
Problem Statement
A BCD number between 0 and 99 is stored in an R/W memory location called the
Input Buffer (INBUF) . Write a main program and a conversion subroutine
(BCDBIN) to convert the BCD number into its equivalent binary number. Store the
result in a memory location defined as the Output Buffer (OUTBUF).
Program
START : LXI SP, STACK; Initialize stack pointer
LXI H, INBUF Point HL index to the Input Buffer Memory
location where BCD number is stored.
LXI B,OUTBUF Point BC index to the Output Buffer memory
where binary number will be stored.
MOV A, M Get BCD number
193
MICROPROCESSOR ARCHITECTURE
BCDBIN : Function : This subroutine converts a BCD number into its binary
equivalent
Input : A 2-digit packed BCD number in the accumulator
Output : A binary number in the accumulator
No other register contents are destroyed.
Example : Assume BCD number is 72.
PUSH B ; Save BC registers
PUSH D ; Save DE registers A 0111 0010 7210
MOV B,A ; Save BCD number B 0111 0010 7210
ANI 0FH ; Mask most significant four bits A 0000 0010 0210
MOV C,A ; Save unpacked BCD1 in C C 0000 0010 0210
MOV A,B ; Get BCD again A 0111 0010 7210
ANI F0H ; Mask least significant four bits A 0111 0000 7010
RRC : Convert most significant four
RRC; bits into unpacked BCD2
RRC
RRC
MOV D,A; Save BCD2 in D A 0000 0111 0710
XRA A; Clear accumulator D 0000 0111 0710
MVI E,0AH ; Set E as multiplier of 10 E 0000 10 10 0AH
SUM : ADD E ; Add 10 until (D) =0 Add E as many times as (D)
DCR D; Reduce BCD2 by one
JNZ SUM ; Is multiplication complete ? After adding E seven times A
;If not ,go back and add again contains : 0100 0110
RET
194
Chapter 10: Code Conversion with BCD
Program Description
1. In writing assembly language programs, the use of labels is a common
practice. Rather than writing a specific memory location or a port number a
programmer uses such labels as INBUF (Input Buffer) and OUTBUF (Output
Buffer ). Using labels give flexibility and ease of documentation.
2. The main program initializes the stack pointer and two memory indexes. It
brings the BCD number into the accumulator and passes that parameter to the
subroutine.
3. After returning from the subroutine , the main program stores the binary
equivalent in the Output Buffer memory.
4. The subroutine saves the contents of the BC and DE registers because these
registers are used in the subroutine. Even if this particular main program does
not use the DE registers, the subroutine may be called by some other program
in which the DE registers are being used. Therefore, it is good practice to
save the registers that are used in the subroutine, unless parameters are passed
to the subroutine. The accumulator contents are not saved because that
information is passed to the subroutine.
5. The conversion from BCD to binary is illustrated in the subroutine with the
example of 72BCD converted to binary.
Program Execution
To execute the program on a single-board computer, complete the following steps:
1. Assign memory addresses to the instructions in the main program and in the
subroutine .Both can be assigned consecutive memory addresses.
2. Define STACK: the stack location with a 16- bit address in the R/W memory
(such as 2099H).
3. Define INBUF (Input Buffer) and OUTBUF (Output Buffer): two memory
locations in the R/W memory (e.g. 2050H and 2060H).
4. Enter a BCD byte in the Input Buffer (e.g. 2050H).
5. Enter and execute the program.
6. Check the contents of the Output Buffer memory location(2060H) and verify
the answer.
195
MICROPROCESSOR ARCHITECTURE
To represent this number in BCD requires twelve bits or three BCD digits, labelled
here as BCD3 (MSB) , and BCD1(LSB)
0010 0101 0101
BCD3 BCD2 BCD1
The conversion can be performed as follows :
Step 1: If the number is less than 100 , go to Step 2; otherwise , divide by 100 or
subtract 100 repeatedly until the remainder is less than 100.The quotient is the most
significant BCD digit , BCD3
196
Chapter 10: Code Conversion with BCD
Problem Statement
A binary number is stored in memory location BINBYT. Convert the number into
BCD; store each BCD as two unpacked BCD digits in the output Buffer. To
perform this task, write a main program and two subroutines: one to supply the
powers of ten and the other to perform the conversion.
Program
This program converts an 8- bit binary number into a BCD number; thus it requires
12 bits to represent three BCD digits. The result is stored as three unpacked BCD
digits in three Output-Buffer memory locations.
PWRTEN: ; this subroutine loads the power of 10 in register B and calls the
binary – to- BCD conversion routine.
; Input : Binary number in accumulator
;Output : Powers of ten and stores BCD1 in the first Output-
Buffer memory
; Calls BINBCD routine and modifies register B
LXI H,OUTBUF ;Point HL index to Output-Buffer memory
MVI B,64H ;Load 100 in register B
CALL BINBCD ; Call conversion
MVI B,0AH ; Load 10 in register B
CALL BINBCD
MOV M,A Store BCD1
RET
BINBCD ; This subroutine coverts a binary number into BCD and stores
BCD2 and BCD3 in the Output Buffer
; Input : Binary number in accumulator and powers of 10 in B
; Output : BCD2 and BCD3 in Output Buffer
;Modifies accumulator contents
197
MICROPROCESSOR ARCHITECTURE
Program Description
This program illustrates the concepts of the nested subroutine and the multiple-calll
subroutine. The main program calls the PWRTEN subroutine ; in turn the
PWRTEN calls the BINBCD subroutine twice.
1. The main program transfers the byte to be converted to the accumulator and
calls the PWRTEN subroutine.
2. The subroutine PWRTEN supplies the powers of ten by loading register B
and the address of the first Output-Buffer memory location , and calls the
conversion routine BINBCD.
3. In the BINBCD conversion routine , the Output-Buffer memory is used as a
register. It is incremented for each subtraction loop. This step also can be
achieved by using a register in the microprocessor. The BINBCD subroutine
is called twice, once after loading register B with 64H (10010 ) and again after
loading register B with 0AH (1010).
4. During the first call of BINBCD, the subroutine clears the Output Buffer ,
stores BCD3, and points the HL registers to the next Output-Buffer location.
The instruction ADD B is necessary to restore the remainder because one
extra subtraction is performed to check the borrow.
5. During the second call of BINBCD , the subroutine again clears the output
buffer, stores BCD2 , and points to the next buffer location. BCD3 is already
in the accumulator after the ADD instruction, which is stored in the third
Output- Buffer memory by the instruction MOV M,A in the PWRTEN
subroutine.
This is an efficient subroutine; it combines the functions of storing the answer
and finding a quotient. However, two subroutines are required, and the
second subroutine is called twice for a conversion.
198
Chapter 10: Code Conversion with BCD
Problem Statement
A set of three packed BCD numbers (six digits) representing time and temperature
are stored in memory locations starting at XX50H. The seven-segment codes of the
digit 0 to 9 for a common-cathode LED are stored in memory locations starting at
XX70H, and the Output-Buffer memory is reserved at XX90H.
Write a main program and two subroutines, called UNPAK and LEDCOD , to
unpack the BCD numbers and select an appropriate seven-segment code for each
digit. The codes should be stored in the Output-Buffer memory.
Program
LXI SP,STACK ; Initialize stack pointer
LXI H, XX50H ; Point HL where BCD digits are stored.
MVI D,03H ; Number of digits to be converted is placed
in D
CALL UNPAK Call subroutine to unpack BCD numbers
HLT ; End of conversion
UNPAK: ; This subroutine unpacks the BCD number in two single digits
;Input : Starting memory address of the packed BCD numbers in
HL registers
;Number of BCDs to be converted in register D
Output : Unpacked BCD into accumulator and output
;Buffer address in BC
;Calls subroutine LEDCOD
LXI B,BUFFER ;Point BC index to the buffer memory
199
MICROPROCESSOR ARCHITECTURE
200
Chapter 10: Code Conversion with BCD
201
MICROPROCESSOR ARCHITECTURE
These conversions are done through software ,as in the following illustrative
program.
Main Program
LXI SP,STACK ; Initialize the stack pointer
LXI H, XX50H ; Point index where binary number is
stored.
LXI D,XX60H ; Point index where ASCII code is
stored.
MOV A,M ;Transfer byte
MOV B,A ;Save byte
202
Chapter 10: Code Conversion with BCD
Program Description
1. The main program transfers the binary data byte from the memory locations
to the accumulator.
2. It shifts the high-order nibble into the low-order nibble, calls the conversion
subroutine, and stores the converted value in the memory.
3. It retrieves the byte again and repeats the conversion process for the low-
order nibble.
In this program, the masking instruction ANI is used once in the subroutine rather
than twice in the main program as illustrated in the program for BCD –To –
Common-Cathode Code Conversion.
203
MICROPROCESSOR ARCHITECTURE
Problem Statement
Write a subroutine to convert an ASCII Hex number into its binary equivalent. A
calling program places the ASCII number in the accumulator , and the subroutine
should pass the conversion to the accumulator.
Subroutine
ASCBIN : This subroutine converts an ASCII Hex number into its binary
equivalent
;Input: ASCII Hex number in the accumulator
;Output : Binary equivalent in the accumulator
SUI 30H ; Subtract 0 bias from the number
CPI 0AH ; Check whether number is between 0 to 9
RC ; If yes , return to main program
SUI 07H ; If not , subtract 07H to find number
between A and F
RET
Program Description:
This program subtracts the ASCII weighting digits from the number. This process
is exactly opposite to that of the Illustrative Program that converted binary into
ASCII Hex .However, this program uses two return instructions , an illustration of
the multiple-ending subroutine.
10.6 Summary
The system-monitor program of the instrument converts each key into equivalent
4- bit binary number and stores two BCD number in an 8-bit register or a memory
location. These numbers are called packed BCD.
Even if data are entered in decimal digits, it is inefficient to process data in BCD
numbers because, in each 4- bit combination, digit A though F are unused.
Therefore, BCD numbers are generally converted into binary numbers for data
processing.
The conversion of a BCD number into its binary equivalent employs the principle
of positional weighting in a given number.
204
Chapter 10: Code Conversion with BCD
necessary to convert the binary results into their equivalent BCD numbers just
before they are displayed. Results are quite often stored in R/W memory locations
called the Output Buffer.
The conversion of binary to BCD is performed by dividing the number by the
powers of ten; the division is performed by the subtraction method.
When a BCD number is to be displayed by a seven-segment LED, it is necessary
to convert the BCD number to its seven-segment code. The code is determined by
hardware considerations such as common-cathode or common-anode LED; the cod
has no direct relationship to binary numbers. Therefore, to display a BCD digit at
a seven-segment LED, the table look-up technique is used.
In the look-up technique the codes of the digits to be displayed are stored
sequentially in memory. The conversion program locates the code of a digit based
on its magnitude and transfers the code to the MPU to send out to a display port.
The American Standard Code for Information Interchange ( known as ASCII) is
used commonly in data communication. It is a seven-bit code, and its 128( 27 )
combinations are assigned different alphanumeric characters. For example, the
hexadecimal capital letters 30H to 39H represent 0 to 9 ASCII decimal numbers.
and 41H to 5AH represent capital letters A though Z ; in this code , bit D7 is zero.
In serial data communication, bit D7 is used for parity checking.
The ASCII keyboard is a standard input device for entering programs in a
microcomputer. When an ASCII character is entered, the microprocessor receives
the binary equivalent of the ASCII Hex number. For example, when the ASCII key
for digit 9 is pressed, the microprocessor receives the binary equivalent of 39H,
which must be converted to the binary 1001 for arithmetic operations. Similarly, to
display digit 9 at the terminal, the microprocessor must send out the ASCII Hex
code (39H) .
Q5) Rewrite the BCDBIN subroutine to include storing results in the Output
Buffer . Eliminate unnecessary PUSH and POP instructions.
Q6) Write a program for BCD to common cathode LED code conversion.
205
MICROPROCESSOR ARCHITECTURE
206
UNIT 4
11
BCD ARITHMETIC AND 16-BIT
DATA OPERATION
11.0 Objectives
11.1 Introduction
11.4.1:- 16- Bit Data Transfer (Copy) and Data Exchange Group
11.4.3 Instruction Related to the Stack Pointer and the Program Counter
11.5 Multiplication
11.7 Summary
207
MICROPROCESSOR ARCHITECTURE
11.0 Objectives
11.1 Introduction
In microprocessor applications, various number systems and codes are used to
input data or to display results. The ASCII (American Standard Code for
Information Interchange) keyboard is a commonly used input device for disk-
based microcomputer systems. Similarly, alphanumeric characters (letters and
numbers) are displayed on a CRT( cathode ray tube) terminal using the ASCII code.
However, inside the microprocessor, data processing is usually performed in
binary. In some instances, arithmetic operations are performed in BCD numbers.
Therefore, data must be converted from one code to another code. The
programming techniques used for code conversion fall into four general categories.
1. Conversion based on position of adigit in a number (BCD to binary and vice
versa) .
2. Conversion based on hardware consideration (binary to seven-segment code
using table look-up procedure).
3. Conversion based on sequential order of digits (binary to ASCII and vice
versa).
4. Decimal adjustment in BCD arithmetic operations. (This is an adjustment
rather than a code conversion).
This chapter discusses these techniques with various examples as subroutines. The
subroutines are written to demonstrate industrial practices in writing software, and
can be verified on single- board microcomputers. In addition, instructions related
to 16- bit data operations are introduced and illustrated.
208
Chapter 11: BCD Arithmetic and 16-Bit Data Operation
In some applications, input /output data are presented in decimal numbers, and the
speed of data processing is unimportant. In such applications, it may be convenient
to perform arithmetic operations directly in BCD numbers. However, the addition
of two BCD numbers may not represent an appropriate BCD value. For example,
the addition of 34BCD and 26BCD results in 5AH as shown below:
The microprocessor cannot recognize BCD numbers; it adds any two numbers in
binary.
In BCD addition, any number larger than 9 (from A to F) is invalid and needs to be
adjusted by adding 6 in binary.
For example, after 9, the next BCD number is 10; However, in Hex it is A. The
Hex number A can be adjusted as a BCD number by adding 6 in binary .The BCD
adjustment in 8-bit binary register can be shown as follows:
A= 0000 1010
+6= 0000 0110
________________________________________________________
0 0 0 1 0000 10 BCD
Any BCD sum can be adjusted to proper BCD value by adding 6 when the sum
exceeds 9 . In case of packed BCD, both BCD1 and BCD2 need to be adjusted; if a
carry is generated b adding 6 to BCD1, the carry should be added to BCD2, as shown
in the following example.
209
MICROPROCESSOR ARCHITECTURE
The value of the least significant four bits is larger than 9. Add 6.
The value of the most significant four bits is larger than 9, Add 6 and the carry from
the previous adjustment.
In this example, the carry is generated after the adjustment of the least significant
four bits for the BCD digit and is again added to the adjustment of the most
significant four bits.
Instruction
DAA : Decimal Adjust Accumulator
This is a 1- byte instruction
It adjusts an 8- bit number in the accumulator to form two BCD numbers by using
the process described above.
It uses the AC and the CY flags to perform the adjustment.
210
Chapter 11: BCD Arithmetic and 16-Bit Data Operation
Problem Statement
A set of ten packed BCD numbers is stored in the memory location starting at
XX50H.
1. Write a program with a subroutine to add these numbers in BCD. If a carry
is generated, save it in register B, and adjust it for BCD. The final sum will
be less than 9999BCD .
2. Write a second subroutine to unpack the BCD sum stored in registers A and
B, and store them in the output-buffer memory starting at XX60H. The most
significant digit (BCD4) should be stored at XX60H and the least significant
digit (BCD1) at XX63H.
211
MICROPROCESSOR ARCHITECTURE
UNPAK: ; This subroutine unpacks the BCD in the accumulator and the
carry register and stores them in the output buffer.
212
Chapter 11: BCD Arithmetic and 16-Bit Data Operation
Program Description
1. The expected maximum sum is 9090, which requires two registers. The main
program clears the accumulator to save BCD1 and BCD2, clears register B to
save BCD3 and BCD4, and call the subroutine to add the numbers. The BCD
bytes are added until the counter becomes zero.
3. The main program calls the UNPAK subroutine,which takes the BCD
number from the accumulator (e.g. 57BCD), unpacks it into two separate BCD
(e.g. 05BCD and 07BCD), stores them in the output buffer. When a subroutine
stores a BCD number in memory, it decrements the index because BCD1 is
stored first.
213
MICROPROCESSOR ARCHITECTURE
When subtracting two BCD numbers, the instruction DAA cannot be used to
decimal adjust the result of two packed BCD numbers; the instruction applies only
to addition. Therefore, it is necessary to devise a procedure to subtract two BCD
numbers. Two BCD numbers can be subtracted by using the procedure of 100’s
complement (also known as 10’s complement), similar to 2’s complement. The
100’s complement of a subtrahend can be added to a minuend as illustrated:
Problem Statement
Write a subroutine one packed BCD number from another BCD number. The
minuend is placed in register B, and subtrahend is placed is register C by the calling
program. Return the answer into the accumulator.
Subroutine
SUBBCD ; This subroutine subtracts two BCD numbers and adjusts the result
to BCD values by using the 100’s complement method.
; Input : A minuend in register B and a subtrahend in register C
; Output : The result is placed in the accumulator
MVI A,99H
SUB C ; Find 99’s complement of subtrahend
INR A ;Find 100’s complement of subtrahend
ADD B ; Add minuend to 100’s complement of
subtrahend
DAA ; Adjust for BCD
RET
214
Chapter 11: BCD Arithmetic and 16-Bit Data Operation
The instructions deal primarily with 8-bit data (except LXI). However, in some
instances data larger than eight bits must be manipulated, especially in arithmetic
manipulations and stack operations. Even if the 8085 is an 8- bit microprocessor,
its architecture allows specific combinations of two 8-bit registers to form 16-bit
registers. Several instructions in the instruction set are available to manipulate 16
bit data.
11.4.1:- 16- Bit Data Transfer (Copy) and Data Exchange Group
LHLD:- Load HL registers direct
This is a 3-byte instruction.
The second and third bytes specify a memory location ( the second
byte is a line number and the third byte is a page number) .
Transfers the contents of the specified memory location to L register.
Transfers the contents of the next memory location to H register
Example 11.2:- Memory locations 2050H and 2051H contain 3FH and 42H,
respectively, and register pair DE contains 856FH. Write instructions to exchange
the contents of DE with the contents of the memory locations.
215
MICROPROCESSOR ARCHITECTURE
Instructions:
Machine Code Mnemonics
2A LHLD 2050
50 H 42 3F L 3F 2050
20 42 2051
EB XCHG
D 42 3F E 3F 2050
H 85 6F L 42 2051
22 SHLD 2050H
50 H 85 6F L 6F 2050
20 85 2051
Example 11.3 Registers BC contain 2793H and register DE contain 3182H . Write
instructions to add these two16- bit numbers, and place the sum in memory
locations 2050H and 2051H.
Before instructions: B 27 93 C
D 31 82 E
Instructions
MOV A,C A 93 F 93
ADD E A 15 CY=1 F +82
MOVA,B 27
ADC D +31
SHLD 2050H
216
Chapter 11: BCD Arithmetic and 16-Bit Data Operation
These instructions subtract the contents of the operand and borrow from the
contents of the accumulator.
Instructions
MOV A,C (B) 85 38 (C)
SUB E ------
MOV C,A (D) 62 A5 (E)
MOV A,B ______________________
-1 1 / 93
SBB D (B) 22 93 ( C)
MOV B,A
217
MICROPROCESSOR ARCHITECTURE
Example 11.5 Write instructions of the stack pointer register at output ports
Instructions
LXI H, 0000H ; Clear HL
DAD SP ; Place the stack pointer contents in HL
MOV A,H ; Place high-order address of the stack pointer in the
accumulator
OUT PORT1
MOV A,L ; Place low-order address of the stack pointer in the
accumulator
OUT PORT2
The instruction DAD SP adds the contents of the stack pointer register to the HL
register pair, which is already cleared. This is only instruction in the 8085 that
enables the programmer to examine the contents of the stack pointer register.
11.4.3 Instruction Related to the Stack pointer and the Program Counter
The contents of L are exchanged with the contents of the memory location shown
by the stack pointer, and the contents of H are exchanged with the contents of
memory location of the stack pointer +1.
Example 11.6 :- Write a subroutine to set the Zero flag and check whether the
instruction JZ (Jump on Zero) functions properly, without modifying any register
contents other than flags.
Subroutine
CHECK: PUSH H
MVI L,FFH ; Set all bits in L to logic 1
PUSH PSW ;Save flags on the top of the stack
XTHL ; Set all bits in the top stack
location
POP PSW ; Set Zero flag
JZ NOERROR
JMP EEROR
NOERROR: POP H
RET
218
Chapter 11: BCD Arithmetic and 16-Bit Data Operation
The instruction PUSHPSW places the flags in the top location of the stack,and the
instruction XTHL changes all the bits in that location to logic 1 . The instruction
POPPSW sets all the flags.
This example shows that the flags can be examined, and can be set or reset to check
malfunctions in the instructions.
The contents of H specify the high-order byte and contents of L specify the low-
order byte.
This instruction can be used to load a new address in the stack pointer register.
The contents of H specify the high-order byte and the contents of L specify the low-
order byte.
11.5 Multiplication
219
MICROPROCESSOR ARCHITECTURE
For example,
108
X 15
___________
Step 1 : (108 X 5) = 540
Step 2 : shift left and add (108 X 1) = +108
1620
In this example, the multiplier multiplies each digit of the multiplicand, starting
from the farthest right, and adds the product by shifting to the left. The same process
can be applied in binary multiplication.
Problem Statement
A multiplicand is stored in memory location XX50H and a multiplier is stored in
location XX51H. Write a main program to
1. Transfer the two numbers placed in registers H and L.
2. Store the product in the Output Buffer at XX90H.
Write a subroutine to
1. Multiply two unsigned numbers placed in registers H and L.
2. Return the result into the HL pair.
Main Program
220
Chapter 11: BCD Arithmetic and 16-Bit Data Operation
Subroutine
MLTPLY : This subroutine multiplies two 8-bit unsigned numbers
; Input : Multiplicand in register E and multiplier in register D
; Output : Results in HL register
MLTPLY: MOV A,D ; Transfer multiplier to accumulator
MVI D,00H ; Clear D to use in DAD instruction
LXI H,0000H ; Clear HL
MVI B,08H ;Set up register B to count eight rotations
NXTBIT: RAR ;Check if multiplier bit is 1
JNC NOADD ; If not, skip adding multiplicand
DAD D ; If multiplier is 1, add multiplicand to HL and
place partial result in HL.
NOADD: XCHG ; Place multiplicand in HL
DAD H ; And shift left
XCHG ; Retrieve shifted multiplicand
DCR B ; One operation is complete, decrement counter
JNZ NXTBIT ; Go back to next bit
RET
Program Description
1. The objective of the main program is to demonstrate use of the instruction
LHLD, SHLD, and XCHG. The main program transfers the two bytes
(multiplier and multiplicand) from memory locations to the HL registers by
using the instruction LHLD, places them in DE register by the instruction
XCHG, and places the result in the Output Buffer by the instruction SHLD.
2. The multiplier routine follows the format –add and shift to the left. The
routine places the multiplier in the accumulator and rotates it eight times until
the counter (B) becomes zero. The reason for clearing D is to use the
instruction DAD to add register pairs.
3. After each rotation, when a multiplier bit is 1, the instruction DAD D
performs the addition,and DAD H, shifts bits to the left. When a bit is 0, the
subroutine skips the instruction DAD D and just shifts the bits.
221
MICROPROCESSOR ARCHITECTURE
Problem Statement
A set of five 16-bit readings of the current consumption of industrial control units
is monitored by meters and stored at memory locations starting at XX50H . The
low- order byte is stored first (e.g., at XX50H), followed by the high-order byte(e.g.
at XXX51H) . The corresponding maximum limits for each control unit are stored
starting at XX90H.
Subtract each reading from its specified limit, and store the difference in place of
the readings. If any reading exceeds the maximum limit, call the indicator routine
and continue checking.
Main Program
222
Chapter 11: BCD Arithmetic and 16-Bit Data Operation
Program Description
This is a 16- bit subtraction routine that subtracts one byte at a time. The low-order
bytes are subtracted by using the instruction SUB M . If a borrow is generated, it is
accounted for by using the instruction SBB M (subtract with Carry) for the high-
order bytes. In the illustrative example, the first subtraction (00H -90H) generates
a borrow that is subtracted from the high-order bytes. The instruction XCHG
changes the index pointer alternately between the set of readings and the maximum
limits.
223
MICROPROCESSOR ARCHITECTURE
11.7 Summary
224
Chapter 11: BCD Arithmetic and 16-Bit Data Operation
225
UNIT 4
12
SOFTWARE DEVELOPMENT
SYSTEM AND ASSEMBLERS
Unit Structure
12.1 Objectives
12.2 Introduction
12.3 Microprocessors-Based Software Development system
12.4 Operating System and Programming Tools
12.5 Assemblers and Cross-Assemblers, Writing Program Using Cross
Assemblers.
12.1 Objectives
12.2 Introduction
1. The assembly language level differs in a significant respect from the micro-
architecture, ISA and operating system machine levels- it is implemented by
translation rather than by interpretation.
2. Programs that convert a user’s program written in some language to another
language are called translators.
3. The language in which the original program is written is called the source
language and the language to which it is converted is called the target
language.
226
Chapter 12: Software Development System and Assemblers
1. It is simply a computer that enables the user to write, modify, debug and test
programs.
2. In a microprocessor-based development system, a microprocessor is used to
develop software for a particular microprocessor.
3. Generally, the microprocessor has a large R/W memory(typically 8M to 64
M), disk storage, and a video terminal with an ASCII keyboard.
4. The System(I/Os, files, programs etc) is managed by a program called the
operating system.
5. Software development system includes an ASCII keyboard, a CRT terminal,
an MPU board with 8M to 64M R/W memory and disc controllers and disk
drivers.
6. The disk controller is an interfacing circuit through which the microprocessor
unit can access a disk and provide Read/Write control signals.
7. The disk drives have Read/Write elements, which are responsible for reading
and writing data on the disk.
8. At present, most systems are equipped a 3.5-inch disk stores 1.44M bytes of
information.
227
MICROPROCESSOR ARCHITECTURE
11. Hard Disk- Another type of storage memory used with computers called a
hard disk. In general the disk is fastened in a dust free drive mechanism. It is
highly precise and reliable. It requires sophisticated controller circuitry. It is
more stable than the floppy disk. They are available in various sizes and their
storage capacity is quite large in the order of gigabytes.
12. CD-ROM- A CD-ROM is a optical disk that uses a laser beam to store digital
information that can be read with a laser diode. The disk is immune to dust
and mechanical wear because of its optical nature.It comes in various
size(3.5-14 inch) and stores huge amount of data from 100 mb to several gb.
228
Chapter 12: Software Development System and Assemblers
229
MICROPROCESSOR ARCHITECTURE
between IBM and Microsoft ended and microsoft started new series
which name is window operating system.c)1981- DOS1.1 Renamed
version of QDOS(Quick and Dirty operating system) which was
purchased by Microsoft from Seattle Computer products. d)1982-
supported use of double sided disks. e)1983-DOS 2.0 supported
IBM’s 10 mb hard disk and some other additional features. f)1984-
DOS 3.0 support for high density 3.5 inch floppy disk. Allowed
partition on hard disk. g)1991- DOS 5.0, much upgraded version
included text editor and improved BASIC interpreter etc. h) 1993-
DOS 6.0- Added a disk compression utility antivirus program and disk
defragmenter. i)1995- DOS 7.0, this version is part of MS windows
95, supports long file names but remove a large number of utilities.
j)1997-DOS 7.1, support for FAT 32 hard disks and is part of later
versions of MS windows 95.
5.3 MS-DOS parts- The DOS OS is a set of programs which are stored on
some secondary storage device, normally on floppy disk. It is then
loaded in to RAM when required. The DOS software is divided in to
three parts stored in three different files on disk. The disk which
contains these three files is called a Bootable disk.
5.4 The three files loaded on this disk are IO.SYS, MSDOS.SYS and
COMMAND.COM. The IO.SYS file contains the device drivers for
the standard devices such as keyboard, disk, floppy, printer and
monitor are present. All these device drivers are often called
BIOS(Basic Input Output System). The MSDOS.SYS file is also
called DOS Kernel. It contains all the modules for process
management. These modules are written in machine independent
manner so that they could be easily ported.
5.5 File in DOS-A file is a organized collection of data stored on storage
device such as magnetic tape, disk. The file is used to store only one
kind of information. Different types of files are used in computer such
as text file, batch file, database file etc. Some file extensions and their
meanings
9 .CC Source program file
9 .ftn Fortran source program file
9 .pas Pascal Source program file
9 .obj object file
9 .exe Executable File
230
Chapter 12: Software Development System and Assemblers
231
MICROPROCESSOR ARCHITECTURE
7. Unix- It is a multi user, multitasking OS. It was designed for mini computers
but it is now used on various machines ranging from Microcomputers to
supercomputers. It is widely used in Engineering, Scientific and Research
Environment as it open source software.
8. Programming Tools/ Paradigm
232
Chapter 12: Software Development System and Assemblers
233
MICROPROCESSOR ARCHITECTURE
supporting units like control channels. The basic I/O devices can fall in
to 3 categories
9 Block Device- It stores information in fixed size block each one
with its own address. For eg Disks.
9 Character Device- It’s delivers or accepts a stream of characters.
The individual characters are not addressable. For eg Printers,
Keyboard etc.
9 Linux treats each device as file. Like file, it open the device, write
data to it and read from it. After using the device, OS then closes
it.
9 Device drivers are responsible for treating every device as file.
Device drivers is a program that controls particular device. When
OS kernel writes data to a particular device then device drivers
of that device carries out appropriate action for that device.
234
Chapter 12: Software Development System and Assemblers
1. Assemblers
Fig1 Assembler
235
MICROPROCESSOR ARCHITECTURE
ADD R1=’3’
Where M=label Add=Opcode an R1 is register operand
Label Opcode Operand LC Value(Locat
J1 START 200
MOVE R R1=3 200
MOVE M R1,X 201
L1 MOVE R R2 =2 202
LTORG 203
X DS 1 204
END
236
Chapter 12: Software Development System and Assemblers
237
MICROPROCESSOR ARCHITECTURE
2. Cross-Assembler
A cross-assembler that runs on a computer with one type of processor but generates
machine code for a different type of processor.For eg, if we use a PC with the 8086
compatible machine language to generate a machine code for the 8085 processor,
we need a cross-assembler program that runs on the PC compatible machine but
generates the machine code for 8085 mnemonics. It takes assembly language as
input and give machine language as output.
The above figure explains that there is an assembler which is running on machine
B but converting assembly code of Machine A to machine code, this assembler is
cross-assembler.
238
Chapter 12: Software Development System and Assemblers
239
MICROPROCESSOR ARCHITECTURE
240
Chapter 12: Software Development System and Assemblers
Miscellaneous Questions
241
Unit 4
13
INTERRUPTS
Unit Structure
13.0 Objectives
13.1 Introduction
13.2 8085 Interrupt
13.2.1 Restart Instructions
13.2.2 Implementation of Interrupt Process
13.2.3 Multiple Interrupts & Priorities
13.3 8085 Vectored Interrupts
13.3.1 TRAP
13.3.2 RST 7.5, RST 6.5 and RST 5.5
13.3.3 Interrupt Driven Clock Illustration
13.4 Restart as Software Instructions
13.4.1 Breakpoint Technique Illustration
13.5 Additional I/O Concepts
13.5.1 Programmable Interrupt Controller
13.5.2 Direct Memory Access
13.6 Summary
13.7 List of References
13.8 Unit End Exercise
13.0 Objectives
x Know the difference between the types of interrupt and how to handle them
242
Chapter 13: Interrupts
13.1 Introduction
x The process is asynchronous as the peripheral can interrupt any time but the
response is fully under the control of the microprocessor.
243
MICROPROCESSOR ARCHITECTURE
x They are 1 byte instructions that transfer the program control to specific
address and executed in similar way as CALL instruction.
244
Chapter 13: Interrupts
x തതതതതതത.
It is inserted in the microprocessor by external hardware and the signalܣܶܰܫ
x For example consider the instruction RST 5 which is built using resistors and
a tri-state buffer as shown in figure.
245
MICROPROCESSOR ARCHITECTURE
x During the machine cycle M2, the high order address of the program counter
is stored on the stack and during the machine cycle M3, the low order address
of the program counter is stored on the stack.
x The Machine cycle M2 and M3 are memory write cycle that stores content
of program counter on stack.
x Problem Statement
o A program to count continuously in binary with a one second delay
between each count. A service routine to flash FFH five times when the
program is interrupted, with some appropriate delay between each
count.
246
Chapter 13: Interrupts
x Main Program
247
MICROPROCESSOR ARCHITECTURE
248
Chapter 13: Interrupts
x But to handle multiple interrupts we need a 8:3 priority encoder that helps in
determining the priority among multiple devices.
x The address line A2- A0 are connected to data lines D5-D3 through tri-state
buffer and 8 devices can be connected.
x The interrupting device request for service, then that input line goes low
which makes Enable line E0 go high to interrupt the processor.
x തതതതതതത Acknowledges and enables buffer and corresponding code for example
ܣܶܰܫ
EF (RST 5) is placed on data line.
x So device connected to Pin I7 has always the highest priority and this is
drawback of this technique.
249
MICROPROCESSOR ARCHITECTURE
x The 8085 microprocessor has five interrupts - INTR, RST 7.5, RST 6.5, RST
5.5 and TRAP.
13.3.1 Trap
250
Chapter 13: Interrupts
251
MICROPROCESSOR ARCHITECTURE
x Problem Statement
o Design a 1-minute timer using a 60 Hz power line as an interrupting
source. The output ports should display minutes and seconds in BCD.
At the end of the minute, the output ports should continue displaying
one minute and zero seconds.
x Hardware Description
o This timer is designed with a 60 Hz AC line with frequency of 16.6 ms
o The circuit uses a step down transformer, the 74121 monostable
multivibrator to provide appropriate pulse width and interrupt pin RST
6.5 which will transfer control to address 0034H when interrupted.
o The interrupt flip-flop is enabled again within 6 μs in the timer service
routine;
x Monitor Program
0034 JMP RWM
252
Chapter 13: Interrupts
x Main Program
Address Label Mnemonics
XX00 LXI SP, XX99H
XX03 RIM
XX04 ORI 08H
XX06 SIM
XX07 LXI B, 0000H
XX0A MVI D, 3CH
XX0C EI
XX0D loop: MOV A, B
XX0E OUT 01H
XX10 MOV A, C
XX11 OUT 02H
XX13 JMP loop
XX16 RWM: JMP rout
x Program Description
o The main program is at memory address XX00H, interrupt service
routine at address XX50H and stack pointer at XX99H.
253
MICROPROCESSOR ARCHITECTURE
x But RST are software instructions and used to set breakpoints which is a
useful debugging technique.
x During this the user examines register and memory content on key press.
x Once the routine is executed, the control is again transferred back to the main
program where the breakpoint was set.
x Problem Statement
o Write a subroutine to implement breakpoint at RST 5 and display
accumulator and flag content when key A is pressed and exit the routine
when key 0 is pressed.
x Problem Analysis
o The accumulator and flag contents is displayed when RST instruction
is encountered.
o The register contents are stored on stack.
o When A key is pressed the content of accumulator is displayed and wait
for key pressed and retrieve content from stack
o When 0 key is pressed it should return to main program.
254
Chapter 13: Interrupts
x Breakpoint Subroutine
Address Label Mnemonics
XX50 brkpt: PUSH PSW
XX51 PUSH B
XX52 PUSH D
XX53 PUSH H
XX54 kychk: CALL kbrd
XX57 CPI 0AH
XX59 JNZ loop
XX5C LXI H, 0007h
XX5F DAD SP
XX60 MOV A.M
XX61 OUT 01H
XX63 DCX H
XX64 MOV A, M
XX65 OUT 02H
XX67 JMP kychk
XX6A loop: CPI 00H
XX6C JNZ kychk
XX6F POP H
XX70 POP D
XX71 POP B
XX72 POP PSW
XX73 RET
x Program Description
o The breakpoint subroutine is located at the address XX50H.
o Initially all registers are stored on the stack
o When key press is detected, A key in our case, the HL register adds SP
content without modifying SP data.
o This is of due importance as if stack contents are altered then data will
not be retrieved correctly with POP and RET instruction.
o The accumulator content is displayed at output port 01H and flag
register content is displayed at output port 02H.
255
MICROPROCESSOR ARCHITECTURE
x There is single interrupt pin in 8085 microprocessor and this limits the
performance to determine interrupt priorities.
256
Chapter 13: Interrupts
x 8259A also can read status and change interrupt mode during program
execution.
x This is done because the peripherals are slow devices and processor cycles
are wasted waiting for the slow responding devices
x The 8085 microprocessor has two pins to support the DMA communication.
o HOLD (Hold) – It is active high input signal to the 8085 from
requesting device to use the system buses.
o HLDA (Hold Acknowledge) – It is active high output signal
indicating microprocessor is relinquishing the control of the system
bus
x The controller sends the request to the HOLD pin of the processor.
x The processor completes the current execution and floats the system bus in
high impedance state and sends HLDA signal.
257
MICROPROCESSOR ARCHITECTURE
x The DMA controller now have control over the buses and transfer data
between memory and peripherals
x Once exchange is over a low signal is sent to HOLD pin and microprocessor
gain regains the control of the buses.
13.6 Summary
x Instruction EI and DI are used to enable and disable the interrupt mask for
the 8085 microprocessor.
x Instruction SIM and RIM are used to implement and read the status of the
various interrupts
x The restart instruction are software instructions and the transfer the control
to vectored location
x Using the 8257 DMA controller, high speed data transfer under control of
external devices can be easily achieved.
258
Chapter 13: Interrupts
x https://tutorialspoint.com
x https://www.brighthubengineering.com
x https://www.javatpoint.com
1. Explain the following instructions (i) EI (ii) DI (iii) RST 5 (iv) SIM
(v) RIM
2. Explain the working of an interrupt in 8085 microprocessor.
3. Illustrate the timing and data flows for 8085 Interrupt acknowledge machine
cycle and execution of RST instruction.
4. Explain the working of 8259A Programmable Interrupt Controller.
5. Write a short note on Direct Memory Access (DMA).
259
UNIT 5
14
THE PENTIUM AND PENTIUM PRO
MICROPROCESSORS
Unit Structure
14.0 Objectives:
14.1 Introduction to Pentium Processors
14.2 Special Pentium Registers
14.2.1 The Programming Model
14.2.1.1 Multipurpose Registers
14.2.1.2 Special-purpose Registers
14.2.1.3 Segment Registers
14.3 Memory Management
14.3.1 Real Mode Memory Addressing
14.3.1.1 Segments and Offsets
14.3.1.2 Default Segment and Offset Registers
14.3.2 Segment and Offset Addressing Scheme Allows Relocation
14.3.2 Memory Paging
14.3.2.1 Paging Registers
14.3.3.2. The Page Directory and Page Table
14.4. Pentium Instructions
14.4.1 Instruction Set
14.4.2 Data Movement
14.4.3 Integer Arithmetic
14.4.4 Logical
14.4.5 Floating Point Arithmetic
14.4.6 I/O
14.4.7 Control Instructions
260
Chapter 14: The Pentium and Pentium Pro Microprocessors
14.0 Objectives
1. Explain Pentium Processors
2. Explain features of Pentium Processors
3. Understand and explain Assembly Programs
4. Explain difference between Pentium and Pro-Pentium Processors
5. Explain various registers used in Pentium
6. Explain Pentium Instructions sets
261
MICROPROCESSOR ARCHITECTURE
They are based on both the architecture used in Atom and that of Core processors.
In the case of Atom architectures, Pentiums are the highest performance
implementations of the architecture. Pentium processors with Core architectures
prior to 2017 were distinguished from the faster, higher-end i-series processors by
lower clock rates and disabling some features, such as hyper-threading,
virtualization and sometimes L3 cache.
The name Pentium is originally derived from the Greek word pente meaning "five",
a reference to the prior numeric naming convention of Intel's 80x86 processors
(8086–80486), with the Latin ending -ium since the processor would otherwise
have been named 80586 using that convention.
The Pentium family of processors originated from the 80486 microprocessor. The
term ''Pentium processor'' refers to a family of microprocessors that share a
common architecture and instruction set. It runs at a clock frequency of either 60
or 66 MHz and has 3.1 million transistors.
262
Chapter 14: The Pentium and Pentium Pro Microprocessors
10. The Pentium processor has been optimized to run critical instructions in
fewer clock cycles than the 80486 processor.
11. 8 bytes of data information can be transferred to and from memory in a single
bus cycle.
12. Supports burst read and burst write back cycles.
13. Supports pipelining.
14. Instruction cache.
15. 8 KB of dedicated instruction cache.
263
MICROPROCESSOR ARCHITECTURE
The Pentium's basic integer pipeline is five stages long, with the stages broken
down as follows:
1. Pre-fetch/Fetch: Instructions are fetched from the instruction cache and
aligned in pre-fetch buffers for decoding.
2. Decode1: Instructions are decoded into the Pentium's internal instruction
format. Branch prediction also takes place at this stage.
3. Decode2: Same as above, and microcode ROM kicks in here, if necessary.
Also, address computations take place at this stage.
4. Execute: The integer hardware executes the instruction.
5. Write-back: The results of the computation are written back to the register
file.
264
Chapter 14: The Pentium and Pentium Pro Microprocessors
where,
FRD - Floating Point Rounding
FDD - Floating Point Division
FADD - Floating Point Addition
FEXP - Floating Point Exponent
FAND - Floating Point And
FMUL - Floating Point Multiply
265
MICROPROCESSOR ARCHITECTURE
Figure 2.1 illustrates the programming model of the 8086 through the Pentium II
microprocessor. The earlier 8086, 8088, and 80286 contain 16-bit internal
architectures, a subset of the registers. The 80386, 80486, Pentium, Pentium Pro,
and Pentium II microprocessors contain full 32-bit internal architectures. The
architectures of the earlier 8086 through the 80286 are fully forward-compatible to
the 80386 through the Pentium II. The shaded areas in this illustration represent
registers that are not found in the 8086, 8088, or 80286 microprocessors.
The programming model contains 8-, 16-, and 32-bit registers. The 8-bit registers
are AH, AL, BH, BL, CH, CL, DH, and DL and are referred to when an instruction
is formed using these two-letter designations. The 16-bit registers
are AX, BX, CX, DX, SP, BP, DI, SI, IP, FLAGS, CS, DS, ES, SS, FS, and GS.
266
Chapter 14: The Pentium and Pentium Pro Microprocessors
ECX (count)
ECX is a general-purpose register that also holds the count for various instructions.
In the 80386 and above, the ECX register also can hold the offset address of
memory data. Instructions that use a count are the repeated string instructions
(REP/REPE/REPNE); and shift, rotate, and LOOP/LOOPD instructions. The shift
and rotate instructions use CL as the count, the repeated string instructions use CX,
and the LOOP/LOOPD instructions use either CX or ECX.
EDX (data)
EDX is a general-purpose register that holds a part of the result from a
multiplication or part of the dividend before a division. In the 80386 and above,
this register can also address memory data.
267
MICROPROCESSOR ARCHITECTURE
EFLAGS
EFLAGS indicate the condition of the microprocessor and control its operation.
Figure 2-2 shows the flag registers of all versions of the microprocessor. Note that
the flags are upward-compatible from the 8086/8088 to the Pentium II
microprocessor. The 8086-80286 contain a FLAG register (16 bits) and the 80386
and above contain an EFLAG register (32-bit extended flag register).
268
Chapter 14: The Pentium and Pentium Pro Microprocessors
The rightmost five flag bits and the overflow flag change after many arithmetic and
logic instructions execute. The flags never change for any data transfer or program
control operation. Some of the flags are also used to control features found in the
microprocessor. Following is a list of each flag bit, with a brief description of their
function.
C (Carry)
Carry holds the carry after addition or the borrow after subtraction. The carry flag
also indicates error conditions, as dictated by some programs and procedures. This
is especially true of the DOS function calls.
P (Parity)
Parity is a logic 0 for odd parity and a logic 1 for even parity. Parity is a count of
ones in a number expressed as even or odd.
If a number contains zero one bits, it has even parity. The parity flag finds little
application in modern programming and was implemented in early Intel
microprocessors for checking data in data communications environments. Today
parity checking is often accomplished by the data communications equipment
instead of the microprocessor.
A (Auxiliary Carry)
The auxiliary carry holds the carry (half-carry) after addition or the borrow after
subtraction between bits positions 3 and 4 of the result. This highly specialized flag
bit is tested by the DAA and DAS instructions to adjust the value of AL after a
BCD addition or subtraction. Otherwise, the A flag bit is not used by
the microprocessor or any other instructions.
Z (Zero)
The zero flag shows that the result of an arithmetic or logic operation is zero. If
Z=1, the result is zero; if Z= 0, the result is not zero.
269
MICROPROCESSOR ARCHITECTURE
S (Sign)
The sign flag holds the arithmetic sign of the result after an arithmetic or logic
instruction executes. If S=1, the sign bit (leftmost hit of a number) is set or negative;
if S=0, the sign bit is cleared or positive.
T (Trap)
The trap flag enables trapping through an on-chip debugging feature. (A program
is debugged to find an error or bug.) If the T flag is enabled (1), the microprocessor
interrupts the flow of the program on conditions as indicated by the debug registers
and control registers. lf the T flag is a logic 0, the trapping (debugging) feature is
disabled.
I (Interrupt)
The interrupt flag controls the operation of the INTR (interrupt request) input pin.
If I=1. the INTR pin is enabled: if I= 0, the INTR pin is disabled. The state of
the I flag bit is controlled by the STI (set I flag) and CLI (clear I flag) instructions.
D (Direction)
The direction flag selects either the increment or decrement mode for the Dl and/or
SI registers during string instructions. If D=1, the registers are automatically
decremented: if D=1, the registers are automatically incremented. The D flag is set
with the STD (set direction) and cleared with the CLD (clear direction) instructions.
0 (Overflow)
Overflows occurs when signed numbers are added or subtracted. An overflow
indicates that the result has exceeded the capacity of the machine. For unsigned
operations, the overflow flag is ignored.
NT (Nested Task)
The nested task flag indicates that the current task is nested within another task in
protected mode operation. This line is set when the task is nested by software.
270
Chapter 14: The Pentium and Pentium Pro Microprocessors
RF (Resume)
The resume flag is used with debugging to control the resumption of execution after
the next instruction.
VM (Virtual Mode)
The VM flag bit selects virtual mode operation in a protected mode system. A
virtual mode system allows multiple DOS memory partitions that are 1M byte in
length to coexist in the memory system. Essentially, this allows the system program
to execute multiple DOS programs.
AC (Alignment Check)
The alignment check flag bit activates if a word or douhleword is addressed on a
non-word or non-douhleword boundary. Only the 80486SX microprocessor
contains the alignment check hit that is primarily used by its companion numeric
coprocessor, the 80487SX, for synchronization.
ID (Identification)
The ID flag indicates that the Pentium—Pentium II microprocessors support the
CPUID instruction. The CPUID instruction provides the system with information
about the Pentium microprocessor, such as its version number and manufacturer.
271
MICROPROCESSOR ARCHITECTURE
CS (Code)
The code segment is a section of memory that holds the code (programs and
procedures) used by the microprocessor. The code segment register defines the
starting address of the section of memory holding code. In real mode operation,
it defines the start of a 64K-byte section of memory; in protected mode, it selects a
descriptor that describes the starting address and length of a section of memory
holding code. The code segment is limited to 64K bytes in the 8088-80286, and 4G
bytes in the 80386 and above when these microprocessors operate in the protected
mode.
DS (Data)
The data segment is a section of memory that contains most data used by a program.
Data are accessed in the data segment by an offset address or the contents of other
registers that hold the offset address. As with the code segment and other segments,
the length is limited to 64K bytes in the 8086-80286, and 4G bytes in the 80386
and above.
ES (Extra)
The extra segment is an additional data segment that is used by some of the string
instructions to hold destination data.
SS (Stack)
The stack segment defines the area of memory used for the stack. The stack entry
point is determined by the stack segment and stack pointer registers. The BP
register also addresses data within the stack segment.
FS and GS
The FS and GS segments are supplemental segment registers available in
the 80386, 80486, Pentium. and Pentium Pro microprocessors to allow
two additional memory segments for access by programs.
272
Chapter 14: The Pentium and Pentium Pro Microprocessors
requires the microprocessor to operate in the real mode. Real mode operation
allows application software written for the 8086/8088, which contain only 1 M byte
of memory, to function in the 80286 and above without changing the software. The
upward compatibility of software is partially responsible for the continuing
success of the Intel family of microprocessors. In all cases, each of these
microprocessors begins operation in the real mode by default whenever power is
applied or the microprocessor is reset.
273
MICROPROCESSOR ARCHITECTURE
274
Chapter 14: The Pentium and Pentium Pro Microprocessors
register is always used with the instruction pointer to address the next instruction
in a program. This combination is CS:IP or CS:EIP, depending upon the
microprocessor’s mode of operation. The code segment register defines the start
of the code segment and the instruction pointer locates the next instruction within
the code segment. This combination (CS:IP or CS:EIP) locates the next instruction
executed by the microprocessor.
Another of the default combinations is the stack. Stack data are referenced through
the stack segment at the memory location addressed by either the stack pointer
(SP/ESP) or the base pointer (BP/EBP). These combinations are referred to as
SS:SP (SS:ESP) or SS:BP (SS:EBP). Note that in real mode, only the rightmost 16
bits of the extended register address a location within the memory segment. In the
80386—Pentium II, never place a number larger than FFFFH into an offset register
if the microprocessor is operated in the real mode. This causes the system to halt
and indicate an addressing error.
Other defaults are shown in Table 3.1 for addressing memory using any Intel
microprocessor with 16-bit registers. Table 3.2 shows the defaults assumed in the
80386 and above when using 32-bit registers. Note that the 80386 and above have
a far greater selection of segment offset address combinations than do the 8086
through the 80286 microprocessors.
275
MICROPROCESSOR ARCHITECTURE
The 8086-80286 microprocessors allow four memory segments and the 80386 and
above allow six memory segments. Figure 3.2 shows a system that contains four
memory segments. Note that a memory segment can touch or even overlap if 64K
bytes of memory are not required for a segment. Think of segments as windows
that can be moved over any area of memory to access data or code. Also note that
a program can have more than four or six segments but can only access four or six
segments at a time.
Suppose that an application program requires 1000H bytes of memory for its code,
190H bytes of memory for its data, and 200H bytes of memory for its stack. This
application does not require an extra segment. When this program is placed in the
memory system by DOS, it is loaded in the TPA at the first available area of
memory above the drivers and other TPA programs. This area is indicated by a free
pointer that is maintained by DOS. Program loading is handled automatically by
the program loader located within DOS. Figure 3.3 shows how this application is
stored in the memory system. The segments show an overlap because the amount
of data in them does not require 64K bytes of memory. The side view of the
segments clearly shows the overlap. It also shows how segments can be moved
over any area of memory by changing the segment starting address. Fortunately,
the DOS program loader calculates and assigns segment starting addresses.
Figure 3.2: A memory system showing the placement of four memory segments
276
Chapter 14: The Pentium and Pentium Pro Microprocessors
Figure 3.3: An Application program containing code, data and stack segment
loaded into DOS system memory
277
MICROPROCESSOR ARCHITECTURE
the entire program is moved to a new area of memory, this offset address of 4 still
points to 4 bytes above the start of the segment. Only the contents of the segment
register must be changed to address the program in the new area of memory.
Without this feature, a program would have to be extensively rewritten or altered
before it is moved. This would require additional time or many versions of a
program for the many different configurations of computer systems.
The registers important to the paging unit are CR0 and CR3. The leftmost bit (PG)
position of CR0 selects paging when placed at a logic 1 level. If the PG bit is cleared
(0), the linear address generated by the program becomes the physical address used
to access memory. If the PG bit is set (1), the linear address is converted to a
physical address through the paging mechanism. The paging mechanism functions
in both the real and protected modes.
CR3 contains the page directory base address, and the PCD and PWT bits. The
PCD and PWT bits control the operation of the PCD and PWT pins on the
278
Chapter 14: The Pentium and Pentium Pro Microprocessors
microprocessor. If PCD is set (1), the PCD pin becomes a logic one during bus
cycles that are not pages. This allows the external hardware to control the level 2
cache memory. (Note that the level 2 cache memory is an external high-speed
memory that functions as a buffer between the microprocessor and the main DRAM
memory system.) The PWT bit also appears on the PWT pin, during bus cycles that
are not pages, to control the write-through cache in the system. The page directory
base address locates the page directory for the page translation unit. Note that this
address locates the page directory at any 4K boundary in the memory system
because it is appended internally with a 000H. The page directory contains 1024
directory entries of 4 bytes each.
Each page directory entry addresses a page table that contains 1024 entries.
The linear address, as it is generated by the software, is broken into three sections
that are used to access the page directory entry, page table entry, and page offset
address. Figure 3.4 shows the linear address and its makeup for paging. Notice
how the leftmost 10 bits address an entry in the page directory. For linear address
00000000H—003FFFFFH, the first entry of the page directory is accessed. Each
page directory entry represents or repages a 4M-byte section of the memory system.
The contents of the page directory select a page table that is indexed by the next 10
bits of the linear address (bit positions 12-21). This means that address
00000000H— 00000FFFH selects page directory entry 0 and page table entry 0.
Notice this is a 4K-byte address range. The offset part of the linear address (bit
positions 0-11) next selects a byte in the 4K-byte memory page. In Figure 2-12, if
the page table 0 entry contains address 00100000H, then the physical address is
00100000H-00100FFFH for linear address 00000000H-00000FFFH. This means
that when the program accesses a location between 00000000H and 00000FFFH,
the microprocessor physically addresses location 00100000H—00100FFFH.
279
MICROPROCESSOR ARCHITECTURE
Because the act of re-paging a 4K-byte section of memory requires access to the
page directory and a page table, which are both located in memory, Intel has
incorporated a cache called the TLB (translation look-aside buffer). In the 80486
micro-processor, the cache holds the 32 most recent page translation addresses.
This means that the last 32-page table translations are stored in the TLB, so if the
same area of memory is accessed, the address is already present in the TLB, and
access to the page directory and page tables is not required. This speeds program
execution. If a translation is not in the TLB, the page directory and page table must
be accessed, which requires additional execution time. The Pentium, Pentium Pro,
and Pentium II contain separate TLBs for each of their instruction and data caches.
Figure 3.5: The format for the linear address (a) and
a page directory or page table entry (b)
280
Chapter 14: The Pentium and Pentium Pro Microprocessors
Figure 3.6: The paging mechanism the 80386, 80486, Pentium, Pentium Pro,
and Pentium II microprocessor
The DOS system and EMM386.EXE use page tables to redefine the area of
memory between locations C8000H—EFFFFH as upper memory blocks. It does
this by repaging extended memory to back-fill this part of the conventional memory
system to allow DOS access to additional memory. Suppose that the
EMM386.EXE program allows access to 16M bytes of extended and conventional
memory through paging and locations C8000H—EFFFFH must be repaged to
locations 110000—138000H, with all other areas of memory paged to their normal
locations. Such a scheme is depicted in Figure 3.7
Here, the page directory contains four entries. Recall that each entry in the page
directory corresponds to 4M bytes of physical memory. The system also contains
four page tables with 1024 entries each. Recall that each entry in the page table
repages 4K bytes of physical memory. This scheme requires a total of 16K of
memory for the four page tables and 16 bytes of memory for the page directory.
As with DOS, the Windows program also repages the memory system. At present,
Windows version 3.11 supports paging for only l6M bytes of memory because of
the amount of memory required to store the page tables. On the Pentium and
Pentium Pro microprocessors, pages can be either 4K bytes in length or 4M bytes
in length. Although no software currently supports the 4M-byte pages, as the
Pentium II and more advanced versions pervade the personal computer, operating
systems of the future will undoubtedly begin to support 4M-byte memory pages.
281
MICROPROCESSOR ARCHITECTURE
Figure 3.7: The page directory, page table 0, and two memory pages
282
Chapter 14: The Pentium and Pentium Pro Microprocessors
I left out the 16-bit ones to reduce presentation of the instruction set.
Note that on a 32-bit machine, with newly written code, the 16-bit form will never
be used.
Examples:
lea EBX, loop_top ; put the address assigned (by the assembler)
; to label loop_top into register EBX
283
MICROPROCESSOR ARCHITECTURE
Examples:
neg [eax + 4] ; takes doubleword at address eax+4
; and finds its additive inverse, then places
; the additive inverse back at that address
; the instruction should probably be
; neg dword ptr [eax + 4]
inc ecx ; adds one to contents of register ecx, and
; result goes back to ecx
284
Chapter 14: The Pentium and Pentium Pro Microprocessors
14.4.4 Logical
not r/m ; logical not
and reg, r/m ; logical and
reg8, r/m8
r/m, reg
r/m8, reg8
r/m, immed
r/m8, immed8
or reg, r/m ; logical or
reg8, r/m8
r/m, reg
r/m8, reg8
r/m, immed
r/m8, immed8
xor reg, r/m ; logical exclusive or
reg8, r/m8
r/m, reg
r/m8, reg8
r/m, immed
r/m8, immed8
test r/m, reg ; logical and to set EFLAGS
r/m8, reg8
r/m, immed
r/m8, immed8
Examples:
and edx, 00330000h ; logical and of contents of register
; edx (bitwise) with 0x00330000,
; result goes back to edx
285
MICROPROCESSOR ARCHITECTURE
There are separate instructions to test and compare the values of floating-point
variables.
14.4.6 I/O
The only instructions which actually allow the reading and writing of I/O devices
are priviledged. The OS must handle these things. But, in writing programs that do
something
useful, we need input and output. Therefore, there are some simple macros defined
to help us do I/O.
286
Chapter 14: The Pentium and Pentium Pro Microprocessors
14.5.1 Modes
The Pentium and Pentium Pro processor has three operating modes:
1. Real-address mode: This mode lets the processor to address "real" memory
address. It can address up to 1Mbytes of memory (20-bit of address). It can
also be called "unprotected" mode since operating system (such as DOS)
code runs in the same mode as the user applications. Pentium and Prentium
Pro processors have this mode to be compatible with early Intel processors
such as 8086. The processor is set to this mode following by a power-up or a
reset and can be switched to protected mode using a single instruction.
2. Protected mode: This is the preferred mode for a modern operating system.
It allows applications to use virtual memory addressing and supports multiple
programming environment and protections.
3. System management mode: This mode is designed for fast state snapshot
and resumption. It is useful for power management.
There is also a virtual-8086 mode that allows the processor to execute 8086
code software in the protected, multi-tasking environment.
287
MICROPROCESSOR ARCHITECTURE
General-purpose Registers
The eight 32-bit general-purpose data registers are used to hold operands for logical
and arithmetic operations, operands for address calculations and memory pointers.
The following shows what they are used for:
The following figure shows the lower 16 bits of the general-purpose registers can
be used with the names AX, BX, CX, DX, BP, SP, SI, and DI (the names for the
corresponding 32-bit ones have a prefix "E" for "extended"). Each of the lower two
bytes of the EAX, EBX, ECX, and EDX registers can be referenced by the names
AH, BH, CH, and DH (high bytes) and AL, BL, CL, and DL (low bytes).
288
Chapter 14: The Pentium and Pentium Pro Microprocessors
Segment Registers
There are six segment registers that hold 16-bit segment selectors. A segment
selector is a special pointer that identifies a segment in memory. The six segment
registers are:
Four data segment registers provide programs with flexible and efficient ways to
access data.
Modern operating system and applications use the (unsegmented) memory model
- all the segment registers are loaded with the same segment selector so that all
memory references a program makes are to a single linear-address space.
When writing application code, you generally create segment selectors with
assembler directives and symbols. The assembler and/or linker then creates the
actual segment selectors associated with these directives and symbols. If you are
writing system code, you may need to create segment selectors directly.
EFLAGS Register
The 32-bit EFLAGS register contains a group of status flags, a control flag, and a
group of system flags. The following shows the function of EFLAGS register bits:
289
MICROPROCESSOR ARCHITECTURE
Note that the value of the EIP may not match with the current instruction because
of instruction prefetching. The only way to read the EIP is to execute a CALL
instruction and then read the value of the return instruction pointer from the
procedure stack.
14.5.3 Addressing
Bit and Byte Order
Pentium and Pentium-Pro processors use "little endian" as their byte order. This
means that the bytes of a word are numbered starting from the least significant byte
and that the least significant bit starts of a word starts in the least significant byte.
290
Chapter 14: The Pentium and Pentium Pro Microprocessors
Data Types
The Pentium/Pentium Pro provide four data types: a byte (8 bits), a word (16 bits),
a doubleword (32 bits), and a quadword (64 bits). Note that a doubleword is
equivalent to "long" in Gnu assembler.
Memory Addressing
One can use either flat memory model or segmented memory mode. With the flat
memory model, memory appears to a program as a single, continuous address
space, called a linear address space. Code (a programs instructions), data, and the
procedure stack are all contained in this address space. The linear address space is
byte addressable, with addresses running contiguously from 0 to 232-1.
With the segmented memory mode, memory appears to a program as a group of
independent address spaces called segments. When using this model, code, data,
and stacks are typically contained in separate segments. To address a byte in a
segment, a program must issue a logical address, which consists of a segment
selector and an offset. (A logical address is often referred to as a far pointer.) The
segment selector identifies the segment to be accessed and the offset identifies a
byte in the address space of the segment. The programs running on a Pentium Pro
processor can address up to 16,383 segments of different sizes and types. Internally,
all the segments that are defined for a system are mapped into the processors linear
address space. So, the processor translates each logical address into a linear address
to access a memory location. This translation is transparent to the application
program.
291
MICROPROCESSOR ARCHITECTURE
The offset part of the memory address can be specified either directly as a static
value (called a displacement) or through an address computation made up of one
or more of the following components:
292
Chapter 14: The Pentium and Pentium Pro Microprocessors
The offset which results from adding these components is called an effective
address of the selected segment. Each of these components can have either a
positive or negative (2's complement) value, with the exception of the scaling
factor.
293
MICROPROCESSOR ARCHITECTURE
In addition, with the AT&T syntax, the name for a long JUMP is ljmp and long
CALL is lcall.
When using directives to define a string, bytes or a word, you often want to make
sure that they are aligned to 32-bit long word by padding additional bytes.
294
Chapter 14: The Pentium and Pentium Pro Microprocessors
asm( "assembly-instruction" );
where assembly-instruction will be inlined into where the asm statement is. This
is a very convenient way to inline assembly instructions that require no
registers. For example, you can use
asm( "cli" );
to clear interrupts and
asm( "sti" );
to enable interrupts.
where statements are the assembly instructions. If there are more than one
instruction, you can use "\n\t" to separate them to make them look
pretty. "input_regs" tells gcc compiler which C variables move to which
registers. For example, if you would like to load variable "foo" into register EAX
and "bar" into register ECX, you would say
Note that you cannot specify register AH or AL this way. You need to get to EAX
first and then go from there.
295
MICROPROCESSOR ARCHITECTURE
the registers in the input register list, you simply say "0" or "1" without the "%"
prefix.
"used_regs" lists the registers that are used (or clobbered) in the assembly code.
To understand exactly how to do this, please try to use gcc to compile a piece of C
code containing the following inline assembly:
and
Also, to avoid the gcc compiler's optimizer to remove the assembly code, you can
put in keyword volitale to ensure your inline. Here are some macro code examples:
Core specifications
x Pentium Pro
x L1 cache: 8, 8 KB (data, instructions)
x L2 cache: 256, 512 KB (one die) or 1024 KB (two 512 KB dies) in a multi-
chip module clocked at CPU-speed
296
Chapter 14: The Pentium and Pentium Pro Microprocessors
x Socket: Socket 8
x Front side bus: 60 and 66 MHz
x VCore: 3.1–3.3 V
x Fabrication: 0.50 μm or 0.35 BiCMOS[18]
x Clockrate: 150, 166, 180, 200 MHz, (capable of 233 MHz on some
motherboards)
x First release: November 1995
14.7 Summary
In this chapter we have studied about processor architecture. The various registers
used in processors and their uses. We have seen the page tables for memory
accessing methods. We have seen various types of instructions sets used in
assembly language programming. We have also seen the features of Pentium Pro
Microprocessors.
297
MICROPROCESSOR ARCHITECTURE
x http://www.x86.org/intel.doc/intelDocs.html
x https://www.byclb.com/TR/Tutorials/microprocessors/ch2_1.htm#:~:text=T
he%2016%2Dbit%20registers%20are,in%20the%2080386%20and%20abo
ve
x https://eun.github.io/Intel-Pentium-Instruction-Set-
Reference/data/index.html
298
UNIT 5
15
CORE 2 AND LATER MICROPROCESSORS
Unit Structure
15.0 Objectives
15.1 Introduction
15.2 Pentium II Software Changes
15.3 Pentium IV
15.4 Core 2, i3, i5 and i7
15.4.1 Core i2
15.4.2 The Microarchitectures of Nehalem
15.4.3 Core i3, i5 and i7
15.5 Summary
15.6 Review Your Learnings:
15.7 Sample Questions:
15.8 References for further reading
15.0 Objectives
15.1 Introduction
299
MICROPROCESSOR ARCHITECTURE
and analyse the architecture before they purchase it for their various day to day use.
In a nutshell, people have not been able to analyse the differences in the
architectures before purchase. Testing performance of computer system is very
necessary because it helps consumers decide what type and configurations of
products to purchase for a particular nature of computing job. However, the
performance is strongly dependent on several factors which include the system
architecture, processor microarchitecture, operating systems, type of compiler, and
program implementation etc. Many processor manufacturers including Intel has
performance analysis tools which can be used to determine the performance of their
architecture. Intel Corporation produces different processors with different
numbers of cores for different nature of jobs, however, it is the important for users
of processor machines to acquire the right processor specifications that would
efficiently process target applications based on the workloads characteristics of the
application program. For instance, some specification of machine works better on
graphics while others perform best on computation. With the evolution of Intel
processor architectures over time, testing performance is necessary. The aim of this
study is to measure the performance of different cores using different applications
(both Single and Multithreaded). The objectives are 1) compare architecture
performance on applications (Single and Multithreaded), 2) measure performance
counters on representative processors and, 3) show methods for exploring
processor architectures. One of the goals of this work is to highlight the advantages
of each feature in a system and to study how the hardware makes use of CPU
resources.
300
Chapter 15: Core 2 and Later Microprocessors
Pentium II
The Pentium II made a number of subtle changes to the Pentium Pro's design and
one big honkin' shift. It re-added the segment register cache previous x86 CPUs
had used but the Pentium Pro hadn't to improve 16-bit performance, doubled the
L1 cache size to 32K while splitting the L1 into instructions and data caches,
widened the execution core by adding MMX support, and, of course, moved from
a socket configuration to Intel's Slot 1. The Pentium Pro used an onboard L2 cache
that was connected to the primary CPU by a dedicated bus, but the cache itself only
ran at half clock. The Pentium Pro's cache, in contrast, had run at full CPU clock.
This design was a huge success for Intel overall -- most of the company’s last x86
competitors were on their last legs by this time.
To trace the history of Intel CPU cores is to trace the history of various epochs in
the evolution of CPU performance. In the 1980s and 1990s, clock speed
improvements and architectural enhancements went hand in hand. From 2005
forward, it was the era of multi-core chips and higher efficiency parts. Since 2011,
Intel has focused on improving the performance of its low power CPUs more than
other capabilities. This focus has paid real dividends — laptops today have far
better battery life and overall performance than they did a decade ago.
Unlike previous Pentium and Pentium Pro processors, the Pentium II CPU was
packaged in a slot-based module rather than a CPU socket. The processor and
associated components...
Intel improved 16-bit code execution performance on the Pentium II, an area in
which the Pentium Pro was at a notable handicap, by adding segment register
caches. Most consumer software of the day was still using at least some 16-bit code,
because of a variety of factors. The issues with partial registers was also addressed
by adding an internal flag to skip pipeline flushes whenever possible. To
compensate for the slower L2 cache, the Pentium II featured 32 KB of L1 cache,
double that of the Pentium Pro, as well as 4 write buffers (vs. 2 on the Pentium
Pro); these can also be used by either pipeline, instead of each one being fixed to
301
MICROPROCESSOR ARCHITECTURE
one pipeline. The Pentium II was also the first P6-based CPU to implement the
Intel MMX integer SIMD instruction set which had already been introduced on the
Pentium MMX.
302
Chapter 15: Core 2 and Later Microprocessors
15.3 Pentium IV
x 64-bit Bus
x The Pentium processors have two separate 8 KB caches on chip, one for
instruction and one for data. It allows the Pentium processor to fetch data
and instructions from cache simultaneously.
x When data is modified, only the data in cache is changed. Memory data is
changed only when Pentium Processor replaces modified data in cache with
a different set of data.
303
MICROPROCESSOR ARCHITECTURE
15.4.1 Core i2
The Intel Core 2 Duo processor belongs to the Intel’s mobile core family. It is
implemented by using two Intel’s Core architecture on a single die. The design of
Intel Core 2 Duo is chosen to maximize performance and minimize power
consumption. It emphasizes mainly on cache efficiency and does not stress on the
clock frequency for high power efficiency. Although clocking at a slower rate than
most of its competitors, shorter stages and wider issuing pipeline compensates the
performance with higher IPC’s. In addition, the Core 2 Duo processor has more
ALU units. Core 2 Duo employs Intel’s Advanced Smart Cache which is a shared
L2 cache to increase the effective on-chip cache capacity. Upon a miss from the
core’s L1 cache, the shared L2 and the L1 of the other core are looked up in parallel
before sending the request to the memory. The cache block located in the other L1
304
Chapter 15: Core 2 and Later Microprocessors
cache can be fetched without off-chip traffic. Both memory controller and FSB are
still located off-chip. The off-chip memory controller can adapt the new DRAM
technology with the cost of longer memory access latency. Intel Advanced Smart
Cache provides a peak transfer rate of 96 GB/sec (at 3 GHz frequency).
The microarchitectures of Intel Core and Intel Core 2 are shown below in Figure
4.1 and Figure 4.2.
305
MICROPROCESSOR ARCHITECTURE
306
Chapter 15: Core 2 and Later Microprocessors
execution and saves the instructions in a special buffer so they do not need to be
continually fetched from cache. This increased branch prediction success for loops
in the code and improved performance. Intel engineers took the concept even
further with the Nehalem architecture by placing the Loop Stream Detector after
the decode stage eliminating the instruction decode from a loop iteration and saving
CPU cycles.
307
MICROPROCESSOR ARCHITECTURE
The comparisons between Intel Core and Nehalem processors are mentioned below
in Table 4.2.
308
Chapter 15: Core 2 and Later Microprocessors
Let’s start differentiating the processors on the basis of the concepts discussed
below!
Total number of cores present: Out of all differences between the intel processor
ranges, this is one that will affect performance the most.
Having several cores can also drastically increase the speed at which certain
programs run. The Core i3 range is entirely dual core, while Core i5 and i7
processors have four cores.It is difficult for an application to take advantage of the
multicore system. Each core is effectively its own processor – your PC would still
work (slowly) with just one core enabled. Having multiple cores means that the
computer can work on more than one task at a time more efficiently.
309
MICROPROCESSOR ARCHITECTURE
Examples:
2.4GHz means 2,400,000,000 clock cycles.
Turbo Boost has nothing to do with fans or forced induction but is Intel’s marketing
name for the technology that allows a processor to increase its core clock speed
dynamically whenever the need arises. Core i3 processors don’t have Turbo Boost,
but Core i5 and Core i7s do. Turbo Boost dynamically increases the clock speed of
Core i5 and i7 processors when more power is required. This means that the chip
can draw less power, produce less heat and only boost when it needs to. For
example, although a Core i3-7300 runs at 4GHz compared to 3.5GHz for the Core
i5-7600, the Core i5 chip can boost up to 4.1GHz when required, so will end up
being quicker. A processor can only Turbo Boost for a limited amount of time. It
is a significant part of the reason why Core i5 and Core i7 processors outperform
Core i3 models in single-core-optimised tasks, even though they have lower base
clock speeds.
Note:
If a processor model ends with a K, it means it is unlocked and can be
‘overclocked’. This means you can force the CPU to run at a higher speed than its
base speed all the time for better performance.
310
Chapter 15: Core 2 and Later Microprocessors
part. When a CPU finds it is using the same data over and over, it stores that data
in its cache. Cache is even faster than RAM because it’s part of the processor itself.
Here, bigger is better. Core i3 chips have 3- or 4MB, while i5s have 6MB and the
Core i7s have 8MB.
What is Hyper-Threading?
It’s one of the concepts which is a little confusing to explain, but also confuses as
it’s available on Core i7 and Core i3, but not on the mid-range core i5. A little
shocking, right? Normally we assume that we get more features as we go higher
towards the processor range, but not here. Back to the concept, A thread in
computing terms is a sequence of programmed instructions that the CPU has to
process. For example: If a CPU consists of one core, it can process only one thread
at once, so can only do one thing at once.
Hyper-Threading is a clever way to let a single core handle multiple thread. It
essentially tricks operating system into thinking that each physical processor core
is, in fact, two virtual (logical) cores. A two-core Core i3 processor will appear as
four virtual cores in Task Manager, and a four-core i7 chip will appear as eight
cores. Whereas the current Core i5 range doesn’t have Hyper-Threading so can also
only process four cores. Due to Hyper-Threading operating system can share
processing tasks between these virtual cores in order to help certain applications
run more quickly, and to maintain system performance when more than one
application is running at once.
From these, we conclude why Core i7 processors are the creme de la creme. Not
only are they quad cores, they also support Hyper-Threading. Thus, a total of eight
threads can run on them at the same time. Combine that with 8MB of cache and
Intel Turbo Boost Technology, which all of them have, and you’ll see what sets the
Core i7 apart from its siblings.
311
MICROPROCESSOR ARCHITECTURE
15.5 Summary
312
Chapter 15: Core 2 and Later Microprocessors
x https://www.pdfdrive.com/computer-system-architecture-morris-mano-
third-edition-e51589001.html
x https://www.pdfdrive.com/microprocessor-architecture-programming-and-
applications-with-the-8085-d176171206.html
x https://www.researchgate.net/publication/278912508_Performance_Analysi
s_of_Dual_Core_Core_2_Duo_and_Core_i3_Intel_Processor/link/55afa4da
08aeb0ab4668933e/download
x http://www.x86.org/intel.doc/intelDocs.html
x https://www.byclb.com/TR/Tutorials/microprocessors/ch2_1.htm#:~:text=T
he%2016%2Dbit%20registers%20are,in%20the%2080386%20and%20abo
ve
x https://eun.github.io/Intel-Pentium-Instruction-Set-
Reference/data/index.html
x https://www.lpthe.jussieu.fr/~talon/pentiumII.pdf
x http://www.darshan.ac.in/Upload/DIET/Documents/CE/2150707-MPI-
Study-Material_04112017_033410AM.pdf
313
UNIT 5
16
SUN SPARC MICROPROCESSOR
Unit Structure
16.0 Objectives:
16.1 SUN SPARC Architecture
16.1.1 Integer Unit:
16.1.2 Integer Unit: Register Window
16.1.3 Floating-point Unit (FPU)
16.1.4 Coprocessor Unit (CU)
16.2. Register File
16.2.1 Integer Unit: Register Window
16.2.2 Advantage: Register Window
3. Data Types
4. Instruction Format
16.4.1 Arithmetic/Logical/Shift instructions
16.4.2 Load/Store Instructions
16.4.3 Branch Instructions
16.4.4 SPARC Fundamental Instructions
16.4.4.1 Load/Store Instructions
16.4.4.2 Arithmetic/Logical Instructions
16.4.4.3 Call Instruction
16.4.4.4 Synthetic Instructions 13
16.5. Summary
16.6. Review Your Learnings:
16.7. Questions
16.8. References for further reading
314
Chapter 16: Sun Sparc Microprocessor
16.0 Objectives
315
MICROPROCESSOR ARCHITECTURE
• On-chip 16Kb data and instruction caches with 2Mb external cache
• A large “windowed” register file — at any one instant, a program sees 8
global integer registers plus a 24-register window into a larger register file.
316
Chapter 16: Sun Sparc Microprocessor
The SPARC architecture's definition includes the IU (Integer Unit) which is the
CPU, the FPU (Floating Point Unit) and the CP (Co-Processor) which is optional
for the user. Other options are the memory management unit and cache.
An important concept of the SPARC architecture is borrowed from the Berkeley
RISC chips, the TMS 9900 mainly. This is register windowing. When a program is
317
MICROPROCESSOR ARCHITECTURE
running it has access to 32 32-bit processor registers which include eight global
registers plus 24 registers that belong to the current register window. The first 8
registers in the window are called the in registers (i0-i7). When a function is called,
these registers may contain arguments that can be used. The next 8 are the local
registers which are scratch registers that can be used for anything while the function
executes. The last 8 registers are the out registers which the function uses to pass
arguments to functions that it calls.
When one function calls another, the callee can choose to execute a SAVE
instruction. This instruction decrements an internal counter, the current workspace
pointer, shifting the register window downward. The caller's out registers then
become the callee' s in registers, and the callee gets a new set of local and out
registers for its own use. Only the pointer changes because the registers and return
address do not need to be stored on a stack. The CALL instruction automatically
saves its own address in 07 (output register 7) which becomes input register 7 if the
CWP is decremented. Therefore, the callee can access the return address whether
or not it has decremented the CWP.
Register windows are also used to save the processor contexts when traps, or
interrupts occur. The SPARC OS's always ensure that there is a register window
not being used below the current one. If a trap occurs, then the CWP is decremented
and the new window saves the processor context.
The chip that was implemented by Sun had seven overlapping windows which
brought the total of registers to (7*16) + 7 (without counting g0) which is 119
registers. If six levels are not enough due to recursive or deeply nested function
calls, then the program attempts to decrement the CWP to the last unused window
and it discovers that the window has been marked invalid in a register called the
window invalid mask register. This causes a trap and the processor has an
opportunity to "spill" register s in order to make more room. It writes some of the
contents out to memory.
A long series of subroutine returns can cause a window underflow, which
consequently causes the processor to call in a trap handler that fills registers from
memory. All the spilling and filling is hidden from an executing user program
usually. Spilling and filling registers is an essential part of Unix multitasking on
SPARC.
Sparc has 32 general purpose integer registers visible to the program at any given
time. Of these, 8 registers are global registers, and 24 registers are in a register
window. A window consists of three groups of 8 registers, the out, local, and in
registers. See table 1. A Sparc implementation can have from 2 to 32 windows, thus
318
Chapter 16: Sun Sparc Microprocessor
319
MICROPROCESSOR ARCHITECTURE
writing out data to memory. In the figure, the capacity of the register windows is
fully utilized. An additional call will thus exceed capacity, triggering a window
overflow trap. At the other end, a window underflow trap occurs when the register
window "cache" if empty and more data needs to be fetched from memory.
320
Chapter 16: Sun Sparc Microprocessor
321
MICROPROCESSOR ARCHITECTURE
x Instead, the state variables are held in the current window, and the next
window is opened for the new procedure.
x A refinement on this idea in that the input and output registers of adjacent
windows overlap, allowing variables and parameters to be passed to the
next process without physically moving data.
x The additional registers are hidden from view until you call a subroutine or
other function. Where other processors would push parameters on a stack
for the called routine to pop off, SPARC processors just "rotate" the register
window to give the called routine a fresh set of registers.
x The old window and the new window overlap, so that some registers are
shared.
322
Chapter 16: Sun Sparc Microprocessor
SPARC is "big-endian"- it stores multiple byte objects in memory with the most
significant byte at the lowest address.
There are very few addressing modes on the SPARC, and they may be used only
in certain very restricted combinations. The three main types of SPARC
instructions are given below, along with the valid combinations of addressing
modes. There are only a few unusual instructions which do not fall into these
categories.
x All "action" instructions (add, sub, and, or, etc.) take three operands.
323
MICROPROCESSOR ARCHITECTURE
Examples:
x The operands are written in the reverse direction for store instructions, so that
the destination is always last.
x One of reg1 or const13 can be omitted. The assembler will supply $g0 or 0.
(This is a shorthand provided by the assembler. Both are always there in
machine language.)
Examples:
ld [%L1+%L2], %L3 !word at address [%L1+%L2]->%L3
ld [%L1+8],%L2 !word at address [%L1+8]->%L2
ld [%L1],%L2 !word at address [%L1]->%L2
st %g0,[%i2+0] !0 -> word at address in %i2
st %g0,[%i2] !same as above
Examples:
call printf
be Loop
324
Chapter 16: Sun Sparc Microprocessor
That's it. Period. No other modes or combinations of modes are possible. This is a
RISC machine and R stands for "Reduced".
x All 32 bits of the register are always affected by a load. If a shorter data item
is loaded, it is padded by either adding zeroes (for unsigned data), or by sign
extension (for signed data).
325
MICROPROCESSOR ARCHITECTURE
Examples:
add %L1,%L2,%L3 ;add %L1+%L2 -> %L3
subcc %L4,10,%G0 ;sub %L4-10, set cc, discard result
or %o3,0xFF,%o3 ;set lowest 8 bits of %o3 to 1's
xnor %L6,%G0,%L6 ;complement %L6 (same as NOT in 680x0)
call printf
326
Chapter 16: Sun Sparc Microprocessor
16.5 Summary
16.7 Questions
327
MICROPROCESSOR ARCHITECTURE
x http://datasheets.chipdb.org/Intel/x86/Pentium%20II/SpecUpdate/24333745
.pdf
x https://en.wikipedia.org/wiki/Pentium_II
x https://www.lpthe.jussieu.fr/~talon/pentiumII.pdf
x https://eun.github.io/Intel-Pentium-Instruction-Set-
Reference/data/index.html
x https://www.pdfdrive.com/computer-system-architecture-morris-mano-
third-edition-e51589001.html
x https://www.pdfdrive.com/microprocessor-architecture-programming-and-
applications-with-the-8085-d176171206.html
328