Lecture 2
Lecture 2
AND
INTERFACING
(Internal Architecture)
What is Microprocessor?
The word comes from the combination Micro and Processor.
Processor means a device that processes whatever.
The microprocessor is a programmable device that takes in
numbers, performs on them arithmetic or logical operations
according to the program stored in memory and then produces other
numbers as a result.
Basic Concepts of Microprocessors
Differences between:
• Microprocessor – silicon chip which includes ALU, register circuits
& control circuits. It is a general purpose chip.
• Microcomputer – a computer with a microprocessor as its CPU.
Includes memory, I/O etc.
• Microcontroller – silicon chip which includes microprocessor,
memory & I/O in a single package, designed for a very specific
task.
A Microprocessor-based System
• From the above description, we can draw the following block diagram
to represent a microprocessor-based system:
• Harvard Architecture
• Two memories (instruction & data)
Self Study:
• Hall—chp1: fig: 1.8,1.9, 1.10, RISC vs CISC
• Marut— chp 1,3
Data Bus
The CPU is connected to memory and I/O device through a
strip of wires called a bus.
• EU contains
• Control circuitry
• Instruction decoder
• ALU
• General purpose register
• Pointer and Index register
• Flag register.
Execution Unit
• Control System has two component
• Instruction decoder-- works to translate or decode instructions which are fetched from the
memory into a series of actions which EU caries out
• Control unit-- generate timing and control signals to perform internal operation
8 bits 8 bits
AH AL
AX Accumulator
General
Purpose
BH BL Base
BX
register
CX
CH CL Count
DX DH DL
Data
SP Stack Pointer
Pointer
BP Base Pointer
SI Source Index
Index
DI Destination Index
General Purpose Registers
AH AL AX
BH BL BX
CH CL CX
DH DL DX
General Purpose Registers
AH AL AX
BH BL BX
CH CL CX
DH DL DX
General Purpose Registers
AH AL AX
BH BL BX
CH CL CX
DH DL DX
General Purpose Registers
AH AL AX
BH BL BX
CH CL CX
DH DL DX
General Purpose Registers
Register Purpose
AX Arithmetic/logic/ I/O operation, Word multiply, word divide
SP
BP
SI
DI
Pointer and Index Register
SP
BP
SI
DI
Flag Register
• A flag is a flip flop which indicates some conditions produced by the execution of
an instruction or controls certain operations of the EU .
U U U U OF DF IF TF SF ZF U AF U PF U CF
U - Unused
Flag Register
Flag Purpose
Carry (CF) Holds the carry after addition or the borrow after subtraction.
Also indicates some error conditions, as dictated by some
programs and procedures .
Parity (PF) PF=0;odd number of 1, PF=1;even number of 1.
Auxiliary (AF) Holds the carry (half – carry) after addition or borrow after subtraction
between bit positions 3 and 4 of the result
(for example, in BCD addition or subtraction.)
Zero (ZF) Shows the result of the arithmetic or logic operation.
ZF=1; result is zero. ZF=0; The result is 0
Sign (SF) Holds the sign of the result after an arithmetic/logic instruction
execution. SF=1; negative, SF=0; positive
Flag Register
Flag Purpose
If set then processor enters the single step execution mode by
Trap (TF)
generating internal interrupts after the execution of each instruction
A control flag (debugging)
AL = 80h 7F = 0 1 1 1 1 1 1 1
CF = 0; there is no carry out of bit 7 +1
PF = 0; 80h has an odd number of ones ---------------------------
80 = 1 0 0 0 0 0 0 0
AF = 1; there is a carry out of bit 3 into bit 4
ZF = 0; the result is not zero 34F5 + 95EB = ?
SF = 1; bit seven is one
OF = 1; the sign bit has changed CF = 0 ; PF = 0 ; AF = 1
ZF = 0 ; SF = 1 ; OF = 0
Example
• 35 + 19 = ?
• 35 + 5B = ?
• 35 + D3 = ?
• 9E + D3 = ?
mov AL,43
add AL,94
Bus Interface Unit (BIU)
Contains
• 6-byte Instruction Queue (Q)
• The Segment Registers (CS, DS, ES, SS)
• The Instruction Pointer (IP)
• The Address Summing block (Σ)
34
The Queue
• As shown in the above figure, while the EU is busy in decoding the instruction
corresponding to memory location 100F0, the BIU fetches the next six instruction
bytes from locations 100F1 to 100F6 numbered as 1 to 6.
• These instruction bytes are stored in the 6 byte queue on the first in first out
(FIFO) basis.
• When EU completes the execution of the existing instruction and becomes ready
for the next instruction, it simply reads the instruction bytes in the sequence 1,
2…. from the Queue.
• Thus the Queue will always hold the instruction bytes of the next instructions to
be executed by the EU.
The Queue
Pipelining:
• The process of fetching the next instruction when the present instruction is
being executed is called as pipelining.
• Pipelining has become possible due to the use of queue.
• BIU (Bus Interfacing Unit) fills in the queue until the entire queue is full.
• BIU restarts filling in the queue when at least two locations of queue are
vacant.
The Queue
Advantages of pipelining:
• The execution unit always reads the next instruction byte from the queue in
BIU. This is faster than sending out an address to the memory and waiting for
the next instruction byte to come.
• In short pipelining eliminates the waiting time of EU and speeds up the
processing.
• The 8086 BIU will not initiate a fetch unless and until there are two empty
bytes in its queue. 8086 BIU normally obtains two instruction bytes per fetch.
The Queue
FFFFFH
1 MB
Data segment (64KB)
00000H
Segmented Memory
Advantages of Segmented Memory Scheme
• Allows the memory capacity to be 1Mb although the actual addresses to be
handled are of 16 bit size.
• Allows the placing of code, data and stack portions of the same program in
different parts (segments) of the memory, for data and code protection.
• Permits a program and/or its data to be put into different areas of memory
each time program is executed, i.e. provision for relocation may be done .
• It allows to extend the address ability of a processor i.e. segmentation allows
the use of 16 bit registers to give an addressing capability of 1 MB. Without
segmentation, it would require 20 bit registers.
Segmented Memory
Code segment :
The part of memory from where BIU is currently fetching instruction
code bytes. This address plus the offset value contained in the instruction
pointer (IP) indicates the address of an instruction to be fetched for
execution. (CS : IP)
Stack segment :
A section of memory set aside to store address and data while a sub
program executes. This address plus the offset value contained in the stack
pointer (SP) is used for stack operation. (SS : SP)
• To form a 20bit address of the next instruction, the 16 bit address of the IP is added (by the
address summing block) to the address contained in the CS, which has been shifted four bits to
the left.
• To calculate the effective address of the memory, BIU uses the following formula:
• Effective Address = Starting Address of Segment + Offset
• To find the starting address of the segment, BIU appends the contents of Segment Register
with 0H. Then, it adds offset to it.
Therefore:
EA = 2 2 2 2 0 H
+ 0016H
-------------------
22236H
Summing Block
• The following examples shows the CS:IP scheme of address formation
34BA0(CS)
+8AB4(IP)
3 D 6 5 4 (next address)
44B9F
Segment and Address Register Combination