Beruflich Dokumente
Kultur Dokumente
MICROPROCESSORS
(Common to CSE & ISE)
SYLLABUS
Subject Code: 10CS45 I.A. Marks: 25
Hours/Week: 05 Exam Hours: 03
Total Hours: 52 Exam Marks: 100
PART A
UNIT 1 [7 Hours]
Introduction, Microprocessor Architecture 1: A Historical Background, the Microprocessor-
Based Personal Computer Systems. The Microprocessor and its Architecture: Internal
Microprocessor Architecture, Real Mode Memory Addressing.
UNIT 2 [7 Hours]
Microprocessor Architecture 2, Addressing Modes: Introduction to Protected Mode Memory
Addressing, Memory Paging, Flat Mode Memory Addressing Modes: Data Addressing Modes,
Program Memory Addressing Modes, Stack Memory Addressing Modes.
UNIT 3 [6 Hours]
Programming 1: Data Movement Instructions: MOV Revisited, PUSH/POP, Load-Effective
Address, String Data Transfers, Miscellaneous Data Transfer Instructions, Segment Override
Prefix, Assembler Details. Arithmetic and Logic Instructions: Addition, Subtraction and
Comparison, Multiplication and Division.
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.
PART B
UNIT - 5 [6 Hours ]
Programming 3: Combining Assembly Language with C/C++: Using Assembly Language
with C/C++ for 16-Bit DOS Applications and 32-Bit Applications Modular Programming,
Using the Keyboard and Video Display, Data Conversions, Example Programs.
UNIT - 6 [7 Hours ]
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 ]
Memory Interface 2, I/O Interface 1: Memory Interfacing (continued): Address Decoding,
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
Processing, Hardware Interrupts: INTR and INTA/; Direct Memory Access: Basic DMA
Operation and Definition.
TEXT BOOK:
1. Barry B Brey: The Intel Microprocessors, 8th Edition, Pearson Education, 2009. (Listed topics
only from the Chapters 1 to 13)
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.
TABLE OF CONTENTS
1.1
Introduction: A Historical Background
1.2 The Microprocessor-Based Personal Computer
Systems.
1.3 The Microprocessor and its Architecture
1.7 Introduction to
Protected Mode Memory Addressing
UNIT-3 Programming 1
3.1 Data Movement Instructions: MOV Revisited,
PUSH/POP 59-97
3.2 Load-Effective Address, String Data Transfers,
UNIT 4 : Programming 2:
UNIT 5 Programming 3:
5.6
Practice of simple examples
7.6 practice
UNIT 1
Occasionally the physical limitations of integrated circuits made such practices as a bit
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
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
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
speed, so cache memory is necessary if the processor is not to be delayed by slower external
memory.
The CPU ("central processing unit," synonymous with "microprocessor," or even simply
"processor") is often referred to as the "brain" of the computer.
Choosing the correct processor is vital to the success of your homebuilt computer project.
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.
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
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
electricity or light bulb.(Picture- Abacus).
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).
1.1.2. The Electrical Age
The Electrical age began with the invention of electric motor by Michael Faraday. With
it came a multitude of motor driven adding machines all based on the mechanical calculator
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
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
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
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
machine developed by Herman Hollerith)
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.
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).
Bell labs developed the transistor in 1948, this was closely followed by the development
of Integrated circuits by Jack Kilby of Texas Instruments in 1958. The integrated circuits led to
the development of digital integrated circuits in the 1960's and finally the development of
microprocessor by Intel Corporation in 1971.
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.
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) .
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
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.
The memory structure of all Intel 80x86 to Pentium 4 based personal computer systems are similar. This
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
1. Transient program area (TPA)
2. System area
3. Extended memory system (XMS)
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
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
designed to function in this area using its real mode of operation.
Those computer systems that uses the any of the microprocessors, Intel 80286 through
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 (AT-
Advanced class computer systems). These systems are also called as ISA (Industry standard
architecture) or EISA (Extended ISA).
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
can have 1Mb less than 4Gb to 64GB extended memory. (Note- Modern day computer systems
based on Pentium 4 systems have an extended memory more than 180Gb.)
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 older devices. That is, an 8 bit
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 (
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
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
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.
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
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
needed larger areas of TPA compared to the newer versions.
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.
6. COMMAND.COM- The COMMAND.COM helps to control the computer system using
the keyboard when operated in DOS mode. The COMMAND.COM program processes the
DOS commands as they are typed 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
hotkey.
SYSTEM AREA
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
of the RAM. The system area map is shown in the figure.
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
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
dapterused.
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
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
display system which is done by the separate system BIOS ROM at the location C0000H.
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
controls the working of the computer system. The microprocessor connects to the memory and
I/O devices through the buses.
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
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
veryefficient.
The arithmetic and logical instructions executed by the microprocessor are
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. AND
6. OR
7. NOT
8. NEG
9. Shift
10. Rotate
Data is stored in the memory or the internal registers. The width of the data is either a byte (8-
bits), 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.
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.
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 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.
Formation of Effective address (EA)The data address formed by adding together, a combination of ,BX
or BP register contents, SI or DI register contents and a displacement is called as an effective address or
offset.
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
will be 16 bits wide but the address that is required on the address bus called the physical
address is 20 bits wide.
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+
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 location that is divisible by
16.
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
than one instruction, data and stack segment.
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.
5.
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
conditional flags reflect the condition involving a previous instruction execution. The control
flags controls the functioning of certain instructions.
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
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
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
MSB needs to borrow and there is no borrow from MSB.
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.
3. TF (Trap flag)- If set a trap is executed after each instruction.
Buses
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.
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
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.
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.
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,
and 80486DX, 32 bits
Pentium through Core2 microprocessors transfer 64 bits of data bits of data.
Advantage of a wider data bus is speed in applications using wide data.
In all Intel microprocessors family members, memory is numbered by byte. Pentium through
Core2 microprocessors contain a 64-bit-wide data bus.
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)
MWTC (memory write control)
IORC (I/O read control)( )
IOWC (I/O write control).
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.
Whenever a memory write, I/O write, or I/O read occurs, the same sequence ensues.
Figure 111 The programming model of the 8086 through the Core2 microprocessor including
the 64-bit extensions.
Multipurpose Registers
RAX - a 64-bit register (RAX), a 32-bit register (accumulator) (EAX), a 16-bit register (AX),
or as either of two 8-bit registers (AH and AL).
The accumulator is used for instructions such as multiplication, division, and some of the
adjustment instructions.
Intel plans to expand the address bus to 52 bits to address 4P (peta) bytes of memory.
RBX, addressable as RBX, EBX, BX, BH, BL.
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
RDX, as RDX, EDX, DX, DH, or DL.
a (data) general-purpose register
holds a part of the result from a multiplication
or part of dividend before a division
RBP, as RBP, EBP, or BP.
points to a memory (base pointer) location
for memory data transfers
RDI addressable as RDI, EDI, or DI.
often addresses (destination index) string destination data for the string instructions
RSI used as RSI, ESI, or SI.
the (source index) register addresses source string data for the string instructions
like RDI, RSI also functions as a general-
purpose register
R8 - R15 found in the Pentium 4 and Core2 if 64-bit extensions are enabled.
data are addressed as 64-, 32-, 16-, or 8-bit
sizes and are of general purpose
Most applications will not use these registers until 64-bit processors are common.
the 8-bit portion is the rightmost 8-bit only
bits 8 to 15 are not directly addressable as
a byte
Special-Purpose Registers
Include RIP, RSP, and RFLAGS
segment registers include CS, DS, ES, SS, FS, and GS
RIP addresses the next instruction in a section of memory.
defined as (instruction pointer) a code segment
RSP addresses an area of memory called
the stack.
Figure 1.12 The EFLAG and FLAG register counts for the entire 8086 and Pentium
microprocessor family.
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.
Flag bits, with a brief description of function.
C (carry) holds the carry after addition or borrow after subtraction.
also indicates error conditions
P (parity) is the count of ones in a number expressed as even or odd. Logic 0 for odd parity;
logic 1 for even parity.
if a number contains three binary one bits, it has odd parity
if a number contains no one bits, it has even parity
C (carry) holds the carry after addition or borrow after subtraction.
also indicates error conditions
P (parity) is the count of ones in a number expressed as even or odd. Logic 0 for odd parity;
logic 1 for even parity.
if a number contains three binary one bits, it has odd parity; If a number contains no one bits, it
has even parity
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) shows that the result of an arithmetic or logic operation is zero.
S (sign) flag holds the arithmetic sign of the result after an arithmetic or logic instruction
executes.
T (trap) The trap flag enables trapping through an on-chip debugging feature.
I (interrupt) controls operation of the INTR (interrupt request) input pin.
D (direction) selects increment or decrement mode for the DI and/or SI registers.
O (overflow) occurs when signed numbers are added or subtracted.
an overflow indicates the result has exceeded the capacity of the machine
IOPL used in protected mode operation to select the privilege level for I/O devices.
NT (nested task) flag indicates the current task is nested within another task in protected
mode operation.
RF (resume) used with debugging to control resumption of execution after the next
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
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)
Pentium.
used in multitasking environments to provide virtual interrupt flags
ID (identification) flag indicates that the Pentium microprocessors support the CPUID
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.
Four or six segment registers in various versions of the microprocessor.
A segment register functions differently in real mode than in protected mode.
Following is a list of each segment register, along with its function in the system.
CS (code) segment holds code (programs and procedures) used by the microprocessor.
Pentium 4 comes up in the real-mode after it is reset. It will remain in this mode
unless it is switched to protected-mode by software.
In real mode, the Pentium 4 operates as a very high performance 8086.
Pentium 4 can be used to execute the base instruction set of the 8086 MPU
(backward compatibility).
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).
o gives access to one megabyte (1,048,576 bytes) of directly addressable memory, known as real
mode memory.
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.
Segmented organization
o 16-bit wide segments
Two components
o Base (16 bits)
o Offset (16 bits)
Two-component specification is called logical address, also called effective address.
Logical address translates to a 20-bit physical address.
Segmentation often caused grief for programmers who tried to access large data structures:
o Since an offset cannot exceed 16 bits, you cannot increment beyond 64k.
o 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.
o Successful short-term thinking;
o Catastrophically bad long-term thinking that resulted in never-ending Windows 9x problems!
UNIT-2
2.1 PROTECTED-MODE
Some system control instructions are only valid in the protected mode.
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 32-
bit 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
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.
DESCRIPTORS:
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.
The 8192 descriptor table requires 8 * 8192 = 64K bytes of memory. The
Base (B31 B0): indicates the starting location (base address) of the memory segment. This
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
FFFH). In this case, the segment size could be anywhere between 4K and 4G bytes in steps of
4K bytes.
Example,
Base = Start = 10000000h
Limit = 001FFh and G = 0
So, End = Base + Limit = 10000000h + 001FFh = 100001FFh
Segment Size = 512 bytes
Base = Start = 10000000h
Limit = 001FFh and G = 1
So, End = Base + Limit * 4K = 10000000h + 001FFFFFh = 101FFFFFh
Segment Size = 2M bytes
AV bit: is used by some operating systems to indicate that the segment is available (AV = 1) or
not available (AV = 0).
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
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
supposed to be a maximum of 64K bytes.
Access rights byte: allows complete control over the segment. If the segment is a data segment,
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
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
unavailable in realmode.
.
SELECTORS:
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
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).
Table indicator (TI) bit: selects either the global descriptor table (TI = 0) or the local descriptor
table (TI = 1).
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.
Example:
Real Mode: DS = 0008h, then the data segment begins at location 00080h and its length is 64K
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
stored in memory as shown below.
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 limit of these descriptor tables is 16 bits because the maximum table length is 64K bytes
(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
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
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
time the number in the segment register is changed.
The TR (task register) holds a selector, which accesses a descriptor that defines a task. A task is
most often a procedure or application program. The descriptor for the procedure or application
program is stored in the global descriptor table, so access can be controlled through the privilege
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
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.
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.
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.,
thephysical page number). 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 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, and the first page
table entry. Notice that one page is a 4K-byte address range. So, if that page table entry ontains
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 etween00100000h
and 00100FFFh, the microprocessor physically addresses location 00100000h-0100FFFh
For example, the line 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
for linear address 00000000h-00000FFFh. This means that when the program accesses a location
between 00100000h and 00100FFFh, the microprocessor physically addresses location
0100000h-00100FFFh
Before After
Before After
Before After
SI 5678H 5678H
Before After
AH BCH BCH
Memory Addressing
Before After
Before After
DS:5634H 45H
DS:5635H 86H
LOC DB 78H
Before After
SI 3456H
DS:3456H 78H
Before After
BX A2B2H
Before After
DI 3400H
DS:3400H 86H
Only SI, DI and BX can be used inside [ ] from memory addressing point of view. From user
point of view [BP] is also possible. This scheme provides 3 ways of addressing an operand in
memory.
Before After
Before After
Base register can only be BX or BP. This scheme provides 4 ways of addressing an operand in
memory.
Before After
Before After
Index register can only be SI or DI. This scheme provides 4 ways of addressing an operand in
memory.
Before After
SI 2000H
BX 0300H
Before After
BP 3000H
DI 0020H
This scheme provides 4 ways of addressing an operand in memory. One register must be a Base
register and the other must be an Index register.
Before After
DI 0050H
Before After
SI 4000H
BP 0020H
Displacement
Before After
Before After
Before After
Before After
IN and OUT instructions are allowed to use only AL or AX registers. Port address in the range
00 to FFH is provided in the instruction directly.
I/O port address is provided in DX register. Port address ranges from 0000 to FFFFH. Data
transfer with AL or AX only.
Before After
DX 1234H
Before After
DX 4000H
Before After
DX 5000H
Before After
DX 5000H
Unit - 3
Abbreviations used
SR=CS/DS/ES/SS AR=SI/DI/BX/BP
Conventions used:
ROR R/M, 1/CL for ROR R,1 ROR M,1 ROR R,CL ROR M, CL
Data Transfer group, Arithmetic group, Logical group, Stack group, and I/O group of
instructions explained first. They occupy several chapters in books.
Branch group, String instructions, and Interrupt instructions are explained later.
3.2Operand instructions
ADD/ADC/SUB/SBB R Arithmetic
Before After
BX 1000H
DS:1002H
Before After
BX 1000H
Before After
SI 2000H
Before After
CL 25H
0BH =
Before After
CL 25H
V= 0, Cy = 0 V = 1, Cy = 0
V= 1, Cy = 1 V = 0, Cy = 1
V= 0, Cy = 0 V = 0, Cy = 0
V= 1, Cy = 0 V = 1, Cy = 1
Before After
06H=0000 0110B
3.2.5 OR instruction
Before After
56H=0101 0110B OR
5FH=0101 1111B
0FH=0000 1111B CL
0FH
59H=0101 1001B
06H=0000 0110B
Before After
56H=0101 0110B
MOV
AND/OR/XOR/TEST/CMP
Before After
Before After
Before After
DS:1001H
Before After
DS:1002H
Before After
Before After
3.3.5 Subtract with borrow Immediate data from a Register/ Memory location
Before After
Before After
Before After
Before After
Before After
06H=0000 0110B
Before After
SR
MOV
R16/M16
Before After
CX 2233H
Before After
BX 2000H
DS:2000H 2233H
Before After
DX 2111H
Before After
Before After
DX 1177H
Before After
OUT 30H, AL AL
50H
Before After
DX 2177H
Before After
SHR and SHL: for shifting left / right unsigned numbers SAR used Shifting right a signed
number SHL is also called as SAL, as method for shift left of signed or unsigned number is
the same
Cy 1 0
Cy 1 0
CL 02H
Cy 1 0
CL 02H
Cy 1 0
CL 02H
Cy 1 0
CL 02H
Cy 1 0
Cy 1 0
Before After
MOV BX,SI
DS:2000H 3000H
Before After
SI 1000H 6000H
DS:3000H 6000H
DS:3002H
7000H
Before After
2000:3002H 7000H
2 x (8+24+4+1) = 74 opcodes
Increment R16
Increment R8
Increment M8
24 opcodes BX 2000H
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
24 opcodes BX 2000H
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.
Decrement R16
Decrement R8
DEC DH 8 opcodes Before After
Decrement M8
24 opcodes BX 2000H
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
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.
1234H EDCBH
BX
DH 12H EDH
Perform 1s complement of M8
NOT byteptr [BX] Before After
24 opcodes BX 2000H
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.
24 opcodes BX 2000H
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.
1234H EDCCH
BX
Perform 2s complement of R8
DH 12H EEH
24 opcodes BX 2000H
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.
24 opcodes BX 2000H
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.
PUSH R16
CX 1234H
SP 5678H 5676H
Empty
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.
BX 1234H
SP 3366H 3364H
DS:1234H 5678H
Empty
PUSH SR
CS 1234H
SP 5678H 5676H
Empty
PUSH Flags
Flags 1234H
SP 5678H 5676H
Empty
POP R16
CX 1234H 1122H
SP 5678H 567AH
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.
POP M16
BX 1234H
SP 3366H 3368H
Empty
POP SR
CS 1234H 1122H
SP 5678H 567AH
Empty
POP Flags
SP 5678H 567AH
Empty
CH FEH FEH
AH 34H 01H
CX 00FEH 00FEH
DX 1234H 0000H
AH 34H FFH
NOTE:- IMUL CH instruction multiplies AL and CH treating them as signed numbers. The 16-
bit product is stored in AX.
CH F0H
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.
CX 00F0H
NOTE:- DIV CX instruction divides DX AX by CX treating them as unsigned numbers. The 16-
bit quotient is stored in AX and the 16-bit remainder stored in DX.
8086 has about 13000 opcodes. A book of about 60 pages is needed for printing the opcodes.
Concept of Template
In 8085, MOV r1, r2 (ex. MOV A, B) has the following template.
000 B
001 C
010 D
011 E
100 H
101 L
110 M
111 A
01 11 1 000 = 78H
7 8
01 11 0 010 = 72H
7 2
Using the template for MOV r1, r2 we can generate opcodes of 26 = 64 opcodes.
3.5.6 8086 Template for data transfer between REG and R/M
REG = A register of 8086 (8-bit or 16-bits) (except Segment registers, IP, and Flags registers)
Thus REG = AL/ BL/ CL/ DL/ AH/ BH/ CH/ DH/ AX/ BX/ CX/ DX/ SI/ DI/ BP/ SP
000 AX AL
001 CX CL
010 DX DL
011 BX BL
100 SP AH
101 BP CH
110 SI DH
111 DI BH
Aid to remember: ALl Children Drink Bournvita (AL, CL, DL, BL)
Case of MOD = 11
Example: Code for MOV AX, BX treated as Move from BX to destination register AX
1 0 0 0 1 0 1 1 11 00 0 011 = 8B C3H
Word AX is BX
operation destination
8 B C 3
Example: Alternative code for MOV AX, BX treating it as Move from source register BX to
register AX
1 0 0 0 1 0 0 1 11 01 1 000 = 89 D8H
Word BX is AX
operation source
8 9 D 8
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
1 0 0 0 1 0 1 0 11 00 0 111 = 8A C7H
Byte AL is BH
operation destination
8 A C 7
Example: Alternative code for MOV AL, BH treating it as Move from source register BH to
register AL
1 0 0 0 1 0 0 0 11 11 1 000 = 88 F8H
Byte BH is AL
operation source
8 8 F 8
There are 2 possible opcodes for MOV AL, BH as we can choose either AL or BH as REG.
The table shows 24 memory addressing modes i.e. 24 different ways of accessing data stored in
memory.
Aid to remember:
He says SImple DIet DIRECTs a BoXer' ( [SI], [DI], Direct addressing, [BX] )
1 0 0 0 1 0 1 0 00 00 1 100 = 8A 0CH
Byte No CL is [SI]
operation Disp. destination
8 A 0 C
Note that there is a unique opcode for MOV CL, [SI] as CL only can be REG.
8 9 5 6
Note that there is a unique opcode for MOV 46H[BP], DX as DX only can be REG.
8 9 9 6 in Little Endian
Note that there is a unique opcode for MOV 0F246H[BP], DX as DX only can be REG.
8 9 5 6
1 0 0 0 1 0 1 1 00 01 1 110 12 = 8B 1E 12 34H
34H
8 B 1 E In Little Endian
Note that when MOD = 00 and R/M = 110, it represents Direct Addressing.
Unit 4
4.1 Branch group of instructions
Branch instructions provide lot of convenience to the programmer to perform operations selectively,
repetitively etc.
Conditional Jump instructions in 8086 are just 2 bytes long. 1-byte opcode followed by 1-byte signed
displacement (range of 128 to +127).
Jumps based on a single flag Jumps based on more than one flag
JZ r8 ;Jump if zero flag set (if result is 0). JE also means same.
JNZ r8 ;Jump if Not Zero. JNE also means same.
JS r8 ;Jump if Sign flag set to 1 (if result is negative)
JNS r8 ;Jump if Not Sign (if result is positive)
JC r8 ;Jump if Carry flag set to 1. JB and JNAE also mean same.
JNC r8 ;Jump if No Carry. JAE and JNB also mean same.
JP r8 ;Jump if Parity flag set to 1. JPE (Jump if Parity Even) also means same.
Exa JNP r8 ;Jump if No Parity. JPO (Jump if Parity Odd) also means same.
mpl JO r8 ;Jump if Overflow flag set to 1 (if result is wrong)
es
JNO r8 ;Jump if No Overflow (if result is correct)
for
JE
or
JZ JE is abbreviation for Jump if Equal. JNE is abbreviation for Jump if Not
Equal.
inst
ruc
JB is abbreviation for Jump if Below. JNAE is for Jump if Not Above or Equal.
tion
Only examples using JE instruction given for forward and backward jumps.
CMP SI, DI
JE SAME
(if SI = DI)
Should be <=127 :
bytes
CMP SI, DI
JE BACK
: :
SUB BX, AX :
SAME:
15
Range for JMP (unconditional jump) can be +2 = + 32K. JMP instruction discussed in detail
later
Above and Below used for comparing Unsigned numbers. Greater than and less than used when
comparing signed numbers. All Intel microprocessors use this convention.
Conditional Jumps based on multiple flags are used after a CMP (compare) instruction.
Jump if No Jump if
[(S=1 AND V=0) OR (S=0 AND V=0)] OR [(S=0 AND V=0) OR (S=1 AND V=1)] AND
Z=1 Z=0
[(surely negative) or (wrong answer positive!)] [(surely positive) or (wrong answer negative!)]
or Equal and not equal
JNLE / JG instruction
No Jump if
Jump if
[(S=0 AND V=0) OR (S=1 AND V=1)] AND [(S=1 AND V=0) OR (S=0 AND V=1)] OR
Z=0 Z=1
[(surely positive) or (wrong answer negative!)] [(surely negative) or (wrong answer positive!)]
and not equal or equal
Jump if No Jump if
[S=1 AND V=0] OR [S=0 AND V=1] [S=0 AND V=0] OR [S=1 AND V=1]
Jump if No Jump if
[S=0 AND V=0] OR (S=1 AND V=1) [S=1 AND V=0] OR (S=1 AND V=1)
(surely positive) or (wrong answer negative!) (surely negative) or (wrong answer positive!)
Near Jump or Intra segment Jump Far Jump or Inter segment Jump
Near Jump
2-bytes Short Jump (EB r8) 3-bytes Long Jump (E9 r16) 2 or more bytes
7 15
Range: + 2 Range: +2 Starting with FFH
Three Near Jump and two Far Jump instructions have the same mnemonic JMP, but they have
different opcodes
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.
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).
Assembler generates only 2 byte Short Jump code for forward jump, if the SHORT assembler
directive is used.
CS:0000H :
FRWD = CS:FFFFH :
FRWD = CS:FFF0H :
CS:FFFFH :
CS:FFFFH :
Ex.1: JMP DX
As stated earlier, three Near Jump and two Far Jump instructions have the same mnemonic
JMP but different opcodes.
Also called Far Direct Jump. It is the common inter segment jump scheme
It is a 5 byte instruction. 1 byte opcode (EAH), 2 byte offset value, 2 byte segment value
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.
DS:3234H 5678H
DS:3236H ABCDH
Iteration Instructions
Iteration instructions
: :
JNZ AGAIN
Used for backward jump only. Maximum distance for backward jump is only 128 bytes.
JNZ AGAIN
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.
JCXZ SKIP
LOOP AGAIN
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.
MOV BX, DX
ADD SI, DI
CALL instruction is used to branch to a subroutine. There are no conditional Call instructions in
8086.
CALL instructions
Near CALL or Intra segment CALL Far CALL or Inter segment CALL
Near Direct CALL Near Indirect CALL Far Direct CALL Far Indirect CALL
It is a 3-byte instruction. It has the format CALL r16 and has the range + 32K bytes.
Covers the entire Code segment. It is the most common CALL instruction.
It is functionally same as the combination of the instructions PUSH IP and ADD IP, r16.
DS:3234H 5678H
DS:3236H ABCDH
PUSH CS
PUSH IP
Not commonly used. Instruction length depends on the way the called location is specified.
DS:3234H 5678H
DS:3236H ABCDH
Solution:
JC NEXT
NEXT:
RET instructions
Near RET or Intra segment RET Far RET or Inter segment RET
Ex:
RET
SP = SP + d16
RET d16 is useful for flushing out the parameters that were passed to the subroutine using the
stack
Main Program
:
Subroutine
COMPUTE PROC Near IP
: Var1
COMPUTE ENDP
RET
RET d16 is useful for flushing out the parameters that were passed to the subroutine using the
stack.
Unit -5
Often it is a good idea to link assembly language programs or routines with high-level programs
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
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.
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
declare global any data that will be used.
Use the EXTERN directive to declare global data and procedures as external. It is best to
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.
push ebp
mov ebp, esp
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."
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.
C passes arguments to procedures on the stack. For example, consider the following statements
from a C main program:
|
extern int Sum();
|
int a1, a2, x;
|
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:
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
the sum of the input arguments via register EAX, might look like the following:
_Sum
push ebp ; create stack frame
mov ebp, esp
mov eax, [ebp+8] ; grab the first argument
mov ecx, [ebp+12] ; grab the second argument
add eax, ecx ; sum the arguments
pop ebp ; restore the base pointer
ret
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
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.
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
means "address of." We say that &a2 is a "pointer" to the variable a2. Using the above statement,
the stack would contain the following upon entering Sum:
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).
Assembly can return values to the C calling program using only the EAX register. If the returned
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:
char AL
short AX
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:
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.
global _main
extern _printf
section .data
section .code
_main
push dword text
Notice that the procedure is declared global, and its name must be _main, which is the starting
point of all C code.
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
procedures involved in calling C functions, refer to another text on the subject.
Unit-6
GND 1 40 Vcc
AD14 2 39 AD15
AD13 3 38 A16/S3
AD12 4 37 A17/S4
AD11 5 36 A18/S5
AD10 6 35 A19/S6
AD9 7 34 BHE/S7
AD8 8 33 MN/MX
AD7 9 32 RD
AD6 10 31 RG/GT0 (HOLD)
AD5
AD4
11
12
8086 30
29
RQ/GT1 (HLDA)
LOCK (WR)
AD3 13 28 S2 (M/I0)
AD2 14 27 S1 (DT/R)
AD1 15 26 S0 (DEN)
AD0 16 25 QS0 (ALE)
NMI 17 24 QS1 (INTA)
INTR 18 23 TEST
CLK 19 22 READY
GND 20 21 RESET
The following pin function descriptions are for the microprocessor 8086 in either minimum or
maximum mode. The 8086 pins signals are TTL compatible.
These lines constitute the time multiplexed memory/IO address during the first clock cycle
(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.
T4 T1 T2 T3 T4
Fig. .2
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.
The status of the flag is indicated through this bus.
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.
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
operations to one segment from erroneously overlapping into another segment and destroying information
in that segment.
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
floats to 3-state during "hold" state. This pin is Low during T1 state for the first interrupt acknowledge
cycle.
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)
TEST pin is examined by the "WAIT" instruction. If the TEST pin is Low, execution
continues. Otherwise the processor waits in an "idle" state. This input is
synchronized internally during each clock cycle on the leading edge of CLK.
It is a level triggered input which is sampled during the last clock cycle of each instruction to
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.
An edge triggered input, causes a type-2 interrupt. A subroutine is vectored to via the interrupt
vector look up table located in system memory. NMI is not maskable internally by software. A
transition from a LOW to HIGH on this pin initiates the
interrupt at the end of the current instruction. This input is internally synchronized.
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
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 CLK
CLK
SYSTEM RESET
Fig. .3
Flags Cleared
CS register FFFFH
DS register 0000H
SS register 0000H
ES register 0000H
Queue Empty
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
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
operation is not guaranteed if the setup and hold times are not met.
X1
X2 CLK
F/C READY
8086 p
Csync
RESET
RDY1
AEN1
AEN2 PCLK
Fig..4
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
generate READY, RESET and
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
Indicates that the processor is performing a write memory or write IO cycle, depending on the
state of the M / IO signal. WR is active for T2, T3 and Tw of any write cycle. It is active LOW,
and floats to 3-state OFF during local bus "hold
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.
latch. It is an active high pulse during T1 of any bus cycle. ALE signal is never floated.
transceiver. DEN is active LOW during each memory and IO access. It will be low beginning with T2
until the middle of T4, while for a write cycle, it is active from the beginning of T2 until the middle of T4.
It floats to tri-state off during local bus "hold acknowledge".
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
will lower the HLDA and when the processor needs to run another cycle, it will again drive the local bus
and control lines.
The following pins function descriptions are for the 8086/8088 systems in maximum mode (i.e..
MN/ MX = 0). Only the pins which are unique to maximum mode are described below.
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
of a bus cycle. These status lines are encoded as shown in table 3.
S2 S1 S0 Characteristics
0 0 0 Interrupt acknowledge
0 1 1 Halt
1 0 0 Code access
1 0 1 Read memory
1 1 0 Write memory
1 1 1 Passive State
Table 3
CPU clock cycle and is not related to the bus cycle activity. This mechanism allows
(1) A processor to detect execution of a ESCAPE instruction which directs the co-processor to
perform a specific task and
(2) An in-circuit Emulator to trap execution of a specific memory location.
QS1 QS1 Characteristics
0 0 No operation
Table 4
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
completion of the instruction. This signal is active
LOCK XCHG reg., Memory ; Register is any register and memory GT0
These pins are used by other processors in a multi processor organization. Local bus masters of
other processors force the processor to release the local bus at the end of the processors current bus cycle.
Each pin is bi-directional and has an internal pull up
One bank is connected to the lower half of the 16-bit data bus (D0 D7) and contains even address
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.
Higher Lower
Address Address
Bank Bank
(512K x 8) BHE (512K x 8) A0
ODD EVEN
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.
x + 1 x
x + 3 x + 2
x + 5 x + 4
BHE = 1 A0 = 0
D8-D15 D0-D7
A1-A19
D0-D15
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
bank. It is illustrated in fig. 6.
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-
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.
6.2 .6 8-bit Data from Odd Address Bank
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
the lower memory bank. It is illustrated in fig. 7
x + 1 x
x + 3 x + 2
BHE =0 A0 = 1
A1-A19
D0-D7
D8-D15
D0-D15
Fig. 7
x+1 x
x+3 x+2
A0 = 0
BHE =0
A1-A19 D8-D15
D0-D7
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
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
(with the odd address 0005 as shown in fig. 9 (a)) is accessed.
A1-A19 A1-A19
A1-A9 A1-A9
D0-D7 D0-D7
D8-D15 D8-D15
(a) First Access from Odd Address (b) Next Access from Even Address Fig. 9
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
bank is enabled and the odd memory bank is disabled.
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
is used to strobe the addresses into the 8282 I/O latches.
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.
When MN/ MX pin is strapped to GND, the 8086 treats pin 24 through 31 to be in maximum
mode. An 8288 bus controller interprets status information coded into S0, S1 and S2 to generate bus
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
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
Clock CLK M/IO
READY Control
generator INTA
RES RESET Bus
RD
AEN2 WR
AEN1
F/C MN/MX +5V
D0 - D15
8286 16
DT/R T
DEN OE
+5V
MN/MX Gnd CLK MRDC
CLK
S0 S0
Clock READY MWTC
RES S1 S1
generator
S2 S2 AMWC
RESET
IORC
DEN IOW C
DT/R AIOWC
Wait-State ALE INTA
Generator
STB A0 - A19
OE
Address Bus
8282
AD0-AD15
Latch BHE
A16-A19
T
OE DATA
8286
Transceiver
During T1 state of a read machine cycle an 8086 first asserts the M/ IO signal. It will assert this
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
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
going high or going low at this point. The crossed lines indicate the time at which a valid address is on
the bus.
T1 T2 T3 Twait T4
CLK
AD0-AD15
BHE
ALE
S2-S0
M/IO
RD
READY
DT/R
DEN
WR
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
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-
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
valid data is made available on the data bus.
If the READY input pin is not high at the sampled time in a machine cycle, the 8086 will insert
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.
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
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
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
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
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
address lines. After the address information is latched, the 8086 remove the address information from
AD0 - AD15 and outputs the desired data on these lines.
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
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
8088 handles only 8-bits at a time. 16-bit operands are fetched or written in two
A16/S3(4)
A19/S6
8088 WR (LOCK)
IO/M (S2)
Test
DT/R(S1)
Ready
DEN (S0)
ALE (QS0)
Reset
INTA (QS1)
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.
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
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
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.
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
minimum mode. This is shown in table 5
0 0 0 Code Access
0 0 1 Read Memory
0 1 0 Write Memory
0 1 1 Passive
1 0 0 Interrupt Acknowledge
1 1 1 Halt
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.
Fig 15 illustrates the 8088 microprocessor system configuration. The Address-Data lines AD0-
AD7 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
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
lines. The output of 74LS244 is always enabled.
OE
A19/S6 - A16/S3 A19 - A16
74LS373
ALE G
74LS
A15 - A8
244
OE
8088 OE
G A0 - A7
AD0 - AD7
74LS373
DT/R DEN
D0 - D7
74LS244
G D/R
Fig. 15
UNIT -7
Unit-8
8.1 Interrupt Driver I/O
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.
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.
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. 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.
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.
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.
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.
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.
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.
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.
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
nterrupt address vector by using external hardware. The daisy chain priority scheme is based on
mostly hardware and is therefore faster than the polled interrupt.
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.
There are three basic types of DMA: block transfer, cycle stealing, and interleaved DMA.
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.
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.
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
Interrupt driven I/O data transfer done immediately after I/O device interrupts
(Ex. Collect newspaper when the door bell rings indicating delivery of newspaper)
Interrupt types
Ex. NMI and INTR pins Ex. INT n, INT 3, INTO Ex. Divide by zero error,
instructions Single step interrupt
Every interrupt type in 8086 has an 8-bit Interrupt type number (ITN) as shown below.
2 NMI 7 No Coprocessor
4. Reset T flag (so that interrupt service subroutine, ISS, is not executed in single step)
5. PUSH CS
6. PUSH IP
RAM locations 0 to 003FFH are used to store IVT. It contains 256 Interrupt
Vectors (IV) each of 4 bytes.
00000H 1234H
00004H 3344H
: : :
003FCH 6677H
4. PUSH CS
5. PUSH IP
In INT n, which is a 2-byte instruction, n is the ITN. INT n has the opcode CDH
4. PUSH CS
5. PUSH IP
Ex. DIV BL
Before After
BL 02H
4. PUSH CS
5. PUSH IP
Processor makes a branch to the subroutine at location 5678:1234H if the contents of IVT is as
shown in the table above.
4. PUSH CS
5. PUSH IP
Processor makes a branch to the subroutine at location 5566:3344H as per the IVT
4. PUSH CS
5. PUSH IP
INT 4
Next: .
2. Activate INTA o/p twice. In response 8086 receives ITN n instruction from an external device
like 8259 PIC
4. PUSH CS
5. PUSH IP
IP
CS
If several interrupts occur during the execution of an instruction, in which order interrupts will be
serviced? There will be priorities as indicated below.
NMI
INTR
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.
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.
Knowledge of 8255 essential for students in the Microprocessors lab for interfacing experiments.
A6
RD* Port C
PC7-4
Con trol Port
A5 D7-0
Port B PC3-0
A4 A1
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)
Selection of Ports
A1 A0 Selected port
0 0 Port A
0 1 Port B
1 0 Port C
1 1 Control port
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.
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.
There are 3 modes of operation for the ports of 8255. Mode 0, Mode 1, and Mode 2.
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.
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.
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.
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.
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.
PC7, 6, 3 are used as handshake signals by Port A when configured as output port in Mode 1.
Mode definition control word is used to configure the ports of 8255 as input or output in Mode 0, Mode 1,
or Mode
0 - PB as output
0 0 Port A in Mode 0
1 - PB in Mode 1
0 1 Port A in Mode 1
0 - PB in Mode 0
1 0/1 Port A in Mode 2
1 0 0 1 1 0 0 0 = 98H
PA in Mode 0 PB as output
PA as input PB in Mode 0
PC Upper as input