Chapter 5 
Computer Organization
Objectives
At the end of this chapter, you should be able to:
1.	describe the basic units of a computer system;
2.	describe the stored program concept in computer system;
3.	describe the functions of each component in a CPU;
4.	describe the instruction execution process: fetch cycle and execution cycle;
5.	distinguish the different categories of memory;
6.	describe the operations of a memory;
7.	describe the organization of a memory; and
8.	describe the principles of operations of the different secondary storage devices.

Reference

1.	M. Marris Mano, "Computer System Architecture," third edition, Prentice Hall.

2.	V. Carl Hamacher, Zvonko G. Vranesic, Safwat G. Zaky, "Computer Organization," McGraw-Hill, 3rd ed. 1990.

3.	Andrew S. Tanenbaum, "Structured Computer Organization," 3rd ed. Prentice Hall, 1990.

4.	Herman Lam, John O'Malley, "Fundamentals of Computer Engineering,” Wiley, 1988.

1. General Principles
Digital computers are electronic machines capable of performing arithmetic and logical operations.  A typical microcomputer system consists of a Central Processing Unit (CPU), Main Memory, and Input / output devices.  They are connected by different buses. (Figure 5.1)  

Figure 5.1  A typical microcomputer system.	
The physical parts of the computer system are called hardware.  However, a computer system does not operate by itself.  It performs the different tasks under the command of programs.  A program is a sequence of instructions that specify the operations, operands, and the processing sequence.  The processing task may be altered by specifying a new program with different instructions or specifying the same instructions with different data.
A computer instruction is a binary code that specifies a sequence of micro-operations for the computer. The instruction codes together with data are stored in memory.  The CPU reads each instruction from memory, decodes it, and executes it by issuing a sequence of micro-operations to different hardware components.  Every computer has its own unique instruction set.  The stored program concept, i.e. ability to store and execute instructions, is the most important property of a general-purpose computer.
Each instruction will be assigned a binary code, called the machine code, consisting of two parts as depicted in Figure 5.2

Opcode	Address	
Figure 5.2	
•	The specification of the operation to be performed by the instruction, such as add, load, etc., is called the operation code or the opcode.  It is stored in the opcode field.
•	The address part specifies the source or the destination of the operand.  It is stored in the address field of the instruction code.  Note that while every operation must have the opcode part, the address part is not always needed.
Consequently, it is unavoidable to have instructions of different lengths.  Therefore, the longer instructions should occupy several words in memory.  

2. The Central Processing Unit
The function of the CPU is to execute programs stored in the main memory by fetching and decoding them, then executing them one after another.
2.1 Components of CPU
Figure 5.3 shows the components of a simplified CPU.

Figure 5.3 Components of a simplified CPU.	
2.1.1 Timing and Control Unit
Timing and control unit is responsible for the synchronization of the system and generating the different required control signals in various operations.
There is a high-frequency oscillator which generates the clock signal.
It is also responsible for decoding an instruction during the execution cycle.
It also provides a reset function to initialize the CPU along with other components in the microprocessor system.
2.1.2 Arithmetic and Logic Unit (ALU)
ALU consists of dedicated logic circuits to perform various arithmetic and logical operations.
It produces the results of different operations and places them into the accumulator.
Along with the results, ALU also changes the flags in the Processor Status Registers.
2.1.3 Accumulator
Accumulator is used extensively for data manipulations.
It is commonly used to store the operands and results of different operations.
2.1.4 Instruction Register (IR)
During the fetch cycle, an instruction is transferred from the main memory to the Instruction Register.
The Instruction Register will pass the instruction to the Timing and Control Unit for instruction decoding.
This register is controlled only by the Timing and Control Unit.
2.1.5 Program Counter (PC)
A Program Counter is the place to store the address information of the next instruction to be executed.
The content of the Program Counter is updated by the Timing and Control Unit after the instruction decoding.
2.1.6 Stack Pointer (SP)
Stack is a special implementation of memories.  The data stored in the stack will be retrieved in a Last In First Out basis.
The Stack pointer (SP) contains the address of next free memory location.
Storing a data in the stack is called push.  The data are stored in the location pointed to by the Stack Pointer. After the operation the content of the SP will be incremented.
Retrieving a data from the stack is called pop.  This operation first decrement the content of the pointer and the data in the memory location pointed by the SP will be retrieved.
2.1.7 Processor Status Register (PSR)
Flag register contains various bits of status information.
The commonly used flags include: zero, carry, overflow, interrupt, and negative.
These flags are set or cleared by the various components in CPU, after an operation.  Programmers know from these flags the result of an operation.
2.1.8 General Purpose Registers
General Purpose Registers are used to store temporary data, usually the result from an operation and will be used again in a later operation.
They are resident on the CPU and can be manipulated rapidly without selecting external chips.
They are sometimes used for indexing purposes.
2.2 Instruction fetch-execute cycle
The control unit is responsible for fetching the code of the instruction to be executed from the memory and then decoding the instruction code and generating control signals which will cause the instruction to be executed. 
This breakdown is usually formulated as follows:  The instruction cycle consists of the fetch cycle and the execute cycle.  We will see that decoding is not a localized one-time operation but usually takes place in several steps of the execute cycle.  The fetch cycle is identical for all instructions.  The execute cycle is different for different instructions.
2.2.1 The fetch cycle
Fetching the instruction requires both the availability of the address of the next instruction and a means of exchange of information with the memory.
The address of the next instruction is stored in a dedicated register, the Program Counter (PC).
The CPU and the memory are connected by two buses.  The address bus will be used by the CPU to deliver the address of the location to be accessed.  The data bus will be used to communicate data - in a more general sense, including instruction codes - between the memory and the CPU.  In addition there must be a set of control lines.  Communication of data over a bus means that the source register is connected to the bus for a length of time sufficient for the data to be accepted and processed by the target component.
In order to guarantee that the CPU has enough time to process the data and to provide a source register for transmission from CPU to memory, there will be a Memory Data Register (MDR) on the CPU side of the bus.  Its function will be to hold data items communicated between the memory and the CPU in either direction.
The source register for the communication of the address to the memory will be called the Memory Address Register (MAR) and will also be a part of the CPU.  The communication of the address is unidirectional from the CPU to the memory.
The communication of data is bi-directional to allow for both retrieval of data from memory and storage of results in memory.  A control line from the CPU to memory must be available to indicate the desired direction of the transfer since the knowledge of the address is not sufficient to determine whether reading or writing is required.
In this model fetching the next instruction requires the transfer of the address from the PC to MAR, generation of the READ control signal, and waiting for the memory to place the data on the data bus from which it is copied into MDR.  Note that all communication between the CPU and the memory is via MDR and MAR.
To complete the fetch cycle, it remains to store the instruction code temporarily for decoding.  The register used for this purpose is usually called the instruction register (IR).  After the instruction is decoded, the content of the program counter will be updated and the fetch cycle completes.
2.2.2 The execute cycle
During the execute cycle, the CPU performs the different tasks according to the instruction.  Consequently, different resources will be required for different types of instructions.
At the end of the execute cycle, the contents of the Processor Status Register will be updated.
3. Semiconductor Memories
3.1 Introduction
A semiconductor memory is an integrated circuit which is capable of storing a binary number and recalling it when addressed or selected by a computer or other digital devices.  It is one of the storage devices used in computers.  A memory is used to store either programs or data in a computer.  In both cases, the contents are all binary information.
There are several methods to categorize the different types of memories.  One of the methods is based on the way a memory is accessed, either saving or retrieval of information in a memory.  The time required to locate and access a memory is called the access time.  Random access devices are those in which any location may be selected at random.  Therefore, access to the content is direct and required approximately equal access time for each location.  On the other hand, Sequential access devices are those in which the locations are sequentially arranged.  Access to a location must pass through all preceding locations.  Therefore, access time in a sequential access device varies according to the location.
Memory devices can also be categorized as volatile and non-volatile devices.  Volatile devices are those in which the data stored will be lost when power supply is off.  Non-volatile devices are those in which the data stored will not be lost when power is off.
In the next section, we will introduce several types of memory devices with their characteristics.
3.2 Random Access Memory and Read Only Memory
3.2.1 Random access memory
Random Access Memory (RAM) is a read / write memory.  Data can be read from or written into the memory in a random access mode.  However, it is a volatile device.  Data will be lost if power is off.
There are two basic types of RAM in use today, dynamic RAM  and Static RAM.
3.2.1.1 Dynamic RAM
Dynamic RAMs are designed for high capacity, moderate speeds, and low power consumption.  Their memory cells are basically charge-storage capacitors with driver transistors.  The presence or absence of charge in a capacitor is interpreted by the sense line of the RAM as 1 or 0.
The charge in a capacitor has tendency to discharge itself, therefore dynamic RAMs are required periodic charging to maintain the data stored.  This periodic charging is called refreshing.
3.2.1.2	Static RAM
Static RAMs are made of flip-flops and logic gates.  Since a flip-flop is a bistable elements, it can be used to store the binary values.  Operations of flip-flops are fast and do not require refreshing.
However, due to the unit complexity, the capacity of static RAM is low compared with dynamic RAM.  For the same reason, power consumption and the cost of unit storage are high, too.
Table 5.1 compares the different characteristics of dynamic and static RAMs.

	Dynamic RAM	Static RAM	
Power Consumption	Low	high	
Capacity	High	low	
Price	Cheap	expensive	
Refreshing	Required	not required	
Speed	Slow	fast	
Table 5.1	
3.2.2 Read Only Memory
Read Only Memories (ROM) are those in which the data is permanently programmed either at the time of manufacture or by the user prior to the memory being installed.  They are non-volatile memories.  Still, they are random access devices.  
There are different types of ROMs.  The read only refers to the applications at the end user’s view.  Writing the information into the ROM is required prior to use.
3.2.2.1	Standard ROMs
Standard ROMs are programmed by the manufacturer.  Users can only read the data or execute programs in the ROM.  Usually, standard ROMs store certain standard applications for general user applications.
3.2.2.2	Programmable ROMs
 Programmable ROMs (PROM) can be programmed permanently by the user or distributor using special equipment.  They can only be programmed once.  Before the data is written into the PROM, users should verify the correctness of the contents.
3.2.2.3	Erasable Programmable ROMs
Erasable programmable ROMs (EPROM) can be programmed and erased by the user for many times.  Erasure is carried out by shining high intensity ultra-violet light through a special transparent window at the top of the memory IC.  Erasing and writing to the ROM are assisted by a special device called EPROM writer.
3.2.2.4	Electrically Erasable Programmable ROMs
Electrically erasable programmable ROMs (EEPROM) are similar to the EPROM.  Instead of erasure of entire chip, user can erase a single bit electrically in one operation.  Again, the operations require a special equipment.
3.3. Memory Organization
3.3.1 Introduction
A memory is usually organized into N locations where N is generally some power of 5.  The content in each location is called a word.  Each word is assigned an address in the memory and consists of same number of bits called the word length. (Figure 5.4)

Figure 5.4 A memory map.	
A memory with 4096 locations, each storing 16 bits data, is called a 4096-word 16-bit memory or a 4K 16-bit memory.
Basically two operations can be operated on a RAM, reading from a memory, which retrieves the content in a memory location, and writing to a memory, which storing a data into a memory location.  However, operation on a ROM is limited to read only.
3.3.2 Operations on a memory
The read and write operations are assisted by two external circuits, the memory address register (MAR) and memory data register (MDR) as in Figure 5.5.

Figure 5.5 Access to a RAM.	
In general, for an n-bit address information, a total of 2n locations can be addressed.  As in Figure 5.5, to perform a read operation, the computer places the address information of the location in which the data are to be read into the memory address register.  This register, consists of n binary devices, usually flip-flops, so that a total number of 2n words can be addressed.
The data can then be passed to the memory data register after a the read signal is passed into the memory.  The size of the memory data register is the same as the word length of the memory so as to cater for the content in the memory.
In most cases, reading the contents from a memory location will not destroy or change the contents in the location.  This is called a non-destructive read.  If in case a read operation to the memory causes any change in the content in the memory, the read operation is called a destructive read operation.
To write a data into the memory, the data is first placed in the MDR, and the address in the MAR.  Then a signal is passed to the write line. The memory will store the data in the MDR into the specified location.  After the operation, the data originally stored in the location will be lost.

