FMPMC Unit 1
FMPMC Unit 1
1.1 Introduction
Microcomputer: The term microcomputer is generally synonymous with
personal computer, or a computer that depends on a microprocessor.
Microcomputers are designed to be used by individuals, whether in
the form of PCs, workstations or notebook computers.
A microcomputer contains a CPU on a microchip (the
microprocessor), a memory system (typically ROM and RAM), a bus
system and I/O ports, typically housed in a motherboard.
Microprocessor: A silicon chip that contains a CPU. In the world of
personal computers, the terms microprocessor and CPU are used
interchangeably.
A microprocessor (sometimes abbreviated µP) is a digital electronic
component with miniaturized transistors on a single semiconductor
integrated circuit (IC).
One or more microprocessors typically serve as a central processing
unit (CPU) in a computer system or handheld device.
Microprocessors made possible the advent of the microcomputer.
At the heart of all personal computers and most working stations
sits a microprocessor.
Microprocessors also control the logic of almost all digital devices,
from clock radios to fuel-injection systems for automobiles.
Three basic characteristics differentiate microprocessors:
Instruction set: The set of instructions that the microprocessor can
execute.
Bandwidth: The number of bits processed in a single instruction.
Clock speed: Given in megahertz (MHz), the clock speed determines
how many instructions per second the processor can execute.
In both cases, the higher the value, the more powerful the CPU. For
example, a 32-bit microprocessor that runs at 50MHz is more
powerful than a 16-bit microprocessor that runs at 25MHz.
1
In addition to bandwidth and clock speed, microprocessors are
classified as being either RISC (reduced instruction set computer) or
CISC (complex instruction set computer)
2
Microprocessor and Microcontroller
Accumulator
Accumulator is nothing but a register which can hold 8-bit data.
Accumulator aids in storing two quantities. The data to be processed by
arithmetic and logic unit is stored in accumulator. It also stores the result of the
operation carried out by the Arithmetic and Logic unit. The accumulator is also
called an 8-bit register. The accumulator is connected to Internal Data bus and
ALU (arithmetic and logic unit). The accumulator can be used to send or receive
data from the Internal Data bus.
3
Fig. 1.1 8085 Architecture
4
Microprocessor and Microcontroller
Yes. Stack pointer maintains the address of the last byte that is entered into
stack.
Each time when the data is loaded into stack, Stack pointer gets
decremented. Conversely it is incremented when data is retrieved from stack.
Temporary Register
As the name suggests this register acts as a temporary memory during the
arithmetic and logical operations. Unlike other registers, this temporary
register can only be accessed by the microprocessor and it is completely
inaccessible to programmers. Temporary register is an 8-bit register.
Flags
Flags are nothing but a group of individual Flip-flops. The flags are mainly
associated with arithmetic and logic operations. The flags will show either a
logical (0 or 1) (i.e.) a set or reset depending on the data conditions in
accumulator or various other registers. A flag is actually a latch which can hold
some bits of information. It alerts the processor that some event has taken
place.
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
Fig. 1.2 Flag Register
Intel processors have a set of 5 flags.
1. Carry flag
2. Parity flag
3. Auxiliary carry flag
4. Zero flag
5. Sign flag
Consider two binary numbers.
For example
1100 0000
1000 0000
When we add the above two numbers, a carry is generated in the most
significant bit. The number in the extreme right is least significant bit, while the
number in extreme left is most significant bit. So, a ninth bit is generated due to
the carry. So how to accommodate 9th bit in an 8-bit register?
For this purpose, the Carry flag is used. The carry flag is set whenever a
carry is generated and reset whenever there is no carry. But there is an
5
auxiliary carry flag? What is the difference between the carry flag and auxiliary
carry flag?
Let’s discuss with an example. Consider the two numbers given below
0000 1100
0000 1001
When we add both the numbers a carry is generated in the fourth bit from
the least significant bit. This sets the auxiliary carry flag. When there is no
carry, the auxiliary carry flag is reset. So, whenever there is a carry in the most
significant bit Carry flag is set. While an auxiliary carry flag is set only when a
carry is generated in bits other than the most significant bit.
Parity checks whether it’s even or add parity. This flag returns a 0 if it is
odd parity and returns a 1 if it is an even parity. Sometimes they are also called
as parity bit which is used to check errors while data transmission is carried
out.
Zero flag shows whether the output of the operation is 0 or not. If the value
of Zero flag is 0 then the result of operation is not zero. If it is zero the flag
returns value 1.
Sign flag shows whether the output of operation has positive sign or
negative sign. A value 0 is returned for positive sign and 1 is returned for
negative sign.
6
Microprocessor and Microcontroller
7
data. If READY is low, the CPU will wait an integral number of clock
cycle for READY to go high before completing the read or write
cycle. READY must conform to specified setup and hold times.
Interrupt control
As the name suggests this control interrupts a process. Consider that a
microprocessor is executing the main program. Now whenever the interrupt
signal is enabled or requested the microprocessor shifts the control from main
program to process the incoming request and after the completion of request,
the control goes back to the main program. For example, an Input/output
device may send an interrupt signal to notify that the data is ready for input.
The microprocessor temporarily stops the execution of main program and
transfers control to I/O device. After collecting the input data, the control is
transferred back to main program. Interrupt signals present in 8085 are:
INTR
RST 7.5
RST 6.5
RST 5.5
TRAP
INTR is maskable 8080A compatible interrupt. When the interrupt occurs
the processor fetches from the bus one instruction, usually one of these
instructions: One of the 8 RST instructions (RST0 - RST7). The processor saves
current program counter into stack and branches to memory location N * 8
(where N is a 3 - bit number from 0 to 7 supplied with the RST instruction).
8
Microprocessor and Microcontroller
9
Address bus and Data bus
We know that 8085 is an 8-bit microprocessor. So, the data bus present in
the microprocessor is also 8-bits wide. So, 8-bits of data can be transmitted
from or to the microprocessor. But 8085 processor requires 16-bit address bus
as the memory addresses are 16-bit wide. The 8 most significant bits of the
address are transmitted with the help of address bus and the 8 least significant
bits are transmitted with the help of multiplexed address/data bus. The eight-
bit data bus is multiplexed with the eight least significant bits of address bus.
The address/data bus is time multiplexed. This means for few microseconds,
the 8 least significant bits of address are generated, while for next few seconds
the same pin generates the data. This is called Time multiplexing. But there are
situations where there is a need to transmit both data and address
simultaneously. For this purpose, a signal called ALE (address latch enables) is
used. ALE signal holds the obtained address in its latch for a long time until the
data is obtained and so when the microprocessor sends the data next time the
address is also available at the output latch. This technique is called
Address/Data demultiplexing.
10
Microprocessor and Microcontroller
11
1.5 Instruction Set
The 8085 instruction set can be classified into the following five functional
headings.
Data Transfer Instructions: Includes the instructions that moves (copies)
data between registers or between memory locations and registers. In all data
transfer operations, the content of source register is not altered. Hence the data
transfer is copying operation.
Arithmetic Instructions: Includes the instructions, which performs the
addition, subtraction, increment or decrement operations. The flag conditions
are altered after execution of an instruction in this group.
Logical Instructions: The instructions which performs the logical
operations like AND, OR, EXCLUSIVE-OR, complement, compare and rotate
instructions are grouped under this heading. The flag conditions are altered
after execution of an instruction in this group.
Branching Instructions: The instructions that are used to transfer the
program control from one memory location to another memory location are
grouped under this heading.
Machine Control Instructions: Includes the instructions related to
interrupts and the instruction used to halt program execution.
12
Microprocessor and Microcontroller
13
1.9 Branching Instructions
This group of instructions alters the sequence of program execution either
conditionally or unconditionally.
Opcode Operand Description
JMP 16-bit address Jump unconditionally
Jx 16-bit address Jump conditionally
14
Microprocessor and Microcontroller
Immediate Addressing
In immediate addressing mode, the data is specified in the instruction itself.
The data will be a part of the program instruction.
EX. MVI B, 3EH - Move the data 3EH given in the instruction to B register;
LXI SP, 2700H.
Direct Addressing
In direct addressing mode, the address of the data is specified in the
instruction. The data will be in memory. In this addressing mode, the program
instructions and data can be stored in different memory.
EX. LDA 1050H - Load the data available in memory location 1050H in to
accumulator; SHLD 3000H
Register Addressing
In register addressing mode, the instruction specifies the name of the
register in which the data is available.
EX. MOV A, B - Move the content of B register to A register; SPHL; ADD C.
Implied Addressing
In implied addressing mode, the instruction itself specifies the data to be
operated. EX. CMA - Complement the content of accumulator; RAL
15
1.12 Assembly Language Programming
An assembly language is a low-level programming language for a computer,
or other programmable device, in which there is a very strong (generally one-
to-one) correspondence between the language and the architecture's machine
code instructions. Each assembly language is specific to a particular computer
architecture, in contrast to most high-level programming languages, which are
generally portable across multiple architectures, but require interpreting or
compiling.
Assembly language is converted into executable machine code by a utility
program referred to as an assembler; the conversion process is referred to as
assembly, or assembling the code.
Assembly language uses a mnemonic to represent each low-level machine
operation or opcode. Some opcodes require one or more operands as part of
the instruction, and most assemblers can take labels and symbols as operands
to represent addresses and constants, instead of hard coding them into the
program.
16
Microprocessor and Microcontroller
What is an Assembler?
An assembler is a software tool - a program -- designed to simplify the task
of writing computer programs. If you have ever written a computer program
directly in a machine-recognizable form such as binary or hexadecimal code,
you will appreciate the advantages of programming in a symbolic assembly
language.
Assembly language operation codes (opcodes) are easily remembered
(MOV for move instructions, JMP for jump). You can also symbolically express
addresses and values referenced in the operand field of instructions. Since you
assign these names, you can make them as meaningful as the mnemonics for
the instructions. For example, if your program manipulates a date as data, you
can assign it the symbolic name DATE. If your program contains a set of
instructions used as a timing loop (a set of instructions executed repeatedly
until a specific amount of time has passed), you can name the instruction group
TIMER.
17
Fig. 1.16 Function of an Assembler
18
Microprocessor and Microcontroller
19
UNIT I(2)-8086 MICROPROCESSOR
3.1 Introduction
The 8086 is a 16-bit microprocessor intended to be used as the CPU in a
microcomputer. The term “16-bit” means that its arithmetic logic unit, internal
registers, and most of its instructions are designed to work 16-bit binary words.
It has 16-bit data bus and 20-bit address bus.
Words will be stored in two consecutive memory locations. If the first byte
of a word is at an even address, the 8086 can read the entire word in one
operation. If the first byte of the word is at an odd address, the 8086 will read
the first byte in one operation, and the second byte in another operation.
Features
8086 is a 40 pin IC.
It is a 16-bit processor.
Its operating voltage is 5 volts.
Its operating frequency is 5 MHz
The total memory addressing capacity is 1MB (external).
It has 16-bit data bus and 20-bit address bus.
It has fourteen 16-bit registers.
It has around 20000 transistors in its circuitry and it is made in
HMOS technology.
Pipelining improves the performance of the processor so that
operation is faster.8086 uses two stage of pipelining.
First is Fetch Stage and the second is Execute Stage.
Fetch stage that prefetch upto 6 bytes of instructions stores them in
the queue.
Execute stage that executes these instructions.
Operates in two modes: 8086 operates in two modes:
90
Microprocessor and Microcontroller
AD15-AD0
These are the time multiplexed memory I/O address and data lines.
Address remains on the lines during T1 state, while the data is available on the
data bus during T2, T3, TW and T4. Here T1, T2, T3, T4 and TW are the clock
states of a machine cycle. TW is a wait state. These lines are active high and
float to a tristate during interrupt acknowledge and local bus hold acknowledge
cycles.
91
A19/S6, A18/S5, A17/S4, A16/S3: These are the time multiplexed
address and status lines. During T1, these are the most significant address lines
or memory operations. During I/O operations, these lines are low. During
memory or I/O operations, status information is available on those lines for T2,
T3, TW and T4.The status of the interrupt enable flag bit(displayed on S5) is
updated at the beginning of each clock cycle. The S4 and S3 combined, indicate
which segment register is presently being used for memory accesses as shown
in the following table.These lines float to tri-state off during the local bus hold
acknowledge. The status line S6 is always low(logical). The address bits are
separated from the status bits using latches controlled by the ALE signal.
RD-Read: Read signal, when low, indicates the peripherals that the
processor is performing a memory or I/O read operation. RD is active low and
92
Microprocessor and Microcontroller
shows the state for T2, T3, TW of any read cycle. The signal remains in high-
impedance during the 'hold acknowledge'.
Ready: This is the acknowledgement from the slow devices or memory that
they have completed the data transfer. The signal made available by the devices
is synchronized by the 8284A clock generator to provide ready input to the
8086. The signal is active high.
Reset: This input causes the processor to terminate the current activity and
start execution from FFFF0H. The signal is active high and must be active for at
least four clock cycles. It restarts execution when the RESET returns low.
RESET is also internally synchronized.
CLK-Clock Input: The clock input provides the basic timing for processor
operation and bus control activity. It’s an asymmetric square wave with 33%
duty cycle. The range of frequency for different 8086 versions is from 5MHz to
10MHz.
VCC : +5V power supply for the operation of the internal circuit. GND
ground for the internal circuit.
93
MN/MX: The logic level at this pin decides whether the processor is to
operate in either minimum (single processor) or maximum (multiprocessor)
mode.
The following pin functions are for the minimum mode operation of 8086.
DEN-Data Enable This signal indicates the availability of valid data over
the address/data lines. It is used to enable the transceivers (bidirectional
buffers) to separate the data from the multiplexed address/data signal. It is
active from the middle of T2 until the middle of T4 DEN is in high-impedance
state during 'hold acknowledge' cycle.
94
Microprocessor and Microcontroller
control lines. When the processor detects the HOLD line low, it lowers the
HLDA signal. HOLD is an asynchronous input, and it should be externally
synchronized. If the DMA request is made while the CPU is performing a
memory or I/O cycle, it will release the local bus during T 4 provided:
1. The request occurs on or before T 2 state of the current cycle.
2. The current cycle is not operating over the lower byte of a word (or
operating on an odd address).
3. The current cycle is not the first acknowledge of an interrupt
acknowledge sequence.
4. A Lock instruction is not being executed.
The following pin functions are applicable for maximum mode operation of
8086.
S2, S1, S0 -Status Lines: These are the status lines which reflect the type of
operation, being carried out by the processor. These become active during T4 of
the previous cycle and remain active during T1 and T2 of the current bus cycle.
The status lines return to passive state during T3 of the current bus cycle so
that they may again become active for the next bus cycle during T4. Any change
in these lines during T3 indicates the starting of a new cycle, and return to
passive state indicates end of the bus cycle. These status lines are encoded in
the following table.
Table 3.3 Status Lines Indication
S2 S1 S0 Indication
0 0 0 Interrupt acknowledge
0 0 1 Read I/O port
0 1 0 Write I/O port
0 1 1 Halt
1 0 0 Code access
1 0 1 Read memory
1 1 0 Write memory
1 1 1 Passive
Lock
This output pin indicates that other system bus masters will be prevented
from gaining the system bus, while the LOCK signal is low. The LOCK signal is
activated by the 'LOCK' prefix instruction and remains active until the
completion of the next instruction. This floats to tri-state off during "hold
95
acknowledge". When the CPU is executing a critical instruction, which requires
the system bus, the LOCK prefix instruction ensures that other processors
connected in the system will not gain the control of the bus. The 8086, while
executing the prefixed instruction, asserts the bus lock signal output, which
may be connected to an external bus controller.
96
Microprocessor and Microcontroller
Instruction Queue
To increase the execution speed, BIU fetches as many as six instruction
bytes ahead to time from memory. The prefetched instruction bytes are held for
the EU in a first in first out group of registers called an instruction queue. When
the EU is ready for its next instruction, it simply reads the instruction from this
instruction queue. This is much faster than sending out an address to the
system memory and to send back the next instruction byte. Fetching the next
instruction while the current instruction executes is called pipelining.
98
Microprocessor and Microcontroller
Flag Register
A 16-bit flag register is a flip-flop which indicates some condition produced
by the execution of an instruction or controls certain operations of the EU. They
are modified automatically by CPU after mathematical operations. It has 9 flags
and they are divided into two categories:
1. Conditional Flags
2. Control Flags
Conditional Flags
Conditional flags represent result of last arithmetic or logical instructions.
Carry Flag (CF): This flag will be set to one if the arithmetic
operation produces the carry in MSB position. It is also used in
multiple-precision arithmetic.
Auxiliary Flag (AF): If an operation performed in ALU generates a
carry/barrow from lower nibble (i.e. D0 – D3) to upper nibble (i.e.
D4 – D7), the AF flag is set i.e. carry given by D3 bit to D4 is AF flag.
This is not a general-purpose flag; it is used internally by the
processor to perform Binary to BCD conversion.
Parity Flag (PF): This flag is used to indicate the parity of result. If
lower order 8-bits of the result contains even number of 1’s, the
Parity Flag is set to one and for odd number of 1’s, the Parity Flag is
reset i.e. zero.
Zero Flag (ZF): It is set to one; if the result of arithmetic or logical
operation is zero else it is reset.
Sign Flag (SF): In sign magnitude format the sign of number is
indicated by MSB bit. If the result of operation is negative, sign flag
is set to one.
99
Overflow Flag (OF): It occurs when signed numbers are added or
subtracted. An OF indicates that the result has exceeded the
capacity of machine.
Control Flags
Control flags are intentionally set or reset to control certain operations of
the processor with specific instructions put in the program from the user.
Control flags are as follows:
1. Trap Flag (TF): It is used for single step control. It allows user to
execute one instruction of a program at a time for debugging. When
trap flag is set, program can be run in single step mode.
2. Interrupt Flag (IF): It is an interrupt enable/disable flag, i.e. used
to allow/prohibit the interruption of a program. If it is set, the
maskable interrupt is enabled and if it is reset, the interrupt is
disabled.
3. Direction Flag (DF): It is used in string operation. If it is set, string
bytes are accessed from higher memory address to lower memory
address. When it is reset, the string bytes are accessed from lower
memory address to higher memory address.
100
Microprocessor and Microcontroller
101
Fig 3.5 Min/Max mode signals
3.8 Interrupts
An interrupt is the method of processing the microprocessor by peripheral
device. An interrupt is used to cause a temporary halt in the execution of
program. Microprocessor responds to the interrupt with an interrupt service
routine, which is short program or subroutine that instructs the
microprocessor on how to handle the interrupt.
There are two basic type of interrupt, maskable and non-maskable, non-
maskable interrupt requires an immediate response by microprocessor, it
usually used for serious circumstances like power failure. A maskable interrupt
is an interrupt that the microprocessor can ignore depending upon some
predetermined upon some predetermined condition defined by status register.
110
Microprocessor and Microcontroller
Hardware Interrupt
The primary sources of interrupts, however, are the PCs timer chip,
keyboard, serial ports, parallel ports, disk drives, CMOS real-time clock, 4
mouse, sound cards, and other peripheral devices. These devices connect to an
Intel 8259A programmable interrupt controller (PIC) that prioritizes the
interrupts and interfaces with the 80x86 CPU. The 8259A chip adds
considerable complexity to the software that processes interrupts.
Maskable Interrupt
Whenever an external signal activates the INTR pin, the microprocessor will
be interrupted only if interrupts are enabled using set interrupt Flag
instruction. If the interrupts are disabled using clear interrupt Flag instruction,
the microprocessor will not get interrupted even if INTR is activated. That is,
111
INTR can be masked. INTR is a non-vectored interrupt, which means, the 8086
does not know where to branch to service the interrupt. The 8086 has to be
told by an external device like a Programmable Interrupt controller regarding
the branch. Whenever the INTR pin is activated by an I/O port, if Interrupts are
enabled and NMI is not active at that time, the microprocessor finishes the
current instruction that is being executed and gives out a ‘0’ on INTA pin twice.
When INTA pin goes low for the first time, it asks the external device to get
ready. In response to the second INTA the microprocessor receives the 8 bits,
say N, from a programmable Interrupt controller. The action taken is as follows.
1. Complete the current instruction.
2. Activates INTA output, and receives type Number, say N
3. Flag register value, CS value of the return address & IP value of their
turn address are pushed on to the stack.
4. IP value is loaded from contents of word location N x 4.
5. CS is loaded from contents of the next word location.
6. Interrupt Flag and trap Flag are reset to 0.
At the end of the ISS, there will be an IRET instruction. This performs
popping off from the stack top to IP, CS and Flag registers. Finally, the register
values which are also saved on the stack at the start of ISS, are restored from
the stack and a return to the interrupted program takes place using the IRET
instruction.
Software Interrupt
There are instructions in 8086 which cause an interrupt. They are
INT instructions with type number specified.
INT 3, Break Point Interrupt instruction.
INTO, Interrupt on overflow instruction.
These are instructions at the desired places in a program. When one of
these instructions is executed a branch to an ISS takes place. Because their
execution results in a branch to an ISS, they are called interrupts. Software
Interrupt instructions can be used to test the working of the various Interrupt
handlers- For example, we can execute INTO instruction to execute type 0 ISS,
without really having to divide a number by 0. Similarly, we can execute INT 2
instruction to test NMI ISS.
112
Microprocessor and Microcontroller
113
INTO - Interrupt on overflow instruction
The overflow flag, OF, will be set if the signed result of an arithmetic
operation on two signed numbers is too large to be represented in the
destination register or memory location. For example, if we add the 8-bit signed
number 01101100 and the 8- bit signed number 01010001, the signed result
will be 10111101. This is correct if we add unsigned binary numbers, but it is
not the correct signed result. There are two ways to detect and respond to an
overflow error in a program. One way is to put the jump if overflow instruction,
JO, immediately after the arithmetic instruction. If the overflow flag is Set,
execution will jump to the address specified in the JO instruction. At this
address an error routine may be put which respond to the overflow. The second
way is to put them INTO instruction immediately after the arithmetic
Instruction in the program. The mnemonic for the instruction is INTO. It is a 1-
byte instruction. The op-code for this is CEH. It is a conditional interrupt
instruction. Only if the overflow flag is Set, a branch takes place to an interrupt
handler whose interrupt type number is 4. If the overflow flag is reset, the
execution continues with the next instruction. The execution of INTO results in
the following.
1. Flag register values are pushed on to the Stack.
2. CS value of the return address and IP value of the return address
and IP value of the return address are pushed on to the stack.
3. IP is loaded from the contents of word location 4x4 = 00010H.
4. CS is loaded from the contents of next word location.
5. Interrupt flag and Trap flag are reset to 0.
Thus, a branch to ISS takes place. During the ISS, interrupts are disabled. At
the end of ISS, there will be an IRET instruction, returning back to the
interrupted program. Instructions in the ISS procedure performs the desired
response to the error condition.
Reset
Processor initialization or start up is accomplished with activation (HIGH)
of the RESET pin. The 8086 RESET is required to be HIGH for greater than 4
CLK cycles. The 8086 will terminate operations on the high-going edge of
RESET and will remain dormant as long as RESET is HIGH. The low-going
transition of RESET triggers an internal reset sequence for approximately 10
CLK cycles. After this interval the 8086 operates normally beginning with the
instruction in absolute location FFFF0H.
114
8086 Bus Configuration and Timings
• The maximum mode system timing diagrams are also divided into two
portions as read (input) and write (output) timing diagrams
• The address/data and address/status timings are similar to minimum
mode
• ALE is asserted in T1 just like minimum mode
• The only difference lies in the status signals used and the available
control and advanced command signals (AIOWC, AMWC..)
Memory write timing in Maximum mode
3.11 Methods of Interfacing I/O Devices
There are two ways by which one can interface I/O devices to a
microprocessor. 1)I/O mapped I/O and 2)Memory mapped I/O.
In memory mapped I/O, the 1 Mb memory that can be interfaced to
8086/8088 itself is used to address I/O devices. But in I/O mapped I/O there is
a separate address space for I/O devices.
Some important differences between I/O mapped I/O and memory mapped
I/O are listed below:
Table 3.6 Difference between memory and I/O mapped I/O
118