Microprocessor
Microprocessor
Sumon Rashid
Lecture-1 Asst. Prof., EEE, PUST
What is Microprocessor?
The integrated Circuit (IC) chip containing the CPU is called the microprocessor
and the entire computer including the microprocessor, memory and I/O is called a
microcomputer.
The terms 32-bit and 64-bit refer to the way a computer's processor (also
called a CPU), handles information. The 64-bit version of Windows handles large
amounts of random access memory (RAM) more effectively than a 32-bit system
A 64-bit processor is capable of storing more computational values, including
memory addresses, which means it’s able to access over four billion times as
much physical memory than a 32-bit processor.
1
Introduction to Microprocessor T. H. M. Sumon Rashid
Lecture-1 Asst. Prof., EEE, PUST
2
Introduction to Microprocessor T. H. M. Sumon Rashid
Lecture-1 Asst. Prof., EEE, PUST
Address Bus:
The 8086 CPU is has 20-bit address bus, where the AD0-AD15
and A16-A20 are used as the address bus.
To demultiplex the address signals from the address/data pins
(AD0-AD15) a latch must be used to grab the addresses.
The most widely used latch for demultiplexing is 74LS373 IC.
For 8088 the address bus is 20 bit and data bus is 8-bit. So only
8-bit is latched
3
Introduction to Microprocessor T. H. M. Sumon Rashid
Lecture-1 Asst. Prof., EEE, PUST
Data Bus:
In 8086 CPU Pins AD0 – AD15 are used for the data bus.
The ALE (Address Latch Enable –pin 25) signals whether the information
on pins AD0 –AD15 is used address or data.
When ALE is low indicates that AD0-AD15 will be used as data bus
When ALE is high indicating that AD0-AD15 will be used as address bus
The address and control bus contains output lines only, therefore it is
unidirectional, but the data bus is bidirectional.
4
Introduction to Microprocessor T. H. M. Sumon Rashid
Lecture-1 Asst. Prof., EEE, PUST
5
Introduction to Microprocessor T. H. M. Sumon Rashid
Lecture-1 Asst. Prof., EEE, PUST
2. The CPU also contains Arithmetic and Logic Unit (ALU). The ALU performs
arithmetic (add, subtract, multiply, divide) and logic (AND, OR, NOT) functions.
3. The CPU contains a program counter also known as the Instruction Pointer to point
the address of the next instruction to be executed.
7
Introduction to Microprocessor T. H. M. Sumon Rashid
Lecture-1 Asst. Prof., EEE, PUST
Pipelined processor
Non-pipelined μpr
(first single-chip μpr.)
In a system with pipelining, the data and the address bus are busy
transferring data while the CPU is processing information.
8
Introduction to Microprocessor T. H. M. Sumon Rashid
Lecture-1 Asst. Prof., EEE, PUST
Other microprocessors
80286: Intel introduced 80286 in 1982.
With 16-bit internal and external data bus.
24-bit address bus (224 = 16 megabyte)
Virtual memory. a way of fooling the microprocessor into thinking
that it has access to unlimited memory by swapping data between disk
storage and RAM.
Real mode (faster operation with maximum of 1 Mbytes of memory)
vs. protected mode protecting the operating system for accidental or
deliberate destruction of the user. Protected mode is slower but can
use 16 Mbytes of memory.
80386: introduced in 1985 also known as (80386DX)
With 32-bit internal and external data bus.
32-bit address bus (232 = 4 gigabyte-physical memory). With virtual
memory 64 terabytes (246).
80386SX was later introduced with the same internal structure with
16-bit external data bus and 24-bit address bus. 80386SX was much
cheaper. 9
Introduction to Microprocessor T. H. M. Sumon Rashid
Lecture-1 Asst. Prof., EEE, PUST
Other microprocessors
All microprocessors discussed so far were general-purpose
microprocessors and could not handle mathematical operations rapidly. For
this reason, 8087, 80287, 80387 numeric data processing chips called
math co-processors were used.
10
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-1 (CONT……)
LOAD A, 2:3
LOAD B, 5:2
PROD A, B
STORE 2:3, A
11
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-1 (CONT……)
Small code sizes, high cycles per second Low cycles per second, large code sizes
Transistors used for storing complex instructions Spends more transistors on memory registers
12
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-1 (CONT…)
Intel family:
4004 1971 2,250 0.108 4 8 12
8008 1972 3,500 0.200 8 8 14
8080 1974 6,000 3 8 8 16
8085 1976 6,000 6 8 8 16
8086 1978 29,000 10 16 16 20 1M
8088 1979 29,000 10 8 16 20 1M
80286 1982 134,000 12.5 16 16 24 16M
80386DX 1985 275,000 33 32 32 32 4G
80486SX 1988 275,000 33 16 32 24 16M
Pentium C 1993 3,100,000 66 -200 64 32 32
Pentium-Pro 1995 5,500,000 200 64 32 36
Motorola family:
6800 8 64K
13
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-1 (CONT…)
1 kilobyte is 210 bytes. (Abbreviation K is used) Some floppy disks hold 356K bytes of
data.
1 megabyte is 220 bytes. (a little over a million 1,048,576)
1 gigabyte is 230 bytes (over 1 trillion)
1 terabyte is 240 bytes
14
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-2
15
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-2 (CONT…)
Pipelining
17
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-2 (CONT…)
Pipelining
Intel implemented the concept of pipelining by splitting the internal structure of 8088/86
into two sections.
the execution unit (EU)
the bus interface unit (BIU)
These two sections work simultaneously. BIU accesses memory and peripherals while the
EU executes the instructions previously fetched.
It only works if BIU keeps ahead of EU. Thus BIU has a buffer of queue. (8088 has 4
byte, and 8088 has 6 bytes).
If the execution of any instruction takes to long, the BIU is filled to its maximum capacity
and busses will stay idle. It starts to fetch again whenever there is 2-byte room in the
queue.
Branch Penalty
When there is a jump instruction, the microprocessor must flush out the queue. When a jump
instruction is executed BIU starts to fetch information from the new location in the memory.
In this situation EU must wait until the BIU starts to fetch the new instruction. This is known
as branch penalty.
18
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-2 (CONT…)
READY: READY is the acknowledgement from the addressed memory or I/O device that it will
complete the data transfer.
INTR: Interrupt request is used to request a hardware interrupt. If INTR is held high when IF=1,
the 8086/8088 enters an interrupt acknowledge cycle (INTA become active) after the current
instruction has completed execution.
NMI: The Non-maskable Interrupt input similar to INTR except that the NMI interrupt does not
check to see if the IF flag bit is logic 1.
BHE/S7: The bus high enable pin is used to enable the most significant data bus bits (D15-D8)
during a read or write operation.
TEST: This input pin is examined by a ‘WAIT’ instruction. If TEST is logic 0, the WAIT
Instruction functions as NOP. If TEST is logic 1 then the WAIT instruction waits for TEST to
become logic 0. This pin is most often connected to the 8087 numeric co-processor.
20
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-2 (CONT…)
HOLD: Active-high input from the DMA controller which indicates that the device is requesting
access to memory and I/O space and that the CPU should release the control of the local bus.
HLDA: Active-high output signal. After input on HOLD, the CPU responds with HLDA to
signal that DMA (Direct Memory Access) controller can use the bus.
In computers there is often need to transfer a large amount of data between the
memory and peripherals such as hard disk. In such a case using the CPU to transfer
data is too slow, since the data first must be fetched into the CPU and then sent to its
destination.
For this reason Direct Memory Access controller is used to bypass the CPU and
provide a direct connection between the peripherals and memory, thus transferring the
data as fast as possible.
21
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-2 (CONT…)
MN Vs MX
Minimum mode:
Maximum mode:
operated by strapping the MN/MX pin
to ground
processor derives the status signal S2,
S1, S0.
Another chip called bus controller
derives the control signal using this
status information.
It is designed to be used when a
coprocessor exists in the system.
22
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-2 (CONT…)
Registers of 8086
In the CPU, registers are used store information temporarily. The information can be one
or two bytes of data, or the address of data.
In 8088/8086 general-purpose registers can be accessed as either16-bit or 8-bit registers.
All other registers can be accessed as full 16-bit registers.
AX
16-bit register
AH AL
8-bit reg. 8-bit reg.
Different registers are used for different functions. Registers will be explained later
within the context of instructions and their applications.
24
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-3
25
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-3 (CONT…)
26
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-3 (CONT…)
27
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-3 (CONT…)
PROGRAM SEGMENTS
Physical Address: is the 20-bit address that actually put on the address bus. (in
8086)
• Has a range of 00000H - FFFFFH
28
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-3 (CONT…)
Logical address: is described by combining two parts: Segment address and offset
address.
Segment address is 16-bit data from one of the segment registers (CS, SS, DS
and ES).
Offset address is 16-bit data from one of the index and pointer registers (DI,
SI, SP and BP). Also it could be base register BX. It is a location within 64K
byte segment range. Has a range of 0000H – FFFFH.
To express the 20-bit Physical Address of memory
Multiply Segment register by 10H ( or shift it to left by four bit)
Add it to the offset
Example1: if CS = 002AH, and IP = 0023H, write the logical address that they
represent, then map it to Physical address.
Solution:
Logical address = CS: IP
002A: 0023
Physical address = (CS X 10H) + IP = 002A0 +0023 = 002C3 29
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-3 (CONT…)
Offset value:
IP
BP
DI
SI
or BX
Segment
Register:
CS
SS
DS
30
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-4
An instruction acts on any number of operands. The way an instruction accesses its
operands is called its Addressing modes.
Operands may be of three types:
Implicit
XLAT; automatically takes AL and BX as operands
Explicit
MOV AX, BX; it takes AX and BX as operands
Both Implicit and Explicit
MUL BX; automatically multiply BX explicitly times AX
32
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-4
Memory addressing
Memory (RAM) is the main component of a computer to store temporary data and
machine instructions.
There are different forms of memory addressing modes:
33
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-4 (CONT…)
34
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-4 (CONT…)
36
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-5
INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMING
39
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-5 (CONT…)
POP: Loading the contents of the stack into the CPU register is called a POP.
POP destination
Example: assume that the stack is shown below, and
SP=18FA, show the contents of the stack and
registers as each of the following instructions is
executed.
POP CX
POP DX
POP BX
XCHG
XCHG destination, source
40
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-5 (CONT…)
XLAT
XLAT
A XLAT instruction first adds AL to BX to form a memory address in
data segment. It then copies the contents of this address to AL.
Example: For the figure below, what is the result of executing the following instruction?
41
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-5 (CONT…)
IN
IN accumulator, port
42
SI= DI+ BX +
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-6
ADC: Add with carry EA= [DI + BX + 2H] =[0020 + 0040 + 02H ]= 0062H
Example: let num1=11223344H and num2=55667788H are PA = (DS × 10H) + EA = 1000H +0062H= 1062H
stored at memory locations 200 and 300 respectively in the Memory word stored at location 1062H is 9067
current data segment. ADD num1and num2 and store the AX = AX + 9067
result at memory location 400.
11223344H
55667788H
43
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-6 (CONT…)
MUL
MUL source
44
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-6 (CONT…)
DIV
Div source
AH (remainder) AL (quotient)
IDIV BL 1B 02
45
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-7
3. LOGICAL INSTRUCTIONS
AND
NOT
NOT destination
AND op1, op2
OR xxxx xxxx
OR destination, source. 0000 0111
(OR)
Example: set the lower three bits of BL register
OR BL, 07H xxxx x111
46
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-7
XOR
XOR destination, source.
Example:
XOR BX, CX ; Exclusive OR CX with BX and Result in BX
BX = 0 0 1 1 1 1 0 1 0 1 1 0 1 0 0 1
CX = 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
------------------------------------- --------------
BX = 0 0 1 1 1 1 0 1 1 0 0 1 0 1 1 0
47
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-7
3. LOGICAL INSTRUCTIONS
TEST
TEST operand1, operand2
48
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-7 (CONT…)
SHL
SHL destination, source
;shift left
SHL AX,1
SHR
; Shift Right
;DX=1234H
MOV CL, 2H
SHR DX, CL 49
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-8
ROL
ROL destination, count Example:
MOV AL, 47H ; AL=0100 0111
ROL AL, 1 ; AL=1000 1110 CF=0
ROL AL,1 ; AL=0001 1101 CF=1
ROL AL,1 ; AL=0011 1010 CF=0
ROL AL,1 ; AL=0111 0100 CF=0
RCL
RCL destination, count Example:
;rotate left through carry STC ;set carry, make CF=1
MOV BL,15H ;BL=0001 0101 CF=1
RCL BL,1 ;BL=0010 1011 CF=0
RCL BL,1 ;BL=0101 0110 CF=0
50
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-8 (CONT…)
ROR RCR
; rotate right ;rotate right through carry
Example:
Example: STC ; set carry, make CF=1
MOV BX, C7E5H ; BX=1100 0111 1110 0101 MOV BX, 37F1H ; BX=0011 0111 1111 0001 CF=1
MOV CL, 6 ; CL=6 number of times to rotate MOV CL=5 ;CL=5 number of times to rotate
ROR BX, CL ; BX=1001 0111 0001 1111 CF=1 RCR BX, CL ;BX=0001 1001 1011 1111 CF=1
Example:
Destination >source 0 0
MOV AL, 5
MOV BL, 5 Destination = source 0 1
CMP AL, BL Destination < source 1 0
RET
51
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-8 (CONT…)
Example: Write an instruction sequence to save the current contents of the 8086’s
flags in the memory location pointed to by SI and then reload the flags with the
contents of memory location pointed to by DI.
Solution:
LAHF
MOV [SI], AH
MOV AH, [DI]
SAHF 52
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-8 (CONT…)
GENERAL RULES FOR 8086/8088 INSTRUCTIONS
1. An immediate value (i.e., a constant) cannot be a destination operand.
For example, the following is invalid: ADD 34BFh, BX
2. The destination and source operands must be of the same size, except if the source operand is an
immediate value of a lower size than the destination.
For example, the following is valid: MOV AX, 03H
3. Direct memory to memory transfer is invalid, except for string instructions. Such a transfer must
be done indirectly using a general register of the appropriate size.
For example, if VAR1 and VAR2 are word variables (i.e., word memory operands) then the transfer:
MOV VAR1, VAR2 is invalid. The transfer can be done as:
MOV AX, VAR2
MOV VAR1 , AX
4. The transfer MOV SegmentRegister , SegmentRegister is invalid for all segment registers:
CS, DS, SS, ES.
5. The transfer: MOV SegmentRegister , ImmediateValue is invalid for all Segment
Registers: CS, DS, SS, ES. Such a transfer can be done indirectly using a 16-bit general register.
For example, if a program has a data segment that is defined by a simplified segment
directive .DATA, the DS register can be initialized by:
MOV BX, @DATA
MOV DS, BX
6. The IP, CS, SS, and SP registers cannot be destination operands.
For example, the following is invalid: MOV CS, 2345H 53
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-9
Jump Instructions
JMP
JMP Operand
JMP 1234H
conditional unconditional JMP BX
Conditional Jump
control is transferred to a new location if a certain condition is met.
JC Jump if carry flag CF = 1[CF is checked]
JNZ Jump if not zero (ZF = 0) [ZF is checked]
Unconditional Jump types:
“JMP label” is the unconditional jump in which control is transferred unconditionally
to the target label. Unconditional jump can take the following forms.
a) Intrasegment: Only IP is changed.
i) Short Jump: JMP short Label (8 bit)
54
ii) Near Jump: JMP near Label (16 bit)
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-9
Short Jumps:
All conditional jumps are short jumps. In a short jump the address of the target
must be within –128 to +127 bytes of the memory.
A conditional jump is a two-byte instruction: one byte is the opcode of the J
condition and the second value is a value between 00 to FF.
In a backward jump the second byte is the 2’s complement of the displacement
value.
Note: Two's complement is executed by
1) inverting (i.e. flipping) all bits, then
2) adding a place value of 1 to the inverted
number.
NEAR Jump:
It is exactly same as the short jump, except that the target address can be
anywhere within the range of +32767 to –32768.
FAR Jump:
FAR JUMP, has the format “JMP FAR PTR label”. This is the jump out of the
current code segment, meaning that not only the IP, but also the CS is replaced
with new values. 55
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-9
Conditional Jumps
56
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-9 (CONT…)
57
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-9 (CONT…)
58
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-9 (CONT…)
CALL STATEMENTS
Example: write a procedure named Square that squares the contents of BL and places
the result in BX.
Solution:
Example: write a program that computes y =
Square: PUSH AX (AL)2 + (AH)2 + (DL)2, places the result in
MOV AL, BL CX. Make use of the SQUARE subroutine
MUL BL defined in the previous example. (Assume
MOV BX, AX result y doesn’t exceed 16 bit)
POP AX
RET MOV CX, 0000H
MOV BL, AL
CALL Square
ADD CX, BX
MOV BL, AH
CALL Square
ADD CX, BX
MOV BL, DL
CALL Square
ADD CX, BX
HLT 60
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-10
Interrupt of 8086
61
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-10
Interrupt vectors
62
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-10
Need for Interrupt: Interrupts are particularly useful when interfacing I/O
devices that provide or require data at relatively low data transfer rate.
– The INT instruction works like a FAR call. When it is invoked, it saves CS:
IP and the flags on the stack and goes to the subroutine associated with
the interrupt.
INT xx ;the interrupt number can be 00 – FFH (256 possible interrupts)
Example:
INT data8 ; data8 is an interrupt vector from 0 to 255
INT does the following:
– Pushes flag register (PUSHF)
– Pushes return CS and IP
– Far jumps to [0000 :( 4*data8)]
– Usually clears the interrupt flag disabling the interrupt system
IRET is to INT what RET is to CALL
– Pops flag register (POPF)
63
– Performs a far return
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-10
iv.It has highest priority among all The priority is lower than that of software
interrupts. interrupt.
64
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-10
Programming Languages
Machine Language:
• Programs consist of 0s and 1s are called machine language.
• Assembly Languages provided mnemonics for machine code
instructions.
• Mnemonics refer to codes and abbreviations to make it easier for the
users to remember.
65
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-10
BIOS and DOS contain some very useful subroutines, which can be used through
INT (interrupt) instruction.
66
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-10
Example: Write the code to set the cursor position to row = 15 (= 0FH) and column
= 25 (=19H).
68
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-10
This function waits until a character is input from the keyboard, then character is
not displayed (echoed) to the monitor.
After the interrupt the character will be in AL.
Example:
MOV AH,07 ;keyboard input without echo
INT 21H ;after the interrupt, AL = input character (ASCII)
69
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-10
Ex:
MOV AH,01 ;check for key press
INT 16H ;using INT 16H
70
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-10
Example: Write a program segment to (1) clear the screen and (2) set the cursor at
the center of the screen.
;clearing the screen
MOV AX,0600H ;scroll entire screen
MOV BH,07 ;normal attribute
MOV CX,0000 ;start at 00,00
MOV DX,184FH ;end at 24,79 (hex=18,4F)
INT 10H ;invoke the interrupt
71
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-10
72
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-10 (CONT…)
73
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-11
74
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-11 (CONT…)
MINIMUM MODE
75
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-12
Example: Assume that AX=98F6H and the output port address is 47H, then
OUT 47H, AX
In the above case F6H, the content of AL, goes to port address 47H and 98H, the
content of AH goes into the port address 48H.
In other words the low byte goes to the low port address, and the high byte goes to
the high byte address. 76
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-12 (CONT...)
NOP Instruction
NOP instruction does nothing
takes 3 clock cycles of processor time to execute.
Executing NOP instruction in between two instructions we can get delay of
3 clock cycle.
77
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-12 (CONT...)
For count = 100 and multiplier count 50, the number of dock cycles required
are = [ 4 + (100 - 1)×(2 + 16)+ (2 + 4)]× 50 = 89600
Assuming operating frequency of 8086 system 10 MHz .Total time required for
execution of a given program = 89600 x 0.1 μsec = 8.96 ms
79
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-12 (CONT...)
80
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-12 (CONT...)
Peripheral Devices
Designed to solve one of the most common problems in any microcomputer system, the
generation of accurate time delays under software control.
Instead of setting up timing loops in software, the programmer configures the 8254 to
match his requirements and programs one of the counters for the desired delay.
0 0 0 Counter 0
0 0 1 Counter 1
0 1 0 Counter 2
0 1 1 Control Register
81
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-12 (CONT...)
82
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-13
83
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-13
86
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-13 (CONT...)
– If GATE becomes low at the middle of the count, the count will
stop and the output will be low. The count resumes when the
GATE becomes high again This in effect adds to the total
time the output is low.
87
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-13 (CONT...)
89
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-13 (CONT...)
Source program
Example: consider a gate input waveform of 1 KHz, clock input of 1.5 MHz (T=0.66)Write a
ALP to gives a Low output pulse of 0.2 msec. from the counter 0 only when the gate is given a
low to high transition. Applying a 1 KHz signal at the gate input and draw the output waveform
at OUT 0. The low pulse not produce when the count is loaded in the count register- it starts
only when a low to high transition occurs on the gate.
91
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-13 (CONT...)
92
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-13 (CONT...)
93
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-13 (CONT...)
94
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-13 (CONT...)
95
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-13 (CONT...)
96
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-13 (CONT...)
97
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-14
98
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-14 (CONT...)
1. Two 8-bit ports (port A and port B)and two 4-bit ports (port C upper and lower)
are available. The two 4-bit ports can be combinedly used as a third 8-bit port.
2. Any port can be used as an input or output port.
3. Output ports are latched. Input ports are not latched.
4. A maximum of four ports are available so that overall 16 I/O configuration are
possible.
• All these ports can be selected by programming a register internal to 8255
known as CWR.
• The control word register has two formats. The first format is valid for I/O
modes of operation, i.e. modes 0, mode 1 and mode 2 while the second format is
valid for bit set/reset (BSR) mode of operation.
101
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-14 (CONT...)
In this mode the handshaking control the input and output action of the specified port. Port
C lines PC0-PC2, provide strobe or handshake lines for port B. This group which includes
port B and PC0-PC2 is called as group B for Strobed data input/output. Port C lines PC3-
PC5 provide strobe lines for port A.
This group including port A and PC3-PC5 from group A. Thus port C is utilized for
generating handshake signals. The salient features of mode 1 are listed as follows:
1. Two groups – group A and group B are available for strobed data transfer.
2. Each group contains one 8-bit data I/O port and one 4-bit control/data port.
3. The 8-bit data port can be either used as input and output port. The inputs and
outputs both are latched.
4. Out of 8-bit port C, PC0-PC2 are used to generate control signals for port B and
PC3-PC5 are used to generate control signals for port A. the lines PC6, PC7 may
be used as independent data lines.
102
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-14 (CONT...)
In this mode, 8255 is a bidirectional 8-bit port with handshake signals. The Rd and WR
signals decide whether the 8255 is going to operate as an input port or output port.
Control Word(CW):
For Port B
104
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-15
The port Addresses for the 8255 Example: The 8255 shown in Figure below configured as follows:
Port A as Input, Port B as Output, and all the bits of port C as
Port Address A0 A1 Output.
A 300H 0 0 a) Find the port address assigned to A, B, C and Control register
B 301H 0 1 b) Find the control byte (word) for this configuration.
C 302H 1 0 c) Program the ports to input data from port A and send it to
Control 303H 1 1 both port B and C.
Register
Example: Configure the ports of 8255 as follows: port A=input, B=output/ PC0 –
PC3=input, and PC4-PC7=output. Determine the content of the Control Register
and, Program the 8255 to get data from port A and send it to port B. In addition,
input data from PCL and send out to PCU. (PCL=Lower 4 bits (nibble) of Port C,
PCU; Upper 4 bits (nibble) of Port C) (Assume the standard port addresses of 8255
given above)
D7 D6 D5 D4 D3 D2 D1 D0
Control Word: 1 0 0 1 0 0 0 1 = 91H
MOV AL, 91H ; this control byte is used to initialize the PPI
MOV DX, 303H ; get the address of Control Register
OUT DX, AL ; output the Control Byte to the Control register
MOV DX, 300H ; get the address of Port A
IN AL, DX ; input data from Port A
MOV DX, 301H ; get the address of Port B
OUT DX, AL ; output data to Port B
MOV DX, 302H ; get the address of Port C
IN AL, DX ; get the data from Port C
AND AL, 0FH ; mask the upper bits
MOV CL, 4 ; rotate count =4
ROL AL, CL ; shift the bits to upper position
106
OUT DX, AL ; output PCL to PCU
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-15
Example: For the following configuration find the port address assigned to A, B, C
and Control register
Solution:
Exercise: write an ALP that will input the contents of port B and port C, and then
perform ANDing and output the result to port A. Port A is connected with address
10600h.
107
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-16
Interfacing
problem:
Example 1: write an assembly language program to generate a square wave of frequency
1Hz on the PC2 pin of the 8255 PPI having Port A address at 7000h.
Solution:
The given frequency is 1Hz.
So,
So, TON =TOFF =500ms
The Port A address is 7000h, so the address of CWR is 7006h
108
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-16 (CONT...)
CW:
0 X X X A2 A1 A0 S/R
0 0 0 0 0 1 0 1 =05H= = PC 2 Set
0 0 0 0 0 1 0 0 =04H= = PC 2 Reset
The address of port A is 2008H, so the address of control word register CWR is 200Eh.
MOV AX, 3000h OUT DX, AL; Set PC0 pin of port C
MOV SS, AX; Initialize stack memory segment MOV AL, 00h
MOV SP, 0100h OUT DX, AL; Reset PC0 pin of port C
CALL DELAY; Delay of 1s
MOV DX, 200Eh; Transfer 16-bit port address MOV AL, 01h
in DX register OUT DX, AL; Set PC0 pin of port C
MOV AL, 01h HLT/INT3
When interface with 8086 then A1 and A2 pins of 8086 connected with A0 and A1 pins of 8255.
When interface with 8088 then A0 and A1 pins of 8088 connected with A0 and A1 pins of 8255.
110
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-16 (CONT...)
To the pins of Port A and Port CL, connect 12 LEDs along with their current
limiting resistors. The LEDs glow when the corresponding pins have a high logic
on them.
a) Control register:
=8Ah
111
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-16 (CONT...)
Programming steps:
The ports and the control register address have been given labels and will be
specified using the EQU directive. Since the Port addresses are 8-bit long,
fixed port addressing can be used.
The switch settings at the input port B can be read in directly and transferred
to the output port A.
The data at Port CU can be read in by inputting Port C fully, but the switch
settings will be available only at the upper 4-bits position and have to be
shifted to the position of the lower 4-bits to output it to the LEDs.
112
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-17
Prob:2 Find the address of PA, PB, PC and CR of the following configuration:
Note:
When interface with 8086 then A1 and A2 pins of 8086
connected with A0 and A1 pins of 8255.
When interface with 8088 then A0 and A1 pins of 8088 Fig: I/O Mapped I/O with 8086.
connected with A0 and A1 pins of 8255.
While the conventional motor shaft runs freely, the stepper motor shaft moves in a fixed
repeatable increment, which allows one to move it to a precise position.
Fig: Rotor alignment of the stepper motor. Fig: Stator windings configuration
114
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-17 (CONT...)
The table above shows a normal 4-step Sequence. Note that once, we start with
any of the sequences in Table below (i.e. step 3 [0110] ) we must continue in the
sequence of steps, 4, 1, 2, and so on.
115
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-17 (CONT...)
Example: Given the 8255 connection to the stepper motor of Figure below,
- code a program to rotate it continuously.
- press any key on the IBM PC keyboard to stop it.
(Assume that the 8255 PPI is located at 300H) Use Port A as the output port.
Control word:
= 80H
116
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-17 (CONT...)
MAIN: MOV AL, 80H ; control word for all 8255 ports as out
MOV DX, 303H ; control register address of 8255
OUT DX, AL ; to control register
MOV BL,66H ; or BL=33H, BL=99H or BL=CCH
AGAIN: MOV AH, 01 ; check the key press
INT 16H ; using INT 16
JZ EXIT ; stop if any key pressed
MOV AL, BL ; otherwise send pulse to the stepper motor
MOV DX, 300H ; port A address of 8255
OUT DX, AL
MOV CX, 0FFFFH ; (change this value to see rotation speed)
Call Delay ; set delay
ROR BL, 1 ; rotate for the next step
JMP AGAIN ; and continue until a key is pressed
EXIT:
END MAIN 117
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-18
Memory
ROM
RAM
EPROM PROM
EEPROM UVEPROM
118
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-18 (CONT...)
1. Can be erased and programmed with 1. Can be erased and programmed with
electrical signals. ultraviolet light.
2. The voltage on the floating gate structure allows 2. The photo current from the insulated
storage of information. gate structure allows storage of information.
119
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-18 (CONT...)
120
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-19
8088: 8 x 2764 = 8 KB x 8 = 64 KB
Memory address space: F0000 – FFFFF
121
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-19 (CONT...)
122
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-19 (CONT...)
Memory interfacing
Example: Interface the following Memory ICs with 8086
i) Two 4KB EPROMs ending at FFFFFH
ii) Two 4KB SRAMs starting at 00000H
123
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-19 (CONT...)
124
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-19 (CONT...)
Table-1
ICs Address A19 A18 A17 A16 A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
Odd FFFFF 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
EPROM
FE001 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1
Even FFFFE 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
EPROM
FE000 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
Odd 01FFF 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1
SRAM 00001 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
Even 01FFE 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0
SRAM 00000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Table-2
Bit Chip select
A19 0 SRAM
1 EPROM
A0 0 Either even EPROM or even SRAM
1 Either odd EPROM or odd SRAM
BHE 0 Either even + odd or odd only
1 Even only
125
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-19 (CONT...)
126
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-19 (CONT...)
Based on the above truth table draw the logic diagram to generate unique chip select signals
Note to students:
solution to this kind of question should only include following things. Rest is confined to rough work.
i) Address calculation for each chip
ii) Binary table
iii) Final diagram containing Processor, memory chips, chip selection logic diagram, hardware connection
127
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-19 (CONT...)
Complete diagram to interface two 4KB EPROMS and two 4KB SRAMS to 8086
128
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-20
ADC 0808/0809:
Pin Diagram:
130
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-20 (CONT...)
Analog I/P Address lines Example: Interfacing ADC 0808 with 8086
selected
using 8255 ports. Use port A of 8255 for
C B A transferring digital data output of ADC to the
I / P0 0 0 0
CPU and port C for control signals. Assume that
I/P1 0 0 1
I/P2 0 1 0
an analog input is present at I/P2 of the ADC
I/P3 0 1 1 and a clock input of suitable frequency is
I / P4 1 0 0 available for ADC.
I/P5 1 0 1
I/P6 1 1 0
I/P7 1 1 1
131
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-20 (CONT...)
D7 D6 D5 D4 D3 D2 D1 D0
The required ALP is as follows: 1 0 0 1 1 0 0 0
OUT Port C, AL
OUT Port C, AL
134
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-20 (CONT...)
= 2.56 v
Digital input of DAC is of 8 bits, so n = 8
So, resolution ==2.56/256=10𝑚𝑉
So, if the digital input of DAC is increased by one, then analog output voltage will be
increased by 10 mV. It is called resolution.
To obtain 1V at DAC output, we have to input digital number X, where
X = Total output voltage/Resolution
X=1V/10mV=100
X=(100)D = (64)H
To transfer digital number from (100)D to (1)D in 100 ms that is 100 numbers in 100 ms. So, time required in
transferring one number
= Total time /total number
=100ms/100=1ms/Number
BUS STANDARDS
BUS: A bus connects all the internal computer components to the CPU and Main
memory. A fast bus allows data to be transferred faster, which makes applications run
faster.
BUS
System Bus
I/O Bus
136
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-22
PCI BUS
PCI (Peripheral Component Interconnect) bus is the standard I/O bus found in Pentium
systems and it was developed by Intel in 1993 to replace the various busses which had
been in use on both PCs and Macintoshes. A PCI interface contains a series of register,
located in a small memory device on the PCI interface, which contains information
about the board. The information in these registers allows the computer to automatically
configure the PCI card.
Bus Width
– PCI may be implemented with a 32 or 64-bit data bus.
Bus Speed
– PCI may use a clock speed of 33Mhz or 66Mhz 137
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-22 (CONT...)
Bus Throughput
– PCI maximum throughput ranges from 132MB/s to 538MB/s.
Access Time
– PCI access time can be as fast as 60ns when implemented with a
33Mhz clock.
Devices Per Bus
– The PCI specification provides support for up to 10 physical devices
and 80 logical devices per PCI bus.
Number of Busses
– The PCI specification provides support to up to 256 PCI bus
implementations within a computer system.
Burst Transfers
– The PCI specification provides support for burst transfers.
138
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-22(CONT...)
Pentium
CPU
PCI
Cache Memory
Controller
Video System
Disk
Adapter ROM
Expansion
Bus
Controller
Fig: the system block diagram for the personnel computer that contain a PCI bus. 139
T. H. M. Sumon Rashid
Introduction to Microprocessor Asst. Prof., EEE, PUST
Lecture-23
USB
Universal Serial Bus was born to overcome the limitation of wide range of peripheral
interface using Centronics parallel and RS-232 serial port interface. USB is fast and
flexible for connecting all kinds of peripherals
USB system
THE END
141