You are on page 1of 78

Microprocessors &

Microcontrollers
Lecture 01
Dr. Farzana Kulsoom

1
Objective of this Course
• Develop an understanding of the Intel family of
microprocessors and its internals.
• Use the power of the microprocessor to process data from
various I/O devices interfaced with the microprocessor over
different channels.
• Gain practical insight in Interfacing Techniques with a course
project.

2
COURSE CONTENTS
• Introduction to the Intel Family of Microprocessors
• Microprocessor Architecture and Addressing Modes
• Intel x86 Assembly
• Various types of Instructions in the Intel Assembly
• Using Assembly with C++
• AVR Core Based Microprocessors
• ATMEL AT90USB1286
• Interfacing different components to the Microprocessor
• Memory and I/O Interfacing
• Interrupts
• Direct Memory Access controlled I/O 3
Weekly Lecture Plan
1. Introduction to the Microprocessor
• History of the Microprocessor
• Intel family of Microprocessors
• Number Systems
2. The Microprocessor and Its Architecture
• X86 Architecture
3. Memory Addressing Modes
• X86 Addressing Modes
• Real and Protected Modes
4. Memory Paging
• Review of Memory Addressing modes 4
• Paging mechanism
Weekly Lecture Plan Contd..
5. Data Addressing Modes
• Data Memory addressing modes
• Program memory addressing modes
• Register addressing
6. Intel Assembly
• Data Movement Instructions
• Logic Instructions
7. Intel Assembly
• Arithmetic Instructions
• Program Control Instructions
• Assembler Directives
8. Intel Assembly
• Using Assembly with C++ 5
• Midterm review
Weekly Lecture Plan Contd…
9. ATMEL Microcontrollers
• AVR Core based microcontrollers
• The ATMEL AT90USB1286
10. The 8086 Chipset
• 8086 Chipset
• 8284A Clock Generator
• Bus Latching and Buffering
11. Memory Interfacing
• Interfacing Memory Chips with 8086
• Memory Address Decoding
• 80386 and Pentium Memory Interface
12. Memory Error Detection
• Error Detection
• Parity
• Cyclic Redundancy Check 6
• Error Correction using Hamming Codes
Weekly Lecture Plan Contd…
13. Digital Logic Refresher
• ALU Design
• Bit Slice Design
14. I/O Interfacing
• Interfacing I/O Devices to 8086
• 8255, Timer, Keyboard, 7 Segment Display
15. Interrupts
• 8086 Interrupts
• 8259 Interrupt Controller
16. Video and DMA
• Direct Memory Access 7
• Video Interface
Recommended Books
1. The Intel Microprocessors Architecture, Programming and
Interfacing by Barry B. Brey
2. The AVR Microcontroller and Embedded Systems by Mazidi ,
Prentice Hall

8
Grading
• Rough Grade Breakdown
Course Work 75%
Quizzes 10%
Assignments 15%
MID Semester Exam 25%
End Semester Exam 50%

Lab Work 25%


Lab Reports 60%
Project 40%

9
Microprocessors

•What are Microprocessors?

•Uses of Microprocessors?

10
Microprocessor
• The microprocessor, also known as the Central Processing Unit
(CPU),is the brain of all computers and many household and
electronic devices. Multiple microprocessors, working together, are
the "hearts" of datacentres, super-computers, communications
products, and other digital devices.
• The microprocessor, is the controlling element in a computer
system.
• The microprocessor controls memory and I/O through a series of
connections called buses.
• The buses select an I/O and memory device, transfer data between
an I/O device or memory and microprocessor, and control the I/O
and memory system
• Memory and I/O are controlled through instructions that are stored
in the memory and executed by the microprocessor
11
Microprocessors
• A typical programmable machine can be represented with four
components:
 microprocessor,
 memory,
 input, and output.

12
• Microprocessor (MPU) - a semiconductor device (integrated
circuit) manufactured by using the LSI technique.
• It includes the ALU, register arrays, and control circuits on a single
chip.
• These four components work together or interact with each
other to perform a given task; thus, they comprise a system.
• The physical components of this system are called hardware.
• A set of instructions written for the microprocessor to perform
a task is called a program, and a group of programs is called
software.
Traditional block diagram of a computer

