13
1 How Microprocessors Work  The computer yo u are us ing to r ead this page u ses a microprocessor  to do its work. The microprocessor is the heart of any normal computer, whether it is a desktop machine, a server or a laptop. The microprocessor you are using might be a Pentium, a K6, a PowerPC, a parc or any of the many other brands and types of microprocessors, but they all do appro!imately the same thing in appro!imately the same way. " microprocessor ## also known as a CPU or central processing unit ## is a complete computation engine that is fabricated on a single chip. The $rst microprocessor was the %ntel &''&, introduced in 1()1. The &''& was not very powerful ## all it could do was add and subtract, and it could only do that & bits at a time. *ut it was ama+ing that everything was on one chip. Prior to the &''&, engineers built computers either from collections of chips or from discrete components transistors wired one at a time-. The &''& powered one of the $rst portable electronic calculators. %f you have ever wondered what the microprocessor in your computer is doing, or if you have ever wondered about the dierences between types of microprocessors, then read on. %n this article, you will learn how fairly simple digital logic techni/ues allow a computer to do its 0ob, whether its playing a game or spell checking a document

How Microprocessors Work 23

  • Upload
    nafees

  • View
    213

  • Download
    0

Embed Size (px)

Citation preview

8/20/2019 How Microprocessors Work 23

http://slidepdf.com/reader/full/how-microprocessors-work-23 1/13

1

How Microprocessors Work

The computer you are using to read this page uses a microprocessor to do itswork. The microprocessor is the heart of any normal computer, whether it isa desktop machine , a server or a laptop . The microprocessor you are using might bea Pentium, a K6, a PowerPC, a parc or any of the many other brands and types ofmicroprocessors, but they all do appro!imately the same thing in appro!imately thesame way.

" microprocessor ## also known as a CPU or central processing unit ## is a completecomputation engine that is fabricated on a single chip. The $rst microprocessor wasthe %ntel &''&, introduced in 1()1. The &''& was not very powerful ## all it could dowas add and subtract, and it could only do that & bits at a time. *ut it was ama+ingthat everything was on one chip. Prior to the &''&, engineers built computers eitherfrom collections of chips or from discrete components transistors wired one at atime-. The &''& powered one of the $rst portable electronic calculators.

%f you have ever wondered what the microprocessor in your computer is doing, or ifyou have ever wondered about the di erences between types of microprocessors,then read on. %n this article, you will learn how fairly simple digital logic techni/uesallow a computer to do its 0ob, whether its playing a game or spell checking adocument

8/20/2019 How Microprocessors Work 23

http://slidepdf.com/reader/full/how-microprocessors-work-23 2/13

2

The Intel 8080 was the frst microprocessor in a home computer.

Microprocessor Progression: Intel

The $rst microprocessor to make it into a home computer was the %ntel 3'3', acomplete 3#bit computer on one chip, introduced in 1()&. The $rst microprocessorto make a real splash in the market was the %ntel 3'33, introduced in 1()( andincorporated into the %*4 PC which $rst appeared around 1(32-. %f you are familiarwith the PC market and its history, you know that the PC market moved from the3'33 to the 3'236 to the 3'536 to the 3'&36 to the Pentium to the Pentium %% to thePentium %%% to the Pentium &. "ll of these microprocessors are made by %ntel and allof them are improvements on the basic design of the 3'33. The Pentium & cane!ecute any piece of code that ran on the original 3'33, but it does it about ,'''times faster

ince 2''&, %ntel has introduced microprocessors with multiple cores and millionsmore transistors. *ut even these microprocessors follow the same general rules asearlier chips.

Here are the i!erences "etween the i!erent processors that Intel hasintro uce o#er the $ears.

Compiled from The %ntel 4icroprocessor 7uick 8eference 9uide and T CP*enchmark cores

8/20/2019 How Microprocessors Work 23

http://slidepdf.com/reader/full/how-microprocessors-work-23 3/13

5

"dditional information about the table on this page:

• The ate is the year that the processor was $rst introduced. 4any processorsare re#introduced at higher clock speeds for many years after the originalrelease date.

• Transistors is the number of transistors on the chip. ;ou can see that thenumber of transistors on a single chip has risen steadily over the years.

• Microns is the width, in microns, of the smallest wire on the chip. <orcomparison, a human hair is 1'' microns thick. "s the feature si+e on thechip goes down, the number of transistors rises.

