[Type here] MIDLANDS STATE UNIVERSITY FACULTY OF COMMERCE DEPARTMENT OF INFORMATION SYSTEM INFO133: COMPUTER ARCHITECTURE AND ORGANISATION LECTURER: MR R. GUMBO Office Cephas G. Msipa Teaching and Learning Centre Office 7 Email: gumbor@msu.ac.zw (0772407595) MODULE OUTLINE PREAMBLE This module studies the basic instruction set of computer architecture and organization of a modern computer. It introduces students to the fundamental concepts of computer architecture and organization of modern-day computers, emphasizing both basic principles and the critical role of performance in driving computer design. It conveys concepts through a wealth of concrete examples, highlighting on the CPU Organisation & Operation, Number systems, Operating Systems, Memory Systems, include Assembly language, The Von Neumann Machine Instructions, Registers, translating high level arithmetic into Assembly, Memory and Registers Addressing Modes, Logic Circuits and Input /Output Interfacing, Pipelines, I/O Polling and Interrupts. 1 [Type here] 2 [Type here] Unit 1: Principles of Computer Design Learning Objectives After successful completion of this unit, you should be able to: • Describe software and hardware interaction layers in computer architecture • Describe central processing unit • Describe various machine language instructions • Describe various addressing modes • Describe various instruction types and Instruction cycle 1.1 Introduction This unit discusses the basic principles of computer design. It will focus on the basic layout of the computer, the various components (hard and soft ) that make up the computer and its basic functions of executing machine instructions. 1.2 Brief History of Computers 1.2.1 First Generation: Vacuum Tubes ENIAC (Electronic Numerical Integrator And Computer), designed and constructed at the University of Pennsylvania, was the world’s first general-purpose electronic digital computer. It was enormous, weighing 30 tons, occupying 1500 square feet of floor space, and containing more than 18,000 vacuum tubes. When operating, it consumed 140kilowatts of power. It was also substantially faster than any electromechanical computer, capable of5000 additions per second. The use of the ENIAC for a purpose other than that for which it was built demonstrated its general-purpose nature. 1.2.2 The von Neumann machine The task of entering and altering programs for the ENIAC was extremely tedious. The programming process can be easy if the program could be represented in a form suitable for storing in memory alongside the data. Then, a computer could get its instructions by reading them from memory, and a program could be set or altered by setting the values of a portion of memory. This idea is known as the stored-program concept. The first publication of the idea was in a 1945 proposal by von Neumann for a new computer, the EDVAC (Electronic Discrete Variable Computer). In 1946, von Neumann and his colleagues began the design of a new stored-program computer, referred to as the IAS computer, at the Princeton Institute for Advanced Studies. The IAS computer, although not completed until 1952, is the prototype of all subsequent general-purpose computers. It consists of 3 [Type here] • • • • A main memory, which stores both data and instruction An arithmetic and logic unit (ALU) capable of operating on binary data A control unit, which interprets the instructions in memory and causes them to be executed Input and output (I/O) equipment operated by the control unit 1.2.3 The Second Generation: Transistors The first major change in the electronic computer came with the replacement of the vacuum tube by the transistor. The transistor is smaller, cheaper, and dissipates less heat than a vacuum tube but can be used in the same way as a vacuum tube to construct computers. Unlike the vacuum tube, which requires wires, metal plates, a glass capsule, and a vacuum, the transistor is a solid state device, made from silicon. The transistor was invented at Bell Labs in 1947 and by the 1950s had launched an Electronic revolution. It was not until the late 1950s, however, that fully transistorized computers were commercially available. The use of the transistor defines the second generation of computers. It has become widely accepted to classify computers into generations based on the fundamental hardware technology employed. 1.2.4 The Third Generation: Integrated Circuits In 1958 came the achievement that revolutionized electronics and started the era of Micro- electronics, the invention of the integrated circuit. It is the integrated circuit that defines the third generation of computers. Micro-electronics: Microelectronics means, literally, “small electronics.“ Since the beginnings of digital electronics and the computer industry, there has been a persistent and consistent trend towards the reduction in size of digital electronic circuits. 4 [Type here] 1.2.5 Later Generations With the introduction of large-scale integration (LSI), more than1000 components can be placed on a single integrated circuit chip. Very-large-scale integration (VLSI) achieved more than 10,000 components per chip, while current ultra-large-scale integration (ULSI) chips can contain more than one million components. 1.2.6 Semiconductor memory The first application of integrated circuit technology to computers was construction of the processor (the control unit and the arithmetic and logic unit) out of integrated circuit chips. But it was also found that this same technology could be used to construct memories. 1.2.7 Microprocessors Just as the density of elements on memory chips has continued to rise, so has the density of elements on processor chips. As time went on, more and more elements were placed on each chip, so that fewer and fewer chips were needed to construct a single computer processor. 1.3 Software Software, or program enables a computer to perform specific tasks, as opposed to the physical components of the system (hardware). This includes application software such as a word processor, which enables a user to perform a task, and system software such as an operating system, which enables other software to run properly, by interfacing with hardware and with other software or custom software made to user specifications. 1.3.1. Types of Software Practical computer systems divide software into three major classes: system software, programming software and application software, although the distinction is arbitrary, and often blurred. • System software helps run the computer hardware and computer system. This includes operating systems, device drivers, diagnostic tools, servers, windowing systems, utilities and more. The purpose of systems software is to insulate the applications programmer as much as possible from the details of the particular computer complex being used, especially memory and other hardware features, and such accessory devices as communications, printers, readers, displays, keyboards, etc. • Programming software usually provides tools to assist a programmer in writing computer programs and software using different programming languages in a more convenient way. The tools include text editors, compilers, interpreters, linkers, 5 [Type here] debuggers, and so on. An Integrated development environment (IDE) merges those tools into a software bundle, and a programmer may not need to type multiple commands for compiling, interpreter, debugging, tracing, and etc., because the IDE usually has an advanced graphical user interface, or GUI. • Application software allows end users to accomplish one or more specific (noncomputer related) tasks. Typical applications include industrial automation, business software, educational software, medical software, databases, and computer games. Businesses are probably the biggest users of application software, but almost every field of human activity now uses some form of application software. It is used to automate all sorts of functions. 1.3.2. Operation Computer software has to be "loaded" into the computer's storage (such as a hard drive, memory, or RAM). Once the software is loaded, the computer is able to execute the software. Computers operate by executing the computer program. This involves passing instructions from the application software, through the system software, to the hardware which ultimately receives the instruction as machine code. Each instruction causes the computer to carry out an operation -- moving data, carrying out a computation, or altering the control flow of instructions. Data movement is typically from one place in memory to another. Sometimes it involves moving data between memories and registers which enable high-speed data access in the CPU. Moving data, especially large amounts of it, can be costly. So, this is sometimes avoided by using "pointers" to data instead. Computations include simple operations such as incrementing the value of a variable data element. More complex computations may involve many operations and data elements together. Instructions may be performed sequentially, conditionally, or iteratively. Sequential instructions are those operations that are performed one after another. Conditional instructions are performed such that different sets of instructions execute depending on the value(s) of some data. In some languages this is known as an "if" statement. Iterative instructions are performed repetitively and may depend on some data value. This is sometimes called a "loop." Often, one instruction may "call" another set of instructions that are defined in some other program or module. When more than one computer processor is used, instructions may be executed simultaneously. A simple example of the way software operates is what happens when a user selects an entry such as "Copy" from a menu. In this case, a conditional instruction is executed to copy text from data in a document area residing in memory, perhaps to an intermediate 6 [Type here] storage area known as a 'clipboard' data area. If a different menu entry such as “Paste" is chosen, the software may execute the instructions to copy the text from the clipboard data area to a specific location in the same or another document in memory. Depending on the application, even the example above could become complicated. The field of software engineering endeavours to manage the complexity of how software operates. This is especially true for software that operates in the context of a large or powerful computer system. Currently, almost the only limitations on the use of computer software in applications is the ingenuity of the designer/programmer. Consequently, large areas of activities (such as playing grand master level chess) formerly assumed to be incapable of software simulation are now routinely programmed. The only area that has so far proved reasonably secure from software simulation is the realm of human art—especially, pleasing music and literature. 1.4 Hardware Computer hardware is the physical part of a computer, including the digital circuitry, as distinguished from the computer software that executes within the hardware. The hardware of a computer is in frequently changed, in comparison with software and data, which are "soft" in the sense that they are readily created, modified or erased on the computer. Firmware is a special type of software that rarely, if ever, needs to be changed and so is stored on hardware devices such as read-only memory (ROM) where it is not readily changed (and is therefore "firm" rather than just "soft"). Most computer hardware is not seen by normal users. It is in embedded systems in automobiles, microwave ovens, electrocardiograph machines, compact disc players, and other devices. Personal computers, the computer hardware familiar to most people, form only a small minority of computers (about 0.2% of all new computers produced in 2003). 1.4.1. Personal computer hardware A typical pc consists of a case or chassis in desktop or tower shape and the following parts: Typical Motherboard found in a computer Figure 1.2 Motherboard 7 [Type here] i. Motherboard or system board with slots for expansion cards and holding parts • Central processing unit (CPU) Computer fan - used to cool down the CPU • Random Access Memory (RAM) - for program execution and short term data storage, so the computer does not have to take the time to access the hard drive to find the file(s) it requires. More RAM will normally contribute to a faster PC. RAM is almost always removable as it sits in slots in the motherboard, attached with small clips. The RAM slots are normally located next to the CPU socket. • Basic Input-Output System (BIOS) or Extensible Firmware Interface (EFI) in some newer computers • Buses ii. Power supply - a case that holds a transformer, voltage control, and (usually) a cooling fan iii. Storage controllers of IDE, SATA, SCSI or other type, that control hard disk, CDROM and other drives; the controllers sit directly on the motherboard (on-board) or on expansion cards iv. Video display controller that produces the output for the computer display. This will either be built into the motherboard or attached in its own separate slot (PCI,PCI-E or AGP), requiring a Graphics Card. v. Computer bus controllers (parallel, serial, USB, FireWire) to connect the computer to external peripheral devices such as printers or scanners In addition, hardware can include external components of a computer system. The following are either standard or very common. Input devices o Webcam • Text input devices • Audio input devices o Keyboard o Microphone vi. Output devices • Pointing devices o Mouse • Image, Video output devices o Trackball • Printer: Peripheral device • Gaming devices that produces a hard copy. o Joystick (Inkjet, Laser) o Game pad • Monitor: Device that takes o Game controller signals and displays them. • Image, Video input devices (CRT,LCD) o Image scanner Audio output devices • Speakers: A device that converts analog audio signals into the equivalent air vibrations in order to make audible sound. 8 [Type here] • Headset: A device similar in functionality to that of a regular telephone handset but is worn on the head to keep the hands free. Student-Activity 1. What is computer Software? 2. What is computer Hardware? 3. List various Input and Output devices. 4. Describe various Audio Output devices. 5. What is the function of RAM 1.5 Software-Hardware Interaction layers in Computer Architecture In computer engineering, computer architecture is the conceptual design and fundamental operational structure of a computer system. It is a blueprint and functional description of requirements (especially speeds and interconnections) and design implementations for the various parts of a computer — focusing largely on the way by which the central processing unit (CPU) performs internally and accesses addresses in memory. It may also be defined as the science and art of selecting and interconnecting hardware components to create computers that meet functional, performance and cost goals. "Architecture" therefore typically refers to the fixed internal structure of the CPU (i.e. electronic switches to represent logic gates) to perform logical operations, and may also include the built-in interface (i.e. opcodes) by which hardware resources (i.e. CPU, memory, and also motherboard, peripherals) may be used by the software. It is frequently confused with computer organization. But computer architecture is the abstract image of a computing system that is seen by a machine language (or assembly language) programmer, including the instruction set, memory address modes, processor registers, and addressed data formats; whereas the computer organization is a lower level, more concrete, description of the system that involves how the constituent parts of the system are interconnected and how they interoperate in order to implement the architectural specification. Figure 1.3 A typical vision of a computer architecture as a series of abstraction layers 9 [Type here] 1.5.1 Abstraction Layer An abstraction layer (or abstraction level) is a way of hiding the implementation details of a particular set of functionality. Perhaps the most well-known software models which use layers of abstraction are the OSI 7 Layer model for computer protocols, OpenGL graphics drawing library, and the byte stream I/O model originated by Unix and adopted by MSDOS, Linux, and most other modern operating systems. In computer science, an abstraction level is a generalization of a model or algorithm, away from any specific implementation. These generalizations arise from broad similarities that are best encapsulated by models that express similarities present in various specific implementations. The simplification provided by a good abstraction layer allows for easy reuse by distilling a useful concept or metaphor so that situations where it may be accurately applied can be quickly recognized. A good abstraction will generalize that which can be made abstract; while allowing specificity where the abstraction breaks down and its successful application requires customization to each unique requirement or problem. 1.5.2 Firmware In computing, firmware is software that is embedded in a hardware device. It is often provided on flash ROMs or as a binary image file that can be uploaded onto existing hardware by a user. Firmware is defined as: • The computer program in a read-only memory (ROM) integrated circuit (a hardware part number or other configuration identifier is usually used to represent the software); • The erasable programmable read-only memory (EPROM) chip, whose program may be modified by special external hardware, but not by a general purpose]application program. • The electrically erasable programmable read-only memory (EEPROM) chip, whose program may be modified by special electrical external hardware (not the usual optical light), but not by [a general purpose] application program. 1.5.3 Assembler An assembly language program is translated into the target computer’s machine code by a utility program called an assembler. Typically a modern assembler creates object code by translating assembly instruction mnemonics into opcodes, and by resolving symbolic names for memory locations and other entities. The use of symbolic references is a key feature of assemblers, saving tedious calculations and manual address updates after program modifications. 1.5.4 Kernel In computing, the kernel is the central component of most computer operating systems (OSs). Its responsibilities include managing the system’s resources and the 10 [Type here] communication between hardware and software components. As a basic component of an operating system, a kernel provides the lowest-level abstraction layer for the resources (especially memory, processor and I/O devices) that applications must control to perform their function. It typically makes these facilities available to application processes through inter-process communication mechanisms and system calls. These tasks are done differently by different kernels, depending on their design and implementation. While monolithic kernels will try to achieve these goals by executing all the code in the same address space to increase the performance of the system, micro kernels run most of their services in user space, aiming to improve maintainability and modularity of the code base. A range of possibilities exists between these two extremes. Figure 1.4 A kernel connects the application software to the hardware of a computer. 1.5.6 Operating System An operating system (OS) is a computer program that manages the hardware and software resources of a computer. At the foundation of all system software, an operating system performs basic tasks such as controlling and allocating memory, prioritizing system requests, controlling input and output devices, facilitating networking, and managing files. It also may provide a graphical user interface for higher level functions. It forms a platform for other software. 1.5.7 Application Software Application software is a subclass of computer software that employs the capabilities of a computer directly to a task that the user wishes to perform. This should be contrasted with system software which is involved in integrating a computer's various capabilities, but typically does not directly apply them in the performance of tasks that benefit the 11 [Type here] user. In this context the term application refers to both the application software and its implementation. 1.6 Central Processing Unit A CPU is composed of three components: (a) Control Unit This component is responsible for controlling all CPU operations. This function is performed by giving proper control instructions. (b) Arithmetic and Logic Unit (ALU) This component deals with arithmetic and logical operations. An arithmetic operation refers to addition, subtraction, while logical operation refers to AND, OR, NOT. (c) Register The CPU also consists of small and high-speed memory units to store specific controlled information and data temporarily. This memory has several registers where each of the register conducts a specific function. The main registers are: ProgrammeCounter - PC refers to the next instruction that will be carried out. Instruction Register - IR holds the instructions currently being executed. Figure 1.5 Location of CPU in a computer 12 [Type here] 1.6.1 CPU Organisation The CPU organisationis shownbelow. This section is known as data paths. It has a few registers (usually about 1 to 16 registers) and an ALU. Data is entered into two ALU input registers labelled as A and B as in the figure below. This register holds ALU input during the operation of the ALU. Figure 1.6 Datapaths for CPU ALU performs mathematical operations and other simple operations involving the input and stores the result in the output register. The data in the output register can be stored again in the register and can be returned to memory if instruction is given so. Student Activity 1. Describe various software-hardware interaction layers in computer hardware. 2. Define CPU. Describe its various parts. 1.6.2 Registers The control unit operates the IAS by fetching instructions from memory and executing them one at a time. The control unit and the ALU contain storage locations, called registers, defined as follows: • Memory buffer register (MBR): Contains a word to be stored in memory or sent to the I/O unit, or is used to receive a word from memory or from the I/O unit. • Memory address register (MAR): Specifies the address in memory of the word to be written from or read into the MBR. 13 [Type here] • Instruction register (IR): Contains the 8-bit opcode instruction being executed. • Instruction buffer register (IBR): Employed to hold temporarily the right-hand instruction from a word in memory. • Program counter (PC): Contains the address of the next instruction-pair to be fetched from memory. • Accumulator (AC) and multiplier quotient (MQ): Employed to hold temporarily operands and results of ALU operations. 1.7 Machine Language Instructions A computer executes machine language programs mechanically-that is without understanding them or thinking about them --simply because of the way it is physically put together. This is not an easy concept. A computer is a machine built of millions of tiny switches called transistors, which have the property that they can be wired together in such a way that an output from one switch can turn another switch on or off. As a computer computes, these switches turn each other on or off in a pattern determined both by the way they are wired together and by the program that the computer is executing. Machine language instructions are expressed as binary numbers. A binary number is made up of just two possible digits, zero and one. So, a machine language instruction is just a sequence of zeros and ones. Each particular sequence encodes some particular instruction. The data that the computer manipulates is also encoded as binary numbers. A computer can work directly with binary numbers because switches can readily represent such numbers: Turn the switch on to represent a one; turn it off to represent a zero. Machine language instructions are stored in memory as patterns of switches turned on or off. When a machine language instruction is loaded into the CPU, all that happens is that certain switches are turned on or off in the pattern that encodes that particular instruction. The CPU is built to respond to this pattern by executing the instruction it encodes; it does this simply because of the way all the other switches in the CPU are wired together. 1.7.1 Addressing Modes The address field or fields in a typical instruction format are relatively small. We should be able to reference a large range of locations in main memory. For this, a variety of addressing techniques has been employed. The most common addressing techniques are: • Immediate, Direct, Indirect, Register, Register indirect, Displacement, Stack 14 [Type here] Figure 1.7 Addressing modes 1.7.2 Addressing Techniques • Immediate Addressing The simplest form of addressing is immediate addressing, in which the operand value is present in the instruction Operand = A This mode can be used to define and use constants or set initial values of variables The advantage of immediate addressing is that no memory reference other than the instruction fetch is required to obtain the operand, thus saving one memory or cache cycle in the instruction cycle. The disadvantage is that the size of the number is restricted to the size of the address field, which, in most instruction sets, is small compared with the word length. • Direct Addressing A very simple form of addressing is direct addressing, in which the address field contains the effective address of the operand: EA = A The advantage is it requires only one memory reference and no special calculation. The disadvantage is that it provides only a limited address space. • Indirect Addressing With direct addressing, the length of the address field is usually less than the word length, thus limiting the address range. One solution is to have the address field refer to the address of a word in memory, which in turn contains a full-length address of the operand. This is known as indirect addressing: EA = (A) • Register Addressing 15 [Type here] Register addressing is similar to direct addressing. The only difference is that the address field refers to register rather than a main memory address: EA = R To clarify, if the contents of a register address field in an instruction is 5, then register R5 is the intended address, and the operand value is contained in R5. The advantages of register addressing are that (1) only a small address field is needed in the instruction, and (2) no time-consuming memory references are required because the memory access time for a register internal to the processor is much less than that for a main memory address. The disadvantage of register addressing is that the address space is very limited. • Register Indirect Addressing Just as register addressing is analogous to direct addressing, register indirect addressing is analogous to indirect addressing. In both cases, the only difference is whether the address field refers to a memory location or a register. Thus, for register indirect address, EA = (R) The advantages and limitations of register indirect addressing are basically the same as for indirect addressing. In both cases, the address space limitation (limited range of addresses) of the address field is overcome by having that field refer to a word-length location containing an address. In addition, register indirect addressing uses one less memory reference than indirect addressing. • Displacement Addressing A very powerful mode of addressing combines the capabilities of direct addressing and register indirect addressing. We will refer to this as displacement addressing: EA = A + (R) • Relative addressing For relative addressing, also called PC-relative addressing, the implicitly referenced register is the program counter (PC). That is, the next instruction address is added to the address field to produce the EA. Thus, the effective address is a displacement relative to the address of the instruction. • Base-register addressing For base-register addressing, the interpretation is the following: The referenced register contains a main memory address, and the address field contains a displacement (usually an unsigned integer representation) from that address. The register reference may be explicit or implicit. 16 [Type here] • Indexing For indexing, the interpretation is typically the following: The address field references main memory address, and the referenced register contains a positive displacement from that address. This usage is just the opposite of the interpretation for base-register an important use of indexing is to provide an efficient mechanism for performing iterative operations. • Stack Addressing The final addressing mode that we consider is stack addressing. It is sometimes referred to as apushdown list or last-in-first-out queue. The stack is a reserved block of locations. Items are appended to the top of the stack so that, at any given time, the block is partially filled. Associated with the stack is a pointer whose value is the address of the top of the stack. Alternatively, the top two elements of the stack may be in processor registers, in which case the stack pointer references the third element of the stack. The stack pointer is maintained in a register. Thus, references to stack locations in memory are in fact register indirect addresses. The stack mode of addressing is a form of implied addressing. The machine instructions need not include a memory reference but implicitly operate on the top of the stack 1.7.3 Instruction Types The type of instruction is recognized by the computer control from the four bits in position 12 through 15 of the instruction. If the three opcode bits in positions 12 through 14 are not equal to 111, the instruction is a memory reference type and the bit in the position 15 is taken as the addressing mode. If the bit is 1, the instruction is an input-output instruction. Only three bits of the instruction are used for the operation code. It may seem that the computer is restricted to a maximum of eight distinct operations. Since register reference and input output instructions use the remaining 12 bits as part of the total number of instruction chosen for the basic computer is equal to 25. Data Movement Instructions: Assembly Language Example: Instruction: LOAD [REG] [MEM] LOAD R2 13 STORE [REG] [MEM] STORE 8 R3 Meaning: R2 = M[13] M[8] = R3 Machine Language Instruction: 1 000 0001 0 RR MMMMM 1 000 0010 0 RR MMMMM 17 [Type here] MOVE [REG2] [REG1] MOVE R2 R0 Arithmetic and Logic Instructions: Assembly Language Example: Instruction: ADD [REG1] [REG2] ADD R3 R2 [REG3] R1 SUB [REG1] [REG2] [REG3] AND [REG1] [REG2] [REG3] OR [REG1] [REG2] [REG3] SUB R3 R1 R0 AND R0 R3 R1 OR R2 R2 R3 Branching Instructions: Assembly Language Example: Instruction: BRANCH [MEM] BRANCH 10 BZERO [MEM] BZERO 2 BNEG [MEM] BNEG 7 Other Instructions: Assembly Language Example: Instruction: NOP NOP HALT HALT R2 = R0 1 001 0001 0000 RR RR Meaning: Machine Language Instruction: 1 010 0001 00 RR RR RR R3 = R2 + R1 R3 = R1 - R0 R0 = R3 & R1 R2 = R2 | R3 1 010 0010 00 RR RR RR 1 010 0011 00 RR RR RR 1 010 0100 00 RR RR RR Meaning: Machine Language Instruction: PC = 10 0 000 0001 000 PC = 2 IF ALU MMMMM RESULT 0 000 0010 000 IS ZERO MMMMM PC = 7 IF ALU 0 000 0011 000 RESULT MMMMM IS NEGATIVE Meaning: Do nothing. Halt the machine Machine Language Instruction: 0000 0000 0000 0000 1111 1111 1111 1111 Table 1.1 Data Movement Instructions 18 [Type here] Student Activity 1. How will you express machine level instructions? 2. How does the computer control recognize the type of instruction? 3. Describe various types of machine level instructions. 4. Describe the addressing mode of computer instructions. 1.7.4 Instruction Set Selection Instructions on a RISC architecture are structured in a systematic way. They can be categorized into ALU operations, memory operations, and control operations. AL operations always work on registers, and every register from the register set can be addressed by every ALU operation. Memory operations move values between the register set and memory. This structure makes instruction selection relatively easy, and the Java data types map 1:1 to the instruction architecture. The optimal selection of instructions is more complex on x86 than it is on Alpha for the following reasons: • Different addressing modes: Because a lot of operations exist in different addressing modes, unlike a RISC processor, the correct kind of instruction needs to be chosen in order to avoid any additional instructions for moving values. For example if the values for an addition operation are in a memory and in a register the instruction selection algorithm always picks an add instruction that adds a memory and a register location. • Limited set of registers per instruction: When picking the next instruction, the code generator always checks in which registers the current values are in and chooses the instruction appropriately. If the current register allocation doesn't fit to the instruction at all, values need to be moved. This scheme could be improved with more global analysis, but at the expense of a larger compile-time cost. • Efficient 64-bit operations: The Java byte code contains 64-bit integer and floating-point operations that the x86 platform needs to support. For each of these byte code operations the number of temporary registers and the amount of memory accesses need to be minimized. For example, the following code is one possible implementation of the add (64-bit integer addition) byte code instruction. • mov 0x0(%esp,1),%eax • add 0x8(%esp,1),%eax • mov 0x4(%esp,1),%ecx • adc 0x10(%esp,1),%ecx 1.7.5 Timing and control The control unit is identified as having two components labelled (1) instruction decoder and machine cycle encoding and (2) timing and control. The essence of the control unit is 19 [Type here] the timing and control module. This module includes a clock and accepts as inputs the current instruction and some external control signals. Its output consists of control signals to the other components of the processor plus control signals to the external system bus. The timing of processor operations is synchronized by the clock and controlled by the control unit with control signals. Each instruction cycle is divided into from one to five machine cycles; each machine cycle is in turn divided into from three to five states. Each state lasts one clock cycle. During a state, the processor performs one or a set of simultaneous micro-operations as determined by the control signals. 1.8 Instruction Cycle The basic function performed by a computer is execution of a program, which consists of a set of instructions stored in memory. Instruction processing consists of two steps: The processor reads (fetches) instructions from memory one at a time and executes each instruction. Program execution consists of repeating the process of instruction fetch and instruction execution. The processing required for a single instruction is called an instruction cycle. Figure 1.8 Instruction cycle 1.8.1 Execution Cycle CPU executes the instructions one by one. At the beginning of each instruction cycle, the processor fetches an instruction from memory. The program counter (PC) holds the address of the instruction to be fetched next, the processor always increments the PC after each instruction fetch so that it will fetch the next instruction in sequence. For example, consider a computer in which each instruction occupies one 16-bit word of memory. If the program counter is set to location 300. The processor will next fetch the instruction at location 300. On next instruction cycles, it will fetch instructions from locations 301,302,303, and so on. The fetched instruction is loaded into a register in the processor known as the instruction register (IR). The processor interprets the instruction and performs the required action. In general, these actions fall into four categories: • Processor-memory: Data may be transferred from processor to memory or from memory to processor. 20 [Type here] • Processor-I/O: Data may be transferred to or from a peripheral device by transferring between the processor and an I/O module. • Data processing: The processor may perform some arithmetic or logic operation on data. • Control: An instruction may specify that the sequence of execution be altered. For example, the processor may fetch an instruction from location 149, which specifies that the next instruction be from location 182. The processor will remember this fact by setting the program counter to182.Thus, on the next fetch cycle, the instruction will be fetched from location 182 rather than 150. An instruction’s execution may involve a combination of these actions 1.8.2 Interrupts Besides executing the instructions above, CPU also executes another type of instruction known as interrupts. An interrupt is an external signal sent to the CPU, which requires an immediate response. Basically, the CPU will halt all current executions and save all the data required. Then, the CPU will serve the interrupts. There are three types of interrupts; external interrupts, internal interrupts, and software interrupts. (a) External Interrupts (EI): Most of the EI come from the I/O devices. As the I/O operation is slower than the CPU processing, I/O devices will read or write separately. Once the operation is completed, the I/O devices will send interrupts to the CPU to obtain next data. (b) Internal Interrupts (II): Internal interrupts occur due to invalid data or instructions. For an example, an attempt to divide by zero, an invalid operational code, stack overflow, and violation of protection. (c) Software Interrupts: Both types of interrupts mentioned earlier on are hardware interrupts. The third type of interrupts are produced by software that are used by operating systems. Student Activity 1. Define an instruction cycle. Describe its various parts. 2. While designing the instruction set of a computer, what are the important things to be kept in mind? When is a set of instructions said to be complete? 3. Describe the execution cycle of an instruction. 21 [Type here] 1.8.3 Multi Cycle Implementation The basic idea of the multi cycle implementation is to divide the one long cycle of the single cycle implementation into 3 to 5 shorter cycles. The number of cycles depends on the instruction. • Instruction fetch, program counter increment • Partial instruction decode and branch and jump target computation • Source operand fetch, ALU operation, and program counter update for branches and jumps • Memory access, if needed • Register write, if needed Part of the advantage of the multi cycle implementation is better performance due to reducing the overall instruction time for instructions that do not need a memory access or a register write. Multi cycle processor implementations use Moore or Mealy finite state machines to generate control signals. The multi cycle implementation differs from the single-cycle implementation in the following ways. i. Added internal registers: Registers are added to hold data that is generated in an early cycle but used in a later cycle. The following registers are added. • Instruction register • Memory data register • ALU input registers A and B • ALU Out register The instruction register requires a new control signal IRWrite to determine when it is updated. The other added registers are updated automatically at each clock transition. ii. ALU usage:The ALU can be used for different purposes in different cycles. In addition to its single-cycle use, the ALU can do program counter increments and branch target computations. In order to deal with all possible source operands for these operations, a new control signal ALUSrcAis added and the single-cycle control signal ALUSrc is renamed as ALUSrcB. 22 [Type here] iii. PC update:The program counter is updated twice. The first update is just a simple increment. The second update is a branch or jump update. The single-cycle Branch and Jump control signals are replaced by new PCWriteCond and PCWrite control signals. The values for the two PC updates come from different sources so a new control signal PCSourceis added to select between them. iv. Memory organization:A single-ported memory is used since instructions and data are accessed in different cycles. This requires adding a new control signal IorD that determines the source of the memory address. v. Control signal generation: Different control signals are needed in different cycles. To do this, control circuitry is implemented as a finite state machine. Finite state machines can be classified as either Moore or Mealy machines. 1.8.4 Moore and Mealy Machines The following figure 1.9 shows how multi cycle control circuitry is implemented as a finite state machine. The "next state logic" and "control logic" blocks are combinational logic. Figure 1.9 Finite state machine Generally, finite state control can be implemented as either a Moore machine or a Mealy machine. In a Moore machine, the control signals depend only on the control state. A Moore machine does not use the dashed connection in the figure. In a Mealy machine, the control signals depend on both the control state and the opcode. A Mealy machine does use the dashed connection in the figure. The state diagrams for the MIPS multi cycle implementation do not include any direct dependence of control signals on the opcode. Thus they are intended for use with a 23 [Type here] Moore machine. With a Mealy machine, it is possible to bring up some control signals one cycle earlier. This fact could be used to improve the performance of the processor. Summary • Our computer system consists of software and hardware. Software, or program enables a computer to perform specific tasks, as opposed to the physical components of the system (hardware). • Computer hardware is the physical part of a computer, including the digital circuitry, as distinguished from the computer software that executes within the hardware. • Computer architecture is defined as the science and art of selecting and interconnecting hardware components to create computers that meet functional, performance and cost goals. • A computer architecture is considered as a series of abstraction layers: hardware, firmware, assembler, kernel, operating system and applications • A program has a sequence of instructions which gets executed through a cycle, called instruction cycle. The basic parts of and instruction cycle include fetch, decode, read the effective address from memory and execute. • Unit-2 Control Unit and Microprogramming Learning Objectives After successful completion of this unit, you should be able to: • Describe control unit • Describe data path and control path design • Describe microprogramming • Compare microprogramming and hardwired control • Compare RISC and CISC architecture • Describe pipelining in CPU Design • Describe superscalar processors 2.1 Introduction Process of writing microcode for a microprocessor. Microcode is low-level code that defines how a microprocessor should function when it executes machine-language instructions. Typically, one machine-language instruction translates into several 24 [Type here] microcode instructions. 2.2 Control Unit As the name suggests, a control unit is used to control something. In this case, the control unit provides instructions to the other CPU devices (previously listed) in a way that causes them to operate coherently to achieve some goal as shown in Fig. (2.1). Basically, there is one control unit, because two control units may cause conflict. The control unit of a simple CPU performs the FETCH / DECODE / EXECUTE / WRITEBACK von Neumann sequence. Figure 2.1: A general control unit. To describe how the CPU works we may describe what signals the control unit issues and when. Clearly these instructions are more complicated than those that the control unit receives as input. Thus the control unit must store the instructions within itself, perhaps using a memory or perhaps in the form of a complicated network. In either case, let us describe what the control unit does in terms of a program (for ease of understanding) called the micro-program, consisting naturally of micro-instructions. Let the micro-program be stored in a micro-memory. The control unit may not be micro-programmed, however we can still use microinstructions to indicate what the control unit is doing. In this case we take a logical view of the control unit. The possible instructions are dictated by the architecture of the CPU. Different architectures allow for different instructions and this is a major concept to consider when examining CPU design and operation. We are not interested in design in this subject, but we concentrate on operation. 25 [Type here] 2.2.1 Basic control unit operation You should recall that the basic operation of the CPU is described by the FETCH / DECODE / EXECUTE / WRITEBACK sequence. The control unit is used to implement this sequence using a micro-program. Of the following registers, the first two are a normally only available to the control unit. • Instruction Register, : Stores the number that represents the machine instruction the Control Unit is to execute. (note that this is not the micro- instruction) • Program Counter, : Stores the number that represents the address of the next instruction to execute (found in memory). • General Purpose Registers: Examples are , , , , , to store intermediate results of execution. Consider the example of a as shown in Fig. (2.3). The control unit is not shown. Figure 2.2 PDP8 micro-architecture. 26 [Type here] Modern computers are more complex, but the operation is essentially the same. First consider the micro-program executed by the Control Unit to provide the FETCH: 1. 2. 3. Note the first line may be written , but in this case the path is inferred from the diagram. The second line instructs the memory sub-system to retrieve the contents of the memory at address given by , the contents is put into . The third line does two things at the same time, moves the into the for DECODING and EXECUTING plus it instructs the to increase by 1, so as to point to the next instruction for execution. This increment instruction is available for some registers like the . The ALU does not have to be used in this case. Consider some more small examples of micro-programs which use the PDP8 micro-architecture. Example zero into the register: 1. Example the contents of the . to the and put the result in the 1. 2. Example the two's complement of . 27 [Type here] 1. 2. Example the to obtain the next instruction. 1. 2. Where is previously defined. 2.3 Functions of Control Unit Student activity 1. Discuss the functions of the control unit 2.3.1 Data path and control path design A stored program computer consists of a processing unit and an attached memory system. Commands that instruct the processor to perform certain operations are placed in the memory along with the data items to be operated on. The processing unit consists of data-path and control. The data-path contains registers to hold data and functional units, such as arithmetic logic units and shifters, to operate on data. The control unit is little more than a finite state machine that sequences through its states to (1) Fetch the next instruction from memory, (2)Decode the instruction to interpret its meaning, and (3) Execute the instruction by moving and/or operating on data in the registers and functional units of the data-path. The critical design issues for a data-path are how to "wire" the various components together to minimize hardware complexity and the number of control states to complete a typical operation. For control, the issue is how to organize the relatively complex "instruction interpretation" finite state machine. 28 [Type here] 2.3.2 Microprogramming Process of writing microcode for a microprocessor. Microcode is low-level code that defines how a microprocessor should function when it executes machine-language instructions. Typically, one machine-language instruction translates into several microcode instructions. 2.3.3 RISC Vs. CISC A RISC processor CPU design that favors a smaller and simpler set of instructions that all take same amount of execution time. A RISC architecture has a very few instructions, where processor asses data from memory probably not other than load and store operations since memory access across kills speed of the processor. Also, the complexity of the controller design has been overcome by having operand and opcode bits are fixed in instruction register. At the end of pipelining is added to improve the speed with basic three stages as fetch, decode and execute. RISC generally refers to a streamlined version of its predecessor, the Complex Instruction Set Computer (CISC). At the dawn of processors, there was no formal identification known as CISC, but the term has since been coined to identify them as different from the RISC architecture. Some examples of CISC microprocessor instruction set architectures (ISAs) include the Motorola 68000 (68K), the DEC VAX, PDP-11, several generations of the Intel x86, and 8051. Examples of processors with the RISC architecture include MIPS, PowerPC, Atmel’s AVR, the Microchip PIC processors, Arm processors, RISC-V, and all modern microprocessors have at least some elements of RISC. The progression from 8- and 16-bit to 32-bit architectures essentially forced the need for RISC architectures. Nevertheless, it took a decade before RISC architectures began to take hold, mainly due to lack of software that would run on RISC architectures. Intel also made an impact, since it had the means to continue using the CISC architecture and found no need to redesign from the ground up. The MIPS architecture was one of the first RISC ISAs and has been used widely to teach the RISC architecture. The architecture of RISC computer is shown below: 29 [Type here] 2.3.4 Some history The first integrated chip was designed in 1958 by Jack Kilby. Microprocessors were introduced in the 1970s, the first commercial one coming from Intel Corporation. By the early 1980s, the RISC architecture had been introduced. The RISC design came about as a total redesign because the CISC architecture was becoming more complex. Most credit John Cocke of IBM as having come up with the RISC concept. History tells us that to get a faster computer, some major changes in the microprocessor architecture took place that became RISC, including a uniform format for instructions and easily pipelined instructions. (Pipelining means the processor starts to execute the next instruction before the present instruction is completed.) In the 1970s, memory was costly, so smaller programs were a focus. 2.3.5 What are the differences between RISC and CISC? The short answer is that RISC is perceived by many as an improvement over CISC. There is no best architecture since different architectures can simply be better in some scenarios but less ideal in others. RISC-based machines execute one instruction per clock cycle. CISC machines can have special instructions as well as instructions that take more than one cycle to execute. This means that the same instruction executed on a CISC architecture might take several instructions to execute on a RISC machine. The RISC architecture will need more working (RAM) memory than CISC to hold values as it loads each instruction, acts upon it, then loads the next one. The CISC architecture can execute one, albeit more complex instruction, that does the same operations, all at once, directly upon memory. Thus, RISC architecture requires more RAM but always executes one instruction per clock cycle for predictable processing, which is good for pipelining. One of the major differences between RISC and CISC is that RISC emphasizes efficiency in cycles per instruction and CISC emphasizes efficiency in instructions per program. A fast processor is dependent upon how much time it takes to execute each clock cycle, how many cycles it takes to execute instructions, and the number of instructions there are in each program. RISC has an emphasis on larger program code sizes (due to a smaller instruction set, so multiple steps done in succession may equate to one step in CISC). The RISC ISA emphasizes software over hardware. The RISC instruction set requires one to write more efficient software (e.g., compilers or code) with fewer instructions. CISC ISAs use more transistors in the hardware to implement more instructions and more complex instructions as well. RISC needs more RAM, whereas CISC has an emphasis on smaller code size and uses less RAM overall than RISC. Many microprocessors today hold a mix of RISC- and CISC-like attributes, however, such as a CISC-like ISA that treats instructions as if they are a string 30 [Type here] of RISC-type instructions. Table 2.1 Differences between CISC and RISC • • • Microprogramming is as easy as assembly language to implement, and much less expensive than hardwiring a control unit. The ease of micro coding new instructions allowed designers to make CISC machines upwardly compatible: a new computer could run the same programs as earlier computers because the new computer would contain a superset of the instructions of the earlier computers. As each instruction became more capable, fewer instructions could be used to 31 [Type here] • implement a given task. This made more efficient use of the relatively slow main memory. Because micro program instruction sets can be written to match the constructs of high-level languages, the compiler does not have to be as complicated. 2.3.6 The disadvantages of CISC Still, designers soon realized that the CISC philosophy had its own problems, including: • Earlier generations of a processor family generally were contained as a subset in every new version --- so instruction set & chip hardware become more complex with each generation of computers. • So that as many instructions as possible could be stored in memory with the least possible wasted space, individual instructions could be of almost any length---this means that different instructions will take different amounts of clock time to execute, slowing down the overall performance of the machine. • Many specialized instructions aren't used frequently enough to justify their existence --- approximately 20% of the available instructions are used in a typical program. • CISC instructions typically set the condition codes as a side effect of the instruction. Not only does setting the condition codes take time, but programmers have to remember to examine the condition code bits before a subsequent instruction changes them. 2.4 Pipelining in CPU Design 2.4.1 A Typical Pipeline Consider the steps necessary to do a generic operation: • Fetch opcode. • Decode opcode and (in parallel) pre-fetch a possible displacement or constant operand (or both) • Compute complex addressing mode (e.g., [ebx+xxxx]), if applicable. • Fetch the source value from memory (if a memory operand) and the destination register value (if applicable). 32 [Type here] • Compute the result. • Store result into destination register. Assuming you're willing to pay for some extra silicon, you can build a little "miniprocessor" to handle each of the above steps. The organization would look something like Figure 2.3. Figure 2.3 A Pipelined Implementation of Instruction Execution Note how we've combined some stages from the previous section. For example, in stage four of Figure 2.3 the CPU fetches the source and destination operands in the same step. You can do this by putting multiple data paths inside the CPU (e.g., from the registers to the ALU) and ensuring that no two operands ever compete for simultaneous use of the data bus (i.e., no memory-to-memory operations). If you design a separate piece of hardware for each stage in the pipeline above, almost all these steps can take place in parallel. Of course, you cannot fetch and decode the opcode for more than one instruction at the same time, but you can fetch one opcode while decoding the previous instruction. If you have an n-stage pipeline, you will usually have n instructions executing concurrently. Figure 2.4 Instruction Execution in a Pipeline 33 [Type here] Figure 2.4 shows pipelining in operatoin. T1, T2, T3, etc., represent consecutive "ticks" of the system clock. At T=T1 the CPU fetches the opcode byte for the first instruction. At T=T2, the CPU begins decoding the opcode for the first instruction. In parallel, it fetches a block of bytes from the prefetch queue in the event the instruction has an operand. Since the first instruction no longer needs the opcode fetching circuitry, the CPU instructs it to fetch the opcode of the second instruction in parallel with the decoding of the first instruction. Note there is a minor conflict here. The CPU is attempting to fetch the next byte from the prefetch queue for use as an operand, at the same time it is fetching operand data from the prefetch queue for use as an opcode. How can it do both at once? You'll see the solution in a few moments. At T=T3 the CPU computes an operand address for the first instruction, if any. The CPU does nothing on the first instruction if it does not use an addressing mode requiring such computation. During T3, the CPU also decodes the opcode of the second instruction and fetches any necessary operand. Finally the CPU also fetches the opcode for the third instruction. With each advancing tick of the clock, another step in the execution of each instruction in the pipeline completes, and the CPU fetches yet another instruction from memory. This process continues until at T=T6 the CPU completes the execution of the first instruction, computes the result for the second, etc., and, finally, fetches the opcode for the sixth instruction in the pipeline. The important thing to see is that after T=T5 the CPU completes an instruction on every clock cycle. Once the CPU fills the pipeline, it completes one instruction on each cycle. Note that this is true even if there are complex addressing modes to be computed, memory operands to fetch, or other operations which use cycles on a non-pipelined processor. All you need to do is add more stages to the pipeline, and you can still effectively process each instruction in one clock cycle. A bit earlier you saw a small conflict in the pipeline organization. At T=T2, for example, the CPU is attempting to prefetch a block of bytes for an operand and at the same time it is trying to fetch the next opcode byte. Until the CPU decodes the first instruction it doesn't know how many operands the instruction requires nor does it know their length. However, the CPU needs to know this information to determine the length of the instruction so it knows what byte to fetch as the opcode of the next instruction. So how can the pipeline fetch an instruction opcode in parallel with an address operand? 34 [Type here] One solution is to disallow this. If an instruction as an address or constant operand, we simply delay the start of the next instruction (this is known as a hazard as you shall soon see). Unfortunately, many instructions have these additional operands, so this approach will have a substantial negative impact on the execution speed of the CPU. The second solution is to throw (a lot) more hardware at the problem. Operand and constant sizes usually come in one, two, and four-byte lengths. Therefore, if we actually fetch three bytes from memory, at offsets one, three, and five, beyond the current opcode we are decoding, we know that one of these bytes will probably contain the opcode of the next instruction. Once we are through decoding the current instruction we know how long it will be and, therefore, we know the offset of the next opcode. We can use a simple data selector circuit to choose which of the three opcode bytes we want to use. In actual practice, we have to select the next opcode byte from more than three candidates because 80x86 instructions take many different lengths. For example, an instruction that moves a 32-bit constant to a memory location can be ten or more bytes long. And there are instruction lengths for nearly every value between one and fifteen bytes. Also, some opcodes on the 80x86 are longer than one byte, so the CPU may have to fetch multiple bytes in order to properly decode the current instruction. Nevertheless, by throwing more hardware at the problem we can decode the current opcode at the same time we're fetching the next. 2.4.2 Stalls in a Pipeline Unfortunately, the scenario presented in the previous section is a little too simplistic. There are two drawbacks to that simple pipeline: bus contention among instructions and non-sequential program execution. Both problems may increase the average execution time of the instructions in the pipeline. Bus contention occurs whenever an instruction needs to access some item in memory. For example, if a "mov( reg, mem);" instruction needs to store data in memory and a "mov( mem, reg);" instruction is reading data from memory, contention for the address and data bus may develop since the CPU will be trying to simultaneously fetch data and write data in memory. 35 [Type here] One simplistic way to handle bus contention is through a pipeline stall. The CPU, when faced with contention for the bus, gives priority to the instruction furthest along in the pipeline. The CPU suspends fet ching opcodes until the current instruction fetches (or stores) its operand. This causes the new instruction in the pipeline to take two cycles to execute rather than one. This example is but one case of bus contention. There are many others. For example, as noted earlier, fetching instruction operands requires access to the prefetch queue at the same time the CPU needs to fetch an opcode. Given the simple scheme above, it's unlikely that most instructions would execute at one clock per instruction (CPI). Fortunately, the intelligent use of a cache system can eliminate many pipeline stalls like the ones discussed above. The next section on caching will describe how this is done. However, it is not always possible, even with a cache, to avoid stalling the pipeline. What you cannot fix in hardware, you can take care of with software. If you avoid using memory, you can reduce bus contention and your programs will execute faster. Likewise, using shorter instructions also reduces bus contention and the possibility of a pipeline stall. What happens when an instruction modifies the EIP register? This, of course, implies that the next set of instructions to execute do not immediately follow the instruction that modifies EIP. By the time the instruction JNZ Label; completes execution (assuming the zero flag is clear so the branch is taken), we've already started five other instructions and we're only one clock cycle away from the completion of the first of these. Obviously, the CPU must not execute those instructions or it will compute improper results. 36 [Type here] The only reasonable solution is to flush the entire pipeline and begin fetching opcodes anew. However, doing so causes a severe execution time penalty. It will take six clock cycles (the length of the pipeline in our examples) before the next instruction completes execution. Clearly, you should avoid the use of instructions which interrupt the sequential execution of a program. This also shows another problem - pipeline length. The longer the pipeline is, the more you can accomplish per cycle in the system. However, lengthening a pipeline may slow a program if it jumps around quite a bit. Unfortunately, you cannot control the number of stages in the pipeline. You can, however, control the number of transfer instructions which appear in your programs. Obviously you should keep these to a minimum in a pipelined system. Student Activity 1. Describe various stalls of pipelining. 2.5 Superscalar processors Superscalar is a term coined in the late 1980s. Superscalar processors arrived as the RISC movement gained widespread acceptance, and RISC processors are particularly suited to superscalar techniques. However, the approach can be used on non-RISC processors (e.g. Intel's P6-based processors, the Pentium 4, and AMD's IA32 clones.), with considerable effort. All current desktop and server market processors are now superscalar. The idea, basically, is: as a logical development of pipelined design, where a new instruction starts on successive machine cycles, start up a number of machine instructions on the same machine cycle. By taking advantage of available memory bandwidth (if it is available), fetch a number of instructions simultaneously, and start executing them. [In practice, instructions need to be in a dedicated high-speed cache to be available at a high enough rate for this to work. The development of superscalar from 'vanilla' pipelining came about via more sophisticated, though still nonsuperscalar, pipelining technologies - most of which were seen on supercomputers from the mid 60s onwards. However, true superscalar processors are a concept that is unique to microprocessor-based systems. The first developmental step is to observe that as resources grew in availability, high-performance computer systems (we are really talking about the most powerful machines of their day - Control Data 6600 and 7600, Cray-1, top-ofthe-range IBM mainframes) started to acquire dedicated hardware to execute 37 [Type here] different types of instruction. So for example there may be separate execution units (EX) for floating point and integer operations. Figure 2.5 Multiple Execution Units Once instructions had been decoded, they would be sent to the appropriate execution unit. In general, floating point operations are more complex than integer ones (though integer multiply/divide can also be time consuming), and an FP unit would be broken down into further pipeline stages. Suppose we have an FP operation followed by an integer one. Our basic pipeline would simply halt execution until the FP operation had exited the EX phase, effectively stalling the pipeline because the FP EX stage takes several cycles. However, there is no real need to [always] do that. We could allow the following integer operation to enter the Integer EX unit. Since integer operations typically take quite a bit less time than FP ones, this means that the integer result may well be available before the FP one that preceded it in program order. This is known as out-of-order completion, and brings potential performance benefits as well as big problems, as we will see. A further step would be to observe that now we have admitted the possibility of at least partially executing instructions out of program order, we have a potential mechanism for reducing the impact of data dependencies (i.e. pipeline stalling). Instead of just leaving a pipeline idle while we are waiting for a dependency to resolve, we could pick other, later instructions and execute them instead. We have moved from a situation, with the simple pipeline, where instructions are statically scheduled or ordered, by the compiler, to one where they may be dynamically scheduled by the hardware. (Actually, the situation is a bit more complex than this and we will return to it below.) Superscalar Concept 38 [Type here] As resources continued to grow, yet more execution units could be made available. What is more, these would often be duplicates: there might be two integer units, and two FP units, and perhaps others (for example, to handle memory accesses). To justify the existence of such a large number of execution units, it may no longer sufficient to simply attempt to fetch and decode a single instruction at a time. It is necessary to also attempt to fetch, decode and write back multiple instructions as well. Figure 2.6 Basic Superscalar Structure Note however that it is not the case that we would typically be able to fetch, decode etc. as many instructions as there are execution units - for example, in figure 2.6 most of the pipeline can handle three instructions, but there are five execution units. We can ask ourselves: how many instructions can we profitably attempt to execute in parallel? Like less sophisticated pipelined machines, there seem to be limits on the number of instructions that can effectively be executed in parallel, before speed-up advantages become small - typically, between 2 and 8. All current superscalar machines lie within this band (for example, P6-derived processors and the Pentium 4 have three parallel pipelines). However, techniques are being looked at - and some workers are optimistic - that may increase this dramatically. It has to 39 [Type here] be said though that other workers are very pessimistic. A processor that attempts to execute n instructions simultaneously is said to be of degree n, or n-way. Of course, a superscalar processor will be pipelined as well: for example, a Pentium 3 has 14 pipeline stages. as well as being degree 3. Notice that a key word is 'attempts': there is no guarantee that a superscalar processor will succeed in executing as many instructions as is, in principle, possible. Before proceeding, we will define some useful terminology and concepts. The key problems we have to solve when building superscalar machines concern the various data dependencies, resource conflicts, and branches (especially conditional ones). However, not all phases of instruction execution are equally affected. For example, we can happily fetch and decode instructions regardless of any dependencies. Even though we may be fetching/decoding the wrong instructions, doing so will not affect the state of a program. However, other phases are more critical. • Scheduing - this refers to the process of deciding in what order to execute instructions. The choices are static, when the hardware has no control, and dynamic, when the hardware is permitted to re-order instructions to at least some degree. • Issue - this is essentially when we fetch operands for an instruction. Before we do this, we must be sure that they are either actually available (that is, they have already been computed and stored - either in their final destination or at least somewhere we can access them) or we at least know where they will be available in the future. In practice, resource constraints can also stop instruction issue. In our simple five-stage pipeline, the issue phase occurs when instructions leave the decode stage and enter the execute stage. Instruction issue is generally in program order. • Execution - once issued, instructions can be executed once all their operands are actually available. Execution may in program order (in-order execution) or out of program order (out-of-order execution), depending on the machine. • Speculation and Committal - because we are predicting the outcome of branches (and maybe other things), we do not necessarily know for sure that when we execute an instruction we will actually end up using the result. This process is known as speculation. Once we for sure an instruction is going to be executed then it is committed, or enters the committal phase. The next stage is to store the result. • Write Back - ultimately we must store instruction results in their final 40 [Type here] destinations. (Actually, it is possible to not do this in all cases - for example, if a result actually represents a temporary, intermediate value that will be soon overwritten. However, as we will see, this raises awkward questions when dealing with exceptions, so in general all results are stored.) This phase is known as write back and before proceeding we must be sure that (a) the instruction will actually be committed, and (b) the destination is free to be overwritten - that is, no other instruction is waiting to use its current value as a source operand. Note in some machines, (a) does not necessarily hold - they are prepared to write uncommitted results and then 'back out' of them later on. However, we will not deal with such machines in this module. It is relatively easy to establish (b) when the destination is a register, but difficult when it is a memory word because of the possibility of pointers creating aliases. • Retirement or Completion - finally, an instruction finishes and leaves the pipeline. Typically this happens immediately after write back and we say the instruction is completed or retired. 2.5.1 Classification We can divide superscalar processors into a number of classes of varying complexity. • Static Superscalar - these processors issue and execute instructions in program order. So for example, in a degree 2 machine, it is possible to issue and two instructions simultaneously: given instructions i1 and i2, we may choose to issue both, or only i1 (depending on the presence of hazards). We may not just issue i2. To complicate and confuse matters, because the hardware has a choice (albeit limited) about issuing instructions, we say that instruction issue is dynamic. However, the actual execution of instructions is in-order we say that scheduling is static. • Dynamic Superscalar - these machines permit out-of-order program execution, but they generally still issue instructions in program order. Because we can potentially re-order execution, we now say scheduling is dynamic. • Dynamic with Speculation - these machines add the ability to speculate beyond branches. 2.5.2 Superscalar Operation- Executing Instructions in Parallel With the pipelined architecture we could achieve, at best, execution times of one CPI 41 [Type here] (clock per instruction). Is it possible to execute instructions faster than this? At first glance you might think, "Of course not, we can do at most one operation per clock cycle. So there is no way we can execute more than one instruction per clock cycle." Keep in mind however, that a single instruction is not a single operation. In the examples presented earlier each instruction has taken between six and eight operations to complete. By adding seven or eight separate units to the CPU, we could effectively execute these eight operations in one clock cycle, yielding one CPI. If we add more hardware and execute, say, 16 operations at once, can we achieve 0.5 CPI? The answer is a qualified "yes." A CPU including this additional hardware is a superscalar CPU and can execute more than one instruction during a single clock cycle. The 80x86 family began supporting superscalar execution with the introduction of the Pentium processor. A superscalar CPU has, essentially, several execution units (see Figure 2.7). If it encounters two or more instructions in the instruction stream (i.e., the prefetch queue) which can execute independently, it will do so. Figure 2.7 A CPU that Supports Superscalar Operation There are a couple of advantages to going superscalar. Suppose you have the following instructions in the instruction stream: 42 [Type here] mov( 1000, eax ); mov( 2000, ebx ); If there are no other problems or hazards in the surrounding code, and all six bytes for these two instructions are currently in the prefetch queue, there is no reason why the CPU cannot fetch and execute both instructions in parallel. All it takes is extra silicon on the CPU chip to implement two execution units. Besides speeding up independent instructions, a superscalar CPU can also speed up program sequences that have hazards. One limitation of superscalar CPU is that once a hazard occurs, the offending instruction will completely stall the pipeline. Every instruction which follows will also have to wait for the CPU to synchronize the execution of the instructions. With a superscalar CPU, however, instructions following the hazard may continue execution through the pipeline as long as they don't have hazards of their own. This alleviates (though does not eliminate) some of the need for careful instruction scheduling. As an assembly language programmer, the way you write software for a superscalar CPU can dramatically affect its performance. First and foremost is that rule you're probably sick of by now: use short instructions. The shorter your instructions are, the more instructions the CPU can fetch in a single operation and, therefore, the more likely the CPU will execute faster than one CPI. Most superscalar CPUs do not completely duplicate the execution unit. There might be multiple ALUs, floating point units, etc. This means that certain instruction sequences can execute very quickly while others won't. You have to study the exact composition of your CPU to decide which instruction sequences produce the best performance. 2.5.3 Out of Order Execution In a standard superscalar CPU it is the programmer's (or compiler's) responsibility to schedule (arrange) the instructions to avoid hazards and pipeline stalls. Fancier CPUs can actually remove some of this burden and improve performance by automatically rescheduling instructions while the program executes. To understand how this is possible, consider the following instruction sequence: mov( SomeVar, ebx ); mov( [ebx], eax ); mov( 43 [Type here] 2000, ecx ); A data hazard exists between the first and second instructions above. The second instruction must delay until the first instruction completes execution. This introduces a pipeline stall and increases the running time of the program. Typically, the stall affects every instruction that follows. However, note that the third instruction's execution does not depend on the result from either of the first two instructions. Therefore, there is no reason to stall the execution of the "mov( 2000, ecx );" instruction. It may continue executing while the second instruction waits for the first to complete. This technique, appearing in later members of the Pentium line, is called "out of order execution" because the CPU completes the execution of some instruction prior to the execution of previous instructions appearing in the code stream. Clearly, the CPU may only execute instruction out of sequence if doing so produces exactly the same results as in-order execution. While there a lots of little technical issues that make this problem a little more difficult than it seems, with enough engineering effort it is quite possible to implement this feature. Although you might think that this extra effort is not worth it (why not make it the programmer's or compiler's responsibility to schedule the instructions) there are some situations where out of order execution will improve performance that static scheduling could not handle. Register Renaming One problem that hampers the effectiveness of superscalar operation on the 80x86 CPU is the 80x86's limited number of general purpose registers. Suppose, for example, that the CPU had four different pipelines and, therefore, was capable of executing four instructions simultaneously. Actually achieving four instructions per clock cycle would be very difficult because most instructions (that can execute simultaneously with other instructions) operate on two register operands. For four instructions to execute concurrently, you'd need four separate destination registers and four source registers (and the two sets of registers must be disjoint, that is, a destination register for one instruction cannot be the source of another). CPUs that have lots of registers can handle this task quite easily, but the limited register set of the 80x86 makes this difficult. Fortunately, there is a way to alleviate part of the problem: through register renaming. Register renaming is a sneaky way to give a CPU more registers than it actually has. Programmers will not have direct access to these extra registers, but the CPU can use these additional register to prevent hazards in certain cases. For example, 44 [Type here] consider the following short instruction sequence: mov( 0, eax ); mov( eax, i ); mov( 50, eax ); mov( eax, j ); Clearly a data hazard exists between the first and second instructions and, likewise, a data hazard exists between the third and fourth instructions in this sequence. Out of order execution in a superscalar CPU would normally allow the first and third instructions to execute concurrently and then the second and fourth instructions could also execute concurrently. However, a data hazard, of sorts, also exists between the first and third instructions since they use the same register. The programmer could have easily solved this problem by using a different register (say EBX) for the third and fourth instructions. However, let's assume that the programmer was unable to do this because the other registers are all holding important values. Is this sequence doomed to executing in four cycles on a superscalar CPU that should only require two? One advanced trick a CPU can employ is to create a bank of registers for each of the general purpose registers on the CPU. That is, rather than having a single EAX register, the CPU could support an array of EAX registers; let's call these registers EAX[0], EAX[1], EAX[2], etc. Similarly, you could have an array of each of the registers, so we could also have EBX[0]..EBX[n], ECX[0]..ECX[n], etc. Now the instruction set does not give the programmer the ability to select one of these specific register array elements for a given instruction, but the CPU can automatically choose a different register array element if doing so would not change the overall computation and doing so could speed up the execution of the program. For example, consider the following sequence (with register array elements automatically chosen by the CPU): mov( 0, eax[0] ); mov( eax[0], i ); mov( 50, eax[1] ); mov( eax[1], j ); Since EAX[0] and EAX[1] are different registers, the CPU can execute the first and third instructions concurrently. Likewise, the CPU can execute the second and fourth instructions concurrently. The code above provides an example of register renaming. Dynamically, the CPU automatically selects one of several different elements from a register array in order 45 [Type here] to prevent data hazards. Although this is a simple example, and different CPUs implement register renaming in many different ways, this example does demonstrate how the CPU can improve performance in certain instances through the use of this technique. 2.5.4 Very Long Instruction Word Architecture (VLIW) Superscalar operation attempts to schedule, in hardware, the execution of multiple instructions simultaneously. Another technique that Intel is using in their IA-64 architecture is the use of very long instruction words, or VLIW. In a VLIW computer system, the CPU fetches a large block of bytes (41 in the case of the IA-64 Itanium CPU) and decodes and executes this block all at once. This block of bytes usually contains two or more instructions (three in the case of the IA-64). VLIW computing requires the programmer or compiler to properly schedule the instructions in each block (so there are no hazards or other conflicts), but if properly scheduled, the CPU can execute three or more instructions per clock cycle. The Intel IA-64 Architecture is not the only computer system to employ a VLIW architecture. Transmeta's Crusoe processor family also uses a VLIW architecture. The Crusoe processor is different than the IA-64 architecture insofar as it does not support native execution of IA-32 instructions. Instead, the Crusoe processor dynamically translates 80x86 instructions to Crusoe's VLIW instructions. This "code morphing" technology results in code running about 50% slower than native code, though the Crusoe processor has other advantages. We will not consider VLIW computing any further since the IA-32 architecture does not support it. But keep this architectural advance in mind if you move towards the IA-64 family or the Crusoe family. Student Activity 1. What are superscalar processors? 2. Describe various types of superscalar processors. 3. What are the problems associated with superscalar processors? 2.6 Programmable Logic Array Programmable Logic Devices PLDs are the integrated circuits. They contain an array of AND gates & another array of OR gates. There are three kinds of PLDs based on the type of arrayss, which has programmable feature. 46 [Type here] • Programmable Read Only Memory • Programmable Array Logic • Programmable Logic Array The process of entering the information into these devices is known as programming. Basically, users can program these devices or ICs electrically in order to implement the Boolean functions based on the requirement. Here, the term programming refers to hardware programming but not software programming. In this section we will discuss PLAs. 2.6.1 Programmable Logic Array Programmable Logic Array(PLA) is a fixed architecture logic device with programmable AND gates followed by programmable OR gates. PLA is basically a type of programmable logic device used to build reconfigurable digital circuit. PLDs have undefined function at the time of manufacturing but they are programmed before made into use. PLA is a combination of memory and logic. 2.6.2 Comparison with other Programmable Logic Devices: • • • PLA has programmable AND gate array and programmable OR gate array. PAL has programmable AND gate array but fixed OR gate array. ROM has fixed AND gate array but programmable OR gate array. PLA is the most flexible PLD. The block diagram of PLA is shown in the following figure. Figure 2.8 The block diagram Here, the inputs of AND gates are programmable. That means each AND gate has both normal and complemented inputs of variables. So, based on the requirement, we can program any of those inputs. So, we can generate only the required product terms by using these AND gates. Here, the inputs of OR gates are also programmable. So, we can program any number of required product terms, since all the outputs of AND gates are applied as inputs to each OR gate. Therefore, the outputs of PAL will be in the form of sum of products form. 47 [Type here] Following Truth table will be helpful in understanding function on no of inputs- Figure 2.9 Truth table F1 = AB’C’ + AB’C + ABC’ + ABC on simplifying we get : F1 = AB’ + AC F2 = A’BC + AB’C + ABC on simplifying we get: F2 = BC + AC For realization of above function following circuit diagram will be used. Figure 2.10 The circuit diagram PLA is used for implementation of various combinational circuits using buffer, AND gate and OR gate. In PLA, all the min terms are not realized but only required min terms are implemented. As PLA has programmable AND gate array and programmable OR gate array, it provides more flexibility but disadvantage is, it is not easy to use. Applications: • • • • PLA is used to provide control over data path. PLA is used as a counter. PLA is used as a decoders. PLA is used as a BUS interface in programmed I/O. 48 [Type here] Student activity 1. Using a PLA to implement a set of logic functions 2. Given a PLA table or an internal connection diagram for a PLA, determine the logic functions realized 49 [Type here] • Unit-3 Memory Organization Learning Objectives After successful completion of this unit, you should be able to: • Describe memory subsystem • Describe various storage technologies • Describe memory array organization • Understand memory hierarchy and interleaving • Describe cache and virtual memory • Describe various architectural aids to implement cache and virtual memory. 3.1 Introduction [Type here] Figure 3.1 Memory terminology Let us first examine some common terminology related to memory. A memory location always has a unique identifier called the address. Each memory unit is a cell which stores 1 bit of information. Therefore a D-FF is also a 1-bit memory. A memory location always has a unique identifier called the address. Each memory unit is a cell which stores 1 bit of information. Therefore a D-FF is also a 1-bit memory. A memory word is a collection of bits to form a multibit unit that carries information. A word can be defined to be 8-bit, 16-bit, 32bit or 64-bit. Other word sizes are possible, but not common An 8-bit word is known as a byte, which is the most common. For example, when you were sending or receiving the ASCII character ‘#’ in Lab 1 or Lab 4, you were using a byte with the value 0x23 (0x … is the way to indicate the number following the prefix is a hexadecimal). Memory capacity (i.e. How much memory is in a memory chip?) is measured in kb, Mb, Gb, Tb when measured [Type here] on a chip. However, these memory bits could be organized in different way. For example, a 8Mb chip could be organized as 1M of 8-bit words, 2M of 4-bit words, or 8M of 1-bit storage. The number of unique words in a memory module determines how many bits of address information is required to uniquely specify each location uniquely. 3.1.2 Memory Subsystem What is important is to appreciate the levels of abstraction used to present the system for different specialty of engineering.DE students generally only need to know that application level. That’s why we are teaching you Python programming and you use the Pyboard. Your focus is applications. Underneath that are generally two things: the operating system (such as OSX or Windows) and compiler. For Pyboard, the program on the board (known as “firmware”, partly because it is stored inside the flash memory and it is firm – or fixed) performs both functions of the operating system and the compiler.Underneath that is the instruction set architecture. This is the instructions used by the central processing unit (CPU). For the Pyboard, we use the ARM instruction set. Beneath that are what electronic engineers are trained to do – hardware design. Although most electronic engineers can also do all the other levels pretty well! 3.1.3 Storage Technologies There are different types of memory chips. ROM is read-only. They are now very rare, because flash memory can act as both read-only and read/write memory. PROM are those that you can program (usually once) in the filed. RAM is the most common memory used. These are both read and write. They are called random access memory because you can go to any location individually and perform a read/write operation, only to that location.There are two types of RAMs: static and dynamic. Static RAMS:are those that are generally used for cache memory. They are fast but expensive. The memory density is lower than the dynamic RAM. Static [Type here] memory are large and expensive because each memory bit is made of a simple latch (a special type of flip- flop) which requires 6 transistors. Dynamic RAMs are generally used for main memory or for the video RAM on a GPU. These are slower than static RAM in access and they are dynamic meaning that it uses a capacitor as the storage mechanism. By storing a small charge on the capacitor, it remembers whether the memory bit is ‘1’ (say with charge) or ‘0’ (no charge). DRAMs are high density because each memory only requires one transistor. Therefore they are also cheaper than static RAMs. There are also many types of DRAMs. Most common are the SDRAM or synchronous DRAM. These use a clock signal to synchronise all read/write operations. Then there are those that are known as DDR memory. What it means is that on each clock cycle, there are TWO memory operations – one on the rising each and one on the falling each of the clock signal.There even a QDR memory which transfers four times per clock cycles! Finally, there are the flash memory. These are mostly behaving as ROM. However, a user can electrically erase its contents a block at a time and write back the block. Flash memory therefore is generally reasonably fast (much faster than hard disk) in reading, and slower in writing due to this block erase requirement. Furthermore, flash memory have limited write cycles in its life- time. Therefore when flash memory are used in solid state disks (SSD drives), there needs to have an algorithm that prevent the user using the same area of the disk (i.e. the same memory locations). Flash memory are used in many applications including USB sticks and SD memory cards for portable equipment. 3.2 Memory Array Organization A typical 80x86 processor addresses a maximum of 2n different memory locations, where n is the number of bits on the address bus, as 80x86 processors have 20, 24, 32, and 36 bit address buses (with 64 bits on the way). [Type here] Of course, the first question you should ask is, "What exactly is a memory location?" The 80x86 supports byte addressable memory. Therefore, the basic memory unit is a byte. So with 20, 24, 32, and 36 address lines, the 80x86 processors can address one megabyte, 16 megabytes, four gigabytes, and 64 gigabytes of memory, respectively. Think of memory as a linear array of bytes. The address of the first byte is zero and the address of the last byte is 2n-1. For an 8088 with a 20 bit address bus, the following pseudo-Pascal array declaration is a good approximation of memory: Memory: array [0..1048575] of byte; To execute the equivalent of the Pascal statement "Memory [125] := 0;" the CPU places the value zero on the data bus, the address 125 on the address bus, and asserts the write line (since the CPU is writing data to memory), see Figure 3.1 Figure 3.2 Memory write operation Student Activity: 1. Discuss memory read operations. [Type here] So what happens when the processor accesses a word or a double word? Since memory consists of an array of bytes, how can we possibly deal with values larger than eight bits? Different computer systems have different solutions to this problem. The 80x86 family deals with this problem by storing the L.O. byte of a word at the address specified and the H.O. byte at the next location. Therefore, a word consumes two consecutive memory addresses (as you would expect, since a word consists of two bytes). Similarly, a double word consumes four consecutive memory. The address for the double word is the address of its L.O. byte. The remaining three bytes follow this L.O. byte, with the H.O. byte appearing at the address of the double word plus three (see Figure 1.4). Bytes, words, and double words may begin at any valid address in memory. We will soon see, however, that starting larger objects at an arbitrary address is not a good idea. 3.3 Memory Hierarchy [Type here] Figure 3.3 memory hierarchy In any computer systems, storage of information is always organized in a hierarchy as shown here as a triangle. This has many layers representing different type of storage. At the bottom is remote storage such as storage in the cloud (e.g. dropbox or iCloud), or central file server offered by an organization for its employees. This is the largest and cheapest, and normally the slowest form of storage. This storage could be very large. The next level is local disk storage, which is faster than the remote storage, but slower than the next layer up. Most disks are now 128GB or more. (We use GB for giga byte and Gb for giga bit.) The next level is the main memory or DRAM in the computer. Modern computer would come with 2GB or more of main memory. These normally come on small PCBs and are swappable. In that way, one could “upgrade” the memory, meaning that you can add more to the system. The next two levels are SRAMs on the processor chip itself. They are L2 (level 2) and L1 (level 1) cache memory. Cache memory is usually not large, but has much faster access than all the other types of memory. Information are generally fetched in “cache lines” which is multiple bytes. Finally the fastest memory are the registers inside the Central Processing Unit (CPU).Information moves up and down this hierarchy in these order, going through each layer. 3.3.1 Cache Memory The data or contents of the main memory that are used again and again by CPU, are stored in the cache memory so that we can easily access that data in shorter time. [Type here] Whenever the CPU needs to access memory, it first checks the cache memory. If the data is not found in cache memory then the CPU moves onto the main memory. It also transfers block of recent data into the cache and keeps on deleting the old data in cache to accomodate the new one. 3.3.2 Hit Ratio The performance of cache memory is measured in terms of a quantity called hit ratio. When the CPU refers to memory and finds the word in cache it is said to produce a hit. If the word is not found in cache, it is in main memory then it counts as a miss. The ratio of the number of hits to the total CPU references to memory is called hit ratio. Hit Ratio = Hit/(Hit + Miss) 3.3.3 Principle of locality In computer science, locality of reference, also known as the principle of locality is the tendency of a processor to access the same set of memory locations repetitively over a short period of time. There are two basic types of reference locality – temporal and spatial locality. Temporal locality refers to the reuse of specific data, and/or resources, within a relatively small time duration. Temporal locality states that recently accessed items are likely to be accessed in the near future. Spatial locality (also termed data locality) refers to the use of data elements within relatively close storage locations. It says that items whose addresses are near one another tend to be referenced close together in time. 3.3.4 Temporal locality Temporal locality means current data or instruction that is being fetched may be needed soon. So we should store that data or instruction in the cache memory so that we can avoid again searching in main memory for the same data [Type here] Figure 3.4 Temporal locality When CPU accesses the current main memory location for reading required data or instruction, it also gets stored in the cache memory which is based on the fact that same data or instruction may be needed in near future. This is known as temporal locality. If some data is referenced, then there is a high probability that it will be referenced again in the near future. 3.3.5 Spatial Locality Spatial locality means instruction or data near to the current memory location that is being fetched, may be needed soon in the near future. This is slightly different from the temporal locality. Here we are talking about nearly located memory locations while in temporal locality we were talking about the actual memory location that was being fetched. Figure 3.5 Spatial locality [Type here] • Unit-4 Input-Output Devices and Characteristics Learning Objectives After successful completion of this unit, you should be able to : • describe input-output processing • describe bus interface • describe I/O Interrupt channels • Describe performance evaluation-SPEC-MARKS • Describe various benchmarks of transaction processing 4.1 Introduction An input device sends information to a computer system for processing, and an output device reproduces or displays the results of that processing. Input devices only allow for input of data to a computer and output devices only receive the output of data from another 4.1.2 Input Hardware input hardware Input hardware exists in many different shapes and sizes, and are tailored specifically for particular systems. Below is a list of common input devices. • • • Keyboards o Light pen Touch screens o Graphics tablet Pointing devices • Imaging input devices o Mouse o Digital cameras o Touchpad / trackpad o Webcam o Joystick o Image scanner o Game controllers o Fingerprint scanner Barcode reader • Audio input devices o Microphone o MIDI Keyboard o Drum machine o 4.1.3 Processing Hardware • • • • Processing in a computer system is handled by the Central Processing Unit (CPU) The motherboard of a computer is essential to this process as it houses the CPU, RAM and other integral components Random access memory (RAM) allows for the data being processed to be stored temporarily Data can be processed in a number of ways [Type here] 4.1.4 Output Hardware Output devices are continuously changing as technology advances. Various types of display outputs as well as printers and audio devices continue to evolve daily. These devices are responsible for transmitting data in to a form that we as humans are able to interpret, e.g. text, images, audio, and even events we can feel (see: haptic feedback). • • • • Monitors Printers Haptic sensors (for example, mobile device vibrations upon touch input) Sound cards and speakers 4.1.5 Storage Hardware Often data that has been processed is stored for later processing or reading. Many devices are capable of storing c (obsolete in today's world) • Network-attached storage devices (NAS) 4.2 Input-Output Processor An input-output processor (IOP) is a processor with direct memory access capability. In this, the computer system is divided into a memory unit and number of processors. Each IOP controls and manage the input-output tasks. The IOP is similar to CPU except that it handles only the details of I/O processing. The IOP can fetch and execute its own instructions. These IOP instructions are designed to manage I/O transfers only. 4.2.1 Block Diagram of I/O Processor Below is a block diagram of a computer along with various I/O Processors. The memory unit occupies the central position and can communicate with each processor. [Type here] The CPU processes the data required for solving the computational tasks. The IOP provides a path for transfer of data between peripherals and memory. The CPU assigns the task of initiating the I/O program. The IOP operates independent from CPU and transfer data between peripherals and memory. Figure 4.1 Block diagram The communication between the IOP and the devices is similar to the program control method of transfer. And the communication with the memory is similar to the direct memory access method. In large scale computers, each processor is independent of other processors and any processor can initiate the operation. The CPU can act as master and the IOP act as slave processor. The CPU assigns the task of initiating operations but it is the IOP, who executes the instructions, and not the CPU. CPU instructions provide operations to start an I/O transfer. The IOP asks for CPU through interrupt. Instructions that are read from memory by an IOP are also called commands to distinguish them from instructions that are read by CPU. Commands are prepared by programmers and are stored in memory. Command words make the program for IOP. CPU informs the IOP where to find the commands in memory. 4.3 Bus Interface [Type here] In computer architecture, a bus historically called data highway is a communication system that transfers data between components inside a computer, or between computers. This expression covers all related hardware components (ire, optical fiber, etc.) and software, including communication protocols. Early computer buses were parallel electrical wires with multiple hardware connections, but the term is now used for any physical arrangement that provides the same logical function as a parallel electrical bus. Modern computer buses can use both parallel and bit serial connections, and can be wired in either a multidrop (electrical parallel) or daisy chain topology, or connected by switched hubs, as in the case of USB. Data Bus: • The data bus is a group of eight lines used for data flow. • These lines are bi-directional - data flow in both directions between the MPU and memory and peripheral devices. • The MPU uses the data bus to perform the second function: transferring binary information. • The eight data lines enable the MPU to manipulate 8-bit data ranging from 00 to FF (28 = 256 numbers). [Type here] • The largest number that can appear on the data bus is 11111111. Control Bus: • The control bus carries synchronization signals and providing timing signals. • The MPU generates specific control signals for every operation it performs. These signals are used to identify a device type with which the MPU wants to communicate. 4.3.1 Interrupts Definition: The meaning of ‘interrupts’ is to break the sequence of operation. While the CPU is executing a program, on ‘interrupt’ breaks the normal sequence of execution of instructions, diverts its execution to some other program called Interrupt Service Routine (ISR).After executing ISR , the control is transferred back again to the main program. Interrupt processing is an alternative to polling. Need for Interrupt: Interrupts are particularly useful when interfacing I/O devices that provide or require data at relatively low data transfer rate. Types of Interrupts: There are two types of Interrupts in 8086. They are: (i)Hardware Interrupts and (ii)Software Interrupts (i) Hardware Interrupts (External Interrupts). The Intel microprocessors support hardware interrupts through: Two pins that allow interrupt requests, INTR and NMI • One pin that acknowledges, INTA, the interrupt requested on INTR. INTR and NMI • INTR is a maskable hardware interrupt. The interrupt can be enabled/disabled using STI/CLI instructions or using more complicated method of updating the FLAGS register with the help of the POPF instruction. • When an interrupt occurs, the processor stores FLAGS register into stack, disables further interrupts, fetches from the bus one byte representing interrupt type, and jumps to interrupt processing routine address of which is stored in location 4 * <interrupt type>. Interrupt processing routine should return with the IRET instruction. • NMI is a non-maskable interrupt. Interrupt is processed in the same way as the INTR interrupt. Interrupt type of the NMI is 2, i.e. the address of the NMI processing routine is stored in location 0008h. This interrupt has higher priority than the maskable interrupt. – Ex: NMI, INTR. [Type here] (ii) Software Interrupts (Internal Interrupts and Instructions) .Software interrupts can be caused by: • INT instruction - breakpoint interrupt. This is a type 3 interrupt. • INT <interrupt number> instruction - any one interrupt from available 256 interrupts. • INTO instruction - interrupt on overflow • Single-step interrupt - generated if the TF flag is set. This is a type 1 interrupt. When the CPU processes this interrupt it clears TF flag before calling the interrupt processing routine. • Processor exceptions: Divide Error (Type 0), Unused Opcode (type 6) and Escape opcode (type 7). • Software interrupt processing is the same as for the hardware interrupts. - • Ex: INT n (Software Instructions) Control is provided through: o IF and TF flag bits o IRET and IRETD [Type here] Performance of Software Interrupts 1. It decrements SP by 2 and pushes the flag register on the stack. 2. Disables INTR by clearing the IF. 3. It resets the TF in the flag Register. 5. It decrements SP by 2 and pushes CS on the stack. 6. It decrements SP by 2 and pushes IP on the stack. 6. Fetch the ISR address from the interrupt vector table. Interrupt Vector Table Functions associated with INT00 to INT04 INT 00 (divide error) INT00 is invoked by the microprocessor whenever there is an attempt to divide a number by zero. ISR is responsible for displaying the message “Divide Error” on the screen INT 01 For single stepping the trap flag must be 1 After execution of each instruction, 8086 automatically jumps to 00004H to fetch 4 bytes for CS: IP of the ISR. The job of ISR is to dump the registers on to the screen [Type here] INT 02 (Non maskable Interrupt) • When ever NMI pin of the 8086 is activated by a high signal (5v), the CPU Jumps to physical memory location 00008 to fetch CS:IP of the ISR associated with NMI. INT 03 (break point) • A break point is used to examine the CPU and memory after the execution of a group of Instructions. • It is one byte instruction whereas other instructions of the form “INT nn” are 2 byte instructions. INT 04 (Signed number overflow) There is an instruction associated with this INT 0 (interrupt on overflow). • If INT 0 is placed after a signed number arithmetic as IMUL or ADD the CPU will activate INT 04 if 0F = 1. • In case where 0F = 0, the INT 0 is not executed but is bypassed and acts as a NOP. Performance of Hardware Interrupts • NMI : Non maskable interrupts - TYPE 2 Interrupt • INTR : Interrupt request - Between 20H and FFH Interrupt Priority Structure I/O Interrupts Channels A channel is an independent hardware component that co-ordinate all I/O to a set of controllers. Computer systems that use I/O channel have special hardware components that handle all I/O operations. Channels use separate, independent and low cost processors for its functioning which are called Channel Processors. Channel processors are simple, but contains sufficient memory to handle all I/O tasks. When I/O transfer is complete or an error is detected, the channel controller communicates with the CPU using an interrupt, and informs CPU about the error or the task completion. [Type here] Each channel supports one or more controllers or devices. Channel programs contain list of commands to the channel itself and for various connected controllers or devices. Once the operating system has prepared a list of I/O commands, it executes a single I/O machine instruction to initiate the channel program, the channel then assumes control of the I/O operations until they are completed. Input port: It is used to read data from the input device such as keyboard. The simplest form of input port is a buffer. The input device is connected to the microprocessor through buffer, as shown in the fig.1. This buffer is a tri-state buffer and its output is available only when enable signal is active. When microprocessor wants to read data from the input device (keyboard), the control signals from the microprocessor activates the buffer by asserting enable input of the buffer. Once the buffer is enabled, data from the input device is available on the data bus. Microprocessor reads this data by initiating read command. Output port: [Type here] It is used to send data to the output device such as display from the microprocessor. The simplest form of output port is a latch. The output device is connected to the microprocessor through latch, as shown in the fig.2. When microprocessor wants to send data to the output device is puts the data on the data bus and activates the clock signal of the latch, latching the data from the data bus at the output of latch. It is then available at the output of latch for the output device. Serial and Parallel Transmission: In telecommunications, serial transmission is the sequential transmission of signal elements of a group representing a character or other entity of data. Digital serial transmissions are bits sent over a single wire, frequency or optical path sequentially. Because it requires less signal processing and less chance for error than parallel transmission, the transfer rate of each individual path may be faster. This can be used over longer distances as a check digit or parity bit can be sent along it easily. In telecommunications, parallel transmission is the simultaneous transmission of the signal elements of a character or other entity of data. In digital communications, parallel transmission is the simultaneous transmission of related signal elements over two or more separate paths. Multiple electrical wires are used which can transmit multiple bits simultaneously, which allows for higher data transfer rates than can be achieved with serial transmission. This method is used internally within the computer, for example the internal buses, and sometimes externally for such things as printers, The major issue with this is "skewing" because the wires in parallel data transmission have slightly different properties (not intentionally) so some bits may arrive before others, which may corrupt the message. A parity bit can help to reduce this. However, electrical wire parallel data transmission is therefore less reliable for long distances because corrupt transmissions are far more likely. Interrupt driven I/O: In this technique, a CPU automatically executes one of a collection of special routines whenever certain condition exists within a program or a processor system. Example CPU gives response to devices such as keyboard, sensor and other components when they request for service. When the CPU is asked to communicate with devices, it services the devices. Example each time you type a character on a keyboard, a keyboard service routine is called. It transfers the character you typed from the keyboard I/O port into the processor and then to a data buffer in memory. The interrupt driven I/O technique allows the CPU to execute its main program and only stop to service I/O device when it is told to do so by the I/O system as shown in fig.3. This method provides an external asynchronous input that would inform the processor that it should complete whatever instruction that is currently being executed and fetch a new routine that will service the requesting device. Once this servicing is completed, the processor would resume exactly where it left off. [Type here] An analogy to the interrupt concept is in the classroom, where the professor serves as CPU and the students as I/O ports. The classroom scenario for this interrupt analogy will be such that the professor is busy in writing on the blackboard and delivering his lecture. The student raises his finger when he wants to ask a question (student requesting for service). The professor then completes his sentence and acknowledges student‟s request by saying “YES” (professor acknowledges the interrupt request). After acknowledgement from the professor, student asks the question and professor gives answer to the question (professor services the interrupt). After that professor continues its remaining lecture form where it was left. 4.3.3 Communication between the CPU and the channel The CPU directly can communicate with the channels through control lines. Following diagram shows the word format of channel operation. Figure 4.2 Channel operation [Type here] Student Activity 1. What is the purpose of having a channel? 2. The CPU and the channel are usually in a master-slave relationship. Explain. 4.4 I/O Interrupts Interrupt I/O A way of controlling input/output activity in which a peripheral or terminal that needs to make or receive a data transfer sends a signal that causes a program interrupt to be set. At a time appropriate to the priority level of the I/O interrupt, relative to the total interrupt system, the processor enters an interrupt service routine (ISR). The function of the routine will depend upon the system of interrupt levels and priorities that is implemented in the processor. In a single-level single-priority system there is only a single I/O interrupt – the logical OR of all the connected I/O devices. The associated interrupt service routine polls the peripherals to find the one with the interrupt status set. In a multilevel single-priority system there is a single interrupt signal line and a number of device identification lines. When a peripheral raises the common interrupt line it also sets its unique code on the identification lines. This system is more expensive to implement but speeds the response. In a single-level multiple-priority system the interrupt lines of the devices are logically connected to a single processor interrupt in such a way that an interrupt from a high-priority device masks that of lower-priority devices. The processor polls the devices, in priority order, to identify the interrupting device. A multilevel multiple-priority system has both the property of masking interrupts according to priority and of immediate identification via identification lines. Student Activity 1. What is an Interrupt? 2. What is the purpose of having a channel? 3. The CPU and the channel are usually in a master-slave relationship. Explain. 4. Explain the CPU I/O instructions executed by the CPU. [Type here] 4.4.1 Interrupt-Initiated I/O Interrupt driven I/O is an alternative scheme dealing with I/O. Interrupt I/O is a way of controlling input/output activity whereby a peripheral or terminal that needs to make or receive a data transfer sends a signal. This will cause a program interrupt to be set. At a time appropriate to the priority level of the I/O interrupt. Relative to the total interrupt system, the processors enter an interrupt service routine. The function of the routine will depend upon the system of interrupt levels and priorities that is implemented in the processor. The interrupt technique requires more complex hardware and software, but makes far more efficient use of the computer’s time and capacities. Characteristics • The I/O transfer is initiated by the interrupt command issued to the CPU. • There is no need for the CPU to stay in the loop as the interrupt command interrupts the CPU when the device is ready for data transfer. • The CPU cycles are not wasted as CPU and hence this method is more efficient. • CPU can do any other work until it is interrupted by the command indicating the readiness of device for data transfer • Its module is faster • It can be tricky and complicated to understand if one uses low level language • The performance of the system is enhanced to some extent. [Type here] Below are the basic operations of Interrupt: • CPU issues read command • I/O module gets data from peripheral whilst CPU does other work • I/O module interrupts CPU • CPU requests data • I/O module transfers data Student activity 1. With the aid of a diagram outline an example of a simple interrupt processing 4.5 Performance Evaluation Performance evaluation is at the foundation of computer architecture research and development. Contemporary microprocessors are so complex that architects cannot design systems based on intuition and simple models only. Adequate performance evaluation methods are absolutely crucial to steer the research and development process in the right direction. There are several metrics used Metrics • Latency: Time to completely execute a certain task • Throughput Amount of work that can be done over a period of time • Power instantaneous power during execution of a program • Energy Total energy consumption during the execution of the whole program • Reliability Failure rate [Type here] • CPI, IPC, MIPS, MFLOPS, MTTF, MTBF, AVF, Transactions/minute, Transactions/hour, MIPS/watt, Watts, Joules, Joules/instr, etc Student activity 1. With the aid of an example explain the “Iron Law” of Processor Performance 2. Outline the challenges in performance evaluation 3. Describe the following: (a) Spec-Mark (b) TPC-H (c) TPC-R (d) TPC-W Further Readings 1. Hardware, Input, Processing and Output Devices on Slideshare here 2. Hardware Devices: Input and Output Devices on WikiBooks here [Type here] • Unit 5: Assembly Language Objectives After successful completion of this unit, you should be able to: • • • Understand the basics of assembly language Understand commands of assembly programming Translating high level arithmetic into Assembly 5.1 Introduction Assembly language is a low-level programming language for a computer, or other programmable device specific to a particular computer architecture in contrast to most highlevel programming languages, which are generally portable across multiple systems. Assembly language is converted into executable machine code by a utility program referred to as an assembler like NASM, MASM et 5.1.2 What is Assembly Language? Each personal computer has a microprocessor that manages the computer's arithmetical, logical, and control activities. Each family of processors has its own set of instructions for handling various operations such as getting input from keyboard, displaying information on screen and performing various other jobs. These set of instructions are called 'machine language instructions'. A processor understands only machine language instructions, which are strings of 1's and 0's. However, machine language is too obscure and complex for using in software development. So, the low-level assembly language is designed for a specific family of processors that represents various instructions in symbolic code and a more understandable form. 5.1.3 Advantages of Assembly Language Having an understanding of assembly language makes one aware of − • How programs interface with OS, processor, and BIOS; [Type here] • How data is represented in memory and other external devices; • How the processor accesses and executes instruction; • How instructions access and process data; • How a program accesses external devices. Other advantages of using assembly language are − • It requires less memory and execution time; • It allows hardware-specific complex jobs in an easier way; • It is suitable for time-critical jobs; • It is most suitable for writing interrupt service routines and other memory resident programs. 5.1.4 Visualizing instruction execution Figure 5.1 Visualizing instruction execution [Type here] Assembly language instructions for a hypothetical machine Load x, r1 Load y, r2 Load z, r0 Add r3, r1, r2 Sub r0, r3, r0 Store r0, a Student Activity • • Write assembly language to perform any arithmetic operation With the aid of an example outline how to translate a high level arithmetic into Assembly [Type here] • Unit 6: Logic Gates Objective After successful completion of this unit, you should be able to: • • Understand what logic tables are Implementing truth tables 6.1 Introduction Logic gates are the basic building blocks of any digital system. It is an electronic circuit having one or more than one input and only one output. The relationship between the input and the output is based on a certain logic. Based on this, logic gates are named as AND gate, OR gate, NOT gate etc. o The logic gates are the main structural part of a digital system. o Logic Gates are a block of hardware that produces signals of binary 1 or 0 when input logic requirements are satisfied. o Each gate has a distinct graphic symbol, and its operation can be described by means of algebraic expressions. o The seven basic logic gates includes: AND, OR, XOR, NOT, NAND, NOR, and XNOR. o The relationship between the input-output binary variables for each gate can be represented in tabular form by a truth table. o Each gate has one or two binary input variables designated by A and B and one binary output variable designated by x. Logic gates use the principles of a mathematical system known as Boolean algebra. As well as a standard Boolean expression, the input and output information of any logic gate or circuit can be schemed into a standard table to give a visual representation of the switching function of the system. The table used to [Type here] represent the Boolean expression of a logic gate function is commonly called a Truth Table. A logic gate truth table shows each possible input combination to the gate or circuit with the resultant output depending upon the combination of these input(s). 6.1.2 AND GATE: • The AND gate is an electronic circuit which gives a high output only if all its inputs are high. The AND operation is represented by a dot (.) sign. Figure 6.1 AND gate circuit An AND gate is a circuit with two inputs and an output which is set to one only if both the inputs are 1. This means that it will give a high output only if all of the inputs are high. For example, in a simple lighting circuit with two switches in series the lamp will light only if both switches are pressed. 6.1.3 OR GATE: The OR gate is an electronic circuit which gives a high output if one or more of its inputs are high. The operation performed by an OR gate is represented by a plus (+) sign. [Type here] Figure 6.2 OR gate circuit An OR gate will give a high output if any of the inputs is high. For example, in a simple lighting circuit with two switches in parallel the lamp will light if either switch is pressed. The relationship between the inputs and the output can be captured in a truth table. A and B represent the inputs and Q is the output. Student Activity 1. What is a truth table 2. Discuss the following GATES • NOT • NAND • NOR • XOR • Exclusive NOR 3. Match the following words to the correct definition: [Type here] Further Readings Text books Stallings, W, 2010, Computer Organization and Architecture: Designing for Performance (8th Edition), Prentice Hall Shiva, SG,. 2007, Computer Organization, Design and Architecture, Fourth Edition, Taylor and Francis Group, LLC Ebd-El-Barr, M,. El-Rewini, H,. 2005, Fundamentals of Computer Organization and Architecture (Wiley Series on Parallel and Distributed Computing) Internet resources https://www.d.umn.edu/~gshute/mips/multicycle.xhtml#:~:text=MIPS%20Multic ycle%20Implementation,cycles%20depends%20on%20the%20instruction. http://users.ece.northwestern.edu/~kcoloma/ece361/lectures/Lec01introduction.pdf https://www.freebookcentre.net/ComputerScience-Books-Download/ComputerOrganization-and-Architecture-Lecture-Notes.html You tube videos
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )