Machine Architecture Prof Leslie Smith or what s in the box? Lectures 2 & 3 ITNP23 - Autumn 2014 Lectures 2&3, Slide 1
Basic Machine Architecture In these lectures we aim to: understand the basic architecture of a simple computer. understand the components: CPU, Main Memory, I/O Controllers. understand concepts of stored program, machine cycle, memory mapped I/O. ITNP23 - Autumn 2014 Lectures 2&3, Slide 2
What is a computer? wikipedia A computer is a programmable machine that receives input, stores and manipulates data or information, and provides output in a useful format. While a computer can, in theory, be made out of almost anything, and mechanical examples of computers have existed through much of recorded human history, the first electronic computers were developed in the mid-20th century (1940 1945). http://www.youtube.com/watch?v=0aniyvgewoi&nr=1&feature=fvwp http://www.youtube.com/watch?v=kl_wy-cxbp8&feature=related ITNP23 - Autumn 2014 Lectures 2&3, Slide 3
Background: computers and digital hardware Digital computers consist of large number of gates AND, OR, NOT, NAND And other circuitry that (e.g.) generates digital signals Clocks, lines carrying data These all need switching circuitry And switching circuitry can be built from may different technologies. ITNP23 - Autumn 2014 4 Machine hardware: April 2016
Konrad Zuse s 1st computer 1941 Zuse (1910-1995) Built the Z3 in 1941 (inspecting rebuilt Z3 at Deutsches Museum, 1991) ITNP23 - Autumn 2014 5 Machine hardware: April 2016
IBM 7090 series: from 1959 For large scale scientific and technological applications $2.9 million (equivalent to $23 million now) 50,000 Germanium transistors 6x faster than IBM 709, much lower power consumption: world s most powerful computer in 1960 IBM7090, from1965: credit Australian news and information bureau ITNP23 - Autumn 2014 6 Machine hardware: April 2016
The era of the minicomputer Data General NOVA minicomputer, early 1970 s ITNP23 - Autumn 2014 7 Machine hardware: April 2016
Structure of a simple computer CPU Screen controller Control Unit ALU Bus Main Memory Registers Keyboard controller Disk controller ITNP23 - Autumn 2014 Lectures 2&3, Slide 8
Microcomputers, smartphones, The basic architecture of all of these is the same ITNP23 - Autumn 2014 Lectures 2&3, Slide 9
Basic architecture of a computer Memory unit contains both programs and data CPU runs the program by executing instructions using ALU. Conceptually, this is a von Neumann computer There are alternative designs, e.g. Harvard architecture: separate memory for data and instructions. ITNP23 - Autumn 2014 CSCU9A1: (c) LSS
Execution of a program A program is a sequence of instructions. A machine-code program is a sequence of machine-code instructions. To be executed, a machine-code program must be stored in main memory. Execution takes place within the CPU. Execution follows Fetch-Decode-Execute cycle ITNP23 - Autumn 2014 Lectures 2&3, Slide 11
The CPU The Central Processing Unit (CPU) is where the work takes place. It has three components: Control Unit organises the actions of the CPU, and sequences the actions of the other components to execute programs Arithmetic/Logic Unit (ALU) acts as a calculator, under the direction of the control unit. All data alteration takes placec in the ALU. Registers: individual high-speed storage locations, internal to the CPU, used to hold transient data. Some are dedicated for particular purposes, others are used as temporary stores during computations ITNP23 - Autumn 2014 Lectures 2&3, Slide 12
The CPU : control unit It is the task of the control unit to : 1. Fetch from memory the next instruction to be executed 2. Decode it, that is, determine what should be done 3. Execute it by issuing the appropriate command to the ALU, memory, and I/O Controllers These 3 steps are repeated over and over again until we reach the last instruction of a program (usually HALT, STOP, or QUIT). ITNP23 - Autumn 2014 Lectures 2&3, Slide 13
The Fetch-Execute Cycle ITNP23 - Autumn 2014 CSCU9A1: (c) LSS
The CPU : ALU The subsystem that performs such mathematical and logical operations as addition, subtraction, and comparison for equality. In modern machines, the ALU, control unit and registers are fully integrated into a single component called the processor. For reasons of clarity and convenience, the functions of each are described separately. ITNP23 - Autumn 2014 Lectures 2&3, Slide 15
Main Memory : RAM Main Memory is also called random-access memory (RAM) It traditionally has the following characteristics: It is divided into fixed-sized units called cells. Each cell is associated with a unique identifier called an address. Any location in the memory can be accessed very fast just by specifying the address of the location The time it takes to fetch or store a cell is the same for all cells in memory Programs (and data) are stored in main memory when they are running RAM is linked to CPU in such a way that data can be moved from one to the other very quickly ITNP23 - Autumn 2014 Lectures 2&3, Slide 16
Main Memory : ROM A small part of main memory is non-volatile, read-only memory (ROM) Simply RAM where the ability to store information has been disabled It is only possible to fetch information: it cannot be overwritten In most computers, a section of RAM is set aside as ROM to store essential system instructions which the user cannot overwrite ITNP23 - Autumn 2014 Lectures 2&3, Slide 17
Buses Buses: Each bus consists of several signal wires, so a large number of bits (perhaps 64 bits or more) can be sent simultaneously between the components, making communication between them very fast CPU Screen controller Control Unit ALU Bus Main Memory Registers Keyboard controller Disk controller ITNP23 - Autumn 2014 Lectures 2&3, Slide 18
I/O controllers CPU Screen controller Control Unit ALU Bus Main Memory Registers Keyboard controller Disk controller ITNP23 - Autumn 2014 Lectures 2&3, Slide 19
I/O controllers Input and output operations are slow in comparison with computations done in the CPU Communication with a peripheral is done via a special hardware controller. This can be nearly as complex as the CPU. An I/O controller is like a special-purpose computer with a responsibility to handle the details of input/output, and to compensate for any speed differences between I/O devices and other parts of the computer. It has a small amount of memory known as an I/O buffer and enough I/O control and logic processing capability to handle mechanical functions of the I/O device, such as the read/write head (on a disk), paper feed mechanism (on a printer), and screen display. It is also able to transmit an interrupt signal (see later) when an I/O operation is complete. ITNP23 - Autumn 2014 Lectures 2&3, Slide 20
I/O example: display 1 line of text on a display 1. Transfer the 80 characters from their current location in memory to the I/O buffer storage within the I/O controller (takes place at high speed ~ 10s or 100s of millions of chars per second) 2. The processor then instructs the I/O controller to begin the output operation. 3. The control logic of the I/O controller handles the actual transfer of the 80 chars to the screen (this takes place perhaps at a much slower rate ~100s /1000s of chars per second, depending on the display type) Note that the processor continues to execute instructions while this is going on 4. When all 80 characters have been displayed, the I/O controller sends an interrupt signal to the processor 5. The appearance of this special signal indicates to the processor that the I/O operation is complete. ITNP23 - Autumn 2014 Lectures 2&3, Slide 21
Machine Instruction Set Each type of processor (e.g., Core i7, PowerPC, ARM) has a repertoire of instructions that the CPU is built to recognise and execute This is the instruction-set of the processor A program that is expressed in this instruction-set is in machine code In the first days of computers, programmers wrote in machine code (because there wasn t anything else) Now, we write programs in languages that other programs translate into machine code ITNP23 - Autumn 2014 Lectures 2&3, Slide 22
Machine Code Machine code is binary code not readable by people (without extreme difficulty or training) very readable by machines Binary literally only 1s and 0s like 11100111100000011110010111110000 Internally held as a pattern of voltages representing 1 s and 0 s ITNP23 - Autumn 2014 Lectures 2&3, Slide 23
Machine Code Instructions Instructions in this language have a typical format: operation code field (or op code) address field (s) Operation code: A unique number assigned to each machine language operation recognised by the hardware Address field (s): Memory addresses of the values on which the operation will work Machine code (lines of numbers!) is very hard to read, so instead programmers use a set of mnemonics called assembly language to represent the numerical instructions. ITNP23 - Autumn 2014 Lectures 2&3, Slide 24
Assembly language instructions Some examples from the Intel 8021 instruction set: MOV A, 4 Copy contents of memory location 4 to register A DEC A Take away 1 from (decrement) the contents of register A MOV B, A Copy contents of register A to register B ADD A, B Add contents of register B to register A MOV 4, A Copy contents of register A to memory location 4 Example Let s try this out with the following values: A : initial value 2 B : initial value 4 Memory location 4: initial value 3 In a modern programming language this could be written as x = (x-1)*2! ITNP23 - Autumn 2014 Lectures 2&3, Slide 25
Running a Program Each processor (of any type) has two special registers: The Program Counter (PC): this holds the address in memory of the next instruction to be obeyed The Instruction Register (IR): holds the instruction currently being obeyed At the dawn of time (when your computer is switched on) There is a program sitting in memory, starting at some location in RAM (or ROM, at the dawn of time) The address of this location (probably zero, at the dawn of time) is in the PC The control unit starts the machine cycle (see later) and the machine executes the program (ditto) At the dawn of time, this program will be the bootstrap (it loads the operating system program from disk to memory when you start up your computer), but as the machine continues, the programs will be user programs ITNP23 - Autumn 2014 Lectures 2&3, Slide 26
The Machine Cycle Also known as the fetch/decode/execute cycle Also known as the Von Neumann cycle (see later slide for further information). The processor (all types) endlessly executes the following loop Repeat Fetch instruction from location in PC Increment PC by instruction length Decode instruction Execute instruction The point of the Increment step: the next time round the cycle it fetches the next instruction in the program The machine (unless it s switched off) is always executing this loop (even if apparently idle) It does it at a fixed rate: the clock speed When we say a processor is running at (say) 3 GHz, we mean it executes the cycle 3,000,000,000 times a second... or faster with later versions! ITNP23 - Autumn 2014 Lectures 2&3, Slide 27
Fetch->Decode->Execute a little more detail Each instruction is executed in a number of small steps: 1. Fetch the next instruction from memory into the Instruction Register 2. Change the Program Counter to point to the next instruction 3. Decode the current instruction 4. If the instruction uses a word in memory, determine where it is 5. Fetch the word (in a CPU register if needed) 6. Execute the instruction and repeat until the instruction is Halt 3 Control Unit ALU 6 Instruction Register Program Counter Register Register Register 5 1 4 2 M e m o r y ITNP23 - Autumn 2014 Lectures 2&3, Slide 28
Running Programs So, to run a program: we arrange that its instructions are in contiguous locations in memory place the start address in the PC. stand clear! ITNP23 - Autumn 2014 Lectures 2&3, Slide 29
Machine Cycle Example Here is a snapshot of the state of a simple computer showing the contents of main memory. Trace the execution of the program stored in the main memory. At each step, show the contents of main memory and of all registers used in executing this program. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 MOV A 34 DEC A MOV B A ADD A B MOV 34 A 16 32 4 ITNP23 - Autumn 2014 Lectures 2&3, Slide 30
von Neumann In 1946 he proposed a radically different computer design based on a model called the stored program computer. Until then, all computers were programmed externally using wires, connectors, and plugboards. The memory unit stored only data, not instructions. To solve a different problem on these computers, the user had to rewire virtually the entire machine. For example, the plugboards contained 6000 different switches, and reprogramming involved specifying the new settings for all these switches. Von Neumann proposed that the instructions that control the operation of the computer be encoded as binary values and stored internally in memory along with the data. Now to solve a different problem you would simply rewrite the sequence of instructions, that is, create a new program. Von Neumann invented programming as it is today! ITNP23 - Autumn 2014 Lectures 2&3, Slide 31
Clock Speed versus Instruction Rate Clock speed: Measured in either millions of cycles per second (megahertz (MHz)) or billions of cycles per second (gigahertz (GHz)) The actions of every computer are controlled by a central clock, and the tick rate of this clock is one possible speed measure. Typical clock speeds of today s computers - from 500MHz through to 2-3 GHz but this figure can be misleading as a machine s capability is also how much work it can do between ticks, not just how fast it ticks. Machine Speed Instruction Rate:..is a better measure than clock speed alone It s measured in MIPS (millions of instructions per second) measures how many machine language instructions can be fetched, decoded, and executed in one second. ITNP23 - Autumn 2014 Lectures 2&3, Slide 32
Cache - 1 Not included in our machine architecture diagram, but certainly plays a part in program execution. It is located on or near the processor. Computer designers observed that when a program fetches a piece of data or instruction, there is a high likelihood that: 1. It will access that same instruction or piece of data in the very near future 2. It will likely access the instructions or data that are located near this one. This is known as the principle of locality. ITNP23 - Autumn 2014 Lectures 2&3, Slide 33
Cache - 2 To exploit this, when the computer references a piece of data, it should move the data from RAM to cache. It should also move data in the memory cells located near this item into cache. Cache memory is typically 10 times faster than RAM, but is much smaller (100s of Kilobytes of storage, rather than 100s or Megabytes or Gigabytes.. See later for more on bytes) ITNP23 - Autumn 2014 Lectures 2&3, Slide 34
Cache - 3 When the computer needs a piece of information, it does the following: 1. Looks first in cache to see if the information is there. 2. If it is not, then access the information in RAM 3. Copy the data just fetched into cache along with the k immediately following memory locations. If the cache is full, discard some of the older items that have not been accessed recently. A good analogy to cache is a fridge! Without one, we d have to go to the supermarket every time we needed an item (that usually requires cool storage). With a fridge, we can store food for now, and food we will need in the immediate future, reducing trips to the supermarket (Schneider & Gersting, 2004) Cache size on CPUs and devices (e.g. hard drives) can have a large impact on speed ITNP23 - Autumn 2014 Lectures 2&3, Slide 35
Summary we have discussed the structure of a simple computer its basic components (CPU, Main Memory, I/O controllers) its operation (stored program concept, program execution). ITNP23 - Autumn 2014 Lectures 2&3, Slide 36
end of lecture ITNP23 - Autumn 2014 Lectures 2&3, Slide 37