• Clock spee is the ma!imum rate that the chip can be clocked at. Clockspeed will make more sense in the ne!t section.

• %ata Wi th is the width of the "=>. "n 3#bit "=> can

add?subtract?multiply?etc. two 3#bit numbers, while a 52#bit "=> canmanipulate 52#bit numbers. "n 3#bit "=> would have to e!ecute fourinstructions to add two 52#bit numbers, while a 52#bit "=> can do it in oneinstruction. %n many cases, the e!ternal data bus is the same width as the"=>, but not always. The 3'33 had a 16#bit "=> and an 3#bit bus, while themodern Pentiums fetch data 6& bits at a time for their 52#bit "=>s.

• MIP& stands for @millions of instructions per second@ and is a rough measureof the performance of a CP>. 4odern CP>s can do so many di erent thingsthat 4%P ratings lose a lot of their meaning, but you can get a general senseof the relative power of the CP>s from this column.

<rom this table you can see that, in general, there is a relationship between clockspeed and 4%P . The ma!imum clock speed is a function of the manufacturingprocess and delays within the chip. There is also a relationship between the numberof transistors and 4%P . <or e!ample, the 3'33 clocked at 4A+ but only e!ecutedat '.55 4%P about one instruction per 1 clock cycles-. 4odern processors canoften e!ecute at a rate of two instructions per clock cycle. That improvement isdirectly related to the number of transistors on the chip and will make more sense inthe ne!t section.

WH'T(& ' CHIP)

" chip is also called an integrate circuit . 9enerally it is a small, thin piece ofsilicon onto which the transistors making up the microprocessor have been etched." chip might be as large as an inch on a side and can contain tens of millions oftransistors. impler processors might consist of a few thousand transistors etchedonto a chip 0ust a few millimeters s/uare.

8/20/2019 How Microprocessors Work 23

http://slidepdf.com/reader/full/how-microprocessors-work-23 4/13

&

Intel Pentium * processor

Photo courtesy %ntel Corporation

H+,P-U, ' TIC,+&

• Aow *ytes and *its Bork

• Aow *oolean =ogic Borks

• Aow lectronic 9ates Bork

Microprocessor ,ogic

To understand how a microprocessor works, it is helpful to look inside and learnabout the logic used to create one. %n the process you can also learnabout assem"l$ language ## the native language of a microprocessor ## and many

of the things that engineers can do to boost the speed of a processor.

" microprocessor e!ecutes a collection of machine instructions that tell theprocessor what to do. *ased on the instructions, a microprocessor does three basicthings:

• >sing its "=> "rithmetic?=ogic >nit-, a microprocessor can performmathematical operations like addition, subtraction, multiplication anddivision. 4odern microprocessors contain complete Doating point processorsthat can perform e!tremely sophisticated operations on large Doating pointnumbers.

• " microprocessor can move data from one memory location to another.

• " microprocessor can make decisions and 0ump to a new set of instructionsbased on those decisions.

8/20/2019 How Microprocessors Work 23

http://slidepdf.com/reader/full/how-microprocessors-work-23 5/13

There may be very sophisticated things that a microprocessor does, but those areits three basic activities. The following diagram shows an e!tremely simplemicroprocessor capable of doing those three things:

This is about as simple as a microprocessor gets. This microprocessor has:

• "n a ress "us that may be 3, 16 or 52 bits wide- that sends an address tomemory

• " ata "us that may be 3, 16 or 52 bits wide- that can send data tomemory or receive data from memory

• "n % read- and W write- line to tell the memory whether it wants to setor get the addressed location

• " clock line that lets a clock pulse se/uence the processor

• " reset line that resets the program counter to +ero or whatever- andrestarts e!ecution

=etEs assume that both the address and data buses are 3 bits wide in this e!ample.

Aere are the components of this simple microprocessor:

8/20/2019 How Microprocessors Work 23

http://slidepdf.com/reader/full/how-microprocessors-work-23 6/13

6

• 8egisters ", * and C are simply latches made out of Dip#Dops. ee thesection on @edge#triggered latches@ in Aow *oolean =ogic Borks for details.-

• The address latch is 0ust like registers ", * and C.

• The program counter is a latch with the e!tra ability to increment by 1 whentold to do so, and also to reset to +ero when told to do so.