13
Block Diagram

14
Examples of Microprocessor Systems
• Anti-lock brakes • Modems
• Auto-focus cameras • MPEG decoders
• Automatic teller machines • Network cards
• Automatic toll systems • Network switches/routers
• Automatic transmission • On-board navigation
• Avionic systems • Pagers
• Battery chargers • Photocopiers
• Camcorders • Point-of-sale systems
• Cell phones • Portable video games
• Cell-phone base stations • Printers
• Cordless phones • Satellite phones
• Cruise control • Scanners
• Curbside check-in systems • Smart ovens/dishwashers
• Digital cameras • Speech recognizers
• Disk drives • Stereo systems
• Electronic card readers • Teleconferencing systems
• Electronic instruments • Televisions
• Electronic toys/games • Temperature controllers
• Factory control • Theft tracking systems
• Fax machines • TV set-top boxes
• Fingerprint identifiers • VCR’s, DVD players
• Home security systems • Video game consoles
• Life-support systems • Video phones
• Medical testing systems • Washers and dryers 15
Why Use Microprocessors?
• Small in size
• Cheap to produce
• Able to take over a lot of tasks of varying nature

16
History of Computers
Abacus
• 500 BCE, used in Babylon
• beans or stones moved in grooves in sand or on tablets of
wood, stone, or metal
• early form of beads on wires, used in China
• Primarily used in parts of Asia for performing arithmetic
processes

17

Chinese Abacus
Pascal Calculator
• Blaise Pascal invented the mechanical calculator in 1642
• The gears and wheels design helped in performing addition
and subtraction
• Was able to perform the carry function

18
Charles Babbage
• Father of Modern Computer
• Babbage is credited with inventing the first mechanical
computer
• In 1821 Babbage invented the Difference Engine to compile
mathematical tables
• https://www.youtube.com/watch?v=BlbQsKpq3Ak

19
• Babbage conceived, in 1834, a more ambitious machine, later
called Analytical Engine, a general-purpose programmable
computing engine
• The Analytical Engine has many essential features found in the
modern digital computer
• It was programmable using punched cards, an idea borrowed
from the Jacquard loom used for weaving complex patterns in
textiles

20
Ada Lovelace
• First computer programmer.
• She wrote the programs for the analytical engine

21
Herman Hollerith
• He chose the punched card as the basis for storing and
processing information
• He built the first punched-card tabulating and sorting
machines as well as the first key punch
• He founded the company that was to later become IBM

22
Hollerith Punched card
Alan Turing
• Alan Turing was an English mathematician, wartime code-
breaker and pioneer of computer science.
• Invented Colossus, it was the world's first electronic, digital,
fixed-program, single-purpose computer
• The Automatic Computing Engine (ACE) was an early
electronic stored-program computer design produced by Alan
Turing: The Imitation Game

23
ENIAC
• In 1946, John Mauchly and John Presper Eckert developed the
ENIAC I (Electrical Numerical Integrator And Calculator)
• The American military sponsored their research; the army
needed a computer for calculating artillery-firing tables, the
settings used for different weapons under varied conditions
for target accuracy
• The ENIAC contained 17,468 vacuum tubes, along with 70,000
resistors, 10,000 capacitors, 1,500 relays, 6,000 manual
switches and 5 million soldered joints.
• It covered 1800 square feet (167 square meters) of floor
space, weighed 30 tons, consumed 160 kilowatts of electrical
power. 24
ENIAC

25
History of Microprocessors
• First transistor was invented in 1947.
• Fairchild Semiconductors (founded in 1957) invented the first
IC in 1959.
• In 1968, Robert Noyce, Gordan Moore, Andrew Grove
resigned from Fairchild Semiconductors.
• They founded their own company Intel (Integrated
Electronics).
• Intel grown from 3 man start-up in 1968 to industrial giant by
1981.
• It had 20,000 employees and $188 million revenue.