3.4. Cache Memory
Analysis of a large number of typical programs has shown that the references to memory at any given interval of time tend to be confined within a few localized areas in memory.  This phenomenon is known as the property of locality of reference.
Over a short interval of time, the addresses generated by a typical program refer to a few localized areas of memory repeatedly, while the remainder of memory is accessed relatively infrequently.
If the active portions of the program and data are placed in a fast small memory, the average memory access time can be reduced, thus rducing the total execution time of the program.  Such a fast small memory is referred to as a cache memory.  It is placed between the CPU and the main memory.  The access time of cache memory is less than the access time of main memory by a factor of 5 to 10.
The fundamental idea of cache organization is that by keeping the most frequently accessed instructions and data in the fast cache memory, the average memory access time will approach the access time of the cache.  Although the cache is only a small fraction of the size of main memory, a large fraction of memory requests will be found in the fast cache memory because of the locality of reference property of programs.
The basic operation of the cache is as follows.  When the CPU needs to access memory, the cache is examined.  If the word is found in the cache, it is read from the fast memory.  If the word addressed by the CPU is not found in the cache, the main memory is accessed to read the word.  A block of words containing the one just accessed is then transferred from main memory to cache memory.  The block size may vary from one word to about 16 words adjacent to the one just accessed.  In this manner, some data are transferred to cache so that future references to memory find the required words in the fast cache memory.
3.5. Virtual Memory
In any computer system in which the current active programs and data do not fit into the physical main memory space, secondary storage devices hold the overflow.  The operating system automatically moves programs between the main memory and secondary storage.  Thus, the application programmer does not need to be aware of the limitations imposed by the available main memory.
Techniques that automatically move program and data blocks into the physical main memory when they are required for execution are called virtual memory technieques.
The binary addresses that the processor issues for either instructions or data are called virtual or logical addresses.  The mechanism that translates these into physical addresses is usually implemented by a combination of hardware and software components.  If a virtual address refers to a part of the program or data that is currently in the physical memory, then the contents of the appropriate location in the main memory are accessed immediately.  On the other hand, if the referenced address is not in the main memory, its contents must be brought into a suitable location in the main memory before they can be used.
The simplest method of translation assumes that all programs and data are composed of fixed-length units called pages.  Each page consists of a block of words that occupy contiguous locations in the main memory or in secondary storage.  The size of a page ranges from 1K to 8K bytes in length.  They constitute the basic unit of information that is moved back and forth between the main memory and secondary storage whenever the translation mechanism determines that a move is required.
The virtual memory is meant to bridge the size gap between the main memory and secondary storage and is usually implemented in part by software techniques.
4. Secondary Storage
The secondary storage is a kind of the memory.  They are relative low cost and able to store large amount of data.  They cannot be addressed directly and they are considered as external to the microprocessor.  Contents in the secondary storage must be loaded into the main memory before they can be accessed.  Generally, blocks of data are brought into RAM from these devices.  Although the operations of reading or writing are slower, large amounts of data can be stored in such devices.
Secondary storage devices are usually nonvolatile.  Figure 5.6 shows the pyramid chart of different types of computer storage and memory.  Memory is faster than storage but is expensive and not practical to use for all storage requirements.  Storage is less expensive per megabyte stored but is slower than memory.

Figure 5.6 The pyramid chart compares the different types of computer storage and memory.	
4.1 Magnetic Disk Storage
4.1.1 Floppy disks
A floppy disk, also called a diskette, consists of a circular piece of thin mylar plastic, which is coated with an oxide material such as that used on audio and video recording tape.
Before a floppy disk can be used for storage, it must be formatted.  Formatting prepares a floppy disk for storage by defining the tracks, cylinders, and sectors on the disk surface as in figure 5.7.  A sector is a pie-shaped section of the floppy disk.  A track sector is a section of track within a sector.  Each track sector holds 512 bytes.  For reading and writing purposes, track sectors are grouped into clusters.  A cluster consists of 2 – 8 track sectors depending on the operating system.  A cluster is the smallest unit of floppy disk space used to store data.  Evan if a file consisted of only a few bytes, one cluster would be used for storage.  Although each cluster holds data from only one file, one file can be stored in many clusters.
The formatting process also establishes a directory that will be used to record information about files stored on the floppy disk.  On most personal computers, this directory is called the file allocation table (FAT).  For each file, the FAT stores the file name, the file size, the time and date the file was last changed, and the cluster number where the file begins.

Figure 5.7 Formatting a floppy disk.	

Figure 5.8 Formatting a floppy disk.	
The floppy disk is read / written through a floppy disk drive.  A drive motor rotates the disk so that a read/write head can rest on the top and bottom surface of the rotating floppy disk.  To write data on the disk, the read/write head generates electronic impulses which change the magnetic polarity, or alignment, of magnetic areas along a track on the disk (Figure 5.8).
4.1.2 Hard disks
Hard disks consist of one or more rigid platters coated with a material that allows data to be recorded magnetically on the surface of the platters (Figure 5.9).   The platters, read/write heads, and access arms that move the heads across the disk surface are all enclosed in an airtight sealed case.
	