• The "=> could be as simple as an 3#bit adder see the section on addersin Aow *oolean =ogic Borks for details-, or it might be able to add, subtract,multiply and divide 3#bit values. =etEs assume the latter here.

• The test register is a special latch that can hold values from comparisonsperformed in the "=>. "n "=> can normally compare two numbers anddetermine if they are e/ual, if one is greater than the other, etc. The testregister can also normally hold a carry bit from the last stage of the adder. %tstores these values in Dip#Dops and then the instruction decoder can use thevalues to make decisions.

• There are si! bo!es marked @5# tate@ in the diagram. These are tri/state"u!ers . " tri#state bu er can pass a 1, a ' or it can essentially disconnect itsoutput imagine a switch that totally disconnects the output line from thewire that the output is heading toward-. " tri#state bu er allows multipleoutputs to connect to a wire, but only one of them to actually drive a 1 or a 'onto the line.

• The instruction register and instruction decoder are responsible for controllingall of the other components.

"lthough they are not shown in this diagram, there would be control lines from theinstruction decoder that would:

• Tell the " register to latch the value currently on the data bus

• Tell the * register to latch the value currently on the data bus

• Tell the C register to latch the value currently output by the "=>

• Tell the program counter register to latch the value currently on the data bus

• Tell the address register to latch the value currently on the data bus

• Tell the instruction register to latch the value currently on the data bus

• Tell the program counter to increment

• Tell the program counter to reset to +ero

8/20/2019 How Microprocessors Work 23

http://slidepdf.com/reader/full/how-microprocessors-work-23 7/13

)

• "ctivate any of the si! tri#state bu ers si! separate lines-

• Tell the "=> what operation to perform

• Tell the test register to latch the "=>Es test bits

• "ctivate the 8F line

• "ctivate the B8 line

Coming into the instruction decoder are the bits from the test register and the clockline, as well as the bits from the instruction register.

Microprocessor Memor$

The previous section talked about the address and data buses, as well as the 8Fand B8 lines. These buses and lines connect either to 8"4 or 8G4 ## generallyboth. %n our sample microprocessor, we have an address bus 3 bits wide and a databus 3 bits wide. That means that the microprocessor can address 2 3- 2 6 bytes ofmemory, and it can read or write 3 bits of the memory at a time. =etEs assume thatthis simple microprocessor has 123 bytes of 8G4 starting at address ' and 123bytes of 8"4 starting at address 123.

8G4 stands for read#only memory. " 8G4 chip is programmed with a permanentcollection of pre#set bytes. The address bus tells the 8G4 chip which byte to getand place on the data bus. Bhen the 8F line changes state, the 8G4 chip presentsthe selected byte onto the data bus.

8"4 stands for random#access memory. 8"4 contains bytes of information, and themicroprocessor can read or write to those bytes depending on whether the 8F orB8 line is signaled. Gne problem with todayEs 8"4 chips is that they forgeteverything once the power goes o . That is why the computer needs 8G4.

'M chip

*y the way, nearly all computers contain some amount of 8G4 it is possible tocreate a simple computer that contains no 8"4 ## many microcontrollers do this byplacing a handful of 8"4 bytes on the processor chip itself ## but generallyimpossible to create one that contains no 8G4-. Gn a PC, the 8G4 is called

8/20/2019 How Microprocessors Work 23

http://slidepdf.com/reader/full/how-microprocessors-work-23 8/13

3

the *%G *asic %nput?output ystem-. Bhen the microprocessor starts, it beginse!ecuting instructions it $nds in the *%G . The *%G instructions do things like testthe hardware in the machine, and then it goes to the hard disk to fetch the "ootsector see Aow Aard Fisks Bork for details-. This boot sector is another smallprogram, and the *%G stores it in 8"4 after reading it o the disk. The

microprocessor then begins e!ecuting the boot sectorEs instructions from 8"4. Theboot sector program will tell the microprocessor to fetch something else from thehard disk into 8"4, which the microprocessor then e!ecutes, and so on. This is howthe microprocessor loads and e!ecutes the entire operating system .

Microprocessor Instructions

ven the incredibly simple microprocessor shown in the previous e!ample will havea fairly large set of instructions that it can perform. The collection of instructions isimplemented as bit patterns, each one of which has a di erent meaning whenloaded into the instruction register. Aumans are not particularly good at

