[ Pobierz całość w formacie PDF ]
.So the process goes: fetch and execute; fetch and execute.The CPU works its waythrough memory, with the instruction pointer register leading the way.As it goes itworks, moving data around in memory, moving values around in registers, passing data toperipherals, and "crunching" data in arithmetic or logical operations.Computer programs are lists of binary machine instructions stored in memory.They areno different from any other list of data bytes stored in memory except in how they aretreated when fetched by the CPU.The Foreman's Innardsfile:///E|/TEMP/Chapter%202%20Lifting%20The%20Hood.htm (19 of 22) [9/30/02 08:28:34 PM] file:///E|/TEMP/Chapter%202%20Lifting%20The%20Hood.htmI made the point earlier that machine instructions are binary codes.This is something weoften gloss over, yet to understand the true nature of the CPU, we have to step away fromthe persistent image of machine instructions as numbers.They are not numbers.They arebinary patterns designed to throw electrical switches.Inside the CPU are a very large number of transistors.Some small number of thosetransistors go into making the foreman's pockets machine registers for holdinginformation.The vast bulk of those transistors (which now number over a million inCPUs like the 80386) are switches connected to other switches, which are connected tostill more switches in a mind-numbing complex net-work.The machine instruction 01000000 (40H) directs the CPU to add 1 to the value stored inregister AX.It's very instructive of the true nature of computers to think about theexecution of machine instruction 01000000 in this way: the CPU fetches a bytecontaining the code 01000000 from memory.Once the byte is fully within the CPU, theCPU in essence lets the machine instruction byte push eight transistor switches.The lone1 digit pushes its switch "up" electri-cally; the rest of the digits, all 0s, push their switches"down."In a chain reaction, those eight switches flip the states of first dozens, then hundreds, thenthousands, and finally tens of thousands of tiny transistor switches within the CPU.It isn'trandom this furious moment of electrical activity within the CPU operates utterlyaccording to patterns etched into the silicon of the CPU by Intel's teams of engineers.Ultimately perhaps after hundreds of thousands of individual switch throws the valuecontained in register AX is suddenly one greater than it was before.How this happens is difficult to explain, but you must remember that any number withinthe CPU can also be looked at as a binary code, including numbers stored in registers.Also, most switches within the CPU contain more than one "handle." These switches arecalled gates and work according to the rules of logic.Perhaps two, or three, or even more"up" switch throws have to simultaneously arrive at a particular gate in order for one"down" switch throw to pass through that gate.These gates are used to build complex internal machinery within the CPU.Collections ofgates can add two numbers in a device called an adder, which again is nothing more thana crew of dozens of little switches working together first as gates and then as gatesworking together to form an adder.As part of the cavalcade of switch throws kicked off by the binary code 01000000, thevalue in register AX was dumped trap-door style into an adder, while at the same time thenumber 1 was fed into the other end of the adder.Finally, rising on a wave of switchthrows, the new sum emerges from the adder and ascends back into register AX and thefile:///E|/TEMP/Chapter%202%20Lifting%20The%20Hood.htm (20 of 22) [9/30/02 08:28:34 PM] file:///E|/TEMP/Chapter%202%20Lifting%20The%20Hood.htmjob is done.The foreman of your computer, then, is made of switches just like all the other parts ofthe computer.The chap contains a mind-boggling number of such switches,interconnected in even more mind-boggling ways.But the important thing is that whetheryou are boggled or (like me on off days) merely jaded by it all, the CPU, and ultimatelythe computer, does what we tell it to.We set up a list of machine instructions as a table inmemory, and then, by God, that mute iron brick comes alive and starts earning its keep.Changing CourseThe first piece of genuine magic in the nature of computers is that a string of binary codesin memory tells the computer what to do, step by step.The second piece of that magic isreally the jewel in the crown.There are machine instructions that change the order inwhich machine instructions are fetched and executed.In other words, once the CPU has executed a machine instruction that does somethinguseful, the next machine instruction may tell the CPU to go back and play it again andagain, and again, as many times as necessary.The CPU can keep count of the number oftimes that it has executed that particular instruc-tion or list of instructions, and keeprepeating them until a prearranged count has been met.Or the CPU can arrange to skip certain sequences of machine instructions entirely if theydon't need to be executed at all.What this means is that the list of machine instructions in memory does not necessarilybegin at the top and run without deviation to the bottom.The CPU can execute the firstfifty or a hundred or a thousand instructions, then jump to the end of the program orjump back to the start and begin again.It can skip and bounce up and down the list like astone tossed over a calm pond.It can execute a few instructions up here, then zip downsomewhere else and execute a few more instructions, then zip back and pick up where itleft off, all without missing a beat or even wasting too much time.How is this done? Recall that the CPU contains a register that always contains the addressof the next instruction to be executed.This register, the instruction pointer, is notessentially different from any of the other registers in the CPU.Just as a machineinstruction can add one to register AX, another machine instruction can add (or subtract)some number from the address stored in the instruction pointer.Add one hundred to theinstruction pointer, and the CPU will instantly skip one hundred bytes down the list ofmachine instruc-tions before it continues.Subtract one hundred from the address stored inthe instruction pointer, and the CPU will instantly jump back one hundred bytes up thefile:///E|/TEMP/Chapter%202%20Lifting%20The%20Hood.htm (21 of 22) [9/30/02 08:28:34 PM] file:///E|/TEMP/Chapter%202%20Lifting%20The%20Hood.htmmachine instruction list.And finally, the third whammy: the CPU can change its course of execution based on thework it has been doing.The CPU can "decide" whether or not to execute a giveninstruction or group of instructions, based on values stored in memory, or based on thestate of special one-bit CPU registers called flags [ Pobierz całość w formacie PDF ]
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • agnieszka90.opx.pl