Figure 5.9 Inside a hard disk.	
	Storing data on hard disks is much like storing data on floppy disks except that hard disks usually have multiple platters; and the read/write heads float on a cushion of air and do not touch the disk surface.  Access time for a hard disk is significantly less than access time for a floppy because a hard disk spins faster and, unlike a floppy disk, a hard disk is spinning constantly.
	Data is stored on both sides of a hard disk platter.  Same as a floppy disk, a hard disk must be formatted before it can store data.  Before a hard disk is formatted, it can be divided into separate areas called partitions.  Each partition can function as if it were a separate disk.  
4.1.3 Disks cartridges
	Some hard disk drives, called disk cartridges, are removable.  Disk cartridges (Figure 5.10) provide both the storage capacity and fast access times of hard disks and the portability of floppy disks.
	Bernoulli disk cartridge works with a special drive unit that uses a cushion of air to keep the flexible disk surface from touching the read/write head.  The flexible disk surface reduces the chance of a head crash but causes the cartridges to eventually wear out.
	
Figure 5.10 Iomega JAZ Disk cartridge.	
4.2 Magnetic tape
Magnetic tape consists of a thin ribbon of plastic, one side of which is coated with a material that can be magnetized to record the binary codes that represent data.  Tape is a sequential access storage media because the computer must write and read records one after another.  The most common types of magnetic tape devices are cartridge tape, but some older systems use reel-to-reel tape.  
Same as disk drives, tape drives have an electromagnetic read/write head that can read or write magnetic patterns on the tape representing bits.  Several different methods are used to record bits on the tape. 
On most Quarter-Inch-Cartridge (QIC) tape devices, data is recorded in a single track along the length of the tape.  When the end is reached, the tape reverses direction and data is recorded in another track in the opposite direction.
Digital audio tape (DAT) uses helical scan technology to record data in tracks at a six-degree angle to the tape.
Older, one-half-inch reel-to-reel tape drives record data in nine channels, eight channels for data bits and one channel for a parity bit.

Figure 5.11 Different methods to record data on tape.
Top: quarter-inch-cartridge tape; 
Middle: Digital audio tape; 
Bottom: one-half-inch reel-to-reel tape.	
Tape storage serves as a primary means of backup, a method of transferring data between systems, and a cost-effective way to store data that does not have to be accessed immediately.

4.3 PC Cards
PC cards are small, credit card-sized cards that fit into PCMCIA (Personal Computer Memory Card International Association) expansion slots.  Different versions and sizes of the cards are used for storage, communications, and additional memory.
Most often, PC cards are used on portable computers, but they can be incorporated into desktop systems as well.  Although they are only 10.5mm thick (about .4 inch), PC cards used for storage contain small rotating disk drives 1.3 inches in diameter that can contain more than 200 MB of data.
The storage cards can be useful for people who work with more than one computer or who have to share a computer with others.  Their data can be maintained on a PC storage card and kept with them.
4.4 Optical Disks
Enormous quantities of information are stored on optical disks using a laser to burn microscopic holes on the surface of a hard plastic disk.
A lower power laser reads the disk by reflecting light off the disk surface.  The reflected light is converted into a series of bits that the computer can process.  As in Figure 6.12, to read data, a low-power laser light is reflected from the smooth unpitted areas and is interpreted as 1.  The pitted areas do not reflect the laser beam and are interpreted as 0.  To record data on an optical disk, a high-power laser heats the surface and makes a microscopic pit.

Figure 6.12 Reading and writing an optical disk.	
A full-size, 14-inch optical disk can store 6.9 MB of information.  The smaller disks, called a CD-ROM, just under five inches in diameter, can store more than 800 MB data.
CD-ROM drives are often advertised as double-, triple-, or x-times speed drives.  The ratings refer to how fast the drive can transfer data in relation a standard established for CD-ROM drives used for multimedia applications.  The original standard established a minimum transfer rate of 150 kbps.
Most optical disks are prerecorded and cannot be modified by the user.  Optical disk devices that provide for one-time recording are called WORM devices, an acronym for write once, read many.  The most common erasable optical drives use magneto-optical technology, in which a magnetic field changes the polarity of a spot on the disk that has been heated by a laser.
4.5 Smart Card
Smart cards are same size and thickness of a credit card and contain a thin microprocessor capable of storing recorded information.  When it is inserted into compatible equipment, the information on the smart card can be read and, if necessary, updated.  There are increasing trends in using smart cards in different areas of applications, such as electronic cash, access control, etc.