26
Intel 4004
• Introduced in 1971.
• It was the first microprocessor by Intel.
• It was a 4-bit microprocessor.
• Its clock speed was 740KHz.
• It had 2,300 transistors.
• It could execute around 60,000 instructions per second.

27
INTEL 4040
• Introduced in 1974.
• It was also 4-bit μP.

28
INTEL 8008
• Introduced in 1972.
• It was first 8-bit μP.
• Its clock speed was 500KHz.
• Could execute 50,000 instructions per second.

29
INTEL 8080

• Introduced in 1974.
• It was also 8-bit μP.
• Its clock speed was 2 MHz.
• It had 6,000 transistors.
• Was 10 times faster than 8008.
• Could execute 5,00,000 instructions per second.

30
INTEL 8085
• Introduced in 1976.
• It was also 8-bit μP.
• Its clock speed was 3 MHz.
• Its data bus is 8-bit and address bus is 16-bit.
• It had 6,500 transistors.
• Could execute 7,69,230 instructions per second.
• It could access 64 KB of memory.
• It had 246 instructions.
• Over 100 million copies were sold.

31
INTEL 8086
• Introduced in 1978.
• It was first 16-bit μP.
• Its clock speed is 4.77 MHz, 8 MHz and 10 MHz, depending on
the version.
• Its data bus is 16-bit and address bus is 20-bit.
• It had 29,000 transistors.
• Could execute 2.5 million instructions per second.
• It could access 1 MB of memory.
• It had 22,000 instructions.
• It had Multiply and Divide
instructions. 32
INTEL 8088
• Introduced in 1979.
• It was also 16-bit μP.
• It was created as a cheaper version of Intel’s 8086.
• It was a 16-bit processor with an 8-bit external bus.
• Could execute 2.5 million instructions per second.
• This chip became the most popular in the computer industry
when IBM used it for its first PC.

33
INTEL 80186 & 80188
• Introduced in 1982.
• They were 16-bit μPs.
• Clock speed was 6 MHz.
• 80188 was a cheaper version of 80186 with an 8-bit external
data bus.
• They had additional components like:
• Interrupt Controller
• Clock Generator
• Local Bus Controller
• Counters

34
INTEL 80286
• Introduced in 1982.
• It was 16-bit μP.
• Its clock speed was 8 MHz.
• Its data bus is 16-bit and address bus is 24-bit.
• It could address 16 MB of memory.
• It had 1,34,000 transistors.
• It could execute 4 million
instructions per second.

35
INTEL 80386
• Introduced in 1986.
• It was first 32-bit μP.
• Its data bus is 32-bit and address bus is 32-bit.
• It could address 4 GB of memory.
• It had 2,75,000 transistors.
• Its clock speed varied from 16 MHz to 33 MHz depending
upon the various versions.
• Different versions:
• 80386 DX
• 80386 SX
• 80386 SL
36
• Intel 80386 became the best selling microprocessor in history
INTEL 80486
• Introduced in 1989.
• It was also 32-bit μP.
• It had 1.2 million transistors.
• Its clock speed varied from 16 MHz to 100 MHz depending
upon the various versions.
• It had five different versions:
• 80486 DX
• 80486 SX
• 80486 DX2
• 80486 SL
• 80486 DX4
37
• 8 KB of cache memory was introduced.
INTEL PENTIUM
• Introduced in 1993.
• It was also 32-bit μP.
• It was originally named 80586.
• Its clock speed was 66 MHz.
• Its data bus is 32-bit and address bus is 32-bit.
• It could address 4 GB of memory.
• Could execute 110 million instructions per second.
• Cache memory:
• 8 KB for instructions.
• 8 KB for data.
38
INTEL PENTIUM PRO
• Introduced in 1995.
• It was also 32-bit μP.
• It had L2 cache of 256 KB.
• It had 21 million transistors.
• It was primarily used in server systems.
• Cache memory:
• 8 KB for instructions.
• 8 KB for data.
• It had L2 cache of 256 KB

39
INTEL PENTIUM II
• Introduced in 1997.
• It was also 32-bit μP.
• Its clock speed was 233 MHz to 500 MHz.
• Could execute 333 million instructions per second.
• MMX technology was supported.
• L2 cache & processor were on one circuit.

