Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
UNIT 1 Overview and Instructions INTRODUCTION COMPUTER A Computer is a machine which accepts input information in the digitized form, processes the input according to a set of stored instructions and produces the resulting output information. PROGRAM AND DATA The set of stored instructions written using a computer to solve the task is called program and input and output information is called data. The internal storage where programs are stored is called Memory. Characteristics of computer 1 Speed: Computers perform various operations at a very high speed. 2 Accuracy: Computers are very accurate. Do not make mistakes in calculations. 3 Reliability: Computers gives correct and consistent results always even if they are used in adverse conditions. Many times errors are caused by human interventions not by computer. Computer output is reliable, subject to the condition that the input data and the instructions (programs) are correct. Incorrect input data and unreliable programs give us wrong results. 4 Storage Capacity: The computer can store large amount of data and can be retrieved at any time in fractions of a second. This data can be stored in permanent storage devices like hard disk, CDs etc. 5.Versatility: Computers can do a variety of jobs based on the instructions given to them. They are used in each and every field, making the tasks easier. Limitations of a Computer:1) Not intelligent 2) Inactive Computer = Hardware + Software Hardware: • Hardware is the physical aspect of computers, telecommunications, and other device. • Hardware implies permanence and invariability • The components include keyboard, floppy drive, hard disk, monitor, CPU, printer, wires, transistors, circuits etc. Software: It is a set of programs used to perform certain tasks. Program is set of instructions to carry out a particular task Hardware and Software Hardware Software The physical components making up the Software is a set of programs used to system are termed as Hardware. perform certain tasks(logical component) The components include keyboard, Software’s include compliers, floppy drive, hard disk, monitor, CPU, loaders, Banking s/w, library s/w, printer, wires, transistors, circuits etc. payroll s/w etc. Hardware works based on instructions Software tell the hardware what to do TYPES OF COMPUTER Computers are classified according to size, cost, power of the processor, and type of usage. Some of types of computer are Personal computers(PC) Widely used in homes, schools, and business offices. Notebook computers It’s a compact version of the PC with all the components are packed together into a single unit. Workstations It has a High resolution –Graphics input / output capabilities. Desktop Computers They have processing and storage units, visual display and audio output displays. Enterprise systems or mainframes and Servers Mainframes are used for business data processing in medium and large corporations that require more computing power and storage capacity. Servers: Servers contain sizable database storage units and are capable of handling large volumes of request to access the data. The request and responses are transported over internet communication facilities. Supercomputers They are used for large – scale numerical calculations required in applications such as weather forecasting and aircraft design and simulation. I. Components of a Computer A computer consists of five functionally independent main parts. They are, Input Memory Arithmetic and logic Output Control unit Basic functional units of a computer CU ALU O/P UNIT I/P UNIT MAIN MEMORY UNIT SECONDARY Figure: The operation of a computer can be summarized as follows The computer accepts programs and the data through an input and stores them in the memory. The stored data are processed by the arithmetic and logic unit under program control. The processed data is delivered through the output unit. All above activities are directed by control unit. The information is stored either in the computer’s memory for later use or immediately used by ALU to perform the desired operations. Instructions are explicit commands that 1. Manage the transfer of information within a computer as well as between the computer and its I/O devices. 2. Specify the arithmetic and logic operations to be performed. To execute a program, the processor fetches the instructions one after another, and performs the desired operations. The processor accepts only the machine language program.To get the machine language program, Complier is used. Note: Compiler is software (Translator) which converts the High Level Language program (source program) into Machine language program (object program) Input unit The computer accepts coded information through input unit. The input can be from human operators, electromechanical devices such as keyboards or from other computer over communication lines. Examples of input devices are Keyboard, joysticks, trackballs and mouse are used as graphic input devices in conjunction with display. Microphones can be used to capture audio input which is then sampled and converted into digital code for storage and processing. Keyboard • It is a common input device. • Whenever a key is pressed, the corresponding letter or digit is automatically translated into its corresponding binary code and transmitted over cable to the memory of the computer. Memory unit Memory unit is used to store programs as well as data. Memory is classified into primary and secondary storage. Primary storage It also called main memory. It operates at high speed and it is expensive. It is made up of large number of semiconductor storage cells, each capable of storing one bit of information. These cells are grouped together in a fixed size called word. This facilitates reading and writing the content of one word (n bits) in single basic operation instead of reading and writing one bit for each operation Each word is associated with a distinct address that identifies word location. A given word is accessed by specifying its address. Secondary storage It is slow in speed. It is cheaper than primary memory. Its capacity is high. It is used to store information that is not accessed frequently. Various secondary devices are magnetic tapes and disks, optical disks (CD-ROMs), floppy etc. Arithmetic and logic unit Arithmetic and logic unit (ALU) and control unit together form a processor. Actual execution of most computer operations takes place in arithmetic and logic unit of the processor. Example: Suppose two numbers located in the memory are to be added. They are brought into the processor, and the actual addition is carried out by the ALU. Registers: Registers are high speed storage elements available in the processor. Each register can store one word of data. When operands are brought into the processor for any operation, they are stored in the registers. Accessing data from register is faster than that of the memory. Output unit The function of output unit is to produce processed result to the outside world in human understandable form. Examples of output devices are Graphical display, Printers such as inkjet, laser, dot matrix and so on. The laser printer works faster. Control unit Control unit coordinates the operation of memory, arithmetic and logic unit, input unit, and output unit in some proper way. Control unit sends control signals to other units and senses their states. Example: Data transfers between the processor and the memory are controlled by the control unit through timing signals. Timing signals are the signals that determine when a given action is to take place. Control units are well defined, physically separate unit that interact with other parts of the machine. A set of control lines carries the signals used for timing and synchronization of events in all units Differences between: Primary Memory Secondary Memory Also called as Main memory. Also called as Auxiliary memory. Accessing the data is faster. Accessing the data is slow. CPU can access directly CPU cannot access directly Semiconductor memory. Magnetic memory. Data storage capacity is less. Data storage capacity is more or huge. Expensive. Not expensive. It is Internal memory. It is External memory. Examples : RAM, ROM Examples: hard disk, floppy disk, magnetic tape etc. II.BASIC OPERATIONAL CONCEPTS To perform a given task on computer, an appropriate program is to be stored in the memory. Individual instructions are brought from the memory into the processor, which executes the specified operations. Data to be used as operands are also stored in the memory. Consider an instruction Add LOCA, R0 This instruction adds operand at memory location LOCA to the operand in a register R0 in the processor and the result get stored in the register R0. The original content of LOCA is preserved, whereas the content of R0 is overwritten. This instruction requires the following steps 1) The instruction is fetched from memory into the processor. 2) The operand at LOCA is fetched and added to the content of R0. 3) Resulting sum is stored in register R0. The above add instruction combines a memory access operation with an ALU operation. Same can be performed using two instruction sequences Load LOCA, R1 • ADD R1, R0 Here the first instruction, transfer the contents of memory location LOCA into register R1. • The second instruction adds the contents of R1 and R0 and places the sum into R0. • The first instruction destroys the content of R1 and preserve the value of LOCA, the second instruction destroys the content of R0. Connection between memory and the processor Transfer between the memory and the processor are started by sending the address of the memory to be accessed to the memory unit and issuing the appropriate control signals. The data are then transferred to or from the memory. Processor contains number of registers in addition to the ALU and the Control unit for different purposes. Various registers are Instruction register(IR) Program counter(PC) Memory address register(MAR) Memory data register(MDR) General purpose registers (R0 to Rn-1 ) The below figure shows how the memory and the processor can be connected Memory MAR MDR ALU Processor PC Ro R1 IR . . Control unit Rn-1 N general purpose registers Instruction register (IR): IR holds the instruction that is currently being executed by the processor. Its output is available to the control circuits, which generates the timing signals that controls various processing elements involved in executing the instruction. Program counter (PC): It is a special purpose register that contains the address of the next instruction to be fetched and executed. During the execution of one instruction PC is updated to point the address of the next instruction to be fetched and executed. It keeps track of the execution of a program Memory address register (MAR): The MAR holds the address of the memory location to be accessed. Memory data register(MDR): The MDR contains the data to be written into or read from the memory location, that is being pointed by MAR.These two registers MAR and MDR facilitates communication between memory and the processor. Operating steps Initially program resides in the memory (usually get through the input Unit.) and PC is set to point to the first instruction of the program. The contents of PC are transferred to MAR and Read control signal is sent to the memory. The addressed word (in this case the first instruction of the program) is read out of the memory and located into the MDR .register. Next, the contents of MDR are transferred to the IR. At this point the instruction is ready to be decoded and executed. If the instruction involves an operation to be performed by the ALU, it is necessary to obtain the required operands. If the operands resides in the memory ( it could also be in a general purpose register in the processor), Then the operands required are fetched from the memory to the MDR by sending its address to the MAR and initiating a read cycle. The fetched operands are then transferred to the ALU. After one or more operands are fetched dint his way the ALU can perform the desired operation.. If the result of this operation is to be stored in the memory, then the result is sent to MDR and address of the memory location where the result is to be stored is sent to MAR and write cycle is initiated. During the execution of current instruction the contents of the PC are incremented to point to next instruction to be executed. Thus as soon as the execution of the current instruction is completed, a new instruction fetch may be started. Note: in addition to transferring data between the memory and the processor, the computer accepts data from input devices and sends data to the output devices. Thus some machine instructions with ability to handle IO transfers are provided. Interruption Normal execution of the program may be interrupted if some other device requires urgent service of the processor. For example, a monitoring device in a computer controlled industrial process may detect a dangerous condition. In order to deal with that situation immediately, the normal execution of the current program must be interrupted. To do this the device raises an interrupt signal. An interrupt is the request from an I/O device for the service by the processor. The processor provides the requested service by executing an appropriate interrupt service routine. When the interrupt service routine is completed, the execution of the interrupted program is continued by the processor. Because of such changes, it may alter the internal state of the processor. So its state must be saved in memory location before servicing the interrupt. Normally PC will be used. III. BUS STRUCTURES Bus is a group of lines that serves as a connection path for several individual parts of a computer to transfer the data between them. To achieve a reasonable speed of the operation, a computer must be organized so that, All its units can handle one full word of data at a given time. When a word of data is transferred in a bus, all its bits are transferred in parallel, that is, the bits are transferred simultaneously over many wires, or lines, one bit per line. Input Output Memory Figure: Single Bus Structure Processor A group of lines serves as a connecting path of several devices is called a BUS. The bus must have a separate line for carrying data, address and control signals. Single bus is used to interconnect all the units as shown above and hence the bus can be used for only one transfer at a time, only two units can actively use the bus at any given time. Advantage of using single bus structure is its low cost and its flexibility for attaching peripheral devices. Multiple Bus structure System using multiple buses results in concurrency as it allows two or more transfer at the same time. This leads to high performance but at increased cost. The use of Buffer registers Speed of operation of various devices connected to a common bus varies. Input and output devices such as keyboard and printers are relatively slow compared to processor and storage devices such as optical disks. Consider an example the transfer of encoded character from a processor to a character printer. The efficiency of using processor will be reduced because of variance in their speed. To overcome this problem a buffer register is used. Buffer registers Buffer register is an electronic register that is included with the devices to hold the information during transfer. When the processor sends a set of characters to a printer, those contents is transferred to the printer buffer (buffer register for a printer). Once printer buffer is loaded processor and the bus is no longer needed and the processor can be released for other activity. Purpose of Buffer Register: Buffer register prevent a high speed processor from being locked to a slow I/O devices. Buffer register is used which smooth out timing differences among slow and the fast devices. It allows the processor to switch rapidly from one device to another. IV. PERFORMANCE AND METRICS Performance of a computer can be measured by speed with which it can execute the program. Speed of the computer is affected by Hardware design Machine language instruction of the computer. Because the programs are usually written in high level language. Compiler, which translates high-level language into machine language. For best performance, it is necessary to design a complier, machine instruction set, and the hardware in a coordinated way. Consider a Time line diagram to describe how the operating system overlaps processing, disk transfers, and printing for several programs to make the best possible use of the resources available. The total time required to execute the program is t5 - t0. This is called elapsed time and it is the measure of the performance of the entire computer system. It is affected by the speed of the processor, the disk and the printer. To discuss the performance of the processor we should only the periods during which the processor is active. Elapsed time for the execution of the program depends on hardware involved in the execution of the program. This hardware includes processor and the memory which are usually connected by a BUS (As shown in the bus structure diagram.). When the execution of the program starts, all program instructions and the required data are stored in the main memory. As execution proceeds, instructions are fetched from the main memory one by one by the processor, and a copy is placed in the cache. When execution of the instruction calls for the data located in the main memory, the data are fetched and a copy is placed in the cache. If the same instruction or data is needed later, it is read directly from the cache. The processor and a small cache memory are fabricated into a single IC chip. The speed of such chip is relatively faster than the speed at which instruction and data can be fetched from the main memory. A program can be executed faster if the movement of the instructions and data between the main memory and the processor is minimized, which is achieved by using the cache. To evaluate the performance, we can discuss about, Processor clock Basic performance equation Pipelining and Superscalar operation Clock Rate Instruction Set: CISC and RISC Compiler Performance Measurement Processor clock Processor circuits are controlled by timing signal called a clock. The clock defines regular time intervals, called clock cycle. To execute a machine instruction, the processor divides the action to be performed into sequence of basic steps, such that each step can be completed in one clock cycle. Length of one clock cycle is P and this parameter P affects processor performance. It is inversely proportional to clock rate R=1/P This is measured in cycles per second. Processors used in today’s personal computers and workstations have clock rates from a few hundred millions to over a billion cycles per second is called hertz (Hz). The term “million” is denoted by the prefix Mega (M) and “billion” is denoted by prefix Giga ( G). Hence, 500 million cycles per second is usually abbreviated to 500Mega Hertz (MHz). And 1250 million cycles per second is abbreviated to 1.25 Giga Hertz (GHz). The corresponding clock periods are 2 and 0.8 nano seconds (ns) respectively User program and OS routine sharing of the processor Pointer Disk OS routines Program t0 t1 t2 t3 t4 t4 Time Main memory Cache memory BUS The Processor Cache Processor .Basic performance equation Let T be the time required for the processor to execute a program in high level language. The compiler generates machine language object program corresponding to the source program. Assume that complete execution of the program requires the execution of N machine language instructions. Assume that average number of basic steps needed to execute one machine instruction is S, where each basic step is completed in one clock cycle. If the clock rate is R cycles per second, the program execution time is given by T = (N x S) / R This is often called Basic performance equation. To achieve high performance, the performanc parameter T should be reduced. T value can be reduced by reducing N and S, and increasing R. Value of N is reduced if the source program is compiled into fewer number of machine instructions. Value of S is reduced if instruction has a smaller no of basic steps to perform or if the execution of the instructions is overlapped. Value of R can be increased by using high frequency clock, ie. Time required to complete a basic execution step is reduced. N, S and R are dependent factors. Changing one may affect another. Pipelining and Superscalar operation Pipelining It is a technique of overlapping the execution of successive instructions. This technique improves performance. Consider the instruction Add R1, R2, R3 The above instruction adds the contents of registers R1 and R2, and places the sum to R3. The contents of R1 and R2 are first transferred to the inputs of the ALU. After addition is performed the result is transferred to register R3 from the processor. Here processor can read the next instruction to be executed while performing addition operation of the current instruction and while transferring the result of addition to ALU, the operands required for the next instruction can be transferred to the processor. This process of overlapping the instruction execution is called Pipelining. If all the instructions are overlapped to the maximum degree, the effective value of S is 1. It is impossible always. Individual instructions require several clock cycles to complete but for the pupose of computing T, effective value of S is 1. Superscalar operation A higher degree of concurrency can be achieved if multiple instruction pipelines are implemented in the processor. This means that multiple functional units are used, creating parallel paths through which different instruction can be executed in parallel. With such an arrangement, it becomes possible to start the execution of several instructions in every clock cycle. This mode of operation is called superscalar execution. So there is possibility of reducing the S value even less than 1. Parallel execution should preserve the logical correctness of programs. That is the result produced must be same as those produced by serial execution of program executions. Clock Rate There are two possibilities for increasing the clock rate, R. First, improving the integrated-circuit (IC) technology makes logic circuits faster, which reduces the time needed to complete a basic step. This allows the clock period, P, to be reduced and the clock rate, R, to be increased. Second, reducing the amount of processing done in one basic step also makes it possible to reduce the clock period, P. However, if the actions that have to be performed by an instruction remain the same, the number of basic steps needed may increase. Increases in the value of R by improvements in IC technology affect all aspects of the processor's operation equally with the exception of the time it takes to access the main memory. In the presence of a cache, the percentage of accesses to the main memory is small. Hence, much of the performance can be improved. The value of T will be reduced by the same factor as R is increased because S and N are not affected. Instruction Set: CISC and RISC CISC: Complex Instructional Set Computers ¾ ¾ ¾ ¾ ¾ RISC: Reduced Instructional Set Computers Simple instructions require a small number of basic steps to execute. Complex instructions involve a large number of steps. For a processor that has only simple instructions, a large number of instructions may be needed to perform a given programming task. This could lead to a large value for N and a small value for S. On the other hand, if individual instructions perform more complex operations, fewer instructions will be needed, leading to a lower value of N and a larger value of S. It is not obvious if one choice is better than the other. Processors with simple instructions are called Reduced Instruction Set Computers (RISC) and processors with more complex instructions are referred to as Complex Instruction Set Computers (CISC) ¾ The decision for choosing the instruction set is done with the use of pipelining. Because the effective value of S is close 1. Compiler A compiler translates a high-level language program into a sequence of machine instructions. To reduce N, we need to have a suitable machine instruction set and a compiler that makes good use of it. An optimizing compiler takes advantage of various features of the target processor to reduce the product N x S, which is the total number of clock cycles needed to execute a program. The number of cycles is dependent not only on the choice of instructions, but also on the order in which they appear in the program. The compiler may rearrange program instructions to achieve better performance without changing the logic of the program. Complier and processor must be closely linked in their architecture. They should be designed at the same time. Performance Measurement The computer community adopted the idea of measuring computer performance using benchmark programs. To make comparisons possible, standardized programs must be used. The performance measure is the time it takes a computer to execute a given benchmark program. A nonprofit organization called System Performance Evaluation Corporation (SPEC). Running time on the reference computer SPEC rating = ------------------------------------------------ Running time on the computer under test The test is repeated for all the programs in the SPEC suite, and the geometric means of the results are computed. Let SPECi be the rating for program i in the suite. The overall SPEC rating for the computer is given by n SPEC rating = ⎛ ⎞ ⎜ ∏ SPECi ⎟ ⎝ i =1 ⎠ where n is the number of programs in the suite. 1/ n V. INSTRUCTION AND INSTRUCTION SEQUENCING A computer must have instruction capable of performing four types of basic operations such as Data transfer between the memory and the processor registers. Arithmetic and logic operation on data Program sequencing and control I/O transfers To understand the first two types of instruction, we need to know some notations.. Register Transfer Notation (RTN) Data transfer can be represented by standard notations given below..Processor registers are represented by notations R0, R1, R2…Address of the memory locations are represented by names such as LOC, PLACE, MEM etc..I/O registers are represented by names such as DATAIN, DATAOUT. The content of memory locations are denoted by placing square bracket around the name of the register. Example 1 : R1 Å [ LOC ] This expression states that the contents of memory location LOC are transferred into the processor register R1. Example 2: R3 Å [ R1 ] + [ R2 ] This expression states that the contents of processor registers R1 and R2 are added and the result is stored into the processor register R3. This type of notation is known as Register Transfer Notation (RTN). Note: that the right-hand of an RTN expression always denotes a value, and left-hand side is name of a location where the value is to be placed, overwriting the old contents of that location. Assembly Language Notation To represent machine instructions, assembly language uses statements as shown below ¾ To transfer the data from memory location LOC to processor register R1 Move LOC,R1 ¾ To add two numbers in register R1 and R2 and to place their sum in register R3 ADD R1,R2,R3 BASIC INSTRUCTION TYPES The operation of addition of two numbers is a fundamental capability in any computer. The statement C= A + B in a high-level language program is a command to the computer to add the current values of the two variables called A and B, and to assign the sum to a third variable, C. When the program containing this statement is compiled, the three variables, A,B,C are assigned to distinct location in the memory. Hence the above high-level language statement requires the action C <- [A] + [B] to take place in the computer. Here [A] and [B] represents contents of A and B respectively. To carry out this action, the contents of memory locations A and B are fetched from the memory and transferred into the processor where their sum is computed. This result is then sent back to the memory and stored in location C. Performing a basic instruction is represented in many ways: They are • 3-address instruction • 2 -address instruction • 1-address instruction • 0-address instruction Let us first assume that this action is to be accomplished by a single machine instruction. Furthermore, assume that this instruction contains the memory addresses of the three operands - A, B, and C. This three-address instruction can be represented symbolically as Add A,B,C Operands A and B are called the source operands, C is called the destination operand, and Add is the operation to be performed on the operands. A general instruction of this type has the format Operation Source1,Source2,Destination ¾ If k bits are needed to specify the memory address of each operand, the encoded form of the above instruction must contain 3k bits for addressing purposes in addition to the bits needed to denote the Add operation. For a modern processor with a 32-bit address space, a 3-address instruction is too large to fit in one word for a reasonable word length. Thus, a format that allows multiple words to be used for a single instruction would be needed to represent an instruction of this type. An alternative approach is to use a sequence of simpler instructions to perform the same task, with each instruction having only one or two operands. Suppose that two-address instructions of the form are available. Operation Source,Destination An Add instruction of this type is Add A,B which performs the operation B Å [A] + [B]. When the sum is calculated, the result is sent to the memory and stored in location B, replacing the original contents of this location. This means that operand B is both a source and a destination. A single two-address instruction cannot be used to solve our original problem, which is to add the contents of locations A and B, without destroying either of them, and to place the sum in location C. The problem can be solved by using another two address instruction that copies the contents of one memory location into another. Such an instruction is Move B, C which performs the operation C Å [B], leaving the contents of location B unchanged. The word "Move" is a misnomer here; it should be "Copy." However, this instruction name is deeply entrenched in computer nomenclature. The operation C Å [A] + [B] can now be performed by the two-instruction sequence Move B,C Add A,C In all the instructions given above, the source operands are specified first, followed by the destination. This order is used in the assembly language expressions for machine instructions in many computers. But there are also many computers in which the order of the source and destination operands is reversed. It is unfortunate that no single convention has been adopted by all manufacturers. In fact, even for a particular computer, its assembly language may use a different order for different instructions. We have defined three- and two-address instructions. But, even twoaddress instructions will not normally fit into one word for usual word lengths and address sizes. Another possibility is to have machine instructions that specify only one memory operand. When a second operand is needed, as in the case of an Add instruction, it is understood implicitly to be in a unique location. A processor register, usually called the accumulator, may be used for this purpose. Thus, the one-address instruction Add A means the following: Add the contents of memory location A to the contents of the accumulator register and place the sum back into the accumulator. Let us also introduce the one-address instructions Load A And Store A The Load instruction copies the contents of memory location A into the accumulator, and the Store instruction copies the contents of the accumulator into memory location A. Using only oneaddress instructions, the operation C ( [A] + [B] can be performed by executing the sequence of instructions Load A Add B Store C Note : that the operand specified in the instruction may be a source or a destination, depending on the instruction. In the Load instruction, address A specifies the source operand, and the destination location, the accumulator, is implied. On the other hand, C denotes the destination location in the Store instruction, whereas the source, the accumulator, is implied. Some early computers were designed around a single accumulator structure. Most modern computers have a number of general-purpose processor registers - typically 8 to 32, and even considerably more in some cases. Access to data in these registers is much faster than to data stored in memory locations because the registers are inside the processor. Because the number of registers is relatively small, only a few bits are needed to specify which register takes part in an operation. For example, for 32 registers, only 5 bits are needed. This is much less than the number of bits needed to give the address of a location in the memory. Because the use of registers allows faster processing and results in shorter instructions, registers are used to store data temporarily in the processor during processing. Let Ri represent a general-purpose register. The instructions Load A,Ri Store Ri,A and Add A,Ri are generalizations of the Load, Store, and Add instructions for the single-accumulator case, in which register Ri performs the function of the accumulator. ¾ Even in these cases, when only one memory address is directly specified in an instruction, the instruction may not fit into one word. ¾ When a processor has several general-purpose registers, many instructions involve only operands that are in the registers. In fact, in many modem processors, computations can be performed directly only on data held in processor registers.