remembering bit patterns, so a set of short words are de$ned to represent thedi erent bit patterns. This collection of words is called the assem"l$ language ofthe processor. "n assem"ler can translate the words into their bit patterns veryeasily, and then the output of the assembler is placed in memory for themicroprocessor to e!ecute.

AereEs the set of assembly language instructions that the designer might create forthe simple microprocessor in our e!ample:

• , '%' mem # =oad register " from memory address

• , '%1 mem # =oad register * from memory address

• C 21 con # =oad a constant value into register *

• &'3+1 mem # ave register * to memory address

• &'3+C mem # ave register C to memory address

• '%% # "dd " and * and store the result in C

• &U1 # ubtract " and * and store the result in C

• MU, # 4ultiply " and * and store the result in C

• %I3 # Fivide " and * and store the result in C

• C M # Compare " and * and store the result in test

• 4UMP a r # Hump to an address

• 4+5 a r # Hump, if e/ual, to address

8/20/2019 How Microprocessors Work 23

http://slidepdf.com/reader/full/how-microprocessors-work-23 9/13

(

• 42+5 addr # Hump, if not e/ual, to address

• 46 a r # Hump, if greater than, to address

• 46+ a r # Hump, if greater than or e/ual, to address

• 4, a r # Hump, if less than, to address

• 4,+ a r # Hump, if less than or e/ual, to address

• &T P # top e!ecution

%f you have read Aow C Programming Borks , then you know that this simple piece of C code will calculate the factorial of where the factorial of I I J & J 5 J 2 J1 I 12'-:

a=1;f=1;while (a <= 5){ f = f * a; a = a + 1;}

"t the end of the programEs e!ecution, the variable 7 contains the factorial of .

'ssem"l$ ,anguage

" C compiler translates this C code into assembly language. "ssuming that 8"4starts at address 123 in this processor, and 8G4 which contains the assemblylanguage program- starts at address ', then for our simple microprocessor theassembly language might look like this:

// Assume a is at address 128// Assume F is at address 129 !"#$ 1 // a=1;1 %A&'$1282 !"#$ 1 // f=1; %A&'$ 129 "A A 128 // if a , 5 the -um. t 105 !"#$ 5

!" 0 34 108 "A A 129 // f=f*a;9 "A $ 1281 11 %A&'! 12912 "A A128 // a=a+1;1 !"#$ 11 A 15 %A&'! 1281 3 6 // l . 7a t if10 %:"6

M

o now the /uestion is, @Aow do all of these instructions look in 8G4 @ ach ofthese assembly language instructions must be represented by a binary number. <orthe sake of simplicity, letEs assume each assembly language instruction is given auni/ue number, like this:

• =G"F" # 1

• =G"F* # 2

• CGL* # 5

• "M * # &

• "M C mem #

8/20/2019 How Microprocessors Work 23

http://slidepdf.com/reader/full/how-microprocessors-work-23 10/13

1'

• "FF # 6

• >* # )

• 4>= # 3

• F%M # (

• CG4 # 1'

• H>4P addr # 11

• H 7 addr # 12

• HL 7 addr # 15

• H9 addr # 1&

• H9 addr # 1• H= addr # 16

• H= addr # 1)

• TGP # 13

The numbers are known as opco es . %n 8G4, our little program would look like this:

// Assume a is at address 128// Assume F is at address 129Addr . de/ alue //!"#$ 11 12 // %A&'$ 128 128 // !"#$ 15 1 // %A&'$ 1290 1298 1 //

"A A 1289 1281 // !"#$ 511 512 1 // !" 1 1 // 34 101 115 1 // "A A1291 12910 2 // "A $ 12818 12819 8 // 2 5 // %A&'! 12921 12922 1 //

"A A 1282 1282 // !"#$ 125 12 // A 20 5 // %A&'! 12828 12829 11 // 3 6 8 1 18 // %:"6

;ou can see that seven lines of C code became 13 lines of assembly language, andthat became 52 bytes in 8G4.

%eco ing

The instruction decoder needs to turn each of the opcodes into a set of signals that

drive the di erent components inside the microprocessor. =etEs take the "FFinstruction as an e!ample and look at what it needs to do:

1. Furing the $rst clock cycle, we need to actually load the instruction. Therefore the instruction decoder needs to: activate the tri#state bu er forthe program counter activate the 8F line activate the data#in tri#state bu erlatch the instruction into the instruction register

8/20/2019 How Microprocessors Work 23

http://slidepdf.com/reader/full/how-microprocessors-work-23 11/13

11

2. Furing the second clock cycle, the "FF instruction is decoded. %t needs to dovery little: set the operation of the "=> to addition latch the output of the "=>into the C register

5. Furing the third clock cycle, the program counter is incremented in theory

this could be overlapped into the second clock cycle-.very instruction can be broken down as a set of se/uenced operations like these

that manipulate the components of the microprocessor in the proper order. omeinstructions, like this "FF instruction, might take two or three clock cycles. Gthersmight take $ve or si! clock cycles.

Microprocessor Per7ormance an Tren s

The number of transistors available has a huge e ect on the performance of aprocessor. "s seen earlier, a typical instruction in a processor like an 3'33 took 1clock cycles to e!ecute. *ecause of the design of the multiplier, it tookappro!imately 3' cycles 0ust to do one 16#bit multiplication on the 3'33. Bithmore transistors , much more powerful multipliers capable of single#cycle speedsbecome possible.

4ore transistors also allow for a technology called pipelining . %n a pipelinedarchitecture, instruction e!ecution overlaps. o even though it might take $ve clockcycles to e!ecute each instruction, there can be $ve instructions in various stages of e!ecution simultaneously. That way it looks like one instruction completes everyclock cycle.

4any modern processors have multiple instruction decoders, each with its ownpipeline. This allows for multiple instruction streams, which means that more thanone instruction can complete during each clock cycle. This techni/ue can be /uitecomple! to implement, so it takes lots of transistors.

Tren s

The trend in processor design has primarily been toward full 52#bit "=>s with fastDoating point processors built in and pipelined e!ecution with multiple instructionstreams. The newest thing in processor design is 6&#bit "=>s, and people aree!pected to have these processors in their home PCs in the ne!t decade. There hasalso been a tendency toward special instructions like the 44N instructions- thatmake certain operations particularly eOcient, and the addition of hardware virtualmemory support and =1 caching on the processor chip. "ll of these trends push upthe transistor count, leading to the multi#million transistor powerhouses availabletoday. These processors can e!ecute about one billion instructions per second

8/20/2019 How Microprocessors Work 23

http://slidepdf.com/reader/full/how-microprocessors-work-23 12/13

12

Photo courtesy "4F

*/"it Microprocessors

i!ty#four#bit processors have been with us since 1((2, and in the 21st century theyhave started to become mainstream. *oth %ntel and "4F have introduced 6&#bitchips, and the 4ac 9 sports a 6&#bit processor. i!ty#four#bit processors have 6&#bit "=>s, 6&#bit registers, 6&#bit buses and so on.

Gne reason why the world needs 6&#bit processors is because of their enlargea ress spaces . Thirty#two#bit chips are often constrained to a ma!imum of

2 9* or & 9* of 8"4 access . That sounds like a lot, given that most home computerscurrently use only 2 6 4* to 12 4* of 8"4. Aowever, a &#9* limit can be a severeproblem for server machines and machines running large databases. "ndeven home machines will start bumping up against the 2 9* or & 9* limit prettysoon if current trends continue. " 6&#bit chip has none of these constraints becausea 6&#bit 8"4 address space is essentially in$nite for the foreseeable future ## 2 6&bytes of 8"4 is something on the order of a billion gigabytes of 8"4.

Bith a 6&#bit address bus and wide, high#speed data buses on the motherboard , 6&#bit machines also o er faster %?G input?output- speeds to things like hard diskdrives and video cards . These features can greatly increase system performance.

ervers can de$nitely bene$t from 6& bits, but what about normal users *eyondthe 8"4 solution, it is not clear that a 6&#bit chip o ers @normal users@ any real,tangible bene$ts at the moment. They can process data very comple! datafeatures lots of real numbers- faster. People doing video editing and people doingphotographic editing on very large images bene$t from this kind of computingpower. Aigh#end games will also bene$t, once they are re#coded to take advantage

8/20/2019 How Microprocessors Work 23

http://slidepdf.com/reader/full/how-microprocessors-work-23 13/13

15

of 6&#bit features. *ut the average user who is reading e#mail , browsing the Beband editing Bord documents is not really using the processor in that way.

<or more information on microprocessors and related topics, check out the links onthe ne!t page.