40
INTEL PENTIUM II XEON
• Introduced in 1998.
• It was also 32-bit μP.
• It was designed for servers.
• Its clock speed was 400 MHz to 450 MHz.
• L1 cache of 32 KB & L2 cache of 512 KB, 1MB or 2 MB.
• It could work with 4 Xeons in same system.

41
INTEL PENTIUM III
• Introduced in 1999.
• It was also 32-bit μP.
• Its clock speed varied from 500 MHz to 1.4GHz.
• It had 9.5 million transistors.

42
INTEL PENTIUM IV
• Introduced in 2000.
• It was also 32-bit μP.
• Its clock speed was from 1.3 GHz to 3.8 GHz.
• L1 cache was of 32 KB & L2 cache of 256 KB.
• It had 42 million transistors.
• All internal connections were made from aluminium to copper.

43
INTEL DUAL CORE
• Introduced in 2006.
• It is 32-bit or 64-bit μP.
• It has two cores.
• Both the cores have there own internal bus and L1 cache, but
share the external bus and L2 cache
• It supported SMT technology.
• SMT: Simultaneously Multi-Threading
• E.g.: Adobe Photoshop supported SMT.

44
INTEL CORE 2
• Introduced in 2006.
• It is a 64-bit μP.
• Its clock speed is from 1.2 GHz to 3 GHz.
• It has 291 million transistors.
• It has 64 KB of L1 cache per core and 4 MB of L2 cache.
• It is launched in three different versions:
• Intel Core 2 Duo
• Intel Core 2 Quad
• Intel Core 2 Extreme

45
INTEL CORE I7
• Introduced in 2008.
• It is a 64-bit μP.
• It has 4 physical cores.
• Its clock speed is from 2.66 GHz to 3.33 GHz.
• It has 781 million transistors.
• It has 64 KB of L1 cache per core, 256 KB of L2 cache and 8 MB
of L3 cache.

46
INTEL CORE I5
• Introduced in 2009.
• It is a 64-bit μP.
• It has 4 physical cores.
• Its clock speed is from 2.40 GHz to 3.60 GHz.
• It has 781 million transistors.
• It has 64 KB of L1 cache per core, 256 KB of L2 cache and 8 MB
of L3 cache.

47
INTEL CORE I3
• Introduced in 2010.
• It is a 64-bit μP.
• It has 2 physical cores.
• Its clock speed is from 2.93 GHz to 3.33 GHz.
• It has 781 million transistors.
• It has 64 KB of L1 cache per core, 512 KB of L2 cache and 4 MB
of L3 cache.

48
Number Systems
• There is a speculation of the fact that Humans use base 10 system is
because they have 10 fingers.
• But there is no speculation behind the fact that the computers use
binary system.
• The decimal number system (base 10) you should be familiar with
• A digit in base 10 ranges from 0 to 9.
• A digit in base 2 ranges from 0 to 1 (binary number system).
• A digit in base 2 is also called a ‘bit’.
• A digit in base R can range from 0 to R-1
• A digit in Base 16 can range from 0 to 16-1
• (0,1,2,3,4,5,5,6,7,8,9,A,B,C,D,E,F). Use letters A-F to represent values
10 to 15. Base 16 is also called Hexadecimal or just ‘Hex’.
49
Positional Notation
• Value of number is determined by multiplying each digit by a
weight and then summing. The weight of each digit is a
• POWER of the BASE and is determined by position.
953.78 = 9 x 102 + 5 x 101 + 3 x 100 + 7 x 10-1 + 8 x 10-2
= 900 + 50 + 3 + .7 + .08 = 953.78
1011.11 = 1x23 + 0x22 + 1x21 + 1x20 + 1x2-1 + 1x2-2
= 8 + 0 + 2 + 1 + 0.5 + 0.25
= 11.75
A2F = 10x162 + 2x161 + 15x160
= 10 x 256 + 2 x 16 + 15 x 1
= 2560 + 32 + 15 = 2607
50
Number Systems – Decimal
• Base 10
• Ten digits, 0-9
• Columns represent (from right to left) units, tens, hundreds
etc.
123

