Algorithms


The Processing Cycle

Computers are powerful because they can do repetitive things really fast. When the executable code is loaded into main memory the processor can start executing the machine instructions. When a computer executes or runs a program it constantly repeats a series of processing steps commonly referred to as the processing cycle. The processing cycle consists of four primary steps: instruction fetch, instruction decode, instruction execution, and result store. The step names can be shortened to simply fetch, decode, execute, and store. Different processors will implement the processing cycle differently but for the most part these four processing steps are being carried out in some form or another. The processing cycle is depicted in figure 4-9.

image from book
Figure 4-9: Processing Cycle

Fetch

In the fetch step, an instruction is read from memory and presented to the processor’s decode section. If cache memory is present it is checked first. If the requested memory address contents resides in the cache the read operation will execute quickly. Otherwise, the processor will have to wait for the data to be accessed from the slower main memory.

Decode

In the decode step, the instruction fetched from memory is decoded. If the computer thinks it is getting an instruction but instead it gets garbage there will be problems. A computer system’s ability to recover from such situations is generally a function of a robust operating system.

Execute

If the fetched instruction is successfully decoded, meaning it is a valid instruction in the processor’s instruction set, it is executed. A computer is a bunch of electronic switches. Executing an instruction means the computer’s electronic switches are turned either on or off to carry out the actions required by a particular instruction. (Different instructions cause different sets of switches to be turned on or off.)

Store

After an instruction is executed the results of the execution, if any, must be stored somewhere. Most arithmetic instructions leave the result in one of the processor’s onboard registers. Memory write instructions would then be used to transfer the results to main memory. Keep in mind that there is only so much storage space inside a processor. At any given time, almost all data and instructions reside in main memory, and are only loaded into the processor when needed.

Why A Program Crashes

Notwithstanding catastrophic hardware failure, a computer crashes or locks up because what it was told was an instruction was not! The faulty instruction loaded from memory turns out to be an unrecognizable string of ones and zeros and when it fails to decode into a proper instruction the computer halts.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net