Microprocessor 4th Sem
Microprocessor 4th Sem
10CS45
MICROPROCESSORS
(Common to CSE & ISE)
SYLLABUS
I.A. Marks: 25
Hours/Week: 05
Exam Hours: 03
Total Hours: 52
PART A
UNIT 1
gr
ou
p.
c
om
[7 Hours]
Introduction, Microprocessor Architecture 1: A Historical Background, the MicroprocessorBased Personal Computer Systems. The Microprocessor and its Architecture: Internal
ud
en
ts
[7 Hours]
[6 Hours]
ity
st
UNIT 3
.c
UNIT - 4
[ 6 Hours ]
Programming 2: Arithmetic and Logic Instructions (continued): BCD and ASCII Arithmetic,
Basic Logic Instructions, Shift and Rotate, String Comparisons. Program Control Instructions:
The Jump Group, Controlling the Flow of the Program, Procedures, Introduction to Interrupts,
Machine Control and Miscellaneous Instructions.
Page 1
MICROPROCESSORS
10CS45
PART B
UNIT - 5
[6 Hours ]
Using the Keyboard and Video Display, Data Conversions, Example Programs.
[7 Hours ]
gr
ou
p.
c
UNIT - 6
om
with C/C++ for 16-Bit DOS Applications and 32-Bit Applications Modular Programming,
Hardware Specifications, Memory Interface 1: Pin-Outs and the Pin Functions, Clock
Generator, Bus Buffering and Latching, Bus Timings, Ready and Wait State, Minimum versus
Maximum Mode. Memory Interfacing: Memory Devices
UNIT 7
[ 6 Hours ]
ud
en
ts
8088 Memory Interface, 8086 Memory Interface. Basic I/O Interface: Introduction to I/O
Interface, I/O Port Address Decoding.
UNIT 8
[7 Hours ]
I/O Interface 2, Interrupts, and DMA: I/O Interface (continued): The Programmable
Peripheral Interface 82C55, Programmable Interval Timer 8254. Interrupts: Basic Interrupt
ity
st
Processing, Hardware Interrupts: INTR and INTA/; Direct Memory Access: Basic DMA
Operation and Definition.
.c
TEXT BOOK:
1. Barry B Brey: The Intel Microprocessors, 8th Edition, Pearson Education, 2009. (Listed topics only
REFERENCE BOOKS:
1. Douglas V. Hall: Microprocessors and Interfacing, Revised Edition, TMH, 2006.
2. K. Udaya Kumar & B.S. Umashankar : Advanced Microprocessors & IBM-PC Assembly
Language Programming, TMH 2003.
3. James L. Antonakos: The Intel Microprocessor Family: Hardware and Software Principles and
Applications, Cengage Learning, 2007.
Page 2
MICROPROCESSORS
10CS45
TABLE OF CONTENTS
Introduction, Microprocessor
UNIT - 1
1.3
1.4
1.6
1.7
Introduction to
Protected Mode Memory Addressing
Memory Paging
2.2
2.3
2.4
2.5
ity
st
2.7
.c
Practice of examples
w
w
3.2
3.3
Programming 1
3.4
3.5
3.6
33-58
2.6
UNIT-3
3.1
06-32
UNIT - 2
2.1
ud
en
ts
1.5
Internal Microprocessor
Architecture
Real Mode Memory Addressing.
gr
ou
p.
c
1.1
1.2
Page No.
om
Architecture-I.
59-97
Page 3
MICROPROCESSORS
10CS45
Programming 2:
UNIT 4 :
4.1
4.2
4.3
4.4
gr
ou
p.
c
4.6
UNIT 5
98-116
4.5
Programming 3:
Combining Assembly Language with C/C++
5.2
5.3
5.4
5.5
ud
en
ts
5.1
5.6
ity
st
6.1
6.6
124-144
6.7
Clock Generator
Bus Buffering and Latching
Bus Timings
.c
6.5
117-123
UNIT - 6
6.2
6.3
6.4
om
UNIT - 7
Page 4
MICROPROCESSORS
10CS45
7.1
7.2
7.3
7.4
7.5
7.6
practice
gr
ou
p.
c
UNIT - 8
om
145-159
8.1
/O Interface (continued):
8.2
8.3
8.4
ud
en
ts
8.5
160-175
8.7
.c
ity
st
8.6
Page 5
MICROPROCESSORS
10CS45
UNIT 1
om
and the intended purposes of the processor. The complexity of an integrated circuit is bounded
by physical limitations of the number of transistors that can be put onto one chip, the number of
gr
ou
p.
c
package terminations that can connect the processor to other parts of the system, the number of
interconnections it is possible to make on the chip, and the heat that the chip can dissipate.
Advancing technology makes more complex and powerful chips feasible to manufacture.
ud
en
ts
status register, which indicate the results of the last operation (zero value, negative number,
overflow. or others). The logic section retrieves instruction operation codes from memory, and
initiates whatever sequence of operations of the ALU required to carry out the instruction. A
single operation code might affect many individual data paths, registers, and other elements of
the processor.
ity
st
.c
registers speeded up programs, and complex instructions could be used to make more compact
programs. Floating-point arithmetic, for example, was often not available on 8-bit
microprocessors, but had to be carried out in software. Integration of the floating point unit first
as a separate integrated circuit and then as part of the same microprocessor chip, speeded up
slice approach necessary. Instead of processing all of a long word on one integrated circuit,
multiple circuits in parallel processed subsets of each data word. While this required extra logic
Dept of CSE, SJBIT
Page 6
MICROPROCESSORS
10CS45
to handle, for example, carry and overflow within each slice, the result was a system that could
handle, say, 32-bit words using integrated circuits with a capacity for only 4 bits each.
With the ability to put large numbers of transistors on one chip, it becomes feasible to
om
integrate memory on the same die as the processor. This CPU cache has the advantage of faster
access than off-chip memory, and increases the processing speed of the system for many
applications. Generally, processor speed has increased more rapidly than external memory
memory.
gr
ou
p.
c
speed, so cache memory is necessary if the processor is not to be delayed by slower external
The CPU ("central processing unit," synonymous with "microprocessor," or even simply
ud
en
ts
Choosing the correct processor is vital to the success of your homebuilt computer project.
Here's a little background about the history of microprocessors.
ity
st
In historical background, our aim is to study about the events that led to the
development of microprocessors especially the modern microprocessors, namely, 80x86,
Pentium, Pentium pro, Pentium 3 and the Pentium 4. The historical background can be studied
in three different accounts:
.c
1.1.1 The Mechanical Age: The idea for a system that can compute (calculate) has been
around for a long time, even before the modern electrical and electronic devices came into
existence.
Page 7
10CS45
gr
ou
p.
c
om
MICROPROCESSORS
ABACUS- the Babylonians invented the abacus sometime during 500 BC. The abacus is the
oldest known mechanical calculator. The working mechanism of abacus is quite simple, it used
strings of beads to perform calculations. The abacus was not improved until 1642 when a
mathematician named Blaise Pascal invented a calculator that was constructed of gears and
wheels. Each gear contained 10 teeth that after one complete revolution advanced a second gear
ud
en
ts
one place. The first practical, geared mechanical machines that could automatically compute
information arrived in the 1800's. This was much before humans knew anything about
.c
ity
st
ANALYTICAL
ENGINE-
In
1823
The
Royal
Astronomical
Society
of
This machine was supposed to generate navigational tables for the Royal Navy. Charles
Babbage was aided by Augusta Ada Byron , the countess of Lovelace. Charles Babbage named
this machine 'Analytical Engine'. The Analytical Engine which he conceived had the following
features- it could store 1000 20 digit decimal numbers and a variable program that could
modify the function of this engine. The input to the analytical engine was through punched
Dept of CSE, SJBIT
Page 8
MICROPROCESSORS
10CS45
cards, Charles Babbage borrowed the idea of punched cards from Joseph Jacquard, who used it
to program the weaving machine he invented in 1801. After many years of work, Charles
Babbage realised that it's not possible to make the analytical engine as the machinists of his era
where unable to produce the parts needed for his work. (Picture- Analytical Engine).
om
gr
ou
p.
c
developed by Blaise Pascal. These electrically driven mechanical calculators where common
office equipment until the early 1970's when small handheld calculators began to appear, first
ud
en
ts
introduced by Bomar.
In 1889 Herman Hollerith developed a punched card for storing data, he also made a
mechanical calculator driven by the electric motors. His machine counted, sorted and
ity
st
collated(to arrange in proper sequence) the data stored in the punched card. The United States
governmnet commissioned Herman Hollerith to use his punched card system to store and
tabulate information for the 1890 census. In 1896 Herman Hollerith started a company called
.c
the Tabulating Machine Company which developed machines that used punched cards for
tabulation. After a number of merges, this Tabulating Machine Company was formed into the
International Business Machines Corporations now known as the IBM. (Picture- Tabulating
The first electronic calculating machine , something which did not require an electric
motor was developed by the German Inventor named Konrad Zuse. His Z3 calculating
computer where used in aircraft and missile design during World War 2.
Page 9
om
MICROPROCESSORS
gr
ou
p.
c
German Military codes. This electronic computer was invented by Allan Turing. It used
vacuum tubes to perform calculations. He called this electronic computer Colossus. Colossus
was successful in breaking down the secret German military codes generated by the Enigma
machine. The disadvantage with Colossus was that it was not programmable. Colossus was a
fixed program computer system ,which we call today as a special purpose computer. (Picture-
ity
st
ud
en
ts
.c
The first general purpose, programmable electronic computer was developed in 1946 at
the University of Pennsylvania. This first modern computer was called the ENIAC (Electronic
Numerical Integrator and Calculator). The ENIAC was a huge machine weighing more than 30
tons and used 17000 vacuum tubes and 500 miles of wires. The ENIAC could perform only
100,000 operations per second. The ENIAC was programmed by rewiring it's circuits. The
ENIAC thrust us into the age of computers. (Picture- ENIAC).
Page 10
10CS45
om
the development of digital integrated circuits in the 1960's and finally the development of
gr
ou
p.
c
ud
en
ts
bit wide memory locations. (Bit is either a 0 or 1 , 4-bit wide memory location can also be
called a nibble). The Intel 4004 instruction set contained only 45 instructions. It was fabricated
with the then current state of the art P-channel MOSFET technology. Hence it could only
.c
ity
st
The 4004 microprocessor was readily accepted by the people ,as a result applications
abounded for this device. It was mainly used in early video games and small microprocessor
based applications. The main problems with the early microprocessors where their speed, word
width and memory size. Intel later released the 4040 microprocessor, this was just an update to
the 4004 with improved speed but it did not have any improvement in word width or memory
size. Other companies, particularly Texas instruments also produced 4-bit microprocessors
(TMS 1000) at this time. The 4-bit microprocessors still survives today in low end applications
like microwave ovens and small control systems.
Dept of CSE, SJBIT
Page 11
10CS45
In 1971, Intel developed the 8008 microprocessor, an extended 8-bit version of the 4004
microprocessor. This addressed an expanded memory size (16 K bytes) and also had additional
instructions (48 in total) which enabled it's use in more advanced systems. (byte is an 8-bit wide
binary number and K is 1024) .
om
As engineers demanded more from 8008, it's slow speed , small memory size and
instruction set limited it's use. As an welcoming answer to these demands, Intel developed the
gr
ou
p.
c
8080 microprocessor, the first modern 8-bit microprocessor in 1973. The 8080 addressed an
expanded memory of 64 K bytes which is four times more than the 8008. The 8080 also could
execute instructions 10 times faster than the 8008. An addition instruction which took 20
microseconds(50,000 instructions per second) in 8008 took only 2 microseconds(500,000
instructions per second) in 8080. It also had additional instructions. The 8080 was compatible
with TTL (Transistor-Transistor logic) hence it made it's interfacing easier.
ud
en
ts
The introduction of microprocessors had a huge impact in the way we use computers.
Computers that once took large areas where reduced to the size of small desktops. Although
these desktop computers are small and compact, they possess computing power more than that
of
the
large
size
computers
of
the
previous
generation.
ity
st
Here, in this section, we are going to learn about the structure of a microprocessor based
personal computer system. The block diagram of a personal computer system is shown in the
figure.
This block diagram also applies to any computer system, from the early mainframe computers
.c
to the modern microprocessor based systems. The block diagram consists of three main blocks,
Page 12
gr
ou
p.
c
om
MICROPROCESSORS
ud
en
ts
The memory structure of all Intel 80x86 to Pentium 4 based personal computer systems are similar. This
ity
st
includes the first computers based on 8088 introduced in 1981 by IBM to the most modern computers
based on Pentium 4. The memory structure of microprocessor based computer systems can be divided
into three main regions. These are
.c
Page 13
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
ity
st
It should be noted that the Extended memory system is not available in those computers
based on 8086 or 8088. In these old computers the TPA and System area exists but not the
Extended memory system. The TPA is of size 640 Kb and System area is of size 384Kb. The
.c
TPA and System area together forms the real or conventional memory which is of size 1024Kb
or 1 Mb. It's called as real or conventional memory because each Intel microprocessor is
Pentium 4, has the 640 Kb of TPA and 384 Kb of system area, In addition , these systems also
have an Extended memory. Hence IBM designates these systems as AT class machines (ATAdvanced class computer systems). These systems are also called as ISA (Industry standard
architecture)
or
EISA
(Extended
ISA).
Page 14
10CS45
The extended memory available in the computer systems using the 80286- 80386SX
microprocessors is 15Mb. While the amount of extended memory available in the computer
systems using 80386DX - Pentium microprocessors are 4095Mb, excluding the 1Mb real or
conventional memory. The Computer systems having Pentium pro - Pentium 4 microprocessors
on
Pentium
systems
have
an
extended
memory
more
than
180Gb.)
gr
ou
p.
c
based
om
can have 1Mb less than 4Gb to 64GB extended memory. (Note- Modern day computer systems
Recently, a new bus known as the Peripheral Component Interconnect (PCI) bus has been
introduced in the Pentium- Pentium 4 based systems. The older computers based on 8086/8088
used an 8 bit peripheral bus to interface with 8 bit devices. The ISA machines or AT class
machines which used 80286 or above microprocessors used 16 bit peripheral bus for interface.
The EISA machines that used 80386DX and 80486 microprocessors used 32 bit peripheral bus
for interface. All the new buses were compatible with the
ud
en
ts
interface card is compatible with an 8-bit bus , 16-bit bus or a 32 bit bus. Similarly a 16 bit
interface card is compatible with a 16 bit bus and 32 bit bus.
Another bus type found in the 80486 based computer systems is the VESA local bus or VT bus.
This local bus helps to interface disk and video to the microprocessor. Two new buses have
also been introduced, one is the USB or Universal Serial Bus and the other is the AGP (
ity
st
Advanced graphics port)- The Advanced graphics port transfers data between the video card
and the microprocessor at very high speeds.
The Transient Program area (TPA)
The transient program area or TPA holds the DOS operating system and other programs that control the
.c
computer system. The TPA also holds other active or inactive application programs. We know that the
TPA is 640Kb and since it holds DOS on it a part of this 640 Kb is used up by DOS operating system. The
size of the TPA available for other application programs is 628Kb if MS-DOS version 7.X is used as the
operating system. The older versions of DOS used to take up large spaces of TPA leaving only less than
530Kb for other applications. PC-DOS is another operating system that is found in computer systems.
Both PC-DOS and MS-DOS are compatible with each other, hence both functioned similarly with
application programs. Windows and OS/2 are other operating systems compatible with DOS and allows
DOS programs to execute.
Page 15
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
.c
areas of the TPA are allotted to the system programs, data and drivers. To the left of each area
is a hexadecimal number that shows the memory address that begin and end each data area.
1. Interrupt Vectors - The interrupt vectors which occupy the area between 00000 and 00400
is responsible for accessing various features of the DOS, BIOS and other application programs.
2. BIOS communication area and DOS communication area - BIOS is nothing but Basic
Input/Output System. BIOS is a collection of programs that is stored in the ROM or flash
memory that is used to control the Input/Output devices that is connected to the computer
system. The BIOS and DOS communication areas have transient data that can be used by
programs
to
access
the
I/O
devices
or
other
parts
of
the
computer
system.
Page 16
10CS45
3. IO.SYS - The IO.SYS is a program that loads into the TPA from the disk when the computer
system using MSDOS or PCDOS are switched ON. The programs in the IO.SYS enables the
DOS programs to use the keyboard, the display, printer and other I/O devices.
4. MSDOS - MSDOS occupies two parts of the TPA. One is at the top of TPA which is
om
considerably small and 16 bytes in length. The other is at the bottom and is larger. The memory
size occupied by the DOS depends on the version of the DOS installed. Older versions usually
larger
areas
of
TPA
compared
to
the
newer
versions.
gr
ou
p.
c
needed
5. Device Drivers- Drivers are those files with an extension .SYS such as MOUSE.SYS.
Drivers are programs that control the installable devices like mouse, hand scanner and also
other installable application programs. The size of the driver and the number of drivers vary
from
one
computer
to
the
another.
as
they
are
typed
ud
en
ts
DOS
from
the
keyboard.
7. Free TPA- The free TPA holds the active DOS application programs. These DOS
application programs can be exemplified as the word processor , spreadsheet and CAD
programs. In addition to these, free TPA also holds the TSR (Terminate and Stay Resident)
programs. These remain in the free TPA in an inactive state until initiated by a hot-key or an
interrupt. An example of TSR is the calculator program that is activated upon the ALT+C
ity
st
hotkey.
SYSTEM AREA
.c
The System area which is smaller than the TPA is considerably important. It contains programs
for data storage and these programs are stored in ROM or flash memory and also in some areas
Page 17
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
ity
st
On the left side memory addresses of the particular regions are given in hexadecimal
format. The first area of the system space extends from A0000H to C7FFFH and has the video
display RAM and video control programs. The Video display RAM is stored in two parts, first
.c
from A0000H to A7FFFH and is for the graphical data, second from B0000H to B7FFFH and
stores the text data. The video BIOS contains programs that control the video display of the
computer and is located on ROM or falsh memory. It's area in system space is from C0000H to
C7FFFH. The size and amount of the memory used depends upon the type of video display
adapter used.
The area C8000H - DFFFFH is free system area and is called the open system area. It is mostly
used as the extended memory system in PC and XT machines ( PC and XT machines means
those computers based on 8086/8088 microprocessor) and as an upper memory system in AT
class machines (Computers using 80286 or above microprocessors).
Memory locations E0000H-EFFFFH contains the cassette BASIC language on ROM found in
Dept of CSE, SJBIT
Page 18
10CS45
the older IBM based systems. In almost all the newer systems this particular area is kept open
or free and is also used as RAM to aid the faster operation of DOS application programs.
The system area F0000H to FFFFFH is used by the System BIOS ROM, but this System BIOS
ROM only operates the I/O devices and is not responsible for the controlling of the video
om
display system which is done by the separate system BIOS ROM at the location C0000H. The
system BIOS at the top is divided into two parts, first part is in the area F0000H to F7FFFH and
gr
ou
p.
c
contains programs that set up the computer. The second part contains procedures that control
the I/O devices.
MICROPROCESSOR
Microprocessor can be called as the heart of the microprocessor based personal computer
system. The microprocessor is also known by the names CPU or Central Processing Unit and
ud
en
ts
controls the working of the computer system. The microprocessor connects to the memory and
The microprocessor follows three simple steps in its working1. Transfers data from memory to itself or to the I/O devices.
2. Performs arithmetic and logical calculations.
ity
st
Even though these processes are simple, the microprocessor is able to solve all types of
problems using this approach. The strength of the microprocessor lies in its ability to execute
.c
millions of instructions per second from the software or programs. Software and programs are
nothing but a collection of instructions. These software or program is stored in the memory.
This stored program concept makes the microprocessor or in the main, a computer system itself
efficient.
very
1.
2.
3.
4.
5.
6.
Addition
Subtraction
Multiplication
Division
AND
OR
Dept of CSE, SJBIT
Page 19
10CS45
7. NOT
8. NEG
9. Shift
10. Rotate
gr
ou
p.
c
om
Data is stored in the memory or the internal registers. The width of the data is either a byte (8bits), word (16-bits) or a double word (32-bits). Only the 80386 and above versions are able to
execute all three. 8086 to 80286 could directly manipulate 8-bit and 16-bit data but not 32-bit
data.
A Co-processor called the numeric processor is with the 80486 to aid in arithmetic calculations
dealing with floating point arithmetic. This numerical processor was an additional component
in the older 8086- 80386 processors.
The Microprocessor Called the CPU (central processing unit).The controlling element in a
computer system. The controlling element in a computer system. Controls memory and I/O
ud
en
ts
* buses select an I/O or memory device, transfer data between I/O devices or memory and the
microprocessor control I/O and memory systems microprocessor, control I/O and memory
systems
* Memory and I/O controlled via instructions stored in memory, executed by the stored in
memory, executed by the microprocessor.
ity
st
.c
second from a program or instructions per second from a program or software (group of
instructions) stored in the memory system.
stored programs make the microprocessor and computer system very powerful devices.
Another powerful feature is the ability to make simple decisions based upon numerical
a microprocessor can decide if a number is zero, positive and so forth positive, and so forth
These decisions allow the microprocessor to modify the program flow so programs to modify
the program flow, so programs appear to think through these simple decisions.
Page 20
10CS45
ud
en
ts
gr
ou
p.
c
om
ity
st
Data registers- The registers AX, BX, CX and DX are called as the data registers. They are 16
bits wide and can store both the operands and the results. Each of the data registers can either
be accessed as a whole or the higher byte and the lower byte can be accessed separately.
Example- The whole 16 bits in the register AX can be used together or the higher byte and
.c
lower byte can be accessed separately as AH and AL. The registers BX, CX and DX also are
used
CX
is
used
BX
DX
is
used
as
as
to
hold
a
an
the
base
implied
I/O
register
in
counter
address
during
by
address
calculations.
some
instructions.
some
I/O
operations.
Pointer and Index registers- The pointer and index group include the SP, BP, SI, DI and IP.
The SP and IP are essentially the stack pointer and instruction pointer. The instruction pointer is
also called as the program counter. The complete stack and instruction address is formed by
Dept of CSE, SJBIT
Page 21
10CS45
adding the contents of the SP and IP with the contents in CS and SS. BP or base pointer is used
to address the beginning of a stack. It is used in combination with other registers and/or with a
displacement. SI and DI are the index registers, they are used in combination with the BX or
BP and/or a displacement. The SP and BP can be used to store the operands but not the IP.
om
Formation of Effective address (EA)- The data address formed by adding together, a
an
effective
address
or
offset.
gr
ou
p.
c
called
Displacement- The word displacement is used to indicate any quantity that is added to the
register
contents
to
form
an
effective
address.
Segment registers- The segment registers are CS, SS, DS and ES. The registers that are used
for addressing, SP, BP, SI, DI and IP are 16-bits wide and hence the effective address or offset
ity
st
ud
en
ts
will be 16 bits wide but the address that is required on the address bus called the physical
.c
Formation of physical address- We have seen that the address required on the address bus is 20
bits wide but a problem persists as the effective address formed is only 16 bits wide. Hence the
formation of the physical address requires the addition of the contents of the effective address
with the contents of any of the segment registers. To generate the extra 4 bits , we have to
append four 0 bits to the right most digit of the number in the segment register. Example if CS
= 123A and IP = 341B , the physical address formed by the addition of these two will be
341B+
Page 22
gr
ou
p.
c
om
MICROPROCESSORS
Overlapping segments- The use of segment registers divides the memory space into
overlapping segments with each segment being 64 Kb wide and beginning at a memory
that
is
divisible
by
16.
ud
en
ts
location
ity
st
1. It allows the memory capacity to be 1Mb even though the individual instructions are only 16
bits wide.
2. It allows the instruction, data and stack portion to be 64Kb wide by facilitating the use of more
.c
3. Facilitates the program, data and stack to have separate memory portions.
4. Allows the program and its data to be stored in separate parts of memory while execution of the
program is performed.
8086 PSW
The 8086 PSW is 16 bits, but only 9 of its bits are used. Each bit of 8086 PSW is called a flag.
The flags are divided into two groups, these are conditional flags and control flags. The
Dept of CSE, SJBIT
Page 23
10CS45
conditional flags reflect the condition involving a previous instruction execution. The control
flags controls the functioning of certain instructions.
om
Conditional Flags
1. SF (Sign flag)- It is equal to MSB of the result. In 2's compliment a 1 in the MSB shows that
the result is a negative number and a 0 in the MSB shows that the result is a non-negative
gr
ou
p.
c
number. Hence the sign flag is used to determine whether the result is positive or negative.
2. ZF (Zero flag) - 1 in the zero flag shows that the result is zero and a 0 in the zero flag shows
that the result is a non-zero number.
3. PF (Parity flag) - The PF will become 1 if there are even number of one's in the lower 8-bits of
the PSW.
4. CF (Carry flag) - There are two cases here involving addition and subtraction. In addition a
ud
en
ts
carry out of the MSB causes this flag to be set. In subtraction if the MSB borrows then this flag
is set.
5. AF (Auxillary carry flag)- In addition the carry out of a bit 3 causes this flag to be set. In
subtraction a borrow by bit 3 causes this flah to be set.
6. OF (Overflow flag)- The overflow flag is set when the result is out of range. More specifically,
in addition, if there is a carry into the MSB and the MSB has no carry out and in addition, if the
.c
ity
st
Control flags-
1. DF (Direction flags)- Used by string manipulation instructions. If clear, the string is processed
from the beginning, starting with the first element with the lower address If set, the string is
processed from the higher address to the lower most address.
2. IF (Interrupt enable flag)- If enabled it helps the CPU to recognize the maskable interrupt else
these interrupts are ignored.
Dept of CSE, SJBIT
Page 24
10CS45
Buses
om
A common group of wires that interconnect components in a computer, Transfer address, data,
& control information between microprocessor memory and I/O between microprocessor,
memory and I/O.
gr
ou
p.
c
Three buses exist for this transfer of information: address, data, and control.
Figure 110 shows how these buses interconnect various system components.
The address bus requests a memory location from the memory or an I/O location from the I/O
from the memory or an I/O location from the I/O devices
ud
en
ts
if I/O is addressed, the address bus contains a 16-bit I/O address from 0000H through
FFFFH.
if memory is addressed the bus contains a memory if memory is addressed, the bus contains
a memory address, varying in width by type of microprocessor.
64-bit extensions to Pentium provide 40 address pins allowing up to 1T byte of memory to be
pins, allowing up to 1T byte of memory to be devices.
ity
st
accessed.
The data bus transfers information between the microprocessor and its memory and I/O address
microprocessor and its memory and I/O address space.
Data transfers vary in size, from 8 bits wide to 64 bits wide in various Intel microprocessors.
.c
8088 has an 8-bit data bus that transfers 8 bits of data at a time
8086 80286 80386SL 80386SX d 80386EX f 8086, 80286, 80386SL, 80386SX, and
80386EX transfer 16 bits of data 80386DX 80486SX d 80486DX 32 bit 80386DX, 80486SX,
Page 25
10CS45
Control bus lines select and cause memory or I/O to perform a read or write operation to
perform a read or write operation. In most computer systems, there are four control bus
connections:
MRDC (memory read control)
om
gr
ou
p.
c
Over bar indicates the control signal is active low; over bar indicates the control signal is
active-low;(active when logic zero appears on control line)
The microprocessor reads a memory location by sending the memory an address through the
sending the memory an address through the address bus.
Next, it sends a memory read control signal to cause the memory to read data.
Data read from memory are passed to the microprocessor through the data bus.
ud
en
ts
Whenever a memory write, I/O write, or I/O read occurs, the same sequence ensues.
registers are used during programming and are specified by the instructions
80286 and above contain program-invisible registers to control and operate protected memory.
8086 through the 80286 are fully upward-compatible to the 80386 through Core2.
.c
ity
st
Page 26
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Figure 111 The programming model of the 8086 through the Core2 microprocessor including
.c
Multipurpose Registers
RAX - a 64-bit register (RAX), a 32-bit register (accumulator) (EAX), a 16-bit register (AX),
adjustment instructions.
Intel plans to expand the address bus to 52 bits to address 4P (peta) bytes of memory.
Page 27
10CS45
BX register (base index) sometimes holds offset address of a location in the memory system in
all versions of the microprocessor
RCX, as RCX, ECX, CX, CH, or CL.
a (count) general-purpose register that also holds the count for various instructions
holds
part
of
the
result
points
to
from
multiplication
gr
ou
p.
c
om
memory
(base
pointer)
location
often addresses (destination index) string destination data for the string instructions
the (source index) register addresses source string data for the string instructions
like
RDI,
RSI
purpose register
ud
en
ts
also
functions
as
R8 - R15 found in the Pentium 4 and Core2 if 64-bit extensions are enabled.
data
are
addressed
as
64-,
32-,
16-,
general-
or
8-bit
ity
st
Most applications will not use these registers until 64-bit processors are common.
bits
to
15
are
not
directly
addressable
as
.c
a byte
Special-Purpose Registers
Include RIP, RSP, and RFLAGS
RSP
addresses
an
area
of
memory
called
the stack.
Page 28
10CS45
RFLAGS indicate the condition of the microprocessor and control its operation.
The rightmost five and the overflow flag are changed by most arithmetic and logic operations.
gr
ou
p.
c
om
microprocessor family.
ud
en
ts
Figure 1.12 The EFLAG and FLAG register counts for the entire 8086 and Pentium
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.
P (parity) is the count of ones in a number expressed as even or odd. Logic 0 for odd parity;
ity
st
P (parity) is the count of ones in a number expressed as even or odd. Logic 0 for odd parity;
.c
if a number contains three binary one bits, it has odd parity; If a number contains no one bits, it
has even parity
Page 29
10CS45
A (auxiliary carry) holds the carry (half-carry) after addition or the borrow after subtraction
between bit positions 3 and 4 of the result.
Z (zero)
S (sign) flag holds the arithmetic sign of the result after an arithmetic or logic instruction
executes.
T (trap)
D (direction)
O (overflow)
an
overflow
indicates
IOPL
used
in
RF (resume)
protected
has
mode
exceeded
operation
flag indicates the current task is nested within another task in protected
mode operation.
result
ud
en
ts
the
gr
ou
p.
c
om
instruction.
VM (virtual mode) flag bit selects virtual mode operation in a protected mode system.
AC, (alignment check) flag bit activates if a word or doubleword is addressed on a non-word or
ity
st
non-doubleword boundary.
VIF is a copy of the interrupt flag bit available to the Pentium 4(virtual interrupt)
VIP (virtual) provides information about a virtual mode interrupt for (interrupt pending)
.c
Pentium.
ID (identification)
instruction.
CPUID instruction provides the system with information about the Pentium microprocessor
Segment Registers
Generate memory addresses when combined with other registers in the microprocessor.
Following is a list of each segment register, along with its function in the system.
Dept of CSE, SJBIT
Page 30
10CS45
CS (code) segment holds code (programs and procedures) used by the microprocessor.
Data are accessed by an offset address or contents of other registers that hold the offset address
ES (extra) an additional data segment used by some instructions to hold destination data.
stack entry point is determined by the stack segment and stack pointer registers
the
register
also
allow
two
additional
access by programs
data
within
addresses
gr
ou
p.
c
BP
om
memory
segments
for
Windows uses these segments for internal operations, but no definition of their usage
ud
en
ts
is available.
Pentium 4 comes up in the real-mode after it is reset. It will remain in this mode
ity
st
.c
In addition, a number of new instructions (called extended instruction set) have been
added to enhance its performance and functionality (such new instructions can be run in the
real-mode as well as the protected-mode). In real-mode, only the first 1 M bytes of memory
can be addressed with the typical segment:offset logical address. Each segment is 64K bytes
long.
Notice that the Pentium 4 microprocessor has 36 bit address bus, which means it can
support up to 236 = 64G bytes of total memory (which cannot be addressed in real-mode but
can be addressed in protected mode).
Page 31
10CS45
Strictly converting one address value into a physically meaningful location in the RAM.
strictly converting two address values into a physically meaningful memory location.
gives access to one megabyte (1,048,576 bytes) of directly addressable memory, known as real
om
mode memory.
gr
ou
p.
c
a. Segment Registers
Segment registers are basically memory pointers located inside the CPU.
Segment registers point to a place in memory where one of the following things begin:
1. Data storage
2. Code execution.
ity
st
ud
en
ts
.c
o
o
Page 32
ud
en
ts
gr
ou
p.
c
o
o
om
MICROPROCESSORS
o
o
Segmentation often caused grief for programmers who tried to access large data structures:
Since an offset cannot exceed 16 bits, you cannot increment beyond 64k.
Instead, program must watch out for a 64k boundary and then play games with the segment
register.
This nightmare was originally created to support CP/M-80 programs ported from 8080 chip to
8086.
Successful short-term thinking;
Catastrophically bad long-term thinking that resulted in never-ending Windows 9x problems!
ity
st
o
o
.c
Page 33
10CS45
UNIT-2
2.1 PROTECTED-MODE
om
gr
ou
p.
c
In protected mode, the base:offset logical memory addressing scheme (which is used in real
mode) is changed.
The offset part of the logical memory address is still used. However, when in the protected
mode, the processor can work either with 16-bit offsets (the 16-bit instruction mode) or with 32bit offsets (the 32-bit instructionmode). A 32-bit offset allows segments of up to 4G bytes in
length. Notice that in real-mode the only available instruction mode is the 16-bit mode (during
ud
en
ts
However, the segment base address calculation is different in protected mode. Instead of
appending a 0 at the end of the segment register contents to create a segment base address (which
gives a 20-bit physical address), the segment register contains a selector that selects a descriptor
from a descriptor table. The descriptor describes the memory segment's location,length, and
access rights. This is similar to selecting one card from a deck of cards in one's pocket.
ity
st
Because the segment register and offset address still create a logical memory address, protected
mode instructions are the same as real mode instructions. In fact, most programs written to
function in the real mode will function without change in the protected mode.
DESCRIPTORS:
.c
The selector, located in the segment register, selects one of 8192 descriptors from one of two
tables of descriptors (stored in memory): the global and local descriptor tables. The descriptor
describes the location, length and access rights of the memory segment.
Page 34
10CS45
Limit (L19 L0): contains the last offset address found in a segment. Since this field is 20 bits,
the segment size could be anywhere between 1 and 1M bytes. However, if the G bit
(granularity bit) is set, the value of the limit is multiplied by 4K bytes (i.e., appended with
om
FFFH). In this case, the segment size could be anywhere between 4K and 4G bytes in steps of
4K bytes.
gr
ou
p.
c
Example,
Base = Start = 10000000h
Limit = 001FFh and G = 0
ud
en
ts
AV bit: is used by some operating systems to indicate that the segment is available (AV = 1) or
ity
st
D bit: If D = 0, the instructions are 16-bit instructions, compatible with the 8086-80286
microprocessors. This means that the instructions use 16-bit offset addresses and 16-bit registers
.c
by default. This mode is the 16-bit instruction mode or DOS mode. If D = 1, the instructions are
32-bits by default (Windows XP works in this mode). By default, the 32-bit instruction mode
assumes that all offset addresses and all registers are 32 bits. Note that the default for register
size and offset address can be overridden in both the 16- and 32-bit instruction modes using the
66h and 67h prefixes. In 16-bit protected-mode, descriptors are still used but segments are
the direction of growth is specified. If the segment grows beyond its limit, the microprocessor's
operating system program is interrupted, indicating a general protection fault. You can specify
Dept of CSE, SJBIT
Page 35
10CS45
whether a data segment can be written or is write-protected. The code segment can have reading
inhibited to protect software. This is why It is called protected mode. This kind of protection is
gr
ou
p.
c
om
unavailable in realmode.
.
SELECTORS:
ud
en
ts
Descriptors are chosen from the descriptor table by the segment register.
There are two descriptor tables:
Global descriptors table: contains segment definitions that apply to all programs (also called
system descriptors).
Local descriptors table: usually unique to an application (also called application descriptors).
Each descriptor table contains 8192 descriptors, so a total of 16,384 descriptors are available to
ity
st
an application at any time. This allows up to 16,384 memory segments to be described for each
application. The Figure below shows the segment register in the protected mode. It contains:
13-bit selector field: chooses one of the 8192 descriptors from the descriptor table (213 = 8192).
.c
Table indicator (TI) bit: selects either the global descriptor table (TI = 0) or the local descriptor
Requested privilege level (RPL) field: requests the access privilege level of a memory segment.
The highest privilege level is 00 and the lowest is 11.If the requested privilege level matches or
is higher in priority than the privilege level set by the access rights byte, access is granted.
Windows uses privilege level 00 (ring 0) for the kernel and driver programs and level 11 (ring 3)
for applications. Windows does not use levels 01 or 10. If privilege levels are violated, the
system normally indicates a privilege level violation.
Page 36
gr
ou
p.
c
om
MICROPROCESSORS
Example:
Real Mode: DS = 0008h, then the data segment begins at location 00080h and its length is 64K
ud
en
ts
bytes.
Protected Mode: DS = 0008h = 0000 0000 0000 1000, then the selector selects Descriptor 1 in
the global descriptor table using a requested privilege level of 00. The global descriptor table is
.c
ity
st
Page 37
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Descriptor number 1 contains a descriptor that defines the base address as 00100000h with a
segment limit of 000FFh. This refers to memory locations 00100000h 001000FFh for the data
segment.
The global and local descriptor tables are found in the memory system. In order to specify the
address of these tables, Pentium 4 contains program invisible registers LDTR and GDTR (these
registers are not directly addressed by software).
Dept of CSE, SJBIT
Page 38
10CS45
The GDTR (global descriptor table register), LDTR (local descriptor table register) and IDTR
(interrupt descriptor table register) contain the base address of the descriptor table and its limit.
The limit of these descriptor tables is 16 bits because the maximum table length is 64K bytes
om
(but of course, the table could be smaller than 64K byte, hence the need for the limit).
Before using the protected mode, the interrupt descriptor table, global descriptor table along with
gr
ou
p.
c
the corresponding registers IDTR and GDTR must be initialized. This is why the Pentium 4
boots in the real mode not protected mode, and why the maximum descriptor table size is 64K
.c
ity
st
ud
en
ts
bytes.
Each of the segment registers also contains a program-invisible portion used as a cache to store
the corresponding 8 byte descriptor to avoid repeatedly accessing memory every time the
segment register is referenced (hence the term cache).
These program-invisible registers are loaded with the base address, limit, and access rights each
Dept of CSE, SJBIT
Page 39
10CS45
om
levels. The task register allows a context or task switch in multitasking systems in about 17s.
Notice: The memory system for the Pentium 4 is 4G bytes in size, but access to the area
gr
ou
p.
c
between 4G and 64G is enabled with bit position 4 of the control register CR4 and is accessible
only when 4M paging is enabled. When in this paging mode, address lines A35 A32 are
enabled with a special new addressing mode, controlled by other bits in CR4.
Paging is enabled when the PG bit in control register CR0 is set. The paging mechanism can
function in both the real and protected modes.
ud
en
ts
When paging is enabled, physical memory is divided into small blocks (typically 4K bytes or
4M bytes) in size, and each block is assigned a page number. The operating system keeps a list
of free pages in its memory. When a program makes a request for memory, the OS allocates a
number of pages to the program.
A key advantage to memory paging is that memory allocated to a program does not have to be
ity
st
contiguous, and because of that, there is very little internal fragmentation - thus little memory is
wasted.
.c
the most significant 20 bits of the linear address indicate the linear page number, while the
least significant 12 bits of the linear address indicate the offset within this page. The offset
should remain the same but the linear page number has to be converted into a physical page
number.
Page 40
gr
ou
p.
c
om
MICROPROCESSORS
Each page directory entry is a physical address pointing to a page table, which contains page
table entries. Each page table contains 1024 page table entries, each of which is 4 bytes (32
bits). This means that each page table is 4 K bytes long.
Each page table entry points to the starting physical address of a page in memory (i.e., the
physical page number).
ud
en
ts
This means that if we have one page directory and 1024 page tables, then we have a total of 1M
table entries or 1 M pages. Since each page is 4K bytes long, this will cover a total of 4G bytes
of maximum physical memory.
The figure below Part (a) shows the linear address (generated by the software) and how it selects
one of the 1024 page directory entries from the page directory (using the left most 10 bits) and
ity
st
then selects one of the 1024 page table entries (using the next 10 bits). Part (b) of the figure
shows the page table entry, which contains the physical number that must be associated with the
offset.
For example, the linear addresses 00000000h-00000FFFh access the first page directory entry,
.c
and the first page table entry. Notice that one page is a 4K-byte address range. So, if that page
table entry contains 00100000h, then the physical address of this page is 00100000h-00100FFFh
for linear address 00000000h-00000FFFh. This means that when the program accesses a location
00100000h-00100FFFh.
Page 41
10CS45
For example, the linear addresses 00000000h-00000FFFh access the first page directory entry,
and the first page table entry. Notice that one page is a 4K-byte address range. So, if that page
table entry contains 00100000h, then the physical address of this page is 00100000h-00100FFFh
om
for linear address 00000000h-00000FFFh. This means that when the program accesses a location
between 00100000h and 00100FFFh, the microprocessor physically addresses location
gr
ou
p.
c
00100000h-00100FFFh.
.c
ity
st
ud
en
ts
Page 42
10CS45
Immediate
Register addressing
Addressing mode
(for source
Before
DX ABCDH
After
1234H
Before
After
4DH
23H
.c
ity
st
Memory addressing
ud
en
ts
operand only)
gr
ou
p.
c
om
CH
Page 43
10CS45
CX 1234H
5678H
SI 5678H
5678H
Dl
89H
BCH
AH
BCH
BCH
.c
ity
st
After
ud
en
ts
Before
gr
ou
p.
c
After
om
Before
Page 44
10CS45
Memory Addressing
Indirect Addressing
om
Direct Addressing
Indirect
with
Addressing with
displacement
displacement
Based
Based Indexed
Indexed
addressing with
addressing
displacement
.c
ity
st
ud
en
ts
Register
gr
ou
p.
c
Page 45
10CS45
BX
ABCDH
DS:5634H
45H
DS:5635H
86H
CL
F2H
DS:5634H
45H
DS:5635H
86H
.c
ity
st
LS byte
MS byte
After
ud
en
ts
Before
8645H
Before
45H
After
Program
om
After
gr
ou
p.
c
Before
BH
C5H
78H
.DATA
LOC
DB
78H
Page 46
10CS45
CL
20H
SI
3456H
78H
ud
en
ts
DS:3456H
Before
DX
F232H
BX
A2B2H
After
3567H
DS:A2B2H
67H
LS byte
DS:A2B3H
35H
MS byte
.c
ity
st
78H
om
After
gr
ou
p.
c
Before
Page 47
10CS45
AH
30H
DI
3400H
DS:3400H
86H
86H
om
After
gr
ou
p.
c
Before
Only SI, DI and BX can be used inside [ ] from memory addressing point of view. From user
ud
en
ts
point of view [BP] is also possible. This scheme provides 3 ways of addressing an operand in
.c
ity
st
memory.
Page 48
10CS45
DH
BX
DS:6345H
67H
Before
AX 1000H
After
CDABH
.c
ity
st
67H
4000H
ud
en
ts
45H
gr
ou
p.
c
After
om
Before
Page 49
10CS45
BP
3000H
SS:3045H
ABH
LS byte
It is SS when BP is used
SS:3346H
CDH
MS byte
gr
ou
p.
c
3000 + 45 = 3045H
om
Base register can only be BX or BP. This scheme provides 4 ways of addressing an operand in
memory.
ud
en
ts
Before
ity
st
.c
60H
85H
SI 6000H
DS:8345H
85H
CL
After
After
Before
DX 7000H
B2A2H
Page 50
10CS45
5000H
DS:5037H
A2H
LS byte
DS:5038H
B2H
MS byte
om
DI
gr
ou
p.
c
Index register can only be SI or DI. This scheme provides 4 ways of addressing an operand in
memory.
2.4.7Based Indexed Addressing
ud
en
ts
Before
CL
40H
After
67H
BX
0300H
.c
ity
st
SI 2000H
DS:2300H
67H
Before
CX
6000H
After
6385H
Page 51
10CS45
0020H
gr
ou
p.
c
DI
om
BP 3000H
SS:3020H
85H
LS byte
It is SS when BP is used
SS:3021H
63H
MS byte
This scheme provides 4 ways of addressing an operand in memory. One register must be a Base
ud
en
ts
.c
ity
st
DL
40H
BX
2000H
DI
0050H
After
12H
Before
Page 52
10CS45
DS:2087H
12H
Before
BX
3000H
3665H
gr
ou
p.
c
After
om
SI 4000H
ud
en
ts
BP 0020H
SS:5254H
65H
LS byte
It is SS when BP is used
SS:5255H
36H
MS byte
ity
st
Base
Displace
Register
ment
No
No
Yes
Direct Addressing
No
Yes
No
Register Indirect
Yes
No
No
Yes
No
Yes
.c
Index
Register
Addressing mode
Page 53
10CS45
Displacement
MOV DX, 35H[DI]
No
Yes
Yes
om
displacement
MOV CL, 37H[SI+BX]
Yes
Yes
No
Yes
Yes
Yes
ud
en
ts
gr
ou
p.
c
with displacement
ity
st
IN AL, 83H
Before
AL 34H
After
78H
Ex. 1:
.c
Page 54
10CS45
Before
IN AX, 83H
AX 5634H
F278H
om
Ex. 2:
After
gr
ou
p.
c
Before
OUT 83H, AL
AL 50H
ud
en
ts
Ex. 3:
Before
OUT 83H, AX
After
50H
60H
.c
50H
AX 6050H
ity
st
Ex. 4:
After
IN and OUT instructions are allowed to use only AL or AX registers. Port address in the range
I/O port address is provided in DX register. Port address ranges from 0000 to FFFFH. Data
transfer with AL or AX only.
Page 55
10CS45
Before
IN AL, DX
AL 30H
60H
om
Ex. 1:
After
Before
IN AX, DX
AX 3040H
After
7060H
ud
en
ts
Ex. 2:
gr
ou
p.
c
DX 1234H
DX 4000H
ity
st
OUT DX, AL
Ex. 3:
.c
Before
After
AL 65H
DX 5000H
65H
Page 56
10CS45
Before
OUT DX, AX
AX 4567H
om
Ex. 4:
After
gr
ou
p.
c
DX 5000H
67H
45H
.c
ity
st
ud
en
ts
Page 57
10CS45
Unit - 3
3.1
om
Abbreviations used
gr
ou
p.
c
R=R8/R16
SR=CS/DS/ES/SS
AR=SI/DI/BX/BP
d16=16-bit data
d8=8-bit data
ud
en
ts
M=M8/M16
ity
st
Conventions used:
MOV
.c
R, M
and
MOV
M, R
POP
R16
R16
for PUSH
R16
and
PUSH/POP
for MOV
Page 58
ROR R/M,
1/CL
om
3.1.1
10CS45
ud
en
ts
gr
ou
p.
c
ity
st
Data Transfer group, Arithmetic group, Logical group, Stack group, and I/O group of
instructions explained first. They occupy several chapters in books.
Here, I explain them under:
.c
Branch group, String instructions, and Interrupt instructions are explained later.
Page 59
10CS45
3.2Operand instructions
MOV/XCHG
Data transfer
R
Arithmetic
gr
ou
p.
c
ADD/ADC/SUB/SBB
om
AND/OR/XOR/TEST/CMP
R/M
Logical
ud
en
ts
ity
st
Before
After
DX
1234H
ABCDH
BX
1000H
1234H
DS:1002H
.c
DS:1000H ABCDH
Page 60
10CS45
1234H
BX
1000H
DS:1000H
2000H
3234H
DS:1002H
Before
After
30H
81H
ADC DH ,[SI]
DH
Carry flag
gr
ou
p.
c
DX
ud
en
ts
ADD [BX], DX
After
om
Before
SI 2000H
81H
50H
DS:2001H
60H
ity
st
DS:2000H
.c
After
DH
30H
0BH
CL
25H
SUB DH, CL
Before
0BH =
Page 61
10CS45
After
20H
FAH
DH
Cy flag
CL
25H
gr
ou
p.
c
SBB DH, CL
Before
om
ud
en
ts
23H (+ve)
43H (+ve)
+ 46H (+ve)
+ 54H (+ve)
= 97H (-ve)
V= 0, Cy = 0
ity
st
= 69H (+ve)
V = 1, Cy = 0
Wrong answer
.c
Correct answer
83H (-ve)
F2H (-ve)
+ 94H (-ve)
+ F3H (-ve)
Page 62
= 17H (+ve)
= E5H (-ve)
V= 1, Cy = 1
V = 0, Cy = 1
Wrong answer
Correct answer
F6H (-ve)
- 83H (-ve)
- 43H (+ve)
= 11H (+ve)
= B3H (-ve)
V= 0, Cy = 0
V = 0, Cy = 0
Correct answer
Correct answer
gr
ou
p.
c
94H (-ve)
= 71H (+ve)
V= 1, Cy = 0
- 83H (-ve)
= E3H (-ve)
V = 1, Cy = 1
Wrong answer
ity
st
Wrong answer
66H (+ve)
ud
en
ts
94H (-ve)
- 23H (+ve)
om
MICROPROCESSORS
.c
AND BH, CL
AND
CL
After
56H
06H
0FH
0FH=0000 1111B
BH
Before
06H=0000 0110B
Page 63
10CS45
3.2.5 OR instruction
OR BH, CL
56H=0101 0110B
BH
56H
CL
0FH
OR
0FH=0000 1111B
5FH
ud
en
ts
5FH=0101 1111B
After
gr
ou
p.
c
Before
om
ity
st
XOR BH, CL
.c
56H=0101 0110B
After
56H
59H
BH
XOR
CL
0FH
0FH=0000 1111B
Before
59H=0101 1001B
Page 64
10CS45
BH
56H
56H
56H=0101 0110B
AND
0FH=0000 1111B
CL
0FH
0FH
Temp
45H
06H=0000 0110B
Only flages are affected
gr
ou
p.
c
TEST BH, CL
After
om
Before
06H
CMP BH, CL
ud
en
ts
BH
ity
st
56H=0101 0110B
0FH=0000 1111B
Before
After
56H
56H
CL
0FH
Temp
45H
47H
.c
accessible to programmer.
Page 65
10CS45
ADD/ADC/SUB/SBB
R/M, d8/d16
gr
ou
p.
c
AND/OR/XOR/TEST/CMP
om
MOV
DX
BH
ity
st
ud
en
ts
Before
After
1234H
ABCDH
Before
After
56H
12H
.c
BX
1000H
DS:1000H
20H
After
Before
32H
DS:1001H
Page 66
10CS45
Before
BX 1000H
3234H
DS:1002H
gr
ou
p.
c
DS:1000H 2000H
om
After
Before
DH
30H
ud
en
ts
Carry flag
After
63H
0
.c
ity
st
DH
Before
After
30H
F0H
3.3.5 Subtract with borrow Immediate data from a Register/ Memory location
Page 67
10CS45
DH
Cy flag
Before
After
20H
06H
om
gr
ou
p.
c
Before
AND BH, 0FH
BH
AND
ud
en
ts
56H
Cy flag
After
06H
ity
st
.c
OR BH, 0FH
56H = 0101 0110B
BH
Before
After
56H
5FH
OR
Page 68
10CS45
CL
0FH
om
gr
ou
p.
c
Before
XOR BH, 0FH
BH
XOR
59H
ud
en
ts
56H
After
CL
0FH
ity
st
.c
After
BH
56H
56H
Temp
45H
06H
AND
56H=0101 0110B
Before
0FH=0000 1111B
Page 69
10CS45
Before
CMP BH, 0FH
56H
Temp
45H
AND
After
56H
47H
ud
en
ts
56H=0101 0110B
BH
gr
ou
p.
c
om
06H=0000 0110B
ity
st
SR
R16/M16
.c
MOV
After
DS
1122H
2233H
CX
2233H
MOV DS, CX
Before
Page 70
10CS45
DS
1122H
BX
2000H
DS:2000H
2233H
After
gr
ou
p.
c
Before
om
2233H
ud
en
ts
IN AL/AX, a8/DX
4 opcodes
AL
ity
st
IN AL, DX
DX
Before
After
50H
45H
2111H
.c
IN AL, 30H
Before
AL
After
45H
50H
Input port no. 30H
45H
Page 71
IN AX, DX
10CS45
Before
After
AX 3050H
4045H
45H
40H
gr
ou
p.
c
om
DX 1177H
4 opcodes
OUT 30H, AL
ud
en
ts
Before
After
AL
50H
ity
st
50H
Before
After
AX
3050H
DX
2177H
45H
50H
40H
30H
Before
After
.c
OUT DX, AX
40H
OUT 60H, AX
AX
3050H
Page 72
45H
50H
40H
30H
R/M, 1/CL
gr
ou
p.
c
om
MICROPROCESSORS
ud
en
ts
SHL is also called as SAL, as method for shift left of signed or unsigned number is the same
ROR R/M, 1/CL
ity
st
R/M
.c
ROR BH, 1
Cy
BH
Cy
Before
After
0100 0010
0010 0001
Page 73
10CS45
Before
0100 0010
Cy
R/M
ity
st
Cy
Before
After
BH
0010 0010
1000 1000
CL
02H
Cy
.c
1010 0001
ROL BH, CL
After
ud
en
ts
BH
Cy
om
R/M
gr
ou
p.
c
RCR BH, 1
Page 74
10CS45
R/M
Before
BH
0010 0010
CL
02H
Cy
After
gr
ou
p.
c
om
Cy
1000 0010
ud
en
ts
RCL BH, CL
SHL BH, CL
Cy
R/M
ity
st
.c
BH
Before
After
0010 0010
1000 1000
CL
02H
Cy
R/M
Cy
Page 75
10CS45
After
BH
0100 0100
0001 0001
CL
02H
Cy
om
Before
gr
ou
p.
c
Shift right
R/M
Shift right
BH
CL
Before
After
1100 0000
1111 0000
02H
ity
st
Cy
ud
en
ts
SAR BH, CL
.c
Cy
4 x 24 = 96 opcodes
BX
Before
After
1000H
2000H
Page 76
10CS45
SI
2000H
DS:2000H
3000H
gr
ou
p.
c
om
MOV BX,SI
4 x 24 = 96 opcodes
Before
DS 2000H
ud
en
ts
After
7000H
SI 1000H
DS:3000H
6000H
6000H
ity
st
DS:3002H
7000H
.c
Page 77
Before
After
7000H
ES
2000H
DI
1000H
2000:3000H
6000H
2000:3002H
7000H
.c
ity
st
ud
en
ts
instruction
gr
ou
p.
c
6000H
om
MICROPROCESSORS
Page 78
10CS45
PUSH/ POP
gr
ou
p.
c
om
R16/M16/SR/F
2 x (8+24+4+1) = 74 opcodes
ud
en
ts
Increment R16
8 opcodes
Before
After
Ex. 1
BX
1234H
1235H
FFFFH
0000H
.c
Ex. 2
ity
st
INC BX
INC DH
Ex. 1
Increment R8
8 opcodes
Before
After
DH
12H
13H
DH
FFH
00H
Ex. 2
BX
Increment M8
Page 79
10CS45
Before
BX 2000H
DS:2000H
FFH
00H
DS:2001H
12H
12H
om
24 opcodes
After
gr
ou
p.
c
NOTE:- In this instruction there is a single operand, [BX]. It is not clear whether it is byte or
word operand. Byteptr assembler directive announces to the assembler that it is a byte operation.
Increment M16
BX 2000H
After
ud
en
ts
24 opcodes
Before
DS:2000H
FFH
00H
DS:2001H
12H
13H
.c
DEC BX
ity
st
NOTE:- In this instruction there is a single operand, [BX]. It is not clear whether it is byte or
word operand. wordptr assembler directive announces to the assembler that it is a word
operation.
8 opcodes
Before
After
Ex. 1
BX
1234H
1233H
Ex. 2
BX
0000H
FFFFH
Before
After
12H
11H
w
w
w
Decrement R16
Decrement R8
DEC DH
Ex. 1
8 opcodes
DH
Page 80
10CS45
Ex. 2
DH
00H
FFH
Before
24 opcodes
BX
After
2000H
DS:2000H
00H
DS:2001H
12H
FFH
gr
ou
p.
c
om
Decrement M8
12H
ud
en
ts
NOTE:-In this instruction there is a single operand, [BX]. It is not clear whether it is byte or
word operand. Byteptr assembler directive announces to the assembler that it is a byte operation.
Decrement M16
DEC wordptr [BX]
Before
After
24 opcodes
BX
2000H
DS:2000H
00H
FFH
DS:2001H
12H
11H
ity
st
NOTE:- In this instruction there is a single operand, [BX]. It is not clear whether it is byte or
word operand. wordptr assembler directive announces to the assembler that it is a word
operation.
.c
8 opcodes
Before
After
1234H
EDCBH
BX
NOT BX
Page 81
10CS45
Before
After
12H
EDH
Before
24 opcodes
BX
23H
ud
en
ts
DS:2000H
2000H
gr
ou
p.
c
NOT DH
DS:2001H
12H
om
Perform 1s complement of M8
After
DCH
12H
ity
st
NOTE:- In this instruction there is a single operand, [BX]. It is not clear whether it is byte or
word operand. Byteptr assembler directive announces to the assembler that it is a byte operation.
BX
After
2000H
DS:2000H
34H
CBH
DS:2001H
12H
EDH
.c
24 opcodes
Before
NOTE:- In this instruction there is a single operand, [BX]. It is not clear whether it is byte or
word operand. wordptr assembler directive announces to the assembler that it is a word
operation.
Page 82
10CS45
NEG BX
8 opcodes
Before
After
1234H
EDCCH
BX
Perform 2s complement of R8
8 opcodes
Before
DH
12H
ud
en
ts
NEG DH
gr
ou
p.
c
om
After
EEH
BX
After
2000H
DS:2000H
23H
DDH
DS:2001H
12H
12H
.c
ity
st
24 opcodes
Before
NOTE:- In this instruction there is a single operand, [BX]. It is not clear whether it is byte or
word operand. Byteptr assembler directive announces to the assembler that it is a byte operation.
Before
BX
After
2000H
Page 83
10CS45
DS:2000H
34H
CBH
DS:2001H
12H
EDH
PUSH R16
Ex. PUSH CX
Before
1234H
SP
5678H
After
ud
en
ts
CX
gr
ou
p.
c
om
NOTE:- In this instruction there is a single operand, [BX]. It is not clear whether it is byte or
word operand. wordptr assembler directive announces to the assembler that it is a word
operation.
5676H
Empty
Empty
Full
SS: 5676H
1122H
SS:5678H
3344H
Full
1234H
3344H
.c
ity
st
Suppose SP content is 5678H. It means locations 5678, 567A, 567C in stack segment are full.
Locations 5676, 5674, are empty. Information pushed to location 5676 and SP value changes
to 5676H. Push operation is always on 16 bit data.
Before
BX
1234H
SP
3366H
DS:1234H
5678H
After
3364H
Page 84
10CS45
Empty
SP: 5676H
1122H
Full
SP: 5678H
3344H
Full
5678H
3344H
om
Empty
Ex. PUSH CS
Before
CS
1234H
SP
5678H
gr
ou
p.
c
PUSH SR
After
5676H
Empty
.c
Ex. PUSHF
1122H
SS: 5678H
3344H
Before
Flags
1234H
SP
5678H
1234H
3344H
PUSH Flags
After
5676H
Empty
Empty
SS: 5676H
1122H
Full
SS: 5678H
3344H
Full
Full
1234H
3344H
SS: 5676H
ity
st
Full
ud
en
ts
Empty
Ex. POP CX
POP R16
Before
After
Page 85
10CS45
CX 1234H
1122H
SP 5678H
567AH
Full
1122H
Full
3344H
gr
ou
p.
c
SS: 567AH
Empty
om
Empty
NOTE:- Suppose SP content is 5678H. It means locations 5678, 567A, 567C in stack segment
are full. Locations 5676, 5674, are empty. Information poped from location 5678 and SP
value changes to 567AH. Pop operation is always on 16 bit data.
ud
en
ts
POP M16
Before
After
BX 1234H
3368H
DS:1234H 5678H
1122H
ity
st
Empty
SP 3366H
Full
Full
3344H
.c
Empty 1122H
POP SR
Ex. POP CS
Before
After
CS
1234H
1122H
SP
5678H
567AH
Empty
Page 86
Full
10CS45
SS: 5678H
1122H
Empty
1122H
SS: 567AH
3344H
Full
3344H
Before
Flags
1234H
SP
5678H
SS: 5678H
1122H
SS: 567AH
3344H
Empty
1122H
567AH
Empty
1122H
Full
3344H
ud
en
ts
Full
After
gr
ou
p.
c
Ex. POPF
om
POP Flags
Before
After
CH
FEH
FEH
AL
02H
FCH
AH
34H
01H
01FCH = 508
.c
MUL CH
ity
st
MUL CX
Before
After
Page 87
10CS45
00FEH
AX
0002H
01FCH
DX
1234H
0000H
01FCH = 508
om
CX 00FEH
IMUL CH
Before
CH
FEH
AL
02H
After
FCH
FFFCH = -04
ud
en
ts
FEH = -02
gr
ou
p.
c
AH
34H
FFH
NOTE:- IMUL CH instruction multiplies AL and CH treating them as signed numbers. The 16bit product is stored in AX.
Before
After
CH
F0H
AL
25H
01H
Quotient
AH
01H
35H
Remainder
.c
DIV CH
ity
st
NOTE:- DIV CH instruction divides AX by CH treating them as unsigned numbers. The 8-bit
quotient is stored in AL and the 8-bit remainder stored in AH.
Page 88
10CS45
Before
After
CX 00F0H
om
DIV CX
0001H
Quotient
DX 0000H
0035H
Remainder
gr
ou
p.
c
AX 0125H
NOTE:- DIV CX instruction divides DX AX by CX treating them as unsigned numbers. The 16bit quotient is stored in AX and the 16-bit remainder stored in DX.
Signed Division of AX by R8 and store quotient in AL and remainder in AH
Before
After
ud
en
ts
IDIV CH
CH
F0H
EE = -12H
AL
25H
EEH
Quotient
AH
01H
05H
Remainder
ity
st
F0H = -10H
.c
Page 89
10CS45
3-bit r1 code
3-bit r2 code
Register
000
001
010
011
100
101
ity
st
ud
en
ts
gr
ou
p.
c
Concept of Template
In 8085, MOV r1, r2 (ex. MOV A, B) has the following template.
om
8086 has about 13000 opcodes. A book of about 60 pages is needed for printing the opcodes.
110
M
A
.c
111
MOV A,
01 11 1
7
is
000 = 78H
8
MOV M,
01 11 0
is
010 = 72H
Page 90
10CS45
Using the template for MOV r1, r2 we can generate opcodes of 26 = 64 opcodes.
1 0 0 0
gr
ou
p.
c
3.5.6 8086 Template for data transfer between REG and R/M
om
MOD
REG
R/M
2 bits
3 bits
3 bits
REG = A register of 8086 (8-bit or 16-bits) (except Segment registers, IP, and Flags registers)
ud
en
ts
Thus REG = AL/ BL/ CL/ DL/ AH/ BH/ CH/ DH/ AX/ BX/ CX/ DX/ SI/ DI/ BP/ SP
ity
st
.c
Page 91
10CS45
Register name
When W = 0
000
AX
AL
001
CX
CL
010
DX
DL
011
BX
100
SP
101
BP
110
SI
111
DI
gr
ou
p.
c
When W = 1
om
3-bit Register
code
BL
AH
CH
DH
ud
en
ts
BH
Aid to remember:
ity
st
Case of MOD = 11
.c
Example: Code for MOV AX, BX treated as Move from BX to destination register AX
MOD
REG
R/M
11
00 0
011
AX is
destination
BX
1 0 0 0
Word
operation
B
= 8B C3H
Example: Alternative code for MOV AX, BX treating it as Move from source register BX to
register AX
Dept of CSE, SJBIT
Page 92
1 0 0 0
10CS45
MOD
REG
R/M
11
01 1
000
BX is
source
AX
Word
operation
9
gr
ou
p.
c
= 89 D8H
om
MICROPROCESSORS
There are 2 possible opcodes for MOV AX, BX as we can choose either AX or BX as REG.
Example: Code for MOV AL, BH treated as Move from BL to destination register AL
MOD
11
Byte
operation
REG
R/M
00 0
111
ud
en
ts
1 0 0 0
AL is
destination
= 8A C7H
BH
ity
st
Example: Alternative code for MOV AL, BH treating it as Move from source register BH to
register AL
MOD
REG
R/M
11
11 1
000
BH is
source
AL
Byte
operation
= 88 F8H
.c
1 0 0 0
There are 2 possible opcodes for MOV AL, BH as we can choose either AL or BH as REG.
Page 93
10CS45
MOD = 01
MOD = 10
No
Displacement
8-bit signed
displacement d8
16-bit signed
displacement d16
000
[SI+BX]
[SI+BX+d8]
[SI+BX+d16]
001
[DI+BX]
[DI+BX+d8]
[DI+BX+d16]
010
[SI+BP]
[SI+BP+d8]
[SI+BP+d16]
011
[DI+BP]
[DI+BP+d8]
100
[SI]
[SI+d8]
101
[DI]
[DI+d8]
110
[BP] Direct
Addressing
[BP+d8]
111
[BX]
[BX+d8]
gr
ou
p.
c
MOD = 00
ud
en
ts
R/M
om
[DI+BP+d16]
[SI+d16]
[DI+d16]
[BP+d16]
[BX+d16]
ity
st
The table shows 24 memory addressing modes i.e. 24 different ways of accessing data stored in
memory.
Aid to remember:
.c
He says SImple DIet DIRECTs a BoXer' ( [SI], [DI], Direct addressing, [BX] )
Page 94
10CS45
MOD
REG
R/M
00
00 1
100
Byte
operation
No
Disp.
CL is
destination
[SI]
= 8A 0CH
gr
ou
p.
c
1 0 0 0
om
ud
en
ts
Note that there is a unique opcode for MOV CL, [SI] as CL only can be REG.
D
0
MOD
REG
R/M
d8
01
01 0
110
46H
ity
st
1 0 0 0 1 0
Word
operation
DX is [BP+d8]
source
6
.c
8-bit
Disp.
= 89 56 46H
Note that there is a unique opcode for MOV 46H[BP], DX as DX only can be REG.
Page 95
MOD
REG
R/M
d16
10
01 0
110
F2 46H
Word
operation
16-bit
Disp.
DX is
source
[BP+d16]
= 89 96 F2 46H
Stored as 89 96
46 F2H
om
in Little Endian
gr
ou
p.
c
10CS45
Note that there is a unique opcode for MOV 0F246H[BP], DX as DX only can be REG.
Ex: Code for MOV [BP], DX
MOD
REG
R/M
d8
01
01 0
110
00H
Word
operation
8
= 89 56 00H
ud
en
ts
1 0 0 0 1 0
8-bit
Disp.
DX is [BP+d8]
source
.c
ity
st
MOD
REG
R/M
Direct
addr
00
01 1
110
12
34H
Word
operation
No
Disp.
BX is
Dest.
Direct
addr.
Stored as 8B 1E
34 12H
In Little Endian
1 0 0 0 1 0
= 8B 1E 12 34H
Note that when MOD = 00 and R/M = 110, it represents Direct Addressing.
Dept of CSE, SJBIT
Page 96
10CS45
Unit 4
4.1 Branch group of instructions
om
Branch instructions provide lot of convenience to the programmer to perform operations selectively,
repetitively etc.
Uncondi-tional
jump
Iteration
instructions
CALL instructions
Return
instructions
ud
en
ts
Conditional
jumps
gr
ou
p.
c
Conditional Jump instructions in 8086 are just 2 bytes long. 1-byte opcode followed by 1-byte signed
displacement (range of 128 to +127).
ity
st
.c
JNZ r8
JS r8
JNS r8
JC r8
JNC r8
JP r8
;Jump if zero flag set (if result is 0). JE also means same.
;Jump if Not Zero. JNE also means same.
;Jump if Sign flag set to 1 (if result is negative)
;Jump if Not Sign (if result is positive)
;Jump if Carry flag set to 1. JB and JNAE also mean same.
;Jump if No Carry. JAE and JNB also mean same.
;Jump if Parity flag set to 1. JPE (Jump if Parity Even) also means same.
Page 97
JO r8
JNO r8
om
JNP r8
gr
ou
p.
c
Exa
mpl
es
for
JE
or
JZ
inst
ruc
tion
10CS45
Ex.
JE, JNE, JB, JNAE, JAE and JNB are used after a compare operation.
for
forward jump
Only examples using JE instruction given for forward and backward jumps.
ud
en
ts
CMP SI, DI
JE SAME
ADD CX, DX
;Executed if Z = 0
(if SI not equal to DI)
ity
st
SUB BX, AX
;Executed if Z = 1
(if SI = DI)
.c
SAME:
Page 98
10CS45
om
CMP SI, DI
JE BACK
ADD CX,DX
ud
en
ts
gr
ou
p.
c
Requirement
What if
.c
>127 bytes
ity
st
CMP SI, DI
CMP SI, DI
JE SAME
JNE NEXT
ADD CX, DX
JMP SAME
NEXT:
ADD CX, DX
SUB BX, AX
SAME:
Then do this!
SAME:
SUB BX, AX
15
Range for JMP (unconditional jump) can be +2 = + 32K. JMP instruction discussed in detail later
Page 99
10CS45
gr
ou
p.
c
om
Above and Below used for comparing Unsigned numbers. Greater than and less than used when
comparing signed numbers. All Intel microprocessors use this convention.
ud
en
ts
Conditional Jumps based on multiple flags are used after a CMP (compare) instruction.
Jump if
.c
Cy = 1 OR Z= 1
ity
st
Ex.
Cy = 0 AND Z = 0
CMP BX, CX
Surely Above
JBE BX_BE
Below OR Equal
No Jump if
Page 100
10CS45
No Jump if
Cy = 0 AND Z= 0
Cy = 1 OR Z = 1
Surely Above
Below OR Equal
Ex.
gr
ou
p.
c
Jump if
om
CMP BX, CX
JBE BX_BE
ud
en
ts
Jump if
No Jump if
.c
ity
st
Page 101
10CS45
JNLE / JG instruction
No Jump if
gr
ou
p.
c
Jump if
om
ud
en
ts
ity
st
Jump if
No Jump if
.c
Page 102
10CS45
om
No Jump if
gr
ou
p.
c
Jump if
ud
en
ts
ity
st
.c
w
w
w
Near Jump
2 or more bytes
Page 103
10CS45
15
Range: + 2
Range: +2
gr
ou
p.
c
om
Three Near Jump and two Far Jump instructions have the same mnemonic JMP, but they have
different opcodes
ud
en
ts
For Backward jump: Assembler knows the quantum of jump. Generates Short Jump code if
<=128 bytes is the required jump. Generates code for Long Jump if >128 bytes is the required
jump.
.c
ity
st
For Forward jump: Assembler doesnt know jump quantum in pass 1. Assembler reserves 3
bytes for the forward jump instruction. If jump distance turns out to be >128 bytes, the instruction
is coded as E9 r16 (E9H = Long jump code). If jump distance becomes <=128 bytes, the
instruction is coded as EB r8 followed by code for NOP (E8H = Short jump code).
Page 104
10CS45
JMP SHORT
SAME
gr
ou
p.
c
om
Assembler generates only 2 byte Short Jump code for forward jump, if the SHORT assembler
directive is used.
SAME:
MOV CX, DX
ud
en
ts
ity
st
CS:0000H
CS:8000H
.c
:
JMP FRWD
:
:
FRWD = CS:FFFFH
Page 105
10CS45
BKWD= CS:0000H
:
:
JMP BKWD
:
CS:0000H
Branch!
gr
ou
p.
c
FRWD = CS:FFFFH
om
CS:8000H
ud
en
ts
FRWD = CS:FFF0H
ity
st
CS:FFFFH
CS:0000H
.c
:
:
Forward Branch!
BKWD = CS:0010H
:
backward jump
:
CS:FFF0H
JMP BKWD
:
CS:FFFFH
Page 106
10CS45
Ex.1: JMP DX
gr
ou
p.
c
om
DS:3234H 5678H
Branches to CS:5678H
DS:3236H AB22H
ud
en
ts
If BX contents is 1234H
2 or more bytes,
.c
ity
st
As stated earlier, three Near Jump and two Far Jump instructions have the same mnemonic
JMP but different opcodes.
Page 107
10CS45
It is a 5 byte instruction. 1 byte opcode (EAH), 2 byte offset value, 2 byte segment value
gr
ou
p.
c
om
Also called Far Direct Jump. It is the common inter segment jump scheme
Also called Far Indirect Jump. It is not commonly used. Instruction length depends on the way
jump location is specified. It can be a minimum of 2 bytes.
ud
en
ts
DS:3234H 5678H
ity
st
DS:3236H ABCDH
.c
Iteration Instructions
Iteration instructions
LOOP
LOOPZ or LOOPE
LOOPNZ or LOOPNE
JCXZ
Page 108
10CS45
For 8086processor
gr
ou
p.
c
MVI C, 05H
AGAIN: MOV B, D
LOOP AGAIN
ud
en
ts
DCR C
JNZ AGAIN
om
ity
st
JNZ AGAIN
.c
Page 109
10CS45
Ex.
MOV CX, SI
JCXZ SKIP
AGAIN: MOV BX, DX
:
ud
en
ts
gr
ou
p.
c
om
Jump if CX is Zero is useful for terminating the loop immediately if CX value is 0000H It is a 2
byte instruction. It is used for forward jump only. Maximum distance for forward jump is only
127 bytes.
LOOP AGAIN
.c
ity
st
Page 110
10CS45
gr
ou
p.
c
Ex.
om
LOOP while Zero is a 2-byte instruction. It is used for backward jump only. Backward jump
takes place if after decrement of CX it is still not zero AND Z flag = 1. LOOPE is same as
LOOPZ. LOOPE is abbreviation for LOOP while Equal. LOOPE is normally used after a
compare instruction.
LOOPZ BACK
ud
en
ts
ADD SI, DI
ity
st
CALL instruction is used to branch to a subroutine. There are no conditional Call instructions in
8086.
.c
CALL instructions
Page 111
10CS45
Covers the entire Code segment. It is the most common CALL instruction.
ud
en
ts
gr
ou
p.
c
It is functionally same as the combination of the instructions PUSH IP and ADD IP, r16.
om
It is a 3-byte instruction. It has the format CALL r16 and has the range + 32K bytes.
Not commonly used. Instruction length depends on the way the called location is specified.
Ex.1: CALL AX
ity
st
.c
DS:3236H ABCDH
DS:3234H 5678H
Page 112
10CS45
PUSH IP
IP = 2-byte offset value provided in CALL
om
gr
ou
p.
c
Not commonly used. Instruction length depends on the way the called location is specified.
Ex. CALL dword ptr 2000H[BX]
ud
en
ts
DS:3234H
5678H
DS:3236H
ABCDH
ity
st
.c
Solution:
CALL COMPUTE
; execute only if Cy = 0
NEXT:
JC NEXT
Page 113
10CS45
RET
RET d16
gr
ou
p.
c
om
RET instructions
RET
RET d16
Ex:
Compute
ud
en
ts
Proc Near
:
:
ity
st
RET
Compute
ENDP
.c
Page 114
10CS45
om
SP = SP + d16
gr
ou
p.
c
RET d16 is useful for flushing out the parameters that were passed to the subroutine using the
stack
Main Program
:
:
ud
en
ts
PUSH Var1
PUSH Var2
ity
st
CALL Compute
IP
Var2
Var1
.c
COMPUTE
Subroutine
PROC
:
IP
SP if RET is executed
Var2
Var1
RET 0004H
COMPUTE
Near
ENDP
Page 115
10CS45
SINX
Proc Far
:
:
RET
ud
en
ts
SINX ENDP
gr
ou
p.
c
Ex.
om
ity
st
.c
RET d16 is useful for flushing out the parameters that were passed to the subroutine using the
stack.
Page 116
10CS45
Unit -5
om
Often it is a good idea to link assembly language programs or routines with high-level programs
gr
ou
p.
c
which may contain resources unavailable to you through direct assembly programming--such as
using C's built in graphics library functions or string-processing functions. Conversely, it is often
necessary to include short assembly routines in a compiled high-level program to take advantage
of the speed of machine language.
All high-level languages have specific calling conventions which allow one language to
communicate to the other; i.e., to send variables, values, etc. The assembly-language program
ud
en
ts
that is written in conjunction with the high-level language must also reflect these conventions if
the two are to be successfully integrated. Usually high-level languages pass parameters to
subroutines by utilizing the stack. This is also the case for C.
5.2 Using Assembly Procedures in C Functions
ity
st
In order to ensure that the assembly language procedure and the C program will combine and be
compatible, the following steps should be followed:
Declare the procedure label global by using the GLOBAL directive. In addition, also
.c
place the EXTERN statement outside the segment definitions and to place near data inside
the data segment.
Follow the C naming conventions--i.e., precede all names (both procedures and data)
with underscores.
Page 117
10CS45
push
ebp
mov
ebp, esp
gr
ou
p.
c
accomplish the stack setup, include the following code in the procedure:
om
parameters. Of course, if the procedure doesn't use the stack, then it is not necessary. To
EBP allows us to use this pointer as an index into the stack, and should not be altered throughout
the procedure unless caution is taken. Each parameter passed to the procedure can now be
accessed as an offset from EBP. This is commonly known as a "standard stack frame."
ud
en
ts
It is necessary that the procedure preserve the contents of the registers ESI, EDI, EBP, and all
segment registers. If these registers are corrupted, it is possible that the computer will produce
errors when returning to the calling C program.
ity
st
C passes arguments to procedures on the stack. For example, consider the following statements
from a C main program:
|
.c
x = Sum(a1, a2);
When C executes the function call to Sum, it pushes the input arguments onto the stack in
reverse order, then executes a call to Sum. Upon entering Sum, the stack would contain the
following:
Dept of CSE, SJBIT
Page 118
om
MICROPROCESSORS
Since a1 and a2 are declared as int variables, each takes up one word on the stack. The above
method of passing input arguments is called passing by value. The code for Sum, which outputs
_Sum
gr
ou
p.
c
the sum of the input arguments via register EAX, might look like the following:
ebp
mov
ebp, esp
mov
eax, [ebp+8]
mov
ecx, [ebp+12]
add
eax, ecx
pop
ebp
ret
ud
en
ts
push
It is interesting to note several things. First, the assembly code returns the value of the result to
the C program through EAX implicitly. Second, a simple RET statement is all that is necessary
ity
st
when returning from the procedure. This is due to the fact that C takes care of removing the
passed parameters from the stack.
Unfortunately, passing by value has the drawback that we can only return one output value.
.c
What if Sum must output several values, or if Sum must modify one of the input variables? To
accomplish this, we must pass arguments by reference. In this method of argument transmission,
the addresses of the arguments are passed, not their values. The address may be just an offset, or
both an offset and a segment. For example, suppose Sum wishes to modify a2 directly--perhaps
storing the result in a2 such that a2 = a1 + a2. The following function call from C could be used:
Sum(a1, &a2);
The first argument is still passed by value (i.e., only its value is placed on the stack), but the
second argument is passed by reference (its address is placed on the stack). The "&" prefix
Dept of CSE, SJBIT
Page 119
10CS45
means "address of." We say that &a2 is a "pointer" to the variable a2. Using the above statement,
om
gr
ou
p.
c
Note that the address of a2 is pushed on the stack, not its value. With this information, Sum can
access the variable a2 directly. (Hint: use an index register to hold the offset, then use a memory
access to access the variable).
5.2 .5 Returning a Value from the Procedure
Assembly can return values to the C calling program using only the EAX register. If the returned
ud
en
ts
value is only four bytes or less, the result is returned in register EAX. If the item is larger than
four bytes, a pointer is returned in EAX which points to the item. Here is a short table of the C
variable types and how they are returned by the assembly code:
Register
char
AL
ity
st
Data Type
AX
short
.c
(*)
EAX
Temporary storage space for local variables or data can be created by decreasing the contents of
ESP just after setting up a stack frame at the beginning of the procedure. It is important to restore
the stack space at the end of the procedure. The following code fragment illustrates the basic
idea:
push
ebp
Page 120
10CS45
mov
ebp, esp
sub
esp, 4
esi
push
edi
om
push
4 bytes
...
edi
pop
esi
mov
esp, ebp
pop
ebp
ret
gr
ou
p.
c
pop
; Return to caller
ud
en
ts
In most cases, calling C library routines or functions from an assembly program is more complex
than calling assembly programs from C. An example of how to call the printf library function
from within an assembly program is shown next, followed by comments on how it actually
works.
_main
extern
_printf
ity
st
global
db
text
.c
section .data
"%s", 0
strformat db
section .code
_main
push
dword text
Page 121
10CS45
push
dword strformat
call
_printf
add
esp, 8
om
ret
Notice that the procedure is declared global, and its name must be _main, which is the starting
gr
ou
p.
c
Since C pushes its arguments onto the stack in reverse order, the offset of the string is pushed
first, followed by the offset of the format string. The C function can then be called, but care must
be taken to restore the stack once it has completed.
When linking the assembly code, include the standard C library (or the library containing the
functions you use) in the link. For a more detailed (and perhaps more accurate) description of the
.c
ity
st
ud
en
ts
Page 122
10CS45
Unit-6
40
39
38
37
10
11
12
13
14
8086
15
16
36
35
34
33
32
31
30
29
28
27
26
Vcc
AD15
A16/S3
A17/S4
A18/S5
A19/S6
BHE/S7
MN/MX
RD
RG/GT0 (HOLD)
RQ/GT1 (HLDA)
LOCK (WR)
S2 (M/I0)
S1 (DT/R)
S0 (DEN)
QS0 (ALE)
QS1 (INTA)
TEST
READY
RESET
gr
ou
p.
c
1
2
3
4
5
6
7
8
9
ud
en
ts
GND
AD14
AD13
AD12
AD11
AD10
AD9
AD8
AD7
AD6
AD5
AD4
AD3
AD2
AD1
AD0
NMI
INTR
CLK
GND
om
17
18
19
20
25
24
23
22
21
ity
st
The following pin function descriptions are for the microprocessor 8086 in either minimum or
maximum mode. The 8086 pins signals are TTL compatible.
.c
(T1) and data during T2, T3 and T4 clock cycles. A0 is analogous to BHE for the lower byte of
the data bus, pins D0-D7. A0 bit is Low during T1 state when a byte is to be transferred on the
lower portion of the bus in memory or I/O operations. 8-bit oriented devices tied to the lower
half would normally use A0 to condition chip select functions. These lines are active high and
float to tri-state during interrupt acknowledge and local bus "Hold acknowledge". Fig. 2 shows
the timing of AD0 AD15 lines to access data and address.
Dept of CSE, SJBIT
Page 123
10CS45
AD0 - AD15
T1
Address
T2
T3
T4
Data
Fig. .2
gr
ou
p.
c
om
T4
During T1 state these lines are the four most significant address lines for memory
operations. During I/O operations these lines are low. During memory and I/O operations, status
information is available on these lines during T2, T3, and T4 states.
S5: The status of the interrupt enable flag bit is updated at the beginning of each cycle.
ud
en
ts
S6: When Low, it indicates that 8086 is in control of the bus. During a "Hold
acknowledge" clock period, the 8086 tri-states the S6 pin and thus allows another bus master to
take control of the status bus.
A16/S3
.c
ity
st
A17/S4
Function
Table 1
After the first clock cycle of an instruction execution, the A17/S4 and A16/S3 pins specify which
segment register generates the segment portion of the 8086 address. Thus by decoding these lines and
using the decoder outputs as chip selects for memory chips, up to 4 Megabytes (one Mega per segment)
of memory can be accesses. This feature also provides a degree of protection by preventing write
Page 124
10CS45
operations to one segment from erroneously overlapping into another segment and destroying information
in that segment.
om
gr
ou
p.
c
During T1 state the BHE should be used to enable data onto the most significant half of the data
bus, pins D15 - D8. Eight-bit oriented devices tied to the upper half of the bus would normally use BHE
to control chip select functions. BHE is Low during T1 state of read, write and interrupt acknowledge
cycles when a byte is to be transferred on the high portion of the bus.
The S7 status information is available during T2, T3 and T4 states. The signal is active Low and
cycle.
ud
en
ts
floats to 3-state during "hold" state. This pin is Low during T1 state for the first interrupt acknowledge
The Read strobe indicates that the processor is performing a memory or I/O read cycle. This signal is
active low during T2 and T3 states and the Tw states of any read cycle.
TEST (I)
ity
st
TEST pin is examined by the "WAIT" instruction. If the TEST pin is Low, execution
.c
synchronized internally during each clock cycle on the leading edge of CLK.
determine if the processor should enter into an interrupt acknowledge operation. A subroutine is vectored
to via an interrupt vector look up table located in system memory. It can be internally masked by software
resetting the interrupt enable bit
INTR is internally synchronized. This signal is active HIGH.
Page 125
10CS45
interrupt at the end of the current instruction. This input is internally synchronized.
gr
ou
p.
c
om
Reset causes the processor to immediately terminate its present activity. To be recognised, the
signal must be active high for at least four clock cycles, except after power-on which requires a 50 Micro
Sec. pulse. It causes the 8086 to initialize registers DS, SS, ES, IP and flags to all zeros. It also initializes
CS to FFFF H. Upon removal of the RESET signal from the RESET pin, the 8086 will fetch its next
instruction from the 20 bit physical address FFFF0H. The reset signal to 8086 can be generated by the
8284. (Clock generation chip). To guarantee reset from power-up, the reset input must remain below 1.5
ud
en
ts
volts for 50 Micro sec. after Vcc has reached the minimum supply voltage of 4.5V. The RES input of the
8284 can be driven by a simple RC circuit as shown in fig.3.
X1
X2
F/C
R
+5V
CLK
CLK
8284
RES
8086 p
RESET
RESET
.c
ity
st
Normal
Reset Key
SYSTEM RESET
Fig. .3
Vc (t) = V (1 - e -t /RC)
V = 4.5 volts,
t = 50 Micro sec.
Vc = 1.05V and RC = 188 Micro sec.
C = 0.1 Micro F;
R = 1.88 K ohms.
CPU component
Flags
Contents
Cleared
Page 126
0000H
CS register
FFFFH
DS register
0000H
SS register
0000H
ES register
0000H
Queue
Empty
gr
ou
p.
c
Instruction Pointer
om
MICROPROCESSORS
8086/88 RESET line provide an orderly way to start an executing system. When the processor detects the
positive-going edge of a pulse on RESET, it terminates all activities until the signal goes low, at which
time it initializes the system as shown in
ud
en
ts
table .2.
Ready is the acknowledgement from the addressed memory or I/O device that it will complete the
data transfer. The READY signal from memory or I/O is synchronized by the 8284 clock generator to
form READY. This signal is active HIGH. The 8086 READY input is not synchronized. Correct
ity
st
operation is not guaranteed if the setup and hold times are not met.
.c
Clock provides the basic timing for the processor and bus controller. It is asymmetric with 33%
duty cycle to provide optimized internal timing. Minimum frequency of 2 MHz is required, since the
design of 8086 processors incorporates dynamic cells. The maximum clock frequencies of the 8086-4,
Page 127
10CS45
X1
X2
CLK
F/C
READY
8086 p
Csync
RESET
RDY1
AEN2
PCLK
SYSTEM RESET
RDY2
OSC
Fig..4
gr
ou
p.
c
Vcc
om
AEN1
4MHz, 5MHz and 8MHz respectively. Since the 8086 does not have on-chip clock generation circuitry,
and 8284 clock generator chip must be connected to the 8086 clock pin. The crystal connected to 8284
must have a frequency 3 times the 8086 internal frequency. The 8284 clock generation chip is used to
ud
en
ts
This pin indicates what mode the processor is to operate in. In minimum mode, the 8086 itself
generates all bus control signals. In maximum mode the three status
ity
st
The following 8 pins function descriptions are for the 8086 in minimum mode; MN/ MX = 1.
.c
This pin is used to distinguish a memory access or an I/O accesses. When this pin is Low, it
accesses I/O and when high it access memory. M / IO becomes valid in the T4 state preceding a bus
cycle and remains valid until the final T4 of the cycle. M/ IO
floats to 3 - state OFF during local bus "hold acknowledge".
Page 128
10CS45
om
gr
ou
p.
c
acknowledge ".
It is used as a read strobe for interrupt acknowledge cycles. It is active LOW during T2,
T3, and T4 of each interrupt acknowledge cycle.
ALE is provided by the processor to latch the address into the 8282/8283 address
ud
en
ts
latch. It is an active high pulse during T1 of any bus cycle. ALE signal is never floated.
In minimum mode, 8286/8287 transceiver is used for the data bus. DT/ R is used to control the
direction of data flow through the transceiver. This signal floats to tri-state off during local bus "hold
acknowledge".
ity
st
It is provided as an output enable for the 8286/8287 in a minimum system which uses the
transceiver. DEN is active LOW during each memory and IO access. It will be low beginning with T2
.c
until the middle of T4, while for a write cycle, it is active from the beginning of T2 until the middle of T4.
6.1 .17 HOLD & HLDA (I/O): Hold and Hold Acknowledge
Hold indicates that another master is requesting a local bus "HOLD". To be acknowledged,
HOLD must be active HIGH. The processor receiving the "HOLD " request will issue HLDA (HIGH) as
an acknowledgement in the middle of the T1-clock cycle. Simultaneous with the issue of HLDA, the
processor will float the local bus and control lines. After "HOLD" is detected as being Low, the processor
Dept of CSE, SJBIT
Page 129
10CS45
will lower the HLDA and when the processor needs to run another cycle, it will again drive the local bus
and control lines.
om
The following pins function descriptions are for the 8086/8088 systems in maximum mode (i.e..
gr
ou
p.
c
MN/ MX = 0). Only the pins which are unique to maximum mode are described below.
.
6.2 .1 S2, S1, S0 (O): Status Pins
These pins are active during T4, T1 and T2 states and is returned to passive state (1,1,1 during T3
or Tw (when ready is inactive). These are used by the 8288 bus controller to generate all memory and I/O
operation) access control signals. Any change by S2, S1, S0 during T4 is used to indicate the beginning
S1
S0
Characteristics
Interrupt acknowledge
ity
st
S2
ud
en
ts
Halt
Code access
Read memory
Write memory
Passive State
.c
Table 3
Page 130
10CS45
om
gr
ou
p.
c
(1) A processor to detect execution of a ESCAPE instruction which directs the co-processor to
perform a specific task and
Characteristics
No operation
ud
en
ts
QS1
ity
st
Table 4
.c
It indicates to another system bus master, not to gain control of the system bus while LOCK is
active Low. The LOCK signal is activated by the "LOCK" prefix instruction and remains active until the
Example:
LOCK XCHG reg., Memory
Page 131
10CS45
om
gr
ou
p.
c
The 8086 memory address space can be viewed as a sequence of one million bytes in which any
byte may contain an 8-bit data element and any two consecutive bytes may contain a 16-bit data element.
There is no constraint on byte or word address boundaries. The address space is physically connected to a
16-bit data bus by dividing the address space into two 8-bit banks of up to 512K bytes each.
One bank is connected to the lower half of the 16-bit data bus (D0 D7) and contains even address
ud
en
ts
bytes. i.e., when A0 bit is low, the bank is selected. The other bank is connected to the upper half of the
data bus (D8 - D15) and contains odd address bytes. i.e., when A0 is high and BHE (Bus High Enable)
is low, the odd bank is selected. A specific byte within each bank is selected by address lines A1-A19.
Lower
Address
Bank
(512K x 8)
EVEN
ity
st
Higher
Address
Bank
(512K x 8)
ODD
A1-A19
Address Bus
BHE
A0
D0-D7
.c
D8-D15
Fig. 5
Data can be accessed from the memory in four different ways. They are:
8 - bit data from Lower (Even) address Bank.
8 - bit data from Higher (Odd) address Bank.
16 - bit data starting from Even Address.
16 - bit data starting from Odd Address.
Page 132
10CS45
Odd Bank
x + 3
x + 2
x + 5
x + 4
BHE = 1
D0-D15
A0 = 0
D0-D7
gr
ou
p.
c
D8-D15
A1-A19
om
x + 1
To access memory bytes from Even address, information is transferred over the lower half of the
data bus (D0 - D7). The A0 is output LOW and BHE is output HIGH enabling only the even address
ud
en
ts
Example: Consider loading a byte of data into CH register (higher order 8-bits of CX register)
from the memory location with an even address. The data will be accessed from the even bank via the (D0
- D7) DATA BUS. Although this data is transferred into the 8086 over the lower 8-bit lines, the 8086
automatically redirects the data to the higher 8-bits of its internal 16-bit data path and hence to the CH-
ity
st
register. This capability allows bytes input - output transfer via the AL register to access
I/O device
connected to either
the upper half of the data bus or the lower half of the 16-bit data bus.
.c
To access memory byte from an odd address information, is transferred over the higher half of the
data bus (D8 - D15). The BHE output low enables the upper memory bank. A0 is output high to disable
Page 133
10CS45
Even Bank
Odd Bank
BHE =0
A0 = 1
A1-A19
D0-D7
D8-D15
Fig. 7
6.2 .6 16-bit Data Access starting from Even - Address
Even Bank
ud
en
ts
Odd Bank
gr
ou
p.
c
D0-D15
x
x+2
x+1
x+3
A1-A19
om
x
x + 2
x + 1
x + 3
D8-D15
A0 = 0
BHE =0
D0-D7
ity
st
D0-D15
Fig. 8
16-bit data from an even address is accessed in a single bus cycle. Address lines A1 - A19 select
the appropriate byte within each bank. A0 low and BHE low enables both banks simultaneously. This is
.c
illustrated in fig. 8.
A 16-bits word located at an odd address (two consecutive bytes with the least significant
byte at an odd byte address) is accessed using two bus cycles. During the first bus cycle the lower byte
Page 134
10CS45
Odd Bank
Even Bank
0004
0006
0008
0005
0007
0009
0004
0006
0008
0005
0007
0009
A1-A19
Even Bank
A1-A19
A1-A9
A1-A9
D0-D7
D8-D15
D0-D7
Fig. 9
gr
ou
p.
c
D8-D15
om
Odd Bank
During the second bus cycle, the upper byte (with the even address 0006H as in fig.
9 (b)) is
accessed. During the first bus cycle, A1 - A19 address bus specifies the address and A0 as 1 and BHE is
low. Therefore the even memory bank is disabled and odd memory bank is enabled. During the second
bus cycle, the address is incremented. Therefore A0 is zero and BHE is made high. The even memory
ud
en
ts
8086 can be used either in a minimum mode system or a maximum mode system. The fig. 10
and fig. 11 shows minimum and maximum modes with groups of ICs to generate address bus, data bus
ity
st
and control bus signals. Using these buses, the CPU can be connected to ROM, RAM, PORTS and other
devices to form a complete system.
.c
8282 I/O ports are used to latch the addresses from the 8086 Microprocessor Data/Address bus.
By using three 8282, A0-A15, BHE , A16-A19 lines are latched during T1 state. OE (Output Enable)
input of the 8288 I/O ports are grounded; the bus will therefore, never be floated. ALE signal from 8286
Since the Data Bus is bi-directional, 8286 bi-directional bus transceivers are used, in
order to create a separate Data Bus from the 8086 Address/data Bus. The DT/ R and DEN
outputs from 8086 are used for 8286 "T" signal and OE inputs respectively.
Page 135
10CS45
om
timing and control signals compatible. DEN, DT/ R and ALE control outputs, are now generated by the
8288 bus controller. The DEN from 8288 is inverted and given to 8286 transceiver to enable the output.
The output enable of 8282 latch is grounded. As in minimum mode the address-data lines are latched
gr
ou
p.
c
through 8282 latch. The ALE signal from the 8288 bus controller latches the address during the T1 state
of the microprocessor. The DEN signal is used to enable the transceiver either to transmit or receive data
from I/O devices and memory. The DT/ R signal is used to transmit or receive the data as the need may
be.
PCLK
+5V
AEN2
AEN1
F/C
Wait-State
Generator
M/IO
INTA
RD
WR
Control
Bus
ud
en
ts
RES
CLK
READY
RESET
Clock
generator
MN/MX
ALE
+5V
STB
A0 - A19
OE
AD0-AD15
A16-A19
Address Bus
8282
Latch
ity
st
BHE
DT/R
DEN
BHE
D0 - D15
8286
16
T
OE
.c
Page 136
10CS45
+5V
MN/MX
S0
S1
S2
CLK
READY
Gnd
CLK
MRDC
S0
MWTC
S1
AMWC
S2
RESET
IORC
Wait-State
Generator
DEN
IOW C
DT/R
AIOWC
ALE
INTA
STB
A0 - A19
OE
gr
ou
p.
c
Address Bus
AD0-AD15
A16-A19
8282
Latch
om
RES
Clock
generator
OE
BHE
DATA
8286
Transceiver
ud
en
ts
Fig- 12 shows the timing diagram of 8086 read machine cycle with WAIT state. The clock
(CLK) signal is obtained from the clock-generator 8284. Each cycle of the clock is referred to as a state.
Minimum number of states to access a data is four. They are T1, T2, T3, and T4 states.
During T1 state of a read machine cycle an 8086 first asserts the M/ IO signal. It will assert this
ity
st
signal high if it is going to read from memory during memory read cycle and it will assert M/ IO low if it
is going to do a read from an Input port during its read cycle. The timing diagram in fig. 12 shows two
lines for the M/ IO signal, because the signal may be going LOW or going HIGH for a read cycle. The
.c
point where the two lines cross indicate the time at which the signal becomes valid for this machine cycle.
After asserting M/ IO , the 8086 sends out a high on the address latch enable signal, ALE. The
microprocessor sends out on AD0-AD15, A16 through A19 and BHE lines, the address of the memory
location that it wants to read. Since the latches are enabled by ALE being high, this address information
passes through the latches to their outputs. The 8086 then makes the ALE output low. This disables the
latches (8282) and holds the address information latched on the latch outputs. The address information
latched on the latch outputs can now be used to select the desired memory or port location.
In the timing diagram, the first point at which the two (AD0 AD15) cross represents the time at
which the 8086 has put a valid address on these lines. Two lines DO NOT indicate that all 16 lines are
Dept of CSE, SJBIT
Page 137
10CS45
going high or going low at this point. The crossed lines indicate the time at which a valid address is on
the bus.
T2
T3
Twait
T4
om
T1
CLK
AD0-AD15
gr
ou
p.
c
BHE
ALE
S2-S0
M/IO
RD
READY
DT/R
WR
ud
en
ts
DEN
Since the address information is now held on the latch, the 8086 does not need to send it out any
more. As shown in fig. 12 the 8086 floats the AD0 - AD15 lines so that they can be used to input data
ity
st
from memory or from a port. At about the same time the 8086 also remove the BHE and A16-A19
information from the upper lines and sends out some status information on these lines.
The 8086 is now ready to read data from the addressed memory locations or port. During T2-
.c
state the 8086 asserts its RD signal low. This signal is used to enable the addressed memory device or
port device.
At the end of T3 state the microprocessor makes the RD signal high and reads the data available
on the data bus, provided the READY input signal is high. It is the duty of the external circuit to see that
one or more WAIT states between T3 and T4 states in that machine cycle. An external hardware device
is set up to pulse READY low before the rising edge of the clock in T2 state. After the 8086 finishes T3
of the machine cycle, it enters a WAIT state.
Dept of CSE, SJBIT
Page 138
10CS45
If the READY input is still low at the end of a WAIT state, then the 8086 will insert another
WAIT state. The 8086 will continue inserting WAIT states until the READY input is sampled high
again.
If the READY input is sampled high again during T3 or during the WAIT state, the
om
microprocessor comes out of the WAIT state and will initiate T4 of the machine cycle.
The DEN signal is used to enable bi-directional buffers on the data bus. The data enable signal,
DEN, from the 8086 will enable the data buffer when it is asserted LOW. The data transmit / receive
gr
ou
p.
c
signal DT/ R from the 8086 is used to specify the direction in which the buffers are enabled. When DT/
R is asserted high, the buffers will, if enabled by DEN, transmit data from the 8086 to Memory or I/O
ports. When DT/ R is asserted low, the buffers, if enabled by DEN, will allow data to be received from
Memory or I/O ports of the 8086. DT/ R is asserted during T1 of the machine cycle. The DEN is
ud
en
ts
asserted after the 8086 finishes using the data bus to send the lower 16 address bits.
The 8086 write operation is very similar to the read cycle. During T1 of a write machine cycle the
8086 asserts M/ IO low if the write is going to a port and it asserts M/ IO high if the write is going to
memory. At about the same time the 8086 raises ALE
ity
st
high to enable the address latches. The 8086 then assert BHE and on the lines AD0 - AD19, it output the
address that it will be writing to. When writing to a port, line A16 - A19 will always be low, because the
8086 only sends out 16-bits port addresses. The 8086 brings ALE low again to latch the address on the
outputs of the latches. In addition to holding the address, the latches also function as buffers for the
.c
address lines. After the address information is latched, the 8086 remove the address information from
Page 139
gr
ou
p.
c
om
MICROPROCESSORS
ud
en
ts
If the READY input is sampled LOW by the 8086 before or during T2 of the machine cycle, the
8086 will insert a WAIT state after T3. If the READY input is sampled high before the end of the WAIT
state, the 8086 will go on with state T4 as soon as it completes the WAIT state. The 8086 will continue to
insect wait states for as long
as the READY is sampled low just before the end of each WAIT state.
6.3.1 Comparison of 8086 with the 8088 Microprocessor
ity
st
The 8088 CPU is an 8-bit processor designed around the 8086 internal structure. Most internal
functions of the 8088 are identical to the equivalent 8086 functions. The 8088 handles the external bus
the same way the 8086 does, one difference being hat the
.c
+5V
Gnd(2)
NMI
INTR
Clk
SSo (High)
MN/MX
RD
AD0-AD7(8)
HOLD (RG/GT0)
HLDA (RQ/GT1)
A8-A15(8)
8088
A16/S3(4)
A19/S6
Test
WR (LOCK)
IO/M (S2)
DT/R(S1)
Ready
Reset
DEN (S0)
ALE (QS0)
INTA (QS1)
Page 140
10CS45
consecutive bus cycles. To an assembly language programmer both processors will appear identical with
the exception of execution times. The internal register structure is identical and all instructions produce
the same end result. The pin configuration of 8088 is illustrated in fig. 14.
om
The major differences between 8088 and 8086 are outlined below:
The queue length is 4 bytes in the 8088, where as the 8086 queue comprises of 6 bytes.
The 8088 BIU will fetch a new instruction to load into the queue as soon as it finds a byte
gr
ou
p.
c
hole (space available) in the queue. The 8086 waits until a 2 byte space is available.
The internal execution time of the instruction set is affected by the 8-bit interface. All 16-bit
fetches and writes from / to memory take an additional four clock cycles. The CPU is also
limited by the speed of instruction fetch. When the more sophisticated instructions of the 8088
are being used, the queue has time to fill and the execution proceeds as fast as the execution
unit
ud
en
ts
will allow.
The hardware interface of the 8088 has some major differences as compared to the 8086. The pin
assignments are nearly identical, however, with the following functional changes.
A8-A15: These pins are only address outputs on the 8088. These address lines are latched
internally and remain valid throughout a bus cycle in a manner similar to the 8085 upper
address lines.
ity
st
SS0 provides the S0 status information in the minimum mode. This output occurs on pin 34
in minimum mode only. DT/ R , IO/ M and SS0 provide the complete bus status in
.c
IO/M
DT/R
SSO
CHARACTERISTICS
Code Access
Read Memory
Write Memory
Passive
Page 141
10CS45
Interrupt Acknowledge
Halt
om
gr
ou
p.
c
Table 5
IO/ M has been inverted. i.e., (In 8086, this pin as IO /M)
ALE is delayed by one clock cycle in the minimum mode when entering
HALT to allow the status to be latched with ALE.
ud
en
ts
Fig 15 illustrates the 8088 microprocessor system configuration. The Address-Data lines AD0AD7 are connected to the 74LS373 latch. The address from the multiplexed bus is latched into the
74LS373 when an ALE (Address latch enable) is active during T1 state of the microprocessor. The
address A0-A7 is available on the output of 74LS373 and can be used for memory (along with A16-A19),
and I/O devices. The address lines A8-A15 are not multiplexed with data lines or status lines, hence there
is no need to latch these address lines. The data bus is connected to the 74LS245 transceiver. The
ity
st
74LS245 is controlled by DT/ R and DEN to transmit and receive and Data respectively.
Since 74LS373 and 74LS245 are also buffered chips, it is not required to add buffers to these
chips. The address lines A8-A15 need to be buffered and hence the 74LS 244 buffer is used for these
.c
Page 142
10CS45
OE
A19/S6 - A16/S3
A19 - A16
74LS373
ALE
G
74LS
244
A15 - A8
om
OE
8088
OE
G
AD0 - AD7
A0 - A7
74LS373
D0 - D7
gr
ou
p.
c
DEN
DT/R
74LS244
.c
ity
st
ud
en
ts
Fig. 15
D/R
Page 143
10CS45
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
UNIT -7
Page 144
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Page 145
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Page 146
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Page 147
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Page 148
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Page 149
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Page 150
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Page 151
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Page 152
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Page 153
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Page 154
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Page 155
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Page 156
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Page 157
10CS45
Unit-8
8.1 Interrupt Driver I/O
gr
ou
p.
c
om
A disadvantage of conditional programmed I/O is that the microcomputer needs to check the status bit
(BUSY signal for the A/D converter) by waiting in a loop. This type of I/O transfer is dependent on the
speed of the external device. For a slow device, this waiting may slow down the capability of the
microprocessor to process other data. The interrupt I/O technique is efficient in this type of situation.
Interrupt I/O is a device-initiated I/O transfer. The external device is connected to a pin called the
interrupt (INT) pin on the processor chip. When the device needs an I/O transfer with the microcomputer,
it activates the interrupt pin of the processor chip. The microcomputer usually completes the current
instruction and saves at least the contents of the current program counter on the stack.
ity
st
ud
en
ts
The microcomputer then automatically loads an address into the program counter to branch to a
subroutine like program called the interrupt service routine. This program is written by the user. The
external device wants the microcomputer to execute this program to transfer data. The last instruction of
the service routine is a RETURN, which is typically the same instruction used at the end of a subroutine.
This instruction normally loads the address (saved in the stack before going to the service routine) in the
program counter. Then, the microcomputer continues executing the main program.
.c
There are typically three types of interrupts : external interrupts, traps or internal interrupts, and
software interrupts.
External interrupts are initiated through the microcomputers interrupt pins by external devices such as
A/D converters. A simple example of an external interrupt was given in the previous section.
External interrupts can further be divided into two types: maskable and nonmaskable. A maskable
interrupt is enabled or disabled by executing instructions such as EI or DI. If the microcomputers
interrupt is disabled, the microcomputer ignores the maskable interrupt. Some processors, such as the
Intel 8086, have an interrupt flag bit in the processor status register. When the interrupt is disabled, the
interrupt flat bit is 1, so no maskable interrupts are recognized by the processor. The interrupt flag bit
resets to zero when the interrupt is enabled.
Dept of CSE, SJBIT
Page 158
10CS45
om
The nonmaskable interrupt has higher priority than the maskable interrupt. If both maskable and
nonmaskable interrupts are activated at the same time, the processor will service the nonmaskable
interrupt first.
gr
ou
p.
c
Internal interrupts, or traps, are activated internally by exceptional conditions such as overflow, division
by zero, or execution of an illegal op-code. Traps are handled the
same way as external interrupts. The user writes a service routine to take corrective measures and provide
an indication to inform the user that an exceptional condition has occurred.
ud
en
ts
Many processors include software interrupts, or system calls. When one of these instructions is executed,
the processor is interrupted and serviced similarly to external or internal interrupts. Software interrupt
instructions are normally used to call the operating system. Software interrupt instructions allow the user
to switch from user to supervisor mode.
ity
st
The technique used to find the starting address of the service routine (commonly known as the interrupt
address vector) varies from one processor to another. With some processors, the manufacturers define the
fixed starting address for each interrupt. Other manufacturers use an indirect approach by defining fixed
locations where the interrupt address vector is stored.
.c
When a processor is interrupted, it saves at least the program counter on the stack so tae processor can
return to the main program after executing the service routine. Some processors save only one or two
registers, such as the program counter and status register. Other processors save all microprocessor
registers before going to the service routine. The user should know the specific registers the processor
saves prior to executing the service routine. This will enable the user to use the appropriate return
instruction at the end of the service routine to restore the original conditions upon return to the main
program.
Page 159
10CS45
om
A processor is typically provided with one or more interrupt pins on the chip. Therefore, a special
mechanism is necessary to handle interrupts from several devices that share on of these interrupt lines.
There are two ways of servicing multiple interrupts: polled and daisy chain techniques.
gr
ou
p.
c
Polled interrupts are handled by software and therefore are slower when compared with daisy chaining.
The processor responds to an interrupt by executing one general service routine for all devices. The
priorities of devices are determined by the order in which the routine polls each device. The processor
checks the status of each device in the general service routine, starting with the highest priority device to
service an interrupt. Once the processor determines the source of the interrupt, it branches to the service
routine for the device.
ud
en
ts
In a daisy chain priority system, devices are connected in a daisy chain fashion to set up a priority system.
Suppose one or more devices interrupt the processor. In response, the
processor pushes at lease the PC and generates an interrupt acknowledge (INTA) signal to the highest
priority device. If this device has generated the interrupt, it will accept the INTA. Otherwise, it will pass
the INTA onto the next device until INTA is accepted. Once accepted, the device provides a means for
the processor to find an interrupt address vector by using external hardware. The daisy chain priority
scheme is based on mostly hardware and is therefore faster than the polled interrupt.
ity
st
.c
Direct Memory Access (DMA) is a technique that transfers data between a microcomputers memory and
I/O device without involving the microprocessor. DMA is widely used in transferring large blocks of
data between a peripheral device and the microcomputers memory. The DMA technique uses a DMA
controller chip for the data transfer operation. The main functions of a typical DMA controller are
summarized as follows:
The I/O devices request DMA operation via the DMA request line of the controller chip.
The controller chip activates the microprocessor HOLD pin, requesting the CPU to release
the bus.
The processor sends HLDA (hold acknowledge) back to the DMA controller, indicating that
the bus is disabled. The DMA controller places the current value of its internal registers,
Page 160
10CS45
such as the address register and counter, on the system bus and sends a DMA acknowledge to
the peripheral device. The DMA controller completes the DMA transfer.
om
There are three basic types of DMA: block transfer, cycle stealing, and interleaved DMA.
gr
ou
p.
c
For block transfer DMA, the DMA controller chip takes the bus from the microcomputer to transfer data
between the memory and I/O device. The microprocessor has no access to the bus until the transfer is
completed. During this time, the microprocessor can perform internal operations that do not need the bus.
This method is popular with microprocessors. Using this technique, blocks of data can be transferred.
ud
en
ts
Data transfer between the microcomputer memory and an I/O device occurs on a word-by-word basis
with cycle stealing. Typically, the microprocessor clock is enabled by ANDing an INHIBIT signal with
the system clock. The system clock has the same frequency as the microprocessor clock. The DMA
controller controls the INHIBIT line. During normal operation, the INHIBIT line is HIGH, providing the
microprocessor clock. When DMA operation is desired, the controller makes the INHIBIT line LOW for
one clock cycle. The microprocessor is then stopped completely for the cycle. Data transfer between the
memory and I/O takes place during this cycle. This method is called cycle
stealing because the DMA controller takes away or steals a cycle without microprocessor recognition.
Data transfer takes place over a period of time.
.c
ity
st
With interleaved DMA, the DMA controller chip takes over the system bus when the microprocessor is
not using it. For example, the microprocessor does not use the bus while incrementing the program
counter or performing an ALU operation. The DMA controller chip identifies these cycles and allows
transfer of data between the memory and I/O device. Data transfer takes place over a period for time for
this method.
Status check I/O Data transfer done anytime after I/O device says it is ready
Page 161
10CS45
(Ex. Collect newspaper when the door bell rings indicating delivery of newspaper)
gr
ou
p.
c
om
Interrupt driven I/O data transfer done immediately after I/O device interrupts
ud
en
ts
Interrupt types
Hardware interrupts
Ex. NMI and INTR pins
Software interrupts
Exceptions or Traps
ity
st
ITN
Interrupt type
Divide by 0 error
Out of bound(80286)
Invalid opcode
NMI
No Coprocessor
Overflow error
w
w
Interrupt type
ITN
.c
Every interrupt type in 8086 has an 8-bit Interrupt type number (ITN) as shown below.
instruction 2 interrupts)
Page 162
Reserved by Intel.
20-FF
gr
ou
p.
c
om
5 -1F
10CS45
4. Reset T flag (so that interrupt service subroutine, ISS, is not executed in single step)
ud
en
ts
5. PUSH CS
6. PUSH IP
ity
st
.c
RAM locations 0 to 003FFH are used to store IVT. It contains 256 Interrupt
Vectors (IV) each of 4 bytes.
1234H
00002H
5678H
00004H
3344H
00000H
5678:1234H is IV number 0
Page 163
5566H
003FCH
6677H
003FEH
7788H
5566:3344H is IV number 1
:
7788:6677H is IV number FF
om
00006H
10CS45
ud
en
ts
5. PUSH IP
gr
ou
p.
c
In INT n, which is a 2-byte instruction, n is the ITN. INT n has the opcode CDH
ity
st
.c
4. PUSH CS
5. PUSH IP
6. IP loaded from word location 3 x 4 = 0000CH
7. CS loaded from next word location 0000EH
Page 164
10CS45
AH
After
00H
40H
AL
60H
BL
02H
2030H
gr
ou
p.
c
Before
om
Ex. DIV BL
ud
en
ts
5. PUSH IP
ity
st
4. PUSH CS
.c
Processor makes a branch to the subroutine at location 5678:1234H if the contents of IVT is as
shown in the table above.
Page 165
10CS45
om
gr
ou
p.
c
5. PUSH IP
Processor makes a branch to the subroutine at location 5566:3344H as per the IVT
ud
en
ts
ity
st
.c
5. PUSH IP
JNO Next
INT 4
Next: .
Page 166
10CS45
om
ud
en
ts
gr
ou
p.
c
2. Activate INTA o/p twice. In response 8086 receives ITN n instruction from an external device
like 8259 PIC
ity
st
.c
FLAGS
Page 167
10CS45
NMI
INTR
gr
ou
p.
c
om
If several interrupts occur during the execution of an instruction, in which order interrupts will be
serviced? There will be priorities as indicated below.
.c
ity
st
ud
en
ts
In reality NMI has highest priority! If NMI occurs during the servicing of INT n, processor
branches to NMI routine as IE flag has no effect on NMI.
Page 168
10CS45
om
PPI is abbreviation for Programmable Peripheral Interface. It is an I/O port chip used for interfacing I/O
devices with microprocessor. It is a very commonly used peripheral chip.
gr
ou
p.
c
Knowledge of 8255 essential for students in the Microprocessors lab for interfacing experiments.
8255
Vcc
A7
Gnd
A6
Port A
D7-0
A5
A4
PA7-0
Port C
ud
en
ts
RD*
40 pin DIP
PC7-4
PC3-0
A1
ity
st
There are 3 ports in 8255 from users point of view - Port A, Port B and Port C.
Port C is composed of two independent 4-bit ports : PC7-4 (PC Upper) and PC3-0 (PC Lower)
.c
Selection of Ports
A1
A0
Selected port
Port A
Port B
Port C
Control port
Page 169
10CS45
There is also a Control port from the Processor point of view. Its contents decides the working of 8255.
When CS (Chip select) is 0, 8255 is selected for communication by the processor. The chip select circuit
connected to the CS pin assigns addresses to the ports of 8255.
gr
ou
p.
c
There are 3 modes of operation for the ports of 8255. Mode 0, Mode 1, and Mode 2.
om
For the chip select circuit shown, the chip is selected when A7=0, A6=1, A5=1, A4=1, A3=1, A2=1, and
M/IO*= 0. Port A, Port B, Port C and Control port will have the addresses as 7CH, 7DH, 7EH, and 7FH
respectively.
Mode 0 Operation
It is Basic or Simple I/O. It does not use any handshake signals. It is used for interfacing an i/p device or
an o/p device. It is used when timing characteristics of I/O devices is well known.
ud
en
ts
Mode 1 Operation
It uses handshake I/O. 3 lines are used for handshaking. It is used for interfacing an i/p device or an o/p
device. Mode 1 operation is used when timing characteristics of I/O devices is not well known, or used
when I/O devices supply or receive data at irregular intervals.
ity
st
Handshake signals of the port inform the processor that the data is available, data transfer complete etc.
More details about mode 1 operation is provided later.
.c
Mode 2 Operation
It is bi-directional handshake I/O. Mode 2 operation uses 5 lines for handshaking. It is used with an I/O
device that receives data some times and sends data sometimes. Ex. Hard disk drive. Mode 2 operation is
useful when timing characteristics of I/O devices is not well known, or when I/O devices supply or
receive data at irregular intervals.
Page 170
10CS45
om
gr
ou
p.
c
We have already listed all the 40 pins of 8255. Port C pins act as handshake signals, when Port A and Port
B are configured for other than Mode 0. Port A in Mode 2 and Port B in Mode 1 is possible, as it needs
only 5+3 = 8 handshake signals. After Reset of 8255, Port A, Port B, and Port C are configured for Mode
0 operation as input ports.
PC2-0 are used as handshake signals by Port B when configured in Mode 1. This is immaterial whether
Port B is configured as input or output port.
PC5-3 are used as handshake signals by Port A when configured as input port in Mode 1.
ud
en
ts
PC7, 6, 3 are used as handshake signals by Port A when configured as output port in Mode 1.
PC7-3 are used as handshake signals by Port A when configured in Mode 2.
ity
st
.c
Mode definition control word is used to configure the ports of 8255 as input or output in Mode 0, Mode 1,
or Mode 2.
Page 171
om
MICROPROCESSORS
M2A
M1A
I/P A
I/P CU
1 - PA as input
M2A M1A
M1B
0 - PA as output
I/P B
I/P CL
1 -PCL as input
ud
en
ts
0 - PCU as output
gr
ou
p.
c
0 -PCL as output
1 - PB as input
0 - PB as output
Port A in Mode 0
Port A in Mode 1
0/1
Port A in Mode 2
1 - PB in Mode 1
0 - PB in Mode 0
.c
ity
st
Page 172
10CS45
MD control word
98H
om
PA in Mode 0
PA as input
gr
ou
p.
c
PC Lower as output
PB as output
PB in Mode 0
.c
ity
st
ud
en
ts
PC Upper as input
Page 173
10CS45
Assignment Questions
UNIT- 1
om
4.Distinguish between
Microprocessors.
Accumulator-Based
and
gr
ou
p.
c
3. Draw and explain the block diagram of microprocessor based system and also explain the
general sequence it follows to execute the instructions.
General
Purpose
Register
Based
ud
en
ts
ity
st
12. Describe the Minimum Mode Configuration System of 8086 with a neat block schematic.
UNIT 2
.c
2. Draw the register organization of 8086 and explain typical applications of each
register.
Page 1
10CS45
om
UNIT 3
1. What is bus cycle? Draw memory-read bus cycle in min. mode of operation of 8086.
2. What signals are activated when an I / O port at address ABCD Hex is read by an
gr
ou
p.
c
8086? Indicate the action using the timing diagram for these signals.
4. What is addressing mode? Explain different addressing schemes used in 8086 with examples
of each.
ud
en
ts
5. Which instruction of 8086 can be used for look up table manipulations? Justify your answer
with an example.
6. Examine the overall result of the following 8086 ALP blocks and give single 8086
instructions that can do the same job as the blocks.
i) JNC DOWN
ii) PUSH AX
iii) PUSH AX
INC AX PUSH BX PUSH BX
DOWN: NOP POP AX POP BX
BX POP CX
POP
ity
st
UNIT - 4
.c
1. What is the difference between the NEAR and FAR procedure? Explain.
2. Bring out difference between MACRO and PROCEDURE.
3. Write an assembly language program in 8086 to count the number of positive & negative
numbers present in a series of 10signed 8 bit numbers stored from address ARRAY. Store the
results at locations PNOS & NNOS respectively.
Page 2
10CS45
om
6. Write an 8086 to find the GCD and the LCM of two 16 bit numbers. Explain your program
ONLY through proper comments.
gr
ou
p.
c
7. Write an 8086 ALP subroutine for doing bubble sort of a word array in the ascending order,
returning all registers intact. Explain your program ONLY through comments
8. Write an 8086 ALP to find factorial of a number using recursive algorithm. Write comments
to make the program clear.
9. Write an 8086 ALP to convert set of BCD bytes to binary. Use main program and sub routine
BCD-BIN for conversion. Write comments.
ud
en
ts
10. Write a non-recursive ALP subroutine of 8086, to evaluate the number Fn = Fn-1 + Fn-2 for
any given n > 1. Starting from the definition; F0 = 0 and F1 = 1. Consider the number. Consider
the number n to be such that Fn is not more than a 16 bit unsigned number.
UNIT - 5
1. What are assembler directives? Explain any 6 such directives used in MASM assembler for
8086 programming
2. How does main program and sub routine communicates? Explain with an example.
ity
st
3. With suitable example, explain the following instructions by stating the addressing mode they
belong to:
i) LDS ii) XLAT iii) CWD iv) SCAS
.c
5. Write the flow chart and the 8086 ALP to convert the BCD numbers 0 to 9 to their equivalent
seven segment codes using the look-up table technique. Assume the CODELIST at the relative
addresses from 0 to 9. The BCD number (CHAR) is taken in AL.
UNIT - 6
Page 3
10CS45
UNIT - 7
1. Explain how a software delay program can be written for 100msec delay for an 8086 system
connected with 10MHz crystal.
gr
ou
p.
c
om
2. Explain clearly the process of reading a WORD from an odd address in an 8086 system,
bringing out the necessity of performing two memory read operations in this case, as compared
to reading a WORD from an even address that requires only one memory read operation.
4. Interface eight 8K chips of RAM and four 8K EPROM with 8086. Interface the RAM bank at
a segment address 0B00h and the EPROM bank at a physical address F8000H. Do not allow any
fold bank space.
UNIT - 8
ud
en
ts
2. Draw and explain a typical Stepper Motor Interface. Further, write an ALP to rotate a shaft of
a 4-phase stepper motor in clockwise by 5 rotations.
3. Write short notes on the following:
i) MACROS ii) Control of High Power devices using 8255.
4. What are the criteria to be considered before interfacing memory to the processor?
ity
st
5.Interface a DAC 0800 to 8086 and write a program to generate a triangular waveform.
***********************
.c
6. Interface a set of 8 simple switches and 8 simple LEDS to 8086 using a 8255 PPI chip. The
8255 should be selected for the following addresses. Write a program to indicate the status of the
switches on LEDs
port A:0740 H, port B:0742H, port C:0744H CWR:0746H.
Page 4
10CS45
VTU-Question Bank
Unit-1
1.a. Draw the physical memory system diagram for Intel Pentium microprocessors.
om
July/July 13 [8 marks]
gr
ou
p.
c
1.b. Discuss the functions of segment registers of 8086 with examples. Give some advantages of
memory segmentation.
July/July 13 [6 marks]
July/July 13 [6 marks]
2.a. Explain the memory structure of intel personal computer in detail with neat schematic.
2.c. What is real mode addressing? Explain default segment and offset registers.
ud
en
ts
3.a. With a neat diagram explain the architecture along with function of each block and register.
Dec 2012 [10 Marks]
3.b. How many address lines does an 8086 have?
ity
st
a. How many memory address does this number of address lines allow the 8086 to
access directly?
b. At any given time the 8086 works with 4 segments in this address space. How
many bytes are contained in each segment?
c. Describe the difference between the instructions MOV AX,2347H and MOV
AX,[2347H]
.c
3.c. Write 8086 assembly instruction which will perform the following operations:
i)
ii)
iii)
iv)
v)
Page 1
10CS45
4.b. What is flag register? Explain the flag register format, in detail.
om
5.a Define a microprocessor. Explain the programming model of the 8086 through the CORE-2
microprocessor including the 64-bit extensions.
June 2014[06 marks]
5.b Explain in detail with a neat figure the worning of the internal architecture of the 8086 MP
gr
ou
p.
c
5.c Explain in detail the various bits of a flag register for 8086 MP
Unit-2
ud
en
ts
1.a. Explain how virtual address is translated into physical address with a neat diagram.
1.b. Identify the addressing modes of the following instructions and explain them briefly.
ity
st
1.c. briefly explain the flat mode memory model with a neat diagram.
June/July 13 [06 marks]
.c
2.a. Illustrate the memory paging mechanism in the 80386 mp with suitable schematic.
Dec 13/Jan 14 [06 marks]
2.b. briefly explain various addressing modes of 8086 with suitable examples.
Dec 13/Jan 14 [10 mark]
MOV RAX,RCX
MOV ESP,[BSP]
MOV AX,2341H
MOV CS,AX
Page 2
10CS45
3.a. State and explain instruction formats of 8086. Also generate the opcode for
following
instructions.
Dec 2012 [10 marks]
3.b. Explain the following assembler directive with example.
i) PROC & ENDP ii) PUBLIC & EXTRN iii) MACRO & ENDM
om
3.c. Write the assembly language development tools along with algorithm. Dec 2012 [12 Marks]
iv) ASSUME
gr
ou
p.
c
4.a. Write and explain instruction template for MOV instruction. Also generate opcode for
following instructions: the opcode for MOV is
Jan 2015 [15 Marks]
i)
MOV CL,[BX]
ii)
MOV CS,[BX],DL
iii)
MOV 43H[SI[,DH
iv)
MOV CX,[437A]H
ud
en
ts
1 0 0 0 1 0
4.b. What is an assembler directive? Explain the following assembler directive with example:
Jan 2015 [10 Marks]
ity
st
5.a Explain with an example why and how a 20 bit address is generated in 8086
Unit-3
.c
5.b Explain any five addressing modes in detail with examples in 8086
1. a. Write an ALP using 8086 instructions to search a number placed in location NUM,in an
array of ten numbers placed at location ARRAY.
June/July 13 [8 marks]
1.b. describe the following instructions with an example:
June/July 13 [8 marks]
a) LEA
b) XCHG
c) DAA
Page 3
10CS45
d) MUL
1.c. Give the state of all the status flags bits after the addition of 30a2 with f01ch.
June/July 13 [8 marks]
om
2.a. Write and explain machine code for instruction MOV DL,[BX]
Dec 13/Jan 14 [10 marks]
PUSHF MOVS
LAHF DIV
gr
ou
p.
c
2.c. what is segment override prefix? Illustrate the same with an example.
ud
en
ts
3.b. Explain the types of program execution transfer instruction (Branch instructions) with
examples.
Dec 2012 [10 marks]
4.a. What is the need for unconditional jump instructions, explain different conditional jump
supported by 8086.
Jan 2015 [10 marks]
4.b. Write a delay loop, which produces a delay of 5 clock.
5.a Write 8086 ALP to add 10 non-negative data items using string instructions.
CMP
LAMF
ity
st
LEA
PUSH AX
.c
ORG
Unit-4
i) DB
iv) SEGMENT
1.c. Write an ALP using 8086 instructions to reverse a four digit number
June/July 13[8 marks]
Page 4
10CS45
2.a. Explain with an example how multiple if then else statement can be implemented using ALP
Dec 13/Jan 14[10 marks]
2.b. Differentiate between short, near and far jump instructions with two examples of each
om
gr
ou
p.
c
3.c. Explain the sequence of operation that takes place when a procedure is called and returned
form procedure base to calling program with block diagram.
Dec 2010 [10 Marks]
4.a. Write an assembly level program to cheek a given string is palindrome or not.
ud
en
ts
5.b Explain the the following instruction with examples any four
DAA MUL
ADC SHR
RCL
ity
st
5.c Explain the different types of jump and cell instructions of 8086
Unit-5
June/July 13 [6 marks]
.c
1.b. State the C language elements that can be used in the arm block.
June/July 13 [6 marks]
1.c. Explain the basic rules for using assembly language with C/C++ for 16 bit DOS applications
with the help of examples
June/July 13 [8 marks]
2.a. Illustrate a simple program that uses a character string defined with and display on a separate
line.
Dec 13/Jan 14 [10 marks]
2.b. Differentiate between :
Page 5
10CS45
i) assembler and linker ii) public and extern iii) macros and procedure
2.c. Write an ALP to compute factorial of single digit positive number using recursive procedure
Dec 13/Jan 14 [4 marks]
gr
ou
p.
c
i)
ii)
iii)
iv)
v)
om
3.a. Write an ALP to find NCR using recursive procedure. Assume N & R are non-Negative
numbers.
Dec 2012 [10 marks]
4a. Explain the following instructions or directives in 8086 programming: i) global ii) call iii)
LAHE iv) TYPE v) NEG viii) TEST ix) GROUP x) XLAT
Jan 2015 [10marks]
ud
en
ts
5.a Write a ALP using C/C++ to perform the operation X+Y=Z with proper comments
5.b Define modular programming. Using the concepts of public and extra directives writ a program which
reads data in a program in one module which is then used by another module
June 2014[06 marks]
ity
st
Unit-6
.c
i) ALE ii)INTR
iv)RESET
June/July 13 [5 Marks]
v)BHE
1.b. Explain how address de-multiplexing is done in 8086 processor based systems.
June/July 13 [7 Marks]
June/July 13 [8 Marks]
2.a. Explain the minimum mode pins of 8086 and maximum mode configuration of 8086 with
neat diagram.
Dec 13/Jan 14 [10 Marks]
2.b. Describe internal block diagram of 8288 bus controller with explanation of each pins
Dec 13/Jan 14 [6 Marks]
Page 6
10CS45
3.b. write the timing diagram for a memory read machine cycle.
om
4.a. Write signal activities on 8086 buses, during a simple read operation.
gr
ou
p.
c
4.b. What is need of memory banking? With a neat block diagram, explain the memory banking
in 8086.
Jan 2015 [10 Marks]
5.a Describe in details the uses of the following signals
ACE
RESET
NMI
HOLD
MN/MX
QSI and
QSQ
5.b Explain in detail with a neat figure demultiplexing of address and data lines in 8086
ud
en
ts
5.c Explain with a neat figure the working of 8086 in MIN mode configuration
Unit-7
June/July 13 [2 Marks]
ity
st
1.b. What is memory address decoding? Design a memory system for 8086 for the following
specifications
June/July 13 [10marks]
i)
ii)
.c
1.c. what are the sources of interrupts? Briefly explain the steps taken by a processor to execute
an interrupt instruction.
June/July 13 [8marks]
2.a. with a neat diagram, explain simple NAND gate address decoding logic.
Dec 13/Jan 14 [10 marks]
Page 7
10CS45
3.a. Briefly explain the structure of 8086 interrupt response and interrupt vector table with a neat
diagram.
Dec 2012 [10 Marks]
3.b. explain with block diagram, the working of 8259 and also explain ICWs format.
om
gr
ou
p.
c
5.a Differentiate between memory mapped I/O and I/O mapped I/O
5.b i)64 kbytes EPROM ii)64 kbytes RAM . assume Ram is connected at 30000h and EPROM at
ud
en
ts
F00000h.
5.c Explain how a 3-8 line decoder could be used to interfaced eight 8K memory chips.
Unit-8
ity
st
1.a. briefly explain the control word format of 8255 in I/O mode and BSR mode. Give the
control word format to program port A and port C lower as input and port B and port C upper as
output parts in mode 0.
June/July 13 [10 Marks]
.c
1.b.write an ALP using 8086 instructions to read a byte of data from port A and display its parity
status as 00h or ffh for odd and even parity respectively on port B June/July 13 [5 Marks]
June/July 13 [5 Marks]
2.a. Explain pin out of 8255 along with different operational modes.
Dec 13/Jan 14 [10 marks]
3.a. explain the different methods of parallel data transfer with figure in a programmable
peripheral interface.
Dec 2012 [10 Marks]
Page 8
10CS45
3.b. Explain with the internal block diagram of 8255, the different operational modes and the
control word formats.
Dec 2012 [10 Marks]
4.a. With a neat block diagram, explain the internal block diagram of 8255A.
om
gr
ou
p.
c
4.c. Write on assembly level program to interface logic controller for multiplication of two 8-bit
numbers.
Jan 2015 [10 Marks]
5.a Explain different signals of 8255 PP and control words.
5.b Explain with a neat diagram the interfacing of stepper motor to 8086 using 8255 in detail
.c
ity
st
ud
en
ts
5.c Explain the working of different blocks of 8254 PIT with a neat figure June 2014[06 marks]
Page 9
10CS45
om
1.a. Draw the physical memory system diagram for Intel Pentium microprocessors.
ity
st
ud
en
ts
gr
ou
p.
c
June/July 13 [8 marks]
.c
Protected mode memory addressing (80286 and above) allows access to data and programs
located above the first 1M byte of memory as well as within the first 1M byte of memory.
Addressing this extended section n of the memory system requires a change to the segment plus
offset addressing scheme used with real mode memory addressing. When data and programs are
addressed in extended memory, the offset address is still used to access information located
within the memory segment. The difference is that the segment address, as discussed with real
mode memory addressing, is no longer present in the protected mode. In place of the segment
address, the segment register contains a selector that selects a descriptor from a descriptor table.
The descriptor describes the memory segment's location, length, and access rights. Because the
Page 1
10CS45
segment register and offset address still access memory, protected mode instructions are identical
to real mode instructions. In fact, most programs written to function in the real mode will
function without change in the protected mode. The difference between modes is in the way that
om
the segment register is interpreted by the microprocessor to access the memory segment
.c
ity
st
ud
en
ts
gr
ou
p.
c
1.b. Discuss the functions of segment registers of 8086 with examples. Give some
advantages of memory segmentation
June/July 13 [6 marks]
Page 2
10CS45
A combination of a segment address and an offset address access a memory location in the real
ode. All real mode memory addresses consist of a segment address plus an offset address. The
segment address, located within one of the segment registers, defines the beginning address of
om
ny 64K-byte memory segment. The offset address selects any location within the 64K-byte
memory segment. The microprocessor has a set of rules that apply to segments whenever
memory is addressed. These rules, which apply in either the real or protected mode, define the
gr
ou
p.
c
segment register and offset register combination used by certain addressing modes.
June/July 13 [6 marks]
In 8086, to speed up the execution of program, the instructions fetching and execution of
instructions are overlapped each other. This technique is known as pipelining. In pipelining,
when the n th instruction is executed, the n+1 th instruction is fetched and thus the processing
ud
en
ts
speed is increased
Instruction 1
Instruction 2
Instruction 4
Instruction 3
X
X
Four sample instructions, executed linearly
ID
EX
IF
ID
EX
ID
EX
IF
ID
EX
IF
1
W
1
1
W
.c
IF
ity
st
Page 3
10CS45
2.a. Explain the memory structure of Intel personal computer in detail with neat schematic.
ud
en
ts
gr
ou
p.
c
om
The transient program area (TPA) holds the operating system and other programs that control the
computer system. The TPA also stores any currently active or inactive application. The length of
ity
st
the TPA is bytes. As mentioned, this area of memory holds the system, which requires portion of
the TPA. In practice, the amount of memory for application software is bytes if MSDOSII
version 6.X is used as an operating system. Earlier versions of MSDOS required more of the
TPA and often left only 530K bytes or less for application programs. The memory map shows
.c
how the many areas of the TPA are used for system programs, data, and drivers. It also shows a
large area of memory available for application programs. To the left of each area is a
hexadecimal number that represents the memory addresses that begin and end each data area.
The BIOS and DOS communications areas containtransient data used by programs to access
119de\lices and the internal features of the computer system. These are stored in the TPA so they
echanged as the system operates. Note that the TPA contains read/write memory (called RAM or
random access memory) so it can change as a program executes.
Page 4
10CS45
om
gr
ou
p.
c
BX (base) register : It is used as a pointer to a memory location .It holds offset address relative
to data segment. BX register can be treated as two 8-bit register BH and BL.
CX (counter)register: CX register holds count value for loop an repeat instruction.CX Register
can be treated as two 8-bit register CH and CL.
DX (data) register: The DX is only register used as an I/O address pointer in the IN and OUT
instructions. It also involved in multiplication and division operation. DX register can be treated
as two 8 bit register DH and DL.
ud
en
ts
iv) Pointer and index registers: The 8086 processor has two 16 bit pointer, Stack Pointer (SP)
and Base Pointer (BP) and two 16 bit index registers, Source Index (SI) and Destination Index
(DI).
Stack Pointer (SP) Register: The SP register holds the offset address and always points to the top
of the stack relative to stack segment.
Base Pointer (BP) Register: The BP register holds the offset address relative to stack segment.
The physical address=SS*10h+SP (or BP).
ity
st
Source Index (SI) Register: This register holds the offset address of the data relative to data
segment. In string instructions, SI is used as a pointer to source string element.
.c
Destination Index (DI) Register: This register also holds the offset address of the data relative to
data segment. In string instructions, DI is used as a pointer to destination string element.
v) Flag Register: The 16 bit flag register of the 8086 processor stores information about the
status of the processor and the status of the instruction executed most recently.
Page 5
10CS45
2.c. what is real mode addressing? Explain default segment and offset registers.
gr
ou
p.
c
om
The 80286 and above operate in either the real or protected mode. Only the 8086 and 8088
operate exclusively in the real mode. This section of the text details the operation of the
ud
en
ts
microprocessor in the real mode. Real mode operation allows the microprocessor to address only
the first 1M byte of memory space-even the Pentium microprocessor. Note that the first 1M byte
of memory is called either the real memory or conventional memory system. Both the MSDOS
or PCDOS operating systems assume that the microprocessor is operated in the real mode at all,
times. Real mode operation allows applicationsoftware written for the 8086/8088, which
ity
st
contains only 1Mbyte of memory, to function in the 80286 and above without changing the
software. At present, 95 percent of all software in use is designed to operate in the real mode.
This will most likely change as Windows 95 becomes the new 32-bit operating platform. The
upward compatibility of software is partially responsible for the continuing success of the Intel
.c
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. Note that the
DOS environment is a real mode environment.
A combination of a segment address and an offset address access a memory location in the real
mode. All real mode memory addresses consist of a segment address plus an offset address. The
segment address, located within one of the segment registers, defines the beginning address of
any 64K-byte memory segment. The offset address selects any location within the 64K-byte
memory segment.
Page 6
10CS45
ud
en
ts
gr
ou
p.
c
om
3.a. With a neat diagram, explain the architecture of 8086 microprocessor along with
functions of each block and registers.
Dec 2012 [10 Marks]
ity
st
Bus Interface Unit: The BIU sends out addresses, fetches instructions from memory, reads data
from ports and memory and writes data to ports and memory.
The functional parts of the BIU are:
.c
i) Instruction Queue(IQ)
i) Instruction Queue: The Instruction Queue is of six bytes in length and is used to send up the
execution of programs by pre-fetching six instruction bytes in advance from memory.
The BIU and EU works parallely. The BIU fetches the instruction bytes while the EU is
executing an instruction.
Page 7
10CS45
The process of pre-fetching the instruction in advance while EU is executing the current
instruction is known as pipelining.
ii)Segment Register: The BIIU contains 4 16 bit segment registers. They are:
om
gr
ou
p.
c
These registers are used to store the 16 bit starting address of the four memory segment. The BIU
generates a 20 bit physical address using the segment and the offset component of an address.
ud
en
ts
a) Code Segment Register : Code Segment(64 kb) of memory contains instruction of the
program. The CS register holds the 16 bit starting address of this segment. To access the storage
location of an instruction in the active code segment, the 8086 must generate its 20 bit physical
address. To do this, it combines contents of the instruction pointer register(offset address) with
the values in CS register(base address).
b) Data Segment Register: The DS register holds the starting 16 bit address of the data segment
(64 kb) where most of the datas are stored. The memory offset stored in the registers BX, SI,
and DI operate relative to data segment.
ity
st
c) Stack Segment Register: The SS register holds the starting 16 bit address of the stack segment
(64 kb). The stack is a section of memory set aside to store address and data while a subprogram
is executing.The SP and BP holds the offset address relative to the stack segment.
.c
d) Extra Segment Register: The ES Register holds the starting 16 bit address of the extra segment
(64 kb). The Extra Segment is generally used to make an additional lock of memory available
for data storage. The ES is extensively used in string instructions. It is used as the destination
segment, addressed by the combination of register ES:DI(here DI holds the offset address).
iii) Instruction Pointer Register: The IP always holds the offset address of the next instruction to
be executed. As the instruction is executed, IP is advanced to point the next instruction at the
next memory address. IP doesnt fully specify the address of the next instruction to be executed.
Page 8
10CS45
performs fetching of instruction. the execute phase performs the operation of string the computed
result at the destination .
The functional unit of the EU are
om
i) Control circuitry
ii) Arithmetic and logic unit (ALU)
gr
ou
p.
c
i)control circuitry: the control circuit of the EU directs all internal operation of the processors.
ii)Arithmetic and logic unit: the ALU performs 8-bit or 16-bit arithmetic operation such as
addition , subtraction, multiplication, division, and logical operation of the processor.
ud
en
ts
iii)general purpose register : the 8086 processor has four 16-bit GPRS. The GPRS can be used
to store the intermediate result instead storing it in memory ,because the access speed of data
from GPRS is more compared to memory location. we can use all GPRS for data transfers. The
GPRS are AX, BX, CX, and DX. We can access these register either 16-bit register (or) two 8bit registers Each GPRS have specific function.
ity
st
.c
CX (counter)register: CX register holds count value for loop an repeat instruction.CX Register
can be treated as two 8-bit register CH and CL.
DX (data) register: The DX is only register used as an I/O address pointer in the IN and OUT
instructions. It also involved in multiplication and division operation. DX register can be treated
as two 8 bit register DH and DL.
iv) Pointer and index registers: The 8086 processor has two 16 bit pointer, Stack Pointer (SP)
and Base Pointer (BP) and two 16 bit index registers, Source Index (SI) and Destination Index
(DI).
Stack Pointer (SP) Register: The SP register holds the offset address and always points to the top
of the stack relative to stack segment.
Page 9
10CS45
Base Pointer (BP) Register: The BP register holds the offset address relative to stack segment.
The physical address=SS*10h+SP (or BP).
om
Source Index (SI) Register: This register holds the offset address of the data relative to data
segment. In string instructions, SI is used as a pointer to source string element.
Destination Index (DI) Register: This register also holds the offset address of the data relative to
data segment. In string instructions, DI is used as a pointer to destination string element.
gr
ou
p.
c
v) Flag Register: The 16 bit flag register of the 8086 processor stores information about the
status of the processor and the status of the instruction executed most recently.
ud
en
ts
Conditional Flags: Carry flag (CF), Parity flag (PF), Auxiliary carry flag (AF), Zero flag (ZF),
Sign flag (SF), Overflow flag (OF), Control flags: Trap flag (TF), Interrupt flag (IF), Direction
flag (DF).U-Undefined.
3.c. Write 8086 assembly instruction which will perform the following operations:
Dec 2012 [05 marks]
ii)
iii)
iv)
ity
st
i)
Ans :
.c
i)
mul BL
ii)
mov AL,F3H
iii)
mov sp,bp
Mov CL,02
SHL AL,CL
Page 10
iv)
10CS45
mov CL,02
SHL AL,CL
Microprocessor:
om
.c
ity
st
ud
en
ts
gr
ou
p.
c
4.b. What is flag register? Explain the flag register format, in detail.
Page 11
10CS45
om
gr
ou
p.
c
The operand to be accessed is specified as residing in an internal register of 8086. Fig. below
shows internal registers, any one can be used as a source or destination operand, however only
the data registers can be accessed as either a byte or word.
Direct addressing mode :
ud
en
ts
The instruction Opcode is followed by an affective address, this effective address is directly used
as the 16 bit offset of the storage location of the operand from the location specified by the
current value in the selected segment register.
Register indirect addressing mode :
The EA is specified in either pointer (BX) register or an index (SI or DI) register. The 20 bit
physical address is computed using DS and EA.
ity
st
The EA is specified in either pointer (BX) register or an index (SI or DI) register. The 20 bit
physical address is computed using DS and EA.
.c
The string instructions automatically assume SI to point to the first byte or word of the source
operand and DI to point to the first byte or word of the destination operand. The contents of SI
and DI are automatically incremented (by clearing DF to 0 by CLD instruction) to point to the
next byte or word.
Page 12
10CS45
om
5.a Define a microprocessor. Explain the programming model of the 8086 through the CORE-2
microprocessor including the 64-bit extensions.
June 2014[06 marks]
.c
ity
st
ud
en
ts
gr
ou
p.
c
The integration of a whole CPU onto a single chip or on a few chips greatly reduced the cost of
processing power. The integrated circuit processor was produced in large numbers by highly
automated processes, so unit cost was low. Single-chip processors increase reliability as there are
many fewer electrical connections to fail. As microprocessor designs get faster, the cost of
Page 13
10CS45
manufacturing a chip (with smaller components built on a semiconductor chip the same size)
generally stays the same.
gr
ou
p.
c
om
Before microprocessors, small computers had been implemented using racks of circuit boards
with many medium- and small-scale integrated circuits. Microprocessors integrated this into one
or a few large-scale ICs. Continued increases in microprocessor capacity have since rendered
other forms of computers almost completely obsolete (see history of computing hardware), with
one or more microprocessors used in everything from the smallest embedded systems and
handheld devices to the largest mainframes and supercomputers.
5.b Explain in detail with a neat figure the working of the internal architecture of the 8086 MP
ud
en
ts
2) Execution Unit(EU)
Bus Interface Unit: The BIU sends out addresses, fetches instructions from memory, reads data from ports
and memory and writes data to ports and memory.
The functional parts of the BIU are:
i) Instruction Queue(IQ)
.c
ity
st
Page 14
10CS45
i) Instruction Queue: The Instruction Queue is of six bytes in length and is used to send up the execution
of programs by pre-fetching six instruction bytes in advance from memory.
om
The BIU and EU works parallel. The BIU fetches the instruction bytes while the EU is executing an
instruction.
gr
ou
p.
c
The process of pre-fetching the instruction in advance while EU is executing the current instruction is
known as pipelining.
ii)Segment Register: The BIIU contains 4 16 bit segment registers. They are:
a. Code Segment Register
b. Data Segment Register
c. Stack Segment Register
d. Extra Segment Register
ud
en
ts
These registers are used to store the 16 bit starting address of the four memory segment. The BIU
generates a 20 bit physical address using the segment and the offset component of an address.
a) Code Segment Register : Code Segment(64 kb) of memory contains instruction of the program. The
CS register holds the 16 bit starting address of this segment. To access the storage location of an
instruction in the active code segment, the 8086 must generate its 20 bit physical address. To do this, it
combines contents of the instruction pointer register(offset address) with the values in CS register(base
address).
ity
st
b) Data Segment Register: The DS register holds the starting 16 bit address of the data segment (64 kb)
where most of the datas are stored. The memory offset stored in the registers BX, SI, and DI operate
relative to data segment.
.c
c) Stack Segment Register: The SS register holds the starting 16 bit address of the stack segment (64 kb).
The stack is a section of memory set aside to store address and data while a subprogram is executing.The
SP and BP holds the offset address relative to the stack segment.
d) Extra Segment Register: The ES Register holds the starting 16 bit address of the extra segment (64 kb).
The Extra Segment is generally used to make an additional lock of memory available for data storage.
The ES is extensively used in string instructions. It is used as the destination segment, addressed by the
combination of register ES:DI(here DI holds the offset address).
iii) Instruction Pointer Register: The IP always holds the offset address of the next instruction to be
executed. As the instruction is executed, IP is advanced to point the next instruction at the next memory
address. IP doesnt fully specify the address of the next instruction to be executed.
The 20 bit physical address=base address*10h+offset address
Page 15
10CS45
om
gr
ou
p.
c
i)control circuitry: the control circuit of the EU directs all internal operation of the processors.
addition ,
ud
en
ts
ii)Arithmetic and logic unit: the ALU performs 8-bit or 16-bit arithmetic operation such as
subtraction, multiplication, division, and logical operation of the processor.
iii)general purpose register : the 8086 processor has four 16-bit GPRS. The GPRS can be used to store
the intermediate result instead storing it in memory ,because the access speed of data from GPRS is more
compared to memory location. we can use all GPRS for data transfers. The GPRS are AX, BX, CX, and
DX. We can access these register either 16-bit register (or) two 8-bit registers Each GPRS have specific
function.
ity
st
.c
CX (counter)register: CX register holds count value for loop an repeat instruction.CX Register can be
treated as two 8-bit register CH and CL.
DX (data) register: The DX is only register used as an I/O address pointer in the IN and OUT instructions.
It also involved in multiplication and division operation. DX register can be treated as two 8 bit register
DH and DL.
iv) Pointer and index registers: The 8086 processor has two 16 bit pointer, Stack Pointer (SP) and Base
Pointer (BP) and two 16 bit index registers, Source Index (SI) and Destination Index (DI).
Stack Pointer (SP) Register: The SP register holds the offset address and always points to the top of the
stack relative to stack segment.
Page 16
10CS45
Base Pointer (BP) Register: The BP register holds the offset address relative to stack segment. The
physical address=SS*10h+SP (or BP).
Source Index (SI) Register: This register holds the offset address of the data relative to data segment. In
string instructions, SI is used as a pointer to source string element.
om
Destination Index (DI) Register: This register also holds the offset address of the data relative to data
segment. In string instructions, DI is used as a pointer to destination string element.
gr
ou
p.
c
v) Flag Register: The 16 bit flag register of the 8086 processor stores information about the status of the
processor and the status of the instruction executed most recently.
ud
en
ts
Conditional Flags: Carry flag (CF), Parity flag (PF), Auxiliary carry flag (AF), Zero flag (ZF), Sign flag
(SF), Overflow flag (OF), Control flags: Trap flag (TF), Interrupt flag (IF), Direction flag (DF).UUndefined.
5.c Explain in detail the various bits of a flag register for 8086 MP
When a system is instructed to single-step, it will execute one instruction and then stop. The contents of
registers and memory locations can be examined; if they are correct, the system can be told to go on and
execute the next instruction. The Intel 8086 trap flag and type-1 interrupt response make it quite easy to
ity
st
implement a single-step feature in an 8086-based system. If the trap flag is set, the 8086 will
automatically do a type-1 interrupt after each instruction executes. When the 8086 does a type-1 interrupt,
.c
Page 17
10CS45
Unit-2
1.a. Explain how virtual address is translated into physical address with a neat diagram.
ud
en
ts
gr
ou
p.
c
om
The memory paging mechanism located within the 80386 and above allows any physical
memory location to be assigned to any linear address. The linear address is defined as the
address generated by a program. With the memory paging unit, the linear address is invisibly
ity
st
translated into any physical address. This allows an application written to function at a specific
address to be relocated through the paging mechanism. It also allows memory to be placed into
areas where no memory exists. An example is the upper memory blocks provided by
EMM386.EXE. The EMM386.EXE program reassigns extended memory, in 4K blocks, to the
.c
system memory between the video BIOS and the system BIOS ROMS to provide upper memory
blocks. Without the paging mechanism, the use of this area of memory is impossible.
1.b. Identify the addressing modes of the following instructions and explain them briefly.
June/July 13 [06 marks]
Page 18
10CS45
1.c. Briefly explain the flat mode memory model with a neat diagram.
ud
en
ts
gr
ou
p.
c
om
2.a. Illustrate the memory paging mechanism in the 80386 mp with suitable schematic.
Dec 13/Jan 14 [06 marks]
The memory paging mechanism located within the 80386 and above allows any physical
memory location to be assigned to any linear address. The linear address is defined as the
ity
st
address generated by a program. With the memory paging unit, the linear address is invisibly
translated into any physical address. This allows an application written to function at a specific
address . Paging Registers The paging unit is controlled by the contents of the microprocessor's
control registers. for the contents of control registers CRO through CR3. Note that these registers
.c
are only available to the 80386 through the Pentium Pro microprocessors. Also note that the
Pentium/ Pentium Pro contain an additional control register labeled CR4 that controls extensions
provided in the PentiumJPentium Pro microprocessors. One of these features is a 4M byte page
Page 19
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
2.b. briefly explain various addressing modes of 8086 with suitable examples.
.c
ity
st
Page 20
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Page 21
10CS45
MOV RAX,RCX
MOV ESP,[BSP]
om
MOV AX,2341H
gr
ou
p.
c
MOV CS,AX
ud
en
ts
3.a. State and explain instruction formats of 8086. Also generate the op-code for following
instructions.
Dec 2012 [10 marks]
ity
st
1. The upper 6 bits of the 1st byte are an opcode which indicates the general type of instruction.
A 6 bit opcode for the MOV register memory to from register instruction is find it to be 100010.
.c
2. The D bit is used to indicate whether the data is more to register (or) from the register. If the
instruction moving the data to register then said D=1 If the instruction moving the data from
register then said D=0
3. W bit indicates whether a byte or a word is being moved. If you are moving a byte make W=0,
If you are moving a word make W=1.
4. The 3 bit register field is used to indicate which register is involved in instruction and find the
equivalent binary code of the register fro the table.
5. The 2 bit mode field is used to specify the derived addressing mode
* If the instruction contain both the operands are register then set MOD=11.
* If the instruction having 8 bit displacement then MOD=01
Page 22
10CS45
om
i) MOV AX,BX
gr
ou
p.
c
ii)MOV 46h[BP], DX
i) PROC & ENDP ii) PUBLIC & EXTRN iii) MACRO & ENDM iv) ASSUME
v) SEGMENT, ENDS vi) PROC & ENDP
ud
en
ts
The PROC directive is used to identify the start of a procedure. The PROC directive
follows a name you give the procedure. After the PROC directive the term near or the term far is
used to specify the type of the procedure.
Syntax: procedure name PROC
The PROC directive is used with the ENDP directive to bracket a procedure.
ENDP: End of procedure
ity
st
This directive is used along with the name of the procedure to indicate the end of a procedure to
the assembler. The directive ENDP & PROC must lose the procedure code.
Syntax: procedure name ENDP
.c
PUBLIC : The directive public informs the assembler that are specified variable or segment can
be accessed from other program modules. It helps in managing the multi program modules by
sharing the global variable is procedure.
Syntax: PUBLICvariable 1, variable 2, .., variable n
Ex: PUBLIC XMAX, YMAY
iii) MACRO and ENDM
Page 23
10CS45
The macro definition directives are used to define macro construction and macro function
MACRO. The directive MACRO consists of the name of a macro followed by the keyword
MACRO and macro argument if any.
om
gr
ou
p.
c
The directive ENDM inform the assembler the end of the macro.
ud
en
ts
FORM: ENDM
Ex: pointing macro
ENDM
iv) ASSUME
ity
st
It directly tells the assembler that names have been chosen for the code, data, extra and stack
segment. When the program is loaded, the processor segment register to be pointed to the
respective logical segment.
Syntax: ASSUME SEG, REG: SEGMENT_NAME
.c
ASSUME ES:_Extra
Where assume is an assembler directive segment register. Segment it can be any valid symbol
except the resolved keyword.
v) SEGMENT, ENDS
SEGMENT: This directive is used to indicate the beginning of a logical segment.
The directive segment follows the name of the segment.
Ex: DATA SEGMENT
Page 24
10CS45
:
DATA ENDS
The directive segment & ends enclose the segment data code(or) stack of the program.
om
ENDS: Refers to the end of segment. This directive informs the assembler the and of the
segment.
gr
ou
p.
c
ud
en
ts
This instruction divides an unsigned word by a byte (or) to divide an unsigned double word(32
bits) by a word. When dividing a word by a byte, the word must be in AX register. After the
division AL will contain a 8 bit quotient & AH will contain an 8 bit remainder.If an attempt is
made to divide by 0/ the quotient is too large to fit in AL(i.e>FFh) then 8086 automatically
execute a type 0 interrupt. Divide a double word by a word. i.e, when a double word is divided
by a word, the MSB of the double word must be in DX and the LSB must be in AX.AX contains
quotient and DX-16 bit remainder
Ex: DIV CL : Word in AX/ byte in CL
ii) XLAT: Translate a byte.
ity
st
*The XLATB instruction is used to translate a byte from one code to another code.
*The instruction replaces a byte in the AL register with a byte pointed to BX in a lookup table in
Memory.
.c
*Before the XLATB executed, the lookup table containing the values for the new code must be
put in memory & the offset of the starting address of the lookup table is loaded in BX.
Page 25
10CS45
gr
ou
p.
c
om
Numerical data coming into a computer from a terminal is usually in ASCII code. In this code,
the numbers 0 to 9 are represented by the ASCII codes 30h to 39h. The 8086 allows you to add
the ASCII codes for two decimal digits without marking off the 3 in the upper nibble of each.
The addition of two one digit ASCII coded nos will not result an useful data. AAA instruction is
to executed after the addition so that we get unpack BCD result.
Ex: ADD AL, BL: result: AL=0110 1110=6EH, which is incorrect BCD.
The AAA instruction works only on the AL register. The AAA instruction updates AF and CF
but OF, PF, SF and ZF are left undefined.
iv) XCHG: Exchange instruction
ud
en
ts
Here the contents of source and destination are exchanged both the operands can be registers but
not memory locations.
Ex: XCHG BX, CX
XCHG AX, DX
ity
st
.c
4.a. Write and explain instruction template for MOV instruction. Also generate opcode for
following instructions: the opcode for MOV is
Jan 2015 [15 Marks]
1 0 0 0 1 0
i)
MOV CL,[BX]
ii)
MOV CS,[BX],DL
iii)
MOV 43H[SI[,DH
iv)
MOV CX,[437A]H
(10marks)
Page 26
10CS45
Ans:
(a) Instruction Templates
All instruction have its own hexadecimal codes it is available in one page chart.
om
gr
ou
p.
c
Source ->can be anyone of eight 16- bit regiters or anyone of memory location specified by (24
memory addressing modes).
ud
en
ts
There is large number of possible codes for the 8086 instruction it is not possible to list all in a
simple table.
.c
ity
st
Page 27
10CS45
mov reg,reg
mov reg,memory
mov memory,reg
gr
ou
p.
c
That is
om
The upper 6 bits of the first byte are an opcode which indicates the general type of instruction.
The D bit in the first byte of the instruction is used to indicate whether the data is movad
from the register on to the register.
ud
en
ts
word movement.
ity
st
In mov instruction, one operand must always be a register(reg). so 3-bits in the second
byte are (reg) used tp indicate which register is involved.
code
W=1
W=0
.c
Register
AX
000
BX
011
CL
CX
001
DL
DX
010
AH
SP
AL
BL
BH
CH
D1
BP
100
111
101
Page 28
110
SEG.REG
CODE
CS
01
DS
11
ES
00
SS
10
om
S1
gr
ou
p.
c
DH
10CS45
Remember that in a mov instruction one operand must be a register other than one is may be a
register/ member location.
ud
en
ts
The 2-bit field labled MOD is used to specify the addressing mode.
.c
ity
st
The 3-bit field labeled R/M is used as pattern for each of the 32 possible addressing modes.
R/m -> put the 3-bit code for the other reg.
Page 29
10CS45
If the other operand is a memory location, then effective address( offset reg) can be
specified directly in the instruction.
It can be a reg or sem of 2 reg and a displacement.
om
gr
ou
p.
c
R/m=choose the R/m bits which corresponds to the registers containing the EA.
Here R/m =111.
i)
Mov CL,[BX]
opcode
100010
ud
en
ts
mov reg,memory
W MOD
00
8A0FH
REG
001
R/m
111
ity
st
Find 3-bit code for the register CL and replace it in REG field, ie 001.
.c
Here [BX], read mod-bit pattern from the top of the column. Here MOD=00.
Here R/m=111.
Assemble all these bits in the mov temolate to genarate binary code for mov CL,[BX]
ie. 100010 10
0000
1111
Page 30
ii)
10CS45
Mov cs:[BX],DL
This copies a byte from the DL register to a memory location EA=[BX] and PA= DS*10h+BX
(normally this happens).
om
In this instruction
PA=CS*10h+BX.
gr
ou
p.
c
When an instruction containing segment override prefix is coded, an 8 bit code for the
segment override prefix is put in memory before the code for rest of the instruction.
The code byte for the segment override prefix is 001xx110.
Insert 2 bit code in place of xs to indicate which segment base you want the EA to be added to.
ES=00
MOV CS:[BX],DL
ud
en
ts
CS=01
SS=10
DS=11
Sop
00101110
CS
IP
SP,BP
D1
ES
BX,S1,D1
.c
DS
SS
offset reg
ity
st
Segment reg
1000100000010111
iii)mov 43h[SI],DH
100010 0
110
100
Page 31
10CS45
om
iv) DB
gr
ou
p.
c
4.b. what is an assembler directive? Explain the following assembler directive with
example:
Jan 2015 [10 Marks]
Ans: assembler directive: which are translated to machine code by the assembler.
PUBLIC- indicates that the given segment will be combined with other segment
which have the same name..
ud
en
ts
i)
ity
st
CODE SEGMENT
----------------------
.c
----------------------
ii)
CODE ENDS
PROC:
The directive PROC indicates the bebginning of a procedure. The directive PROC follows the
name of a procedure.
Type of procedure
Page 32
10CS45
(1) Near
(2) Far
General form
om
gr
ou
p.
c
Ex:
The above statement defines the procedure HEX2ASC as neas type. It can only be called within
a segment.
iii)
MACRO:
General form:
ud
en
ts
The directive MACRO informs the assembler the begining of a macro. It consists of the name of
a macro followed by the keyword MACRO and the macro arguments if any.
Int 21h
iv)
.c
ENDM
ity
st
DB:
It is used to define a byte type variable, it can be used to definr a single or multiple byte
variables. Range of values 0-255 for unsigned numbers. -128 127 for signed numbers.
General form:
Name of variable DB initialization value(,s)
Ex: TOTAL DB 0
The above statement informs the sassembler to resreve one byte of memory for a variable named
TOTAL and initialize with value zero during execution of the program.
Page 33
10CS45
5.a Explain with an example why and how a 20 bit address is generated in 8086
gr
ou
p.
c
om
The 80386 provides a one Mbyte + 64 Kbyte memory space for an 8086 program. Segment relocation is
performed as in the 8086: the 16-bit value in a segment selector is shifted left by four bits to form the
base address of a segment. The effective address is extended with four high order zeros and added to
the base to form a linear address as Figure 14-1 illustrates. (The linear address is equivalent to the
physical address, because paging is not used in real-address mode.) Unlike the 8086, the resulting linear
address may have up to 21 significant bits. There is a possibility of a carry when the base address is
added to the effective address. On the 8086, the carried bit is truncated, whereas on the 80386 the
carried bit is stored in bit position 20 of the linear address.
ity
st
ud
en
ts
Unlike the 8086 and 80286, 32-bit effective addresses can be generated (via the address-size
prefix); however, the value of a 32-bit address may not exceed 65535 without causing an
exception. For full compatibility with 80286 real-address mode, pseudo-protection faults
(interrupt 12 or 13 with no error code) occur if an effective address is generated outside the range
0 through 65535.
.c
5.b Explain any five addressing modes in detail with examples in 8086
Page 34
10CS45
om
gr
ou
p.
c
The instruction Opcode is followed by an affective address, this effective address is directly used as the
16 bit offset of the storage location of the operand from the location specified by the current value in the
selected segment register.
The EA is specified in either pointer (BX) register or an index (SI or DI) register. The 20 bit physical
address is computed using DS and EA.
Register indirect addressing mode :
ud
en
ts
The EA is specified in either pointer (BX) register or an index (SI or DI) register. The 20 bit physical
address is computed using DS and EA.
String addressing mode:
The string instructions automatically assume SI to point to the first byte or word of the source operand
and DI to point to the first byte or word of the destination operand. The contents of SI and DI are
automatically incremented (by clearing DF to 0 by CLD instruction) to point to the next byte or word.
I/O mode (direct) :
ity
st
.c
Page 35
10CS45
Unit-3
gr
ou
p.
c
om
A 32-bit offset allows segments of up to 4G bytes in length. Notice that in real-mode the only available
instruction mode is the 16-bit mode (during which accessing 32-bit registers requires the prefix 66h).
However, the segment base address calculation is different in protected mode. Instead of appending a 0 at
the end of the segment register contents to create a segment base address (which gives a 20-bit physical
address), the segment register contains a selector that selects a descriptor from a descriptor table. The
descriptor describes the memory segment's location,length, and access rights. This is similar to selecting
one card from a deck of cards in one's pocket. Because the segment register and offset address still
create a logical memory address, protected mode instructions are the same as real mode instructions. In
fact, most programs written to function in the real mode will function without change in the protected
mode.
1. a. Write an ALP using 8086 instructions to search a number placed in location NUM,in
an array of ten numbers placed at location ARRAY.
June/July 13 [8 marks]
.c
ity
st
ud
en
ts
dec si
add si, si
cmp cx, array [si] ; CX>=ARRAY[SI]
jae bigger ; jump to BIGGER if value is above or equal
dec ax ; subtracts 1 from the destination AX, high = mid-1
mov dx, ax
jmp again
bigger: je success ; jump to SUCCESS if the value is equal
Page 36
gr
ou
p.
c
June/July 13 [8 marks]
ud
en
ts
a)
b)
c)
d)
om
MICROPROCESSORS
LEA
The LEA instruction loads a 16- or 32-bit register with the offset address of the data
specified by the operand(source).
As the first example in Table shows, the operand address NUMB is loaded into register
AX, not the contents of address NUMB.
ity
st
XCHG
The XCHG (exchange) instruction exchanges the contents of a register with the contents
of any other register or memory location.
The XCHG instruction cannot exchange segment register or memory-to-memory data.
Exchanges are byte-, word-, or double word-sized (80386 and above)
Table shows some examples of the XCHG instruction.
XCHG AL,[DI] instruction is Identical to the XCHG [DI],AL LAHF and SAHF
.c
MUL
Page 37
10CS45
numbers are multiplied, a 64-bit product is generated. In the 64-bit mode of the Pentium
4, two 64-bit numbers are multiplied to generate a 128-bit product.
1.c. Give the state of all the status flags bits after the addition of 30a2 with f01ch.
gr
ou
p.
c
om
June/July 13 [8 marks]
2.a. Write and explain machine code for instruction MOV DL,[BX]
ity
st
ud
en
ts
PUSHF
.c
PUSHF MOVS
MOVS
Page 38
One of the more useful string data transfer instructions is MOVS, because it transfers
data from one memory location to another.
This is the only memory-to-memory transfer allowed in the 8086 Pentium 4
microprocessors.
The MOVS instruction transfers a byte, word, or double word from the data segment
location addressed by SI to the extra segment location addressed by DI.
As with the other string instructions, the pointers then are incremented or decremented, as
dictated by the direction flag.
om
10CS45
gr
ou
p.
c
LAHF
The LAHF instruction transfers the rightmost 8 bit s of the flag register into the AH register.
The SAHF instruction transfers the AH register into the rightmost 8 bits of the flag register.
Div
ud
en
ts
XCHG
ity
st
The XCHG (exchange) instruction exchanges the contents of a register with the contents
of any other register or memory location.
The XCHG instruction cannot exchange segment register or memory-to-memory data.
Exchanges are byte-, word-, or double word-sized (80386 and above)
Table shows some examples of the XCHG instruction.
XCHG AL,[DI] instruction is Identical to the XCHG [DI],AL LAHF and SAHF
.c
2.c. what is segment override prefix? Illustrate the same with an example.
The segment override prefix, which may be added to almost any instruction in any memory
addressing mode, allows the programmer to deviate from the default segment. The segment
override prefix is an additional byte that appends the front of an instruction to select an alternate
segment register. About the only instructions that cannot be prefixed are the jump and call
instructions that must use the code segment register for address generation. The segment override
Page 39
10CS45
is also used to select the FS and as segments in the 80386 through the Pentium Pro
microprocessors. For example, the MOV AX,[DI] instruction accesses data within the data
segment by default. If required by a program, this can be changed by prefixing the instruction.
jz last
MOV AX, n
Dec BX
Call fact
.c
MOV BX, AX
ity
st
cmp n,0
ud
en
ts
res dw 1
.code
gr
ou
p.
c
om
Suppose that the data are in the extra segment instead of the data segment. This instruction
MOV res, AX
Fact proc
Cmp BX, 1
Page 40
10CS45
Jz next
Mul BX
Dec BX
om
Cal fact
Fact endp
End
gr
ou
p.
c
Next: ret
3.b. Explain the types of program execution transfer instruction (Branch instructions) with
examples.
Dec 2012 [10 marks]
A branch instruction transfer control from the normal sequence of instruction execution to the
specified destination/ target instruction. These instructions are broadly classified into two groups:
ud
en
ts
The Unconditional branch instructions transfer control to the target location. The target operand
may be specified in the instruction itself.The conditional branch instructions transfer control to
the target location if some specified condition is met (or) satisfied.
ity
st
.c
*Short jump: It is a two bytes instruction which allows jumps to memory location within +127 to
-127 bytes from the address following the jump.
This jump is also called as relative jumps. The target address is computed by adding IP & the
sign extended displacement.
Jmp instruction:
Page 41
10CS45
om
IP-(target-offset)
gr
ou
p.
c
*Short jump:
Syntax: Jmp short label
Ex: JMP SHORT NEXT1
*Near Jump:
ity
st
ud
en
ts
If the target I in the same code segment as the instruction jump if requires only the IP to be
changed to transfer the target location such as jump is called Intra segment jumps.
.c
Near Jumps: It allows a branch within +_32 kb anywhere in the correct code segment. i. e the
target can be anywhere in the correct code segment. The target address is computed by adding
IP+ displacement specified in the instruction.
Far jump:
It allows a jump to any memory location within the real memory system. So near and short jump
called intra segment jump & far jump called inter segment jump.
Inter Segment Jumps:
Page 42
10CS45
This instruction transfer control to the target in a different code segment. This is performed by
loading CS with segment no in which target exists & IP with offset address of the instruction to
which control transforms into the new code segment.
om
gr
ou
p.
c
This transfer control to different CS. It is performed by loading IP & CS with four consecutive
memory locations. The new value for IP is in the 1st two memory locations & the new value of
CS is in the next two memory locations.
Ex: Jmp DWORD PTR [SI]
b)Conditional jumps and sets:
*These Jumps are always short jumps in the 8086/80186,80286 near jumps in 80386 & above.
ud
en
ts
*the conditional jump instructions tests the following flag bits Sign(S), Carry(C), Parity(P) &
Overfiow(O).
*If the condition under test is true, then branch occurs to the specified label
*If the condition is false, the next instruction is sequentially taken &executes.
*The operation of most conditional jump instructions is used after compare (or) subtraction
Instructions.
ity
st
.c
4.a. What is the need for unconditional jump instructions, explain different conditional
jump supported by 8086.
Jan 2015 [10 marks]
Page 43
10CS45
JNZ/JNE Label
Transfer execution control to address Label, if ZF=0
JS Label
om
ud
en
ts
gr
ou
p.
c
JNS Label
JNP Label
JB Label
ity
st
.c
JCXZ Label
Page 44
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
5.a Write 8086 ALP to add 10 non-negative data items using string instructions.
ity
st
.model small
.stack 100h
.data
str1 db 'Enter String ','$'
str2 db 50 dup('$')
str3 db 0dh, 0ah, '$'
.code
.c
main proc
mov ax,@data
mov ds,ax
mov ah,09h
lea dx,str1
int 21h
mov ah,0ah
lea dx,str2
int 21h
Page 45
10CS45
int 21h
mov ah,09h
lea dx,str2+2
int 21h
om
int 21h
mov ah,4ch
int 21h
main endp
LAMF
XCHG
LEA
PUSH AX
LEA
SYNTAX: LEA REGISTER, SOURCE
The LEA instruction loads a 16- or 32-bit register with the offset address of the data specified by
the operand(source).
As the first example in Table shows, the operand address NUMB is loaded into register AX, not
the contents of address NUMB.
XCHG
The XCHG (exchange) instruction exchanges the contents of a register with the contents of any
other register or memory location.
The XCHG instruction cannot exchange segment register or memory-to-memory data.
Exchanges are byte-, word-, or double word-sized (80386 and above)
Table shows some examples of the XCHG instruction.
XCHG AL,[DI] instruction is Identical to the XCHG [DI],AL LAHF and SAHF
Compare.
ity
st
ud
en
ts
gr
ou
p.
c
end main
.c
Algorithm:
operand1 - operand2
result is not stored anywhere, flags are set (OF, SF, ZF, AF, PF, CF) according to result.
C Z S
Example:
MOV AL, 5
MOV BL, 5
CMP AL, BL ; AL = 5, ZF = 1 (so equal!)
RET
O P A
r r r r r r
Page 46
10CS45
om
AH = flags register
gr
ou
p.
c
AH bit: 7 6 5 4 3 2 1 0
[SF] [ZF] [0] [AF] [0] [PF] [1] [CF]
bits 1, 3, 5 are reserved.
C Z S O P A
unchanged
LDS REG, memory Load memory double word into word register and DS.
Algorithm:
ud
en
ts
m DW 1234h
DW 5678h
END
ity
st
RET
.c
unchanged
Note: PUSH immediate works only on 80186 CPU and later!
Algorithm:
SP = SP - 2
SS:[SP] (top of the stack) = operand
Example:
MOV AX, 1234h
PUSH AX
Page 47
10CS45
POP DX ; DX = 1234h
RET
C Z S O P A
om
unchanged
PUSHA No operands Push all general purpose registers AX, CX, DX, BX, SP, BP, SI, DI in the stack.
Original value of SP register (before PUSHA) is used.
Note: this instruction works only on 80186 CPU and later!
gr
ou
p.
c
Algorithm:
PUSH AX
PUSH CX
PUSH DX
PUSH BX
PUSH SP
PUSH BP
PUSH SI
PUSH DI
C Z S O P A
ud
en
ts
unchanged
DQ
ity
st
DQ: Define Quadword: This directive is used to direct the assembler to reserve 4 words (8bytes) of
memory for the specified variable and may initialize it with the specified values
END: END Of Program: The END directive marks the end of an assembly language program.
ENDP: END Of Procedure: The ENDP directive is used to indicate the end of a procedure.
.c
EVEN: Align On Even Memory Address: The EVEN directive updates the location counter to the next
even address, if the current location counter contents are not even, and assigns the following routine or
variable or constant to that address. If the content of the location counter is already even, then the
procedure will be assigned with the same address.
ORG: Origin: The ORG directive directs the assembler to start the memory allotment for the particular
segment, block or code from the declared address in the ORG statement
.PROC: Procedure: The PROC directive marks the start of a named procedure in the statement. Also the
types FAR and NEAR specifies the type of the procedure.
TYPE: The TYPE operator directs the assembler to decide the data type of the specified label and
replaces the TYPE label by the decided data type.
Page 48
10CS45
Unit-4
1.a. Explain the following assembler directives with examples. June/July 13[8 marks]
i) DB
iv) SEGMENT
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
i) The following are some of the data directives used to define different types of
variables used in the data segment:
DB
Define Byte[8 bit integer]
DW Define Word [16-bit signed integer
DD
Define Double Word [32-bit signed integer or real number]
DQ
Define Quad Word [64-bit signed integer or real number]
ii) Is used to tell assembler that the name or labels following the directive are in some other
assembly module.
For Eg, if a procedure is called which is in a program module assembled at
different time, assembler must know that the procedure is external.
The assembler will then put information in the object code file so that the linker
can connect the two modules together.
For a reference to the external named variable, one must specify the type of the
variable Eg: EXTRN DIVISOR: WORD
For a reference it is necessary to specify whether the label is near or far.
Eg: EXTRN SMART_DIVIDE:FAR ; tells the assembler that SMART_DIVIDE
is a label of type far in another assembly module
Names and labels referred to as external in one module must be declared public
iii) PROC
Is used to identify the start of a procedure.
Proc directive follows a name given to the procedure.
After proc directive, the term near or far is used to specify the type of the
procedure.
Eg: FACT PROC NEAR
iv)SEGMENT
Is used to indicate the start of a logical segment.
Preceding the SEGMENT directive is the name of the segment given by user.
Macro
RET instruction
Machine code is generate for instructions each Machine code for instruction is put only once
time when macro is called
in the memory
Page 49
10CS45
1.c. Write an ALP using 8086 instructions to reverse a four digit number
om
Parameter passed as part of statement which Parameters can be passed in registers memory
call macros
locations are stack.
gr
ou
p.
c
.c
ity
st
ud
en
ts
SUCCESS: LEA DX, MSG1 ; loads the EA of operand msg1 to the DX register
MOV AH, 09H
INT 21H
EXIT: MOV AH, 4CH ; exit to DOS function, terminate the process
Page 50
10CS45
INT 21H
END ; end of the program
2.a. Explain with an example how multiple if then else statement can be implemented using
ALP
Dec 13/Jan 14[10 marks]
om
The IF and ENDIF statements allow portions of the program to assemble if some condition is
met. Otherwise, the statements between IF and ENDIF do not assemble. shows how the IF,
gr
ou
p.
c
ELSE, and ENDIF statement are used to conditionally assemble values for the width and length
of paper in a program. Note that TRUE and FALSE are defined as 1 and O. This is important
because these values are not predefined by the assembler. Next, the width and length of the paper
are adjusted by using TRUE and FALSE statements. This can be expanded to ask an entire series
ity
st
ud
en
ts
2.b. Differentiate between short, near and far jump instructions with two examples of each
Dec 13/Jan 14 [10 marks]
.c
Short Jump. Short jumps are called relative jumps because they can be moved, along with their
related software, to any location in current code segment without a change. This is because the
jump address is not stored with the opcode. Instead of a jump address, a distance or displacement
follows the opcode. The short jump displacement is a distance represented by a I-byte signed
number whose value ranges between +127 and -128
Near Jump. The near jump is similar to the short jump except that the distance is farther. A near
jUl11jJ passes control to an instruction in the current code segment located within 32K bytes
from the near jump instruction or 2G in the 80386 and above operated in protected mode. The
near jump is a 3-byte instruction that contains an opcode followed by a signed 16-bit displacernc
Page 51
10CS45
rt. In the 80386 through the Pentium Pro processors, the displacement is 32-bits and the near is 5
bytes long. The signed displacement adds to the instruction pointer (IP) to generate the jump
address. Because the signed displacement is in the range of 32K
om
Far Jump. A far jump instruction (see Figure 6-4) obtains a new segment and offset address to
accomplish the jump. Bytes 2 and 3 of this 5-byte instruction contain the new offset address, and
bytes 4 and 5 contain the new segment address.
gr
ou
p.
c
Procedure
RET instruction
ud
en
ts
Machine code is generate for instructions each Machine code for instruction is put only once
time when macro is called
in the memory
With macro more memory is required
Parameter passed as part of statement which Parameters can be passed in registers memory
call macros
locations are stack.
ity
st
.c
REP is a prefix which is written before one the string instructions. It will cause the CX register to
be determined and the string instruction to be repeated until CX=0. The instruction REP MOCSB
, for example will continue to copy string bytes until the number of bytes loaded into CX has
been copoed.
3.c. Explain the sequence of operation that takes place when a procedure is called and
returned form procedure base to calling program with block diagram.
Ans:
Main Program
:
Page 52
10CS45
:
IP
PUSH Var1
Var2
om
PUSH Var2
Var1
SP before PUSH Var1
gr
ou
p.
c
CALL Compute
:
COMPUTE
Subroutine
PROC
:
IP
Var2
ity
st
RET 0004H
ENDP
.c
COMPUTE
Near
SP if RET is executed
:
Var1
ud
en
ts
4.a. Write an assembly level program to cheek a given string is palindrome or not.
.MODEL SMALL
.DATA
STR DB 'MALAYALAM$'
STRLEN DW ($-STR-1)
Page 53
10CS45
om
.CODE
MOV AX,@DATA
gr
ou
p.
c
MOV DS,AX
MOV ES,AX
MOV CX,STRLEN
LEA SI,STR
LEA DI,REVSTR
DEC DI
BACK:MOV AL,[SI]
MOV [DI],AL
DEC DI
LOOP BACK
ity
st
INC SI
ud
en
ts
ADD DI,CX
MOV CX,STRLEN
.c
LEA DI,REVSTR
LEA SI,STR
CLD
REPE CMPSB
JCXZ SUCCESS
LEA DX,MSG2
MOV AH,09H
Page 54
10CS45
INT 21H
JMP EXIT
SUCCESS:LEA DX,MSG1
om
MOV AH,09H
INT 21H
gr
ou
p.
c
EXIT:MOV AH,4CH
INT 21H
END
Re Entrant Procedure:
ud
en
ts
ity
st
.c
Page 55
10CS45
x86 assembly language is a family of backward-compatible assembly languages, which provide some
level of compatibility all the way back to the Intel 8008. x86 assembly languages are used to produce
object code for the x86 class of processors. Like all assembly languages, it uses short mnemonics to
represent the fundamental instructions that the CPU in a computer can understand and follow. Compilers
om
sometimes produce assembly code as an intermediate step when translating a high level program into
machine code. Regarded as a programming language, assembly coding is machine-specific and low level.
Assembly languages are more typically used for detailed and time critical applications such as small real-
gr
ou
p.
c
Data swap
Exchange.
The xchg instruction swaps the src operand with the dest operand. It's like doing three move
operations: from dest to a temporary (another register), then from src to dest, then from the temporary to
src, except that no register needs to be reserved for temporary storage.
ud
en
ts
If one of the operands is a memory address, then the operation has an implicit LOCK prefix, that is, the
exchange operation is atomic. This can have a large performance penalty.
It's also worth noting that the common NOP (no op) instruction, 0x90, is the opcode for
xchgl %eax, %eax.
Compare and exchange.
The cmpxchg instruction has two implicit operands AL/AX/EAX(depending on the size of arg1) and
ity
st
ZF(zero) flag. The instruction compares arg1 to AL/AX/EAX and if they are equal sets arg1 to arg2
and sets the zero flag otherwise it sets AL/AX/EAX to arg1 and clears the zero flag. Unlike xchg there
is not an implicit lock prefix and if the instruction is required to be atomic then lock must be prefixed.
Move sign extend.
.c
The movs instruction copies the src operand in the dest operand and pads the remaining bits not
Move byte
The movsb instruction copies one byte from the memory location specified in esi to the location
specified in edi. If the direction flag is cleared, then esi and edi are incremented after the operation.
Otherwise, if the direction flag is set, then the pointers are decremented. In that case the copy would
happen in the reverse direction, starting at the highest address and moving toward lower addresses until
ecx is zero.
Page 56
10CS45
5.b Explain the the following instruction with examples any four
June 2014[08
marks]
RCL
Example:
MOV AL, 0Fh ; AL = 0Fh (15)
DAA
; AL = 15h
RET
C Z S O P A
ity
st
r r r r r r
ud
en
ts
om
ADC SHR
gr
ou
p.
c
DAA MUL
MUL REG
memory
Unsigned multiply.
.c
Algorithm:
Example:
MOV AL, 200 ; AL = 0C8h
MOV BL, 4
MUL BL
; AX = 0320h (800)
RET
C Z S O P A
r ? ? r ? ?
CF=OF=0 when high section of the result is zero.
Page 57
10CS45
om
Algorithm:
operand1 = operand1 + operand2 + CF
gr
ou
p.
c
Example:
STC
; set CF = 1
MOV AL, 5 ; AL = 5
ADC AL, 1 ; AL = 7
RET
C Z S O P A
ud
en
ts
r r r r r r
memory, CL
REG, CL Shift operand1 Right. The number of shifts is set by operand2.
Algorithm:
ity
st
Shift all bits right, the bit that goes off is set to CF.
Zero bit is inserted to the left-most position.
Example:
MOV AL, 00000111b
SHR AL, 1
; AL = 00000011b, CF=1.
r r
.c
RET
C O
OF=0 if first operand keeps original sign. STC No operands Set Carry flag.
Page 58
10CS45
shift all bits left, the bit that goes off is set to CF and previous value of CF is inserted to the right-most
position.
gr
ou
p.
c
r r
om
Example:
STC
; set carry (CF=1).
MOV AL, 1Ch
; AL = 00011100b
RCL AL, 1
; AL = 00111001b, CF=0.
RET
C O
5.c Explain the different types of jump and cell instructions of 8086
program flow control
unconditional jumps
ud
en
ts
controlling the program flow is a very important thing, this is where your program can make decisions
according to certain conditions.
The basic instruction that transfers control to another point in the program is JMP.
The basic syntax of JMP instruction:
JMP label
.c
label1:
label2:
a:
ity
st
To declare a label in your program, just type its name and add ":" to the end, label can be any
character combination but it cannot start with a number, for example here are 3 legal label
definitions:
Label can be declared on a separate line or before any other instruction, for example:
x1:
MOV AX, 1
x2: MOV AX, 2
here's an example of JMP instruction:
org 100h
Page 59
10CS45
mov ax, 5
mov bx, 2
; set ax to 5.
; set bx to 2.
; go to 'calc'.
; go to 'stop'.
gr
ou
p.
c
; add bx to ax.
; go 'back'.
stop:
ret
om
jmp calc
ud
en
ts
Of course there is an easier way to calculate the some of two numbers, but it's still a good
example of JMP instruction.
As you can see from this example JMP is able to transfer control both forward and backward. It
can jump anywhere in current code segment (65,535 bytes).
Unlike JMP instruction that does an unconditional jump, there are instructions that do a
conditional jumps (jump only when some conditions are in act). These instructions are divided in
three groups, first group just test single flag, second compares numbers as signed, and third
compares numbers as unsigned.
ity
st
Description
Condition
Opposite
Instruction
JZ , JE
ZF = 1
JNZ, JNE
JC , JB, JNAE
CF = 1
JS
Jump if Sign.
SF = 1
JNS
JO
Jump if Overflow.
OF = 1
JNO
JPE, JP
PF = 1
JPO
JNZ , JNE
ZF = 0
JZ, JE
JNC , JNB,
CF = 0
.c
Instruction
Page 60
10CS45
Equal).
JNS
SF = 0
JS
JNO
OF = 0
JO
JPO, JNP
PF = 0
JPE, JP
gr
ou
p.
c
om
JAE
as you may already notice there are some instructions that do that same thing, that's correct, they even are
assembled into the same machine code, so it's good to remember that when you compile JE instruction you will get it disassembled as: JZ, JC is assembled the same as JB etc...
different names are used to make programs easier to understand, to code and most importantly to
remember. very offset dissembler has no clue what the original instruction was look like that's why it uses
the
most
common
name.
ud
en
ts
if you emulate this code you will see that all instructions are assembled into JNB, the operational code
(opcode) for this instruction is 73h this instruction has fixed length of two bytes, the second byte is
number of bytes to add to the IP register if the condition is true. because the instruction has only 1 byte to
keep the offset it is limited to pass control to -128 bytes back or 127 bytes forward, this value is always
signed.
.c
mov ax, 4
a: mov ax, 5
ret
ity
st
jnc a
jnb a
jae a
Page 61
10CS45
Unit-5
1.a. What is inline assembly? Explain its need.
June/July 13 [6 marks]
An assembler creates object code by translating assembly instruction mnemonics into opcodes,
om
and by resolving symbolic names for memory locations and other entities. The use of symbolic
references is a key feature of assemblers, saving tedious calculations and manual address updates
gr
ou
p.
c
after program modifications. Most assemblers also include macro facilities for performing
textual substitutione.g., to generate common short sequences of instructions as inline, instead
of called subroutines.
Assemblers have been available since the 1950s and are far simpler to write than compilers for
high-level languages as each mnemonic instruction / address mode combination translates
directly into a single machine language opcode. Modern assemblers, especially for RISC
ud
en
ts
architectures, such as SPARC or Power Architecture, as well as x86 and x86-64, optimize
instruction scheduling to exploit the CPU pipeline efficiently.
1.b. State the C language elements that can be used in the arm block.
June/July 13 [6 marks]
There are two main ways of writing ARM assembly language programs. One is to use a
ity
st
dedicated assembler. Such a program takes a text file containing ARM assembly language
instructions, assembles it, and produces another file containing the equivalent machine code.
These two files are called the source files and object files respectively.
.c
An alternative approach is to use the assembler built-in to BBC BASIC. The ability to mix
assembler with BASIC is a very useful feature of the language, and one that is relatively
straightforward to use. For this reason, and because of the widespread availability of BBC
BASIC, we describe how to use its built-in assembler. The examples of the next two chapters are
Page 62
10CS45
the program and starts to assemble ARM instructions into machine code. The end of the source is
marked by the close square bracket,]. If this is read where BASIC is expecting to see an
instruction to be assembled, it leaves assembler mode and starts executing the (BASIC) program
gr
ou
p.
c
To see the effect of entering and leaving the assembler, type in this short program:
om
again.
If you RUN this, you should see something like the following:
Outside the assembler
ud
en
ts
In the assembler
Outside the assembler
Between the two lines produced by the PRINT statements is one which the assembler printed.
Unless you tell it not to, the assembler prints an assembly listing. We shall describe this in detail,
but for now suffice is to say that it consists of three parts: an address (the eight zeros above,
which may be different when you run the program), the machine code instruction in hex, and the
source instruction being assembled.
ity
st
1.c. Explain the basic rules for using assembly language with C/C++ for 16 bit DOS
applications with the help of examples
June/July 13 [8 marks]
USING ASSEMBLY LANGUAGE WITH C++ FOR 16-BIT DOS APPLICATIONS
Use software to build 16-bit applications when attempting any programs in this section.
if you build a 32-bit application and attempt the DOS INT 21H function, the
program will crash
.c
To build a 16-bit DOS application, you will need the legacy 16-bit compiler
It then displays each of the entries by using a few assembly language procedures.
The string procedure displays a character string, no carriage return/line feed combination
is displayedinstead, a space is displayed.
Page 63
10CS45
The Crlf procedure displays a carriage return/line feed combination. the Numb procedure
displays the integer
Before assembly language code can be placed in a C/C++ program, some rules
must be learned.
Note that AX, BX, CX, DX, and ES registers are never used by Microsoft C/C++.
these might be considered scratchpad registers, available to use with assembly language
If you wish to use any of the other registers, make sure that you save them with a PUSH
before they are used and restore them with a POP afterwards.
if
you
fail
to
save
registers
used
by
the program may not function correctly and can crash the computer
gr
ou
p.
c
om
program,
ud
en
ts
2.a. Illustrate a simple program that uses a character string defined with and display on a
separate line.
Dec 13/Jan 14 [10 marks]
.c
ity
st
.model small
.data
str db 80 dup (0) ; duplicate directive initializes allocated bytes with zero
msg1 db 13, 10, Entered String is: , '$' ; allocates the bytes for variable named msg1
.code
start: mov ax, @data
mov ds, ax
include mr.asm ; includes the external file macro read into main program
include md.asm ; includes the external file macro display into main program
mov si, offset str ; copies the contents at offset STR to Source Index
L1: read_byte ; calling the macro read function
mov [si], al ; copies the character read into location of SI
inc si
cmp al, 0dh ; compares the contents of AL and 13 - CR
jne l1 ; jump to L1 if value is not equal
lea dx, msg1
mov ah, 09h ; displays the string in variable MSG1
int 21h
lea si, str MICROPROCESSORS 10CS45 Dept., of ISE ,S.J.B.I.T Page 10
Page 64
10CS45
ud
en
ts
gr
ou
p.
c
om
i) assembler and linker ii) public and extern iii) macros and procedure
i) assembler and linker
.c
ity
st
Assemblers
Assemblers need to
translate assembly instructions and pseudo-instructions into machine instructions
Convert decimal numbers, etc. specified by programmer into binary
Typically, assemblers make two passes over the assembly file
First pass: reads each line and records labels in a symbol table
Second pass: use info in symbol table to produce actual machine code for each line
Linker
Tool that merges the object files produced by
separate compilation or assembly and creates an executable file
Three tasks
Searches the program to find library routines used by program, e.g. printf(), math routines,
Determines the memory locations that code from each module will occupy and relocates its
instructions by adjusting absolute references
Resolves references among files
ii)public and extern
PUBLIC
Large programs are written as separate modules.
Each module is individually assembled, tested and debugged.
When all the modules are correct, their object code files are linked together to form
the complete program.
Page 65
10CS45
ud
en
ts
gr
ou
p.
c
om
For the modules to link together correctly, any variable name or label referred to in
other modules must be declared public in the module where it is defined.
PUBLIC directive is used to tell the assembler that a specified name or label will
be accessed from other modules
Eg: Public sales
EXTRN directive
Is used to tell assembler that the name or labels following the directive are in some
other assembly module.
For Eg, if a procedure is called which is in a program module assembled at
different time, assembler must know that the procedure is external.
The assembler will then put information in the object code file so that the linker
can connect the two modules together.
For a reference to the external named variable, one must specify the type of the
variable Eg: EXTRN DIVISOR: WORD
For a reference it is necessary to specify whether the label is near or far.
Eg: EXTRN SMART_DIVIDE:FAR ; tells the assembler that SMART_DIVIDE
is a label of type far in another assembly module
Names and labels referred to as external in one module must be declared public.
Example
Calling Program
Called Program
DATA SEGMENT
PUBLIC VAR
DATA SEGMENT
VAR DW
..
..
.c
ity
st
DATA ENDS
DATA ENDS
Procedure
RET instruction
Machine code is generate for instructions each Machine code for instruction is put only once
time when macro is called
in the memory
With macro more memory is required
Parameter passed as part of statement which Parameters can be passed in registers memory
Page 66
10CS45
call macros
om
2.c. Write an ALP to compute factorial of single digit positive number using recursive
procedure
Dec 13/Jan 14 [4 marks]
.MODEL SMALL
gr
ou
p.
c
.STACK 64H
.DATA
NUM Db 03H
RES DW?
.CODE
MOV DS,AX
MOV AX,01
MOV CX,[NUM]
CMP CX,00H
MOV BX,CX
CALL FAC
ity
st
JE EXIT
ud
en
ts
MOV AX,@DATA
.c
EXIT:MOV RES,AX
MOV AH,4CH
INT 21H
FAC PROC
CMP BX,01H
JE G
MUL BX
Page 67
10CS45
DEC BX
CALL FAC
G:RET
om
FAC ENDP
END
gr
ou
p.
c
3.a. Write an ALP to find NCR using recursive procedure. Assume N & R are nonNegative numbers.
Dec 2012 [10 marks]
.model small
.data
n dw 6
ncr dw 0
.code
MOV AX, @data
MOV DS, AX
MOV BX, r
Call ncr_proc
.c
Int 3
ity
st
MOV AX, n
ud
en
ts
r dw 2
Ncr_proc.proc
Cmp AX, BX
Jz n1
Cmp BX, 0
Jz n1
Cmp BX, 1
Page 68
10CS45
Jz n2
MOV CX, BX
Dec CX
om
Cmp AX, CX
Jz n2
gr
ou
p.
c
Push AX
Push BX
Dec AX
Call ncr_proc
Pop BX
ud
en
ts
Pop AX
Dec BX
Dec AX
Call ncr_proc
ity
st
Jmp last
Last: ret
.c
Ncr_proc endp
end
DAA
AAM
LOOP
Page 69
iv)
v)
Ans:
10CS45
SUB
XLAT
ud
en
ts
DAA
gr
ou
p.
c
om
DAA: This instruction is used to make sure the result of adding two packed BCD numbers is
adjusted to be a legal BCD number. The result of the addition must be in AL for DAA nimber.
The result of the addition must be in AL for DAA to work correctly. If the lower nibble in AL
after an addition is greater than 9 or AF was set by the addtion, then the DAA instruction will
add 6 to the lower nibble in AL. if the result in the upper nibble of AL is now greater than 9 of if
the carry flag was set by the addition or correction. Then the DAA instrction will add 60H to AL.
a couple of simple examples should clarify how this works.
AAM:
ity
st
The AAM instruction is used to adjust the product to two unpacked BCD digits in AX.
AAM works only after the multiplication of two unpacked BCD bytes, and it works only on an
operand in AL. AAM updates PF,SF, and ZF, but AF,CF, and OF are left undefined.
.c
MUL BH
AAM
Page 70
ii)
10CS45
LOOP:
om
The number of times the instruction sequence is to be repeated is loaded into CX. Each time the
LOOP instrution executes, CX is automatically decremented by 1. If CX is not 0, execution will
jump to a destination specified by a label in the instruction. If CX=0 after the auto decrement,
execution will simply go on to the next instruction after LOOP.
;Point BX at
; first element in array
MOV CX,40 ;Load CX with number of
; elements in array
; get element from array
ADD AL,07
DAA
MOV [BX],AL
ud
en
ts
INC BX
ity
st
LOOP NEXT
gr
ou
p.
c
iii)
SUB:
.c
This instruction subtract the number in the indicated source from the number in the indicated
destination and put the result in the indicated destination.
Ex: SUB CX,BX
SBB CH,AL
SUB AX,3427
SUB BX,[3427H]
iv)
XLAT
Page 71
10CS45
It is used to translate a byte from one code to another code. The instruction replaces a byte in the
AL register with a byte pointed to by BX in a lookup table in memory.
Ex: MOV BX,OFFSET EBCDIC_TABLE
om
XLAT
gr
ou
p.
c
4.a. Explain the following instructions or directives in 8086 programming: i) global ii) call
iii) LAHE iv) TYPE v) NEG viii) TEST ix) GROUP x) XLAT Jan 2015 [10marks]
i) global
ud
en
ts
can be used by any module in the program. The following statement declares the
procedure ROUTINE as a global label.
ROUTINE PROC GLOBAL
ii)call
CALL : Unconditional Call
ity
st
.c
There are two types of procedure depending upon whether it is available in the
same segment or in another segment.
iii TYPE
TYPE The TYPE operator directs the assembler to decide the data type of the
specified label and replaces the 'TYPE label' by the decided data type. For the
word type variable, the data type is 2, for double word type, it is 4, and for byte
Page 72
10CS45
NEG : Negate
The negate instruction forms 2s complement of the specified destination in the
om
NEG
gr
ou
p.
c
instruction. The destination can be a register or a memory location. This instruction can be
implemented by inverting each bit and adding 1 to it.
Eg. NEG AL
ud
en
ts
viii) TEST
TEST : Logical Compare Instruction
The TEST instruction performs a bit by bit logical AND operation on the two operands. The
result of this ANDing operation is not available for further use, but flags are affected.
Eg. TEST AX, BX
TEST [0500], 06H
ity
st
GROUP
.c
GROUP: Group the Related segment The directive is used to form logical groups of segments
with similar purpose or type. This directive is used to inform the assembler to form a logical
group of the following segment names. The assembler passes an information to the linker/loader
to form the code such that the group declared segments or operands must lie within a 64Kbyte
memory segment. Thus all such segments and labels can be addressed using the same segment
base.
The above statement directs the loader/linker to prepare an EXE file such that CODE, DATA
and STACK segment must lie within a 64kbyte memory segment that is named as PROGRAM.
Now, for the ASSUME statement, one can use the label PROGRAM rather than CODE, DATA
and STACK as shown.
ASSUME CS: PROGRAM, DS: PROGRAM, SS: PROGRAM.
Page 73
10CS45
5.a Write a ALP using C/C++ to perform the operation X+Y=Z with proper comments
gr
ou
p.
c
main proc
mov ax,@data
mov ds,ax
om
.model small
.stack 100h
.data
str1 db 'Enter String ','$'
str2 db 50 dup('$')
str3 db 0dh, 0ah, '$'
.code
mov ah,09h
lea dx,str1
int 21h
ud
en
ts
mov ah,0ah
lea dx,str2
int 21h
.c
end main
ity
st
int 21h
mov ah,4ch
int 21h
main endp
5.b Define modular programming. Using the concepts of public and extra directives writ a program
which reads data in a program in one module which is then used by another module June 2014[06
marks]
Page 74
10CS45
Due to a compact encoding inspired by 8-bit processors, most instructions were one-address or twoaddress operations which means that the result was stored in one of the operands. At most one of the
operands could be in memory, but this memory operand could also be the destination, while the other
operand, the source, could be either register or immediate. A single memory location could also often be
om
used as both source and destination which, among other factors, further contributed to a code density
comparable to (and often better than) most eight bit machines.
The degree of generality of most registers were much greater than in the 8080 or 8085. However, 8086
gr
ou
p.
c
registers were more specialized than in most contemporary minicomputers and also used implicitly by
some instructions. While perfectly sensible for the assembly programmer, this made register allocation for
compilers more complicated compared to more orthogonal 16- and 32-bit processors such as the PDP-11,
VAX, 68000, 32016 etc. On the other hand, being more regular than rather minimalistic but ubiquitous 8bit microprocessors such as the 6502, 6800, 6809, 8085, MCS-48, 8051 and other contemporary
accumulator based machines, it was significantly easier to construct an efficient code generator for the
8086 design.
ud
en
ts
Another factor for this was that the 8086 also introduced some new instructions (not present in the 8080
and 8085) to better support stack based high level programming languages such as Pascal and PL/M;
some of the more useful ones were push mem-op, and ret size, supporting the "pascal calling convention"
directly. (Several others, such as push immed and enter, would be added in the subsequent 80186, 80286,
and 80386 processors.)
The 8086 had a 64 KB of 8-bit (or alternatively 32 K-word of 16-bit) I/O space. A 64 KB (one segment)
ity
st
stack growing towards lower addresses is supported in hardware; 2-byte words are pushed to the stack
and the stack top is pointed to by SS:SP. There are 256 interrupts, which can be invoked by both
hardware and software. The interrupts can cascade, using the stack to store the return addresses.
Flags
.c
8086 has a 16-bit flags register. Nine of these condition code flags are active, and indicate the current
state of the processor: Carry flag (CF), Parity flag (PF), Auxiliary carry flag (AF), Zero flag (ZF), Sign
flag (SF), Trap flag (TF), Interrupt flag (IF), Direction flag (DF), and Overflow flag (OF).
Procedure
Accessed during assembly with name given to Accessed by CALL and RET instruction during
macro when defined.
program execution.
Machine code is generate for instructions each time Machine code for instruction is put only once in the
Page 75
10CS45
memory
om
Parameter passed as part of statement which call Parameters can be passed in registers memory
macros
locations are stack.
gr
ou
p.
c
Unit-6
1.a. Explain the functions of following pins of 8086 mp
i) ALE
ii)INTR
iii)HOLD
iv)RESET
June/July 13 [5 Marks]
v)BHE
i) ALE
Address latch enable shows that the 8086/8088address/data bus contains address
information. This address can be a memory address or an I/O port number
ii)INTR
ud
en
ts
INTR is held high when IF =1, the 8086/8088 enters an interrupt acknowledge cycle (INTA
becomes active) after the current instruction has completed execution.
iii)HOLD If the HOLD signal is a logic 1, the microprocessor stops executing software and
places its address, data, and control bus at the high-impedance state.
If the HOLD pin is a logic 0, the microprocessor executes software normally.
ity
st
iv)RESET The reset input causes the microprocessor to reset itself if this pin is held high for a
minimum of four clocking periods. Whenever the 8086 or 8088 is reset, it begins executing
instructions at memory location FFFFOH and disables future interrupts by clearing the IF flag
bit.
.c
v)BHE The bus high enable pin is used in the 8086 to enable the most significant data bus bits
(D l5-D8) during a read or a write operation. The state of S7 is always a logic 1
Page 76
10CS45
1.b. Explain how address de-multiplexing is done in 8086 processor based systems.
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
June/July 13 [7 Marks]
June/July 13 [8 Marks]
Page 77
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
.c
ity
st
2.a. Explain the minimum mode pins of 8086 and maximum mode configuration of 8086
with neat diagram.
Dec 13/Jan 14 [10 Marks]
Pin Functions
Page 78
ity
st
ud
en
ts
om
AD7-ADo The 8088 address/data bus lines compose the multiplexed address data bus of
the 8088 and contain the rightmost 8-bits of the memory address or I/O port number
whenever ALE is active (logic 1) or data whenever ALE is active (logic 0). These pins
are at their high-impedance state during a hold acknowledged.
A15-A8 The 8088 address bus provides the upper-half memory address bits that are
present throughout a bus cycle. These address connections go to their high-impedance
state during a hold acknowledge.
AD15-AD8
The 8086 address/data bus lines compose the upper multiplexed
address/data bus on the 8086.
ALE=1 These lines contain address bits .(A15-A8)
ALE=0 These pins enter a high-impedance state whenever a hold acknowledge occurs
AD19/S6-AD16/S3 The address/status bus bits are multiplexed to provide address signals
A19-A I6 and also status bits S6-S3 These pins also attain a high impedance state during
the hold acknowledge.
Status bit S6 always remains a logic 0,
S5 indicates the condition of the IF flag bits,
S4 and S3 show which segment is accessed during the current bus cycle.
Table 8-4 for the truth table
gr
ou
p.
c
10CS45
.c
RD Whenever the read signal is a logic 0, the data bus is receptive to data from the memory or
I/O devices connected to the system.
READY The ready input is controlled to insert wait states into the timing of the microprocessor.
If the READY pin is placed at a logic 0 level, the microprocessor enters into wait states and
remains idle.
If the READY pin is placed at a logic 1 level, it has no effect on the operation of the
microprocessor.
INTR Interrupt request is used to request a hardware interrupt.
Page 79
10CS45
INTR is held high when IF =1, the 8086/8088 enters an interrupt acknowledge cycle (INTA
becomes active) after the current instruction has completed execution.
Test The Test pin is an input that is tested by the WAIT instruction.
om
gr
ou
p.
c
Non-Maskable Interrupt The non-maskable interrupt input is similar to INTR except that the
NMI interrupt does not check to see if the IF flag bit is a logic 1. If NMI is activated, this
interrupt input uses interrupt vector 2.
Reset The reset input causes the microprocessor to reset itself if this pin is held high for a
minimum of four clocking periods. Whenever the 8086 or 8088 is reset, it begins executing
instructions at memory location FFFFOH and disables future interrupts by clearing the IF flag
bit.
ud
en
ts
CLK The clock pin provides the basic timing signal to the microprocessor. The clock signal
must have a duty cycle of 33% (high for one-third of the clocking period and low for two-thirds)
to provide proper internal timing for the 8086/8088.
VCC This power supply input provides a +5.0 V, 10 % signal to the microprocessor.
ity
st
GND The ground connection is the return for the power supply. Note that the 8086/8088
microprocessors have two pins labeled GND-both must be connected to ground for proper
operation.
MN/MX The minimum/maximum mode pin selects either minimum mode or maximum mode
operation for the microprocessor. If minimum mode is selected, the MN/MX pin must be
connected directly to +5.0 V.
.c
BHE/S7 The bus high enable pin is used in the 8086 to enable the most significant data bus bits
(D l5-D8) during a read or a write operation. The state of S7 is always a logic 1.
Page 80
10CS45
WR The write line is a strobe that indicates that the 8086/8088 is outputting data to a memory or
I/O device. During the time that the WR is a logic 0, the data bus contains valid data for memory
or I/O. This pin floats to a high-impedance during a hold acknowledge.
om
INTA The interrupt acknowledge signal is a response to the INTR input pin. The INTA pin is
normally used to gate the interrupt vector number onto the data bus in response to an interrupt
request.
gr
ou
p.
c
ALE Address latch enable shows that the 8086/8088address/data bus contains address
information. This address can be a memory address or an I/O port number
DT/R The data transmit/receive signal shows that the microprocessor data bus is transmitting
(DTIR = 1) or receiving (DTIR = 0) data. This signal is used to enable external data bus buffers.
DEN Data bus enable activates external data bus buffers.
ud
en
ts
If the HOLD signal is a logic 1, the microprocessor stops executing software and places its
address, data, and control bus at the high-impedance state.
If the HOLD pin is a logic 0, the microprocessor executes software normally.
HLDA Hold acknowledge indicates that the 8086/8088 microprocessors have entered the hold
state.
.c
ity
st
SS0 The SS0 status line is equivalent to the S0 pin in maximum mode operation of the
microprocessor. This signal is combined with IO/M and DTIR to decode the function of the
current bus cycle ( Table 8-5).
Maximum Mode Pins. In order to achieve maximum mode for use with external
coprocessors, connect the MN/MX pin to ground.
Page 81
10CS45
gr
ou
p.
c
om
S2, S1, and S0 The status bits indicate the function of the current bus cycle. These signals are
normally decoded by the 8288 bus controller . Table 8-6 shows the function of these three status
bits in the maximum mode.
ud
en
ts
RO/GT1 and RQ/GTO The request/grant pins request direct memory accesses (DMA) during
maximum mode operation. These lines are both bi-directional and are used to request and grant a
DMA operation
Lock The lock output is used to lock peripherals off the system. This pin is activated by using
the LOCK: prefix on any instruction.
QS1 and QS0 The queue status bits show the status of the internal instruction queue. These pins
are provided for access by the numeric coprocessor (8087).
ity
st
.c
2.b. Describe internal block diagram of 8288 bus controller with explanation of each pins
Dec 13/Jan 14 [6 Marks]
An 8086/8088 system that is operated in maximum mode must have an 8288 bus controller
to provide the signals that are eliminated from the 8086/8088 by the maximum mode
operation.
Page 82
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
I/O (IORC and IOWC) and memory (MRDC and MWTC). It also contains advanced
memory (AMWC) and I/O (AIOWC) write strobes and the INTA signal.
These signals replace the minimum mode ALE, WR, IO/M, DTIR, DEN, and INTA, which
are lost when the 8086/8088 is operated in the maximum mode.
ity
st
Pin Functions.
The following list provides a description of each pin of the 8288 bus controller.
S2, S1, and S0
.c
Status inputs are connected to the status output pins on the 8086/8088 microprocessors.
These three signals are decoded to generate the timing signals for the system.
CLK
The clock input provides internal timing and must be connected to the CLK output pin of the
8284A clock generator.
ALE
The address latch enable output is used to demultiplex the address/data bus.
DEN
Page 83
10CS45
The data bus enable pin controls the bi-directional data bus buffers in the system. Note that
this is an active high-output pin that is the opposite polarity from the DEN signal found on
the microprocessor when operated in the minimum mode.
om
DT/R
The data transmit/receive signal is output by the 8288 to control the direction of the bidirectional data bus buffers.
gr
ou
p.
c
AEN
The address enable input causes the 8288 to enable the memory control signals.
CEN
The control enable input enables the command output pins on the 8288.
IOB
ud
en
ts
The I/O bus mode input selects either the I/O bus mode or system bus mode operation.
AIOWC
The advanced I/O write command output provides I/O with an advanced I/O write control
signal.
IOWC
IORC
ity
st
The I/O write command output provides I/O with its main write signal.
The I/O read command output provides I/O with its read control signal.
.c
AMWC
The advanced memory write control pin provides memory with an early or advanced write
signal.
MWTC
The memory write control pin provides memory with its normal write control signal.
MRDC
The memory read control pin provides memory with a read control signal.
INTA
Page 84
10CS45
The interrupt acknowledge output acknowledges an interrupt request input applied to the
INTR pin.
MCE/PDEN
gr
ou
p.
c
.c
ity
st
ud
en
ts
om
The master cascade/peripheral data output selects cascade operation for an interrupt
controller if IOB is grounded and enables the I/O bus transceivers if IOB is tied high.
3.a. differentiate between memory mapped I/O and direct I/O. Dec 2012 [5 Marks]
I/O mapped I/O
In this device address is 16 bit. Thus A0 to A15 In this I/O device address is 8 bit. Thus A0 to
lines are used to generate device address.
A7 OR A8 to A15 lines are used to generate
device address.
Data trasfer is between any register and I/O Data transfer is between accumulator and I/O
Page 85
10CS45
device.
om
device.
gr
ou
p.
c
Decoding 16bit address may require more Decoding 8 bit address will require less
hardware.
hardware.
.c
ity
st
ud
en
ts
3.b. write the timing diagram for a memory read machine cycle.
Page 86
10CS45
ud
en
ts
gr
ou
p.
c
om
.c
ity
st
AD15-AD0: These are the time multiplexed memory I/O address and data lines. Address remains
on the lines during T1 state, while the data is available on the data bus during T2,T3, TW and
T4. Here T1, T2, T3, T4 and TW are the clock states of a machine cycle. TW is a wait state.
These lines are active high and float to a tristate during interrupt acknowledge and local bus hold
acknowledge cycles.
A19/S6, A18/S5, A17/S4, A16/S3: These are the time multiplexed address and status lines.
During T1, these are the most significant address lines or memory operations. During I/O
operations, these lines are low. During memory or I/O operations, status information is available
on those lines for T2, T3, TW and T4 .The status of the interrupt enable flag bit(displayed on S5)
is updated at the beginning of each clock cycle. The S4 and S3 combinedly indicate which
segment register is presently being used for memory accesses as shown in Table 1.1. These lines
float to tri-state off (tristated) during the local bus hold acknowledge. The status line S6 is
always low(logical). The address bits are separated from the status bits using latches controlled
by the ALE signal.
Page 87
gr
ou
p.
c
om
MICROPROCESSORS
.c
ity
st
ud
en
ts
BHE/S7-Bus High Enable/Status: The bus high enable signal is used to indicate the transfer of
data over the higher order (D15-D8) data bus as shown in Table 1.2. It goes low for the data
transfers over D15-D8 and is used to derive chip selects of odd address memory bank or
peripherals. BHE is low during T1 for read, write and interrupt acknowledge cycles, when- ever
a byte is to be transferred on the higher byte of the data bus. The status information is available
during T2, T3 and T4. The signal is active low and is tristated during 'hold'. It is low during T1
for the first pulse of the interrupt acknowledge cycle.
RD-Read: Read signal, when low, indicates the peripherals that the processor is performing a
memory or I/O read operation. RD is active low and shows the state for T2, T3, TW of any read
cycle. The signal remains tristated during the 'hold acknowledge'.
READY: This is the acknowledgement from the slow devices or memory that they have
completed the data transfer. The signal made available by the devices is synchronized by the
8284A clock generator to provide ready input to the 8086. The signal is active high.
INTR-lnterrupt Request: This is a level triggered input. This is sampled during the last clock
cycle of each instruction to determine the availability of the request. If any interrupt request is
pending, the processor enters the interrupt acknowledge cycle. This can be internally masked by
resetting the interrupt enable flag. This signal is active high and internally synchronized.
Page 88
10CS45
om
TEST: This input is examined by a 'WAIT' instruction. If the TEST input goes low, execution
will continue, else, the processor remains in an idle state. The input is synchronized internally
during each clock cycle on leading edge of clock. NMI-Non-maskable Interrupt: This is an edgetriggered input which causes a Type2 interrrupt. The NMI is not maskable internally by software.
A transition from low to high initiates the interrupt response at the end of the current instruction.
This input is internally synchronized.
gr
ou
p.
c
RESET: This input causes the processor to terminate the current activity and start execution from
FFFF0H. The signal is active high and must be active for at least four clock cycles. It restarts
execution when the RESET returns low. RESET is also internally synchronized.
CLK-Clock Input: The clock input provides the basic timing for processor operation and bus
control activity. Its an asymmetric square wave with 33% duty cycle. The range of frequency for
different 8086 versions is from 5MHz to 10MHz.
VCC : +5V power supply for the operation of the internal circuit. GND ground for the internal
circuit.
ud
en
ts
MN/MX :The logic level at this pin decides whether the processor is to operate in either
minimum (single processor) or maximum (multiprocessor) mode.
M/IO -Memory/IO: This is a status line logically equivalent to S2 in maximum mode. When it is
low, it indicates the CPU is having an I/O operation, and when it is high, it indicates that the
CPU is having a memory operation.
ity
st
4.a. Write signal activities on 8086 buses, during a simple read operation.
Jan 2015 [10 Marks]
.c
AD15-AD0: These are the time multiplexed memory I/O address and data lines. Address remains
on the lines during T1 state, while the data is available on the data bus during T2,T3, TW and
T4. Here T1, T2, T3, T4 and TW are the clock states of a machine cycle. TW is a wait state.
These lines are active high and float to a tristate during interrupt acknowledge and local bus hold
acknowledge cycles.
A19/S6, A18/S5, A17/S4, A16/S3: These are the time multiplexed address and status lines.
During T1, these are the most significant address lines or memory operations. During I/O
operations, these lines are low. During memory or I/O operations, status information is available
on those lines for T2, T3, TW and T4 .The status of the interrupt enable flag bit(displayed on S5)
is updated at the beginning of each clock cycle. The S4 and S3 combinedly indicate which
segment register is presently being used for memory accesses as shown in Table 1.1. These lines
float to tri-state off (tristated) during the local bus hold acknowledge. The status line S6 is
always low(logical). The address bits are separated from the status bits using latches controlled
by the ALE signal.
Page 89
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
ity
st
4.b. What is need of memory banking? With a neat block diagram, explain the memory
banking in 8086.
Jan 2015 [10 Marks]
The 8086 is a 16-bit processor with a 16-bit memory bus. That requires a memory subsystem that
can deliver 16-bits at a time, probably built using two sets of 8-bit memory chips.
.c
The 8088 uses an 8-bit memory bus, to make it cheaper. It was designed to save on the minimum
number of chips needed to build a system.
Memory Banks
8086 has a 16-bit memory bus which means that data transfer can occur at a maximum rate of
16 bits (one word) per bus cycle. However, sometimes only a byte needs to be accessed. This
means that the processor must have both options i.e., both byte and word transfer must be
possible. We know that for a word transfer, two byte locations must be accessed i.e., two
addresses are actually needed.
Page 90
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
marks]
ACE
RESET
NMI
HOLD
MN/MX
June 2014[06
QSI and
QSQ
ii)INTR
ity
st
i) ALE Address latch enable shows that the 8086/8088address/data bus contains address information.
This address can be a memory address or an I/O port number
Interrupt request is used to request a hardware interrupt.
.c
INTR is held high when IF =1, the 8086/8088 enters an interrupt acknowledge cycle (INTA becomes
active) after the current instruction has completed execution.
iii)HOLD If the HOLD signal is a logic 1, the microprocessor stops executing software and places its
address, data, and control bus at the high-impedance state.
iv)RESET The reset input causes the microprocessor to reset itself if this pin is held high for a minimum
of four clocking periods. Whenever the 8086 or 8088 is reset, it begins executing instructions at memory
location FFFFOH and disables future interrupts by clearing the IF flag bit.
v)BHE The bus high enable pin is used in the 8086 to enable the most significant data bus bits (D l5-D8)
during a read or a write operation. The state of S7 is always a logic 1
Page 91
10CS45
5.b Explain in detail with a neat figure demultiplexing of address and data lines in 8086
June 2014[06
ity
st
ud
en
ts
gr
ou
p.
c
om
marks]
.c
Page 92
10CS45
om
the address remain on the bus for three clock periods. However, the low order bitsremain for
only one clock period and they would be lost if they are not saved externally. Also, notice that
the low order bitsof the address disappearwhen they are needed most.
To make sure we have the entire address for the full three clock cycles, we will use an external
latchto save the value of AD7AD0 when it is carrying the address bits. We use the ALE signal
to enable this latch.
gr
ou
p.
c
ALE operates as a pulse during T1, we will be able to latch the address. Then when ALE goes
low, the address is saved and the AD7AD0 lines can be used for their purpose as the bidirectional data lines.
ud
en
ts
The high order address is placed on the address bus and hold for 3 clk periods,
The low order address is lost after the first clk period, this address needs to be hold however we
need to use latch
The address AD7 AD0 is connected as inputs to the latch 74LS373.
The ALE signal is connected to the enable (G) pin of the latch and the OC Output control of
the latch is grounded which you can see in the given diagram
5.c Explain with a neat figure the working of 8086 in MIN mode configuration
marks]
Minimum mode Pins:
June 2014[08
ity
st
Minimum mode operation of the 8086/8088 is obtained by connecting the MN/MX pin directly to +5.0 V.
Do not connect this pin to +5.0
IO/M or M/IO this pin selects memory or I/O. This pin indicates that the microprocessor address bus
contains either a memory address or an I/O port address.
.c
WR The write line is a strobe that indicates that the 8086/8088 is outputting data to a memory or I/O
device. During the time that the WR is a logic 0, the data bus contains valid data for memory or I/O. This
pin floats to a high-impedance during a hold acknowledge.
INTA The interrupt acknowledge signal is a response to the INTR input pin. The INTA pin is normally
used to gate the interrupt vector number onto the data bus in response to an interrupt request.
ALE Address latch enable shows that the 8086/8088address/data bus contains address information. This
address can be a memory address or an I/O port number
DT/R The data transmit/receive signal shows that the microprocessor data bus is transmitting (DTIR = 1)
or receiving (DTIR = 0) data. This signal is used to enable external data bus buffers.
DEN Data bus enable activates external data bus buffers.
Page 93
10CS45
om
.c
ity
st
ud
en
ts
gr
ou
p.
c
SS0 The SS0 status line is equivalent to the S0 pin in maximum mode operation of the microprocessor.
This signal is combined with IO/M and DTIR to decode the function of the current bus cycle ( Table 8-5).
Page 94
10CS45
Unit-7
1.a. List various memory devices.
June/July 13 [2 Marks]
gr
ou
p.
c
om
PROM memory devices are also available, but they are not as common today. The PROM
(programmable read-only memory) is also programmed in the field by burning open tiny
Nichrome or silicon oxide fuses, but once programmed it cannot be erased,
RMM Newer type of read-mostly memory (RMM) is called the flash memory. The flash
memory! is also often called an EEPROM (electrically erasable programmable ROM),
ud
en
ts
ity
st
i)
ii)
Draw memory map.
.c
Page 95
10CS45
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
Large fan-in NAND gates are not efficient Multiple NAND gate IC's might be required to
perform such decoding Rather the 3-to-8 Line Decoder (74LS138) is more common.
Page 96
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
1.c. what are the sources of interrupts? Briefly explain the steps taken by a processor to
execute an interrupt instruction.
June/July 13 [8marks]
interrupt sources and processor handling
ity
st
.c
A hardware interrupt is an electronic alerting signal sent to the processor from an external
device, either a part of the computer itself such as a disk controller or an external peripheral. For
example, pressing a key on the keyboard or moving the mouse triggers hardware interrupts that
cause the processor to read the keystroke or mouse position. Unlike the software type (below),
hardware interrupts are asynchronous and can occur in the middle of instruction execution,
requiring additional care in programming. The act of initiating a hardware interrupt is referred to
as an interrupt request (IRQ).
A software interrupt is caused either by an exceptional condition in the processor itself, or a
special instruction in the instruction set which causes an interrupt when it is executed. The
former is often called a trap or exception and is used for errors or events occurring during
program execution that are exceptional enough that they cannot be handled within the program
itself. For example, if the processor's arithmetic logic unit is commanded to divide a number by
Page 97
10CS45
om
zero, this impossible demand will cause a divide-by-zero exception, perhaps causing the
computer to abandon the calculation or display an error message. Software interrupt instructions
function similarly to subroutine calls and are used for a variety of purposes, such as to request
services from low level system software such as device drivers. For example, computers often
use software interrupt instructions to communicate with the disk controller to request data be
read or written to the disk.
gr
ou
p.
c
Each interrupt has its own interrupt handler. The number of hardware interrupts is limited by the
number of interrupt request (IRQ) lines to the processor, but there may be hundreds of different
software interrupts.
2.a. with a neat diagram, explain simple NAND gate address decoding logic.
.c
ity
st
ud
en
ts
When the 2K 8 EPROM is used, address connections A10A0 of the 8088 are connected to
address inputs A10A0 of the EPROM. The remaining nine address pins (A19A11) are
connected to the inputs of a NAND gate decoder (see Figure 1013). The decoder selects the
EPROM from one of the 2K-byte sections of the 1M-byte memory system in the 8088
microprocessor.In this circuit, a single NAND gate decodes the memory address. The output of
the NAND gate is a logic 0 whenever the 8088 address pins attached to its inputs (A19A11) are
all logic 1s. The active low, logic 0 output of the NAND gate decoder is connected to the CE*
input pin that selects (enables) the EPROM. Recall that whenever CE* is a logic 0, data will be
read from the EPROM only if OE* is also a logic 0. The OE* pin is activated by the 8088 RD*
signal or the MRDC* (memory read control) signal of other family members. If the 20-bit binary
address, decoded by the NAND gate, is written so that the leftmost nine bits are 1s and the
rightmost 11 bits are dont cares (X), the actual address range of the EPROM can be determined.
(A dont care is a logic 1 or a logic 0, whichever is appropriate.) Example below illustrates how
the address range for this EPROM is determined by writing down the externally decoded address
bits (A19A11) and the address bits decoded by the EPROM (A10A0) as dont cares. We really
do not care about the address pins on the EPROM because they are internally decoded. As the
example illustrates, the dont cares are first written as 0s to locate the lowest address and then as
1s to find the highest address.Example also shows these binary boundaries as hexadecimal
addresses. Here, the 2K EPROM is decoded at memory address locations FF800HFFFFFH.
Notice that this is a 2K-byte section of the memory and is also located at the reset location for
the 8086/8088 (FFFF0H), the most likely place for an EPROM in a system
EXAMPLE:
1111 1111 1XXX XXXX XXXX
OR
Page 98
MICROPROCESSORS
10CS45
om
ud
en
ts
gr
ou
p.
c
Although this example serves to illustrate decoding, NAND gates are rarely used to decode
memory because each memory device requires its own NAND gate decoder. Because of the
excessive cost of the NAND gate decoder and inverters that are often required, this option
requires that an alternate be found.
ity
st
2.b. differentiate between memory mapped I/O and direct I/O Dec 13/Jan 14 [5 marks]
The characteristics of isolated I/O are as follows:
.c
- In order to maximize the I/O operations ( isolated ) separate instructions are always provided to
perform these operations.
- One of the disadvantages is that the data transfer only occurs between the I/O port and the AL,
AX registers.
Page 99
MICROPROCESSORS
10CS45
- Complete 1mb of memory cannot be used as they are a part of the memory.
- In case of memory mapped I/O operations no external separate instructions are required.
om
Memory 1M
Memory
I/O
I/O 64K
gr
ou
p.
c
Traditional setup
ud
en
ts
Memory
ity
st
.c
Page 100
10CS45
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
.c
ity
st
3.a. Briefly explain the structure of 8086 interrupt response and interrupt vector table with
a neat diagram.
Dec 2012 [10 Marks]
Page 101
10CS45
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
The 8086 responds to the interrupt by stepping through the following series of major actions.
1. It decrements the stack pointer by 2 and pushes the flag register on the stack.
2. It disables the 8086 INTR interrupt input by clearing the interrupt flag(IF) in the flag
register.
3. It resets the trap flag in the register.
4. It decrements the stack pointer by 2 and pushes the current code segment register
contents on the stack.
Page 102
MICROPROCESSORS
10CS45
5. It decrements the stack pointer again by 2 and pushes the current instruction pointer
contents on the stack.
om
6. It does an indirect far jump to the start of the procedure you wrote to respond to the
interrupt.
gr
ou
p.
c
The starting address of an interrupt-service procedure is often called the interrupt vector or the
interrupt pointer, so the table is referred to as the interrupt-vector table or the interrupt-pointer
table.
Note that the instruction pointer value is put in as the low word of the vector, and the code
segment register is put in as the high word of the vector. Each doubleword interrupt vector is
identified buy a number from 0 to 255.
3.b. explain with block diagram, the working of 8259 and also explain ICWs format.
.c
ity
st
ud
en
ts
Page 103
10CS45
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
4.a Differentiate between memory mapped I/O and I/O mapped I/O
ity
st
marks]
Memory ,apped I/O
June
2014[04
.c
In this device address is 16 bit. Thus A0 to A15 lines In this I/O device address is 8 bit. Thus A0 to A7
are used to generate device address.
OR A8 to A15 lines are used to generate device
address.
address
may
require
Page 104
MICROPROCESSORS
10CS45
4.b i)64 kbytes EPROM ii)64 kbytes RAM . assume Ram is connected at 30000h and
EPROM at F00000h.
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
Page 105
10CS45
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
.c
4.c. what are the sources of interrupts? Briefly explain the steps taken by a processor to execute an
interrupt instruction.
June/July 13 [8marks]
interrupt sources and processor handling
Page 106
MICROPROCESSORS
10CS45
om
A hardware interrupt is an electronic alerting signal sent to the processor from an external device, either a
part of the computer itself such as a disk controller or an external peripheral. For example, pressing a key
on the keyboard or moving the mouse triggers hardware interrupts that cause the processor to read the
keystroke or mouse position. Unlike the software type (below), hardware interrupts are asynchronous and
can occur in the middle of instruction execution, requiring additional care in programming. The act of
initiating a hardware interrupt is referred to as an interrupt request (IRQ).
gr
ou
p.
c
A software interrupt is caused either by an exceptional condition in the processor itself, or a special
instruction in the instruction set which causes an interrupt when it is executed. The former is often called
a trap or exception and is used for errors or events occurring during program execution that are
exceptional enough that they cannot be handled within the program itself. For example, if the processor's
arithmetic logic unit is commanded to divide a number by zero, this impossible demand will cause a
divide-by-zero exception, perhaps causing the computer to abandon the calculation or display an error
message. Software interrupt instructions function similarly to subroutine calls and are used for a variety of
purposes, such as to request services from low level system software such as device drivers. For example,
computers often use software interrupt instructions to communicate with the disk controller to request
data be read or written to the disk.
ud
en
ts
Each interrupt has its own interrupt handler. The number of hardware interrupts is limited by the number
of interrupt request (IRQ) lines to the processor, but there may be hundreds of different software
interrupts.
ity
st
.c
The interrupts initiated by external hardware by sending an appropriate signal to the interrupt pin
of the processor is called hardware interrupt. The 8086 processor has two interrupt pins INTR
and NMI. The interrupts initiated by applying appropriate signal to these pins are called
hardware interrupts of 8086. The software interrupts are program instructions. These instructions
are inserted at desired locations in a program. While running a program, if software interrupt
instruction is encountered then the processor initiates an interrupt. The 8086 processor has 256
types of software interrupts. The software interrupt instruction is INT n, where n is the type
number in the range 0 to 255.
5.b. With a neat block diagram, explain the 8259A system connections.
Jan 2015 [9 Marks]
Architecture and Signal Descriptions of 8259A
Page 107
MICROPROCESSORS
10CS45
The architectural block diagram of 8259A is shown in Fig. 1.1. The functional explanation of
each block is given in the following text in brief.
Interrupt Request Register (IRR)
om
The interrupts at IRQ input lines are handled by Interrupt Request Register internally. IRR stores
all the interrupt requests in it in order to serve them one by one on the priority basis.
In-Service Register (ISR)
gr
ou
p.
c
This stores all the interrupt requests those are being served, i.e ISR keeps a track of the requests
being served.
Priority Resolver
This unit determines the priorities of the interrupt requests appearing simultaneously. The
highest priority is selected and stored into the corresponding bit of ISR during INTA pulse. The
IR0 has the highest priority while the IR7 has the lowest one, normally in fixed priority mode.
ud
en
ts
The priorities however may be altered by programming the 8259A in rotating priority mode.
Interrupt Mask Register (IMR)
This register stores the bits required to mask the interrupt puts. IMR operates on IRR at the
direction of the Priority Resolver.
Interrupt Control Logic
ity
st
This block manages the interrupt and interrupt acknowledge sigD8ls to be sent to the CPU for
serving one of the eight interrupt requests. This also accepts interrupt acknowledge (INTA)
signal from CPU that causes the 8259A to release vector address on to the data bus.
Data Bus Buffer
.c
This tristate bidirectional buffer interfaces internal 8259A bus to the microprocessor system data
bus. Control words, status and vector information pass through buffer during read or write
operations.
This circuit accepts and decodes commands from the CPU. This also allows the status of the
8259A to be transferred on to the data bus.
Cascade Buffer/Comparator This block stores and compares the ID's of all the 8259As used in
the system.
Page 108
10CS45
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
.c
ity
st
Unit-8
Page 109
MICROPROCESSORS
10CS45
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
1.a. briefly explain the control word format of 8255 in I/O mode and BSR mode. Give the
control word format to program port A and port C lower as input and port B and port C
upper as output parts in mode 0.
June/July 13 [10 Marks]
Page 110
MICROPROCESSORS
10CS45
1.b.write an ALP using 8086 instructions to read a byte of data from port A and display its
parity status as 00h or ffh for odd and even parity respectively on port B
om
June/July 13 [5 Marks]
.MODEL SMALL
gr
ou
p.
c
.DATA
PA EQU 0DE90H
PB EQU 0DE91H
CR EQU 0DE93H
CW DB 82H
MOV AX,@DATA
MOV DS,AX
MOV AL,CW
MOV DX,CR
ity
st
OUT DX,AL
ud
en
ts
.CODE
MOV DX,PB
IN AL,DX
.c
MOV BL,AL
MOV BH,0
MOV CX,8
NEXT_BIT:ROR AL,1
JNC NEXT
INC BH
NEXT:LOOP NEXT_BIT
Page 111
MICROPROCESSORS
10CS45
MOV AL,BL
OR AL,AL
JPE DISPFF
DISP:MOV DX,PA
gr
ou
p.
c
OUT DX,AL
CALL DELAY
MOV AL,BH
MOV DX,PA
OUT DX,AL
DISPFF:MOV AL,0FFH
JMP DISP
PUSH SI
PUSH DI
ity
st
ud
en
ts
MOV AH,4CH
INT 21H
om
MOV AL,00H
.c
MOV si,0FFFFH
B1: dec di
jnz B1
DEC SI
JNZ B2
POP DI
Page 112
MICROPROCESSORS
10CS45
POP SI
RET
DELAY ENDP
om
END
ity
st
ud
en
ts
gr
ou
p.
c
1.c. List the features of 8254 PIT (programmable interval timer) June/July 13 [5 Marks]
2.a. Explain pin out of 8255 along with different operational modes.
.c
Page 113
10CS45
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
.c
ity
st
Page 114
10CS45
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
3.a. Explain the different methods of parallel data transfer with figure in a programmable
peripheral interface.
Dec 2012 [10 Marks]
Page 115
10CS45
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
ity
st
When you need to get digital data from a simple switch, such as a thermostat, into a
microprocessor, all you have to do is connect the switch to an input port line and read the port.
The thermostat data is always present and ready, so you can read it at any time.
SIMPLE STROBE I/O
.c
In many application, valid data is present on an external device only at a certain time,so it must
be read in at that time. An example of this is the ASCII encoded keyboard. When a key is
pressed, circuitry on the keyboard sends out the ASCII code for the pressed on eight parallel data
lines, and then sends out a strobe signal on another line to indicate that valid data is present on
the eight data lines.
Page 116
MICROPROCESSORS
10CS45
byte of data. Then the microprocessor sends an Acknowledgement signal(ACK) to the peripheral
to indicate that the data has been read and that peripheral can send the next byte of data. From
the viewpoint of the microprocessor, this operation is referred to as a handshake or strobed input.
om
gr
ou
p.
c
For data transfers where even more coordination is required between the sending system and the
receiving system, a double handshake is used. The circuit connections are the same as those in
fig 9.2. figure 9.1d shows some example waveforms for a double-handshake input from a
peripheral to a microprocessor.
In these waveforms each signal edge has meaning. The sending device asserts its STB line low to
ask,Arre you ready? the receiving system raises its ACK line high to say, Im ready. The
peripheral device then sends the byte of data and raises its STB line high to say, here is some
valid data for you. After it has read in the data, the receiving system drops its ACK line low to
say, I have the data, thank you, and I await your request ti send the next byte of data.
.c
ity
st
ud
en
ts
3.b. Explain with the internal block diagram of 8255, the different operational modes and
the control word formats.
Dec 2012 [10 Marks]
Page 117
10CS45
gr
ou
p.
c
om
MICROPROCESSORS
ud
en
ts
In this mode, Port A and Port B are used as two simple 8-bit I/O ports and Port C as two 4-bit
I/O ports. Each port (or half-port, in case of Port C) can be programmed to function as simply an
input port or an output port. The input/output features in mode 0 are : Outputs are latched, Inputs
are not latched. Ports do not have handshake or interrupt capability.
Mode 1 : Input or Output with handshake
.c
ity
st
In mode 1, handshake signals are exchanged between the microprocessor and peripherals prior to
data transfer. The ports (A and B) function as 8-bit I/O ports. They can be configured either as
input or output ports. Each port (Port A and Port B) uses 3 lines from port C as handshake
signals. The remaining two lines of port C can be used for simple I/O functions. Input and output
data are latched and Interrupt logic is supported.
Page 118
10CS45
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Page 119
10CS45
.c
ity
st
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
Page 120
10CS45
gr
ou
p.
c
om
MICROPROCESSORS
ud
en
ts
This mode is used primarily in applications such as data transfer between the two computers or
floppy disk controller interface. Port A can be configured as the bidirectional port and Port B
either in mode 0 or mode 1. Port A uses five signals from Port C as handshake signals for data
transfer. The remaining three lines from Port C can be used either as simple I/O or as handshake
signals for Port B.
4.a. With a neat block diagram, explain the internal block diagram of 8255A.
Jan 2015 [8 Marks]
ity
st
The 8255 is a widely used, programmable parallel I/O device. It can be programmed to transfer
data under data under various conditions, from simple I/O to interrupt I/O. It is flexible, versatile
and economical (when multiple I/O ports are required). It is an important general purpose I/O
device that can be used with almost any microprocessor.
.c
The 8255 has 24 I/O pins that can be grouped primarily into two 8 bit parallel ports: A and B,
with the remaining 8 bits as Port C. The 8 bits of port C can be used as individual bits or be
grouped into two 4 bit ports : CUpper (CU) and CLower (CL). The functions of these ports are
defined by writing a control word in the control register.
Page 121
10CS45
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
.c
ity
st
Page 122
10CS45
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
ity
st
4.c. Write on assembly level program to interface logic controller for multiplication of two
8-bit numbers.
Jan 2015 [10 Marks]
DISPLAY MACRO MSG
LEA DX,MSG
.c
MOV AH,09H
INT 21H
ENDM
.MODEL SMALL
.STACK 64
.DATA
Page 123
MICROPROCESSORS
10CS45
PA EQU 0DE90H
PB EQU 0DE91H
CR EQU 0DE93H
om
CW DB 82H
OUT DX,AL
DISPLAY M1
MOV AH,08H
INT 21H
ity
st
MOV DX,PB
ud
en
ts
MOV AL,CW
gr
ou
p.
c
IN AL,DX
MOV BL,AL
.c
DISPLAY M2
MOV AH,08
INT 21H
MOV DX,PB
IN AL,DX
MUL BL
MOV DX,PA
Page 124
MICROPROCESSORS
10CS45
OUT DX,AL
CALL DELAY
MOV AL,AH
om
MOV DX,PA
OUT DX,AL
gr
ou
p.
c
MOV AH,4CH
INT 21H
MOV si,0FFFFH
B2: MOV di,0FFFFH
B1: dec di
DEC SI
JNZ B2
POP DI
.c
POP SI
ity
st
jnz B1
ud
en
ts
PUSH DI
RET
DELAY ENDP
END
5.c Explain how a 3-8 line decoder could be used to interfaced eight 8K memory chips.
Page 125
MICROPROCESSORS
10CS45
Note that all three Enables (G2A, G2B, and G1) must be active, e.g. low, low and high,
respectively.
ity
st
ud
en
ts
gr
ou
p.
c
om
.c
marks]
June 2014[08
Page 126
10CS45
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
5.b Explain with a neat diagram the interfacing of stepper motor to 8086 using 8255 in
detail
ity
st
STEPPER MOTOR
.c
A stepper motor is a brushless, synchronous electric motor that converts digital pulses into mechanical
shaft rotation. Every revolution of the stepper motor is divided into a discrete number of steps, and the
motor must be sent a separate pulse for each step.
Fig. 1 shows how to interface the Stepper Motor to microprocessor. As you can see the stepper motor is
connected with Microprocessor output port pins through a ULN2803A array. So when the microprocessor
is giving pulses with particular frequency to ls293A, the motor is rotated in clockwise or anticlockwise.
Page 127
10CS45
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
5.c Explain the working of different blocks of 8254 PIT with a neat figure
.c
ity
st
marks]
June 2014[06
Page 128
10CS45
ud
en
ts
gr
ou
p.
c
om
MICROPROCESSORS
ity
st
Basic operation:
1. The user inputs a control word and then an initial count. The Control Word itself specifies
which Counter is being programmed and which counting Mode is desired.
2. Counting is enabled via the GATE input.
3. Either at the end of a count or during the count, transitions occur on the Counter OUT pin.
4. These OUT pin transitions are used to do things in the system.
5. The types of OUT pin transitions depend on the Mode which was programmed.
.c
Page 129
MICROPROCESSORS
10CS45
Register and is interpreted as a Control Word used to define the operation of the counters.
3. The Control Word Register can only be written to. Status information is available with the
Read-Back command.
gr
ou
p.
c
om
Counters:
1. There are three Counters. Each is fully independent of the others. Each Counter may operate
in a different Mode.
2. Each counter is a 16-bit synchronous down counter.
3. After power-up, the count value and output of all Counters are undefined.
4. Each counter must be programmed before it can be used.
5. Unused counters need not be programmed.
6. Counters are programmed by writing a Control Word and then an initial count.
7. GATE=1 enables counting, GATE=0 disables counting.
.c
ity
st
ud
en
ts
Counter description
Counting element, OLm, OLl, OL:
1. The actual Counter is "CE" in figure 5.
2. OLm and OLl are two 8-bit latches. OL is "Output Latch" The subscripts m and l stand for
"Most significant byte" and "Least significant byte". Both are normally referred to as one unit
and called just OL. These latches "follow" the CE as it counts.
3. If a suitable Counter Latch Command is sent to the 8254, the latches capture the present count
until read by the CPU. Once read, the latches return to "following" the CE.
4. One latch at a time is enabled by the counter's control logic to drive the internal bus. This is
how the 16-bit counter communicates over the 8-bit bus.
5. The CE itself cannot be read. If the user wants to read the count, it is the OL that is being read.
Page 130