1102 + 2101 + 3100


or
1 hundred, 2 tens and 3 units
51
Bases
• When counting upwards in base-10, we increase the units
digit until we get to 10 when we reset the units to zero and
increase the tens digit.
• So, in base-n, we increase the units until we get to n when we
reset the units to zero and increase the n-s digit.
• Consider hours-minutes-seconds as an example of a base-60
number system:
Eg. 12:58:43 + 00:03:20 = 13:02:03

NB. The base of a number is often indicated by a subscript. E.g.


(123)10 indicates the base-10 number 123.

52
Binary

• Base 2
• Two digits, 0 & 1
• Columns represent (from right to left) units, twos, fours, eights
etc.

1111011

126 + 125 + 124 + 123 + 022 + 121 + 120


= 164 + 132 + 116 + 18 + 04 + 12 + 11
= 123
Binary Numbers Terminology
• The basis of all digital data is binary representation.
• Binary - means ‘two’
• 1, 0
• True, False
• Hot, Cold
• On, Off
• We must be able to handle more than just values for real world problems
• 1, 0, 56
• True, False, Maybe
• Hot, Cold, LukeWarm, Cool
• On, Off, Leaky
• Each digit in a binary number is known as a “bit”.
• A group of eight bits makes a binary number known as a “byte”.
• A group of more than eight bits is known as a “word”.
• Typical word lengths – 12, 16, 32, 64.
Decimal to Binary Conversion
Example – Converting (123)10 into binary

123  2 = 61 remainder 1 Least significant bit (rightmost)


61  2 = 30 remainder 1
30  2 = 15 remainder 0
15  2 = 7 remainder 1
72 = 3 remainder 1
32 = 1 remainder 1
12 = 0 remainder 1 Most significant bit (leftmost)

Answer : (123)10 = (1111011)2


Two’s Complement
• One byte (eight bits) can be used to represent the decimal
number range
• 0 to 255 (unsigned)
• -128 to 127 (signed)
• Negative binary numbers are formed by subtracting from
a number one greater than the maximum possible (i.e. 2n
or 256 for a byte)
• For example,

(123)10 = (01111011)2

(-123)10 = (10000101)2 = (133)10 = (256-123)10


Frequently Asked Question

• So how can you tell the difference between:


(-123)10 = (10000101)2
and
(133)10 = (10000101)2

 You can’t unless you know whether you’re using signed or unsigned
arithmetic:

Unsigned  0  x  255
Signed  128  x  127
Hexadecimal
• Base 16
• Sixteen digits, 0-9 and A-F (ten to fifteen)
• Columns represent (from right to left) units, 16s, 256s,
4096s etc.

7B

7161 + 11160 = 123


Decimal to Hex Conversion

Converting (123)10 into hex


123  16 = 7 remainder 11 (or B)
7  16 = 0 remainder 7

Answer : (123)10 = (7B)16


Binary to Hex / Hex to Binary
Each group of four binary bits maps on to a single hex digit.

0111 1011

7B
• Even very long numbers can be converted easily, treating
each hex digit independently.

E.g. 1011 1001 0110 1111 1010

B96FA
Binary Numbers Again
• Recall than N binary digits (N bits) can represent unsigned
integers from 0 to 2N-1.
• 4 bits = 0 to 15
• 8 bits = 0 to 255
• 16 bits = 0 to 65535
• Besides simply representation, we would like to also do
arithmetic operations on numbers in binary form.
• Principle operations are addition and subtraction

61
Binary Arithmetic
The rules for binary arithmetic are:
• 0 + 0 = 0, carry = 0
• 1 + 0 = 1, carry = 0
• 0 + 1 = 1, carry = 0
• 1 + 1 = 0, carry = 1
The rules for binary subtraction are:
• 0 - 0 = 0, borrow = 0
• 1 - 0 = 1, borrow = 0
• 0 - 1 = 1, borrow = 1
• 1 - 1 = 0, borrow = 0
• Borrows, Carries from digits to left of current of digit.
• Binary subtraction, addition works just the same as decimal 62
addition, subtraction.
Binary, Decimal addition

63
Binary Arithmetic - Addition

• Binary long addition works just like decimal long addition.

1 0 0 1 1 1
+ 0 0 1 1 1 0

0 1 1 1 0 0 Carried digits
1 1 0 1 0 1 Result
Subtraction

65
Hex Addition

66
Hex addition
• Why is Ah + 8h = 2 with a carry out of 1?
• The carry out has a weight equal to the BASE (in this case 16).
The digit that gets left is the excess (BASE - sum).
Ah + 8h = 10 + 8 = 18.
18 is GREATER than 16 (BASE), so need a carry out!
Excess is 18 - BASE = 18 - 16 = 2, so ‘2’ is digit.
• Exactly the same thing happens in Decimal.
5 + 7 = 2, carry of 1.
5 + 7 = 12, this is greater than 10!.
So excess is 12 - 10 = 2, carry of 1.
67
Hex Subtraction

68
Hex Subtraction
• Why is 4h – 7h = D with a borrow of 1?
• The borrow has a weight equal to the BASE (in this case 16).
• BORROW+4h – 7h = 16 + 4 -7 = 20 -7 = 13 = Dh.
• Dh is the result of the subtraction with the borrow.
• Exactly the same thing happens in decimal.
3 - 8 = 5 with borrow of 1
borrow + 3 - 8 = 10 + 3 - 8 = 13 - 8 = 5.

69
Subtracting Using Complements
• Computers don’t subtract this way
• They subtract by adding complements because it’s more
efficient
1101011001 1101011001
- 0010111010 +1101000101
(1)1010011110
Now you notice that there is an embarrassing (1) at the left of
the row. The rule now is to take this 1 across to the first column
on the right and add it there, as shown below:
1010011110
1
70
1010011111
Computer Data Formats
• Coding Schemes are used to represent numeric or non-
numeric data and instructions in binary for computers to
understand.
• BCD
• ASCII
• EBCDIC
• Unicode

71
Binary-Coded Decimal (BCD)
• Four bits per digit
Digit Bit pattern
0 0000
Note: the following
bit patterns are not 1 0001
used: 2 0010
3 0011
1010
4 0100
1011
5 0101
1100
1101 6 0110
1110 7 0111
1111 8 1000
72
9 1001
Example
• 709310 = ? (in BCD)

7 0 9 3

0111 0000 1001 0011

73
ASCII (American National Standard Code)
• Each character is coded as a byte
• Most common coding system is ASCII
• Defined in ANSI document X3.4-1977
• 7-bit code
• 8th bit is unused (or used for a parity bit)
• 27 = 128 codes
• Two general types of codes:
• 95 are “Graphic” codes (displayable on a console)
• 33 are “Control” codes (control features of the console or
communications channel)
74
ASCII Chart
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL

75
“Hello, world” Example

Binary Hexadecimal Decimal


H = 01001000 = 48 = 72
e = 01100101 = 65 = 101
l = 01101100 = 6C = 108
l = 01101100 = 6C = 108
o = 01101111 = 6F = 111
, = 00101100 = 2C = 44
= 00100000 = 20 = 32
w = 01110111 = 77 = 119
o = 01100111 = 67 = 103
r = 01110010 = 72 = 114
l = 01101100 = 6C = 108
d = 01100100 = 64 = 100

76
EBCDIC
• Extended BCD Interchange Code (pronounced ebb’-se-
dick)
• 8-bit code
• Developed by IBM
• Rarely used today
• IBM mainframes only

77
Unicode
• 16-bit standard
• Developed by a consortia
• Intended to supersede older 7- and 8-bit codes
• Unicode Version 2.1 developed in 1998
• Improves on version 2.0
• Includes the Euro sign (20AC16 = )
• From the standard:
…contains 38,887 distinct coded characters derived from the supported
scripts. These characters cover the principal written languages of the
Americas, Europe, the Middle East, Africa, India, Asia, and Pacifica.

78

You might also like