Machine Architecture ITNP23: Foundations of Information Technology Una Benlic 4B69 ube@cs.stir.ac.uk
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 Understand the concepts of stored program and machine cycle.
Literature Introduction to Computing Systems, Patt and Patel, latest edition. Computer Science: An Overview, J. G. Brookshear, latest edition, Addison-Wesley
To get the task done by a computer, we need: 1) A computer program that specifies what the computer must do. 2) The computer itself that is to carry out the task
Computer program Set of instructions, each specifying a well-defined piece of work for the computer to carry out. Instruction is the smallest piece of work specified in a computer program. To be executed, a machine-code program must be stored in main memory as sequence of machine-code instructions.
Von Neumann model John von Neumann proposed a fundamental model of a computer for processing computer programs in 1946. Consists of five parts: memory, a processing unit, input, output and a control unit.
Slightly more detailed von Neumann model
Main memory - RAM Random-access memory (RAM) Temporarily stores both software instruction and data. It is basically your computer's short term memory. Memory is divided into fixed-sized units called cells. Each cell is associated with a unique identifier called an address. RAM is measured in MB, e.g., a 256MB memory has 2 28 uniquely identifiable locations, and each location can store 8 bits of informations.
Main memory - ROM Read-Only Memory (ROM) Contents can be accessed and read but can't be changed. Being non-volatile, the information is not lost once the computer has been shut off. ROM includes such things as the computer's BIOS (basic input/output system), which are the instructions the computer follows for booting up. ROM is measured in Megabytes.
Accessing memory location To read the contents of a memory location: place the address of the memory location in the memory's address register (MAR) interrogate the computer's memory The information stored in the location having the address will be placed in the memory's data register (MDR). To write a value in a memory location: write the address of the memory location in the MAR, and the value to be stored in MDR. interrogate the computer's memory with the Write Enable signal asserted.
Two features of a memory location Its address and what is stored there. An analogy: the post office boxes in your local post office.
Central Processing Unit (CPU) Consists of a processing unit and a control unit.
CPU Processing unit Carries out the processing of information in the computer. Can consist of many sophisticated complex functional units, each performing one particular operation (divide, square root, etc). The simplest processing unit is the Arithmetic and Logic Unit (ALU), so called because it is usually capable of performing basic arithmetic functions (like ADD and SUBTRACT) and basic logical operations (like AND, OR and NOT operations). The size of the quantities normally processed by the ALU is often referred to as the word length and each element is referred to as a word. Most microprocessors today that are used in PCs or workstations have a word length of either 32 bits (as in the case of Intel's Pentium IV) or 64 bits (Intel's Itanium processor). A computer often provides some small amount of storage very close to the ALU to allow results to be temporarily stored if they will need to produce additional results in the near future.
CPU control unit Like the conductor of an orchestra - it is in charge of making all the other parts play together. It keeps track of both where we are within the process of executing the program and where we are in the process of executing each instruction. To keep track of which instruction is being executed, it has an Instruction Register (IR) to contain that instruction. To keep track of which instruction is to processed next, it has a Program Counter (PC) register (also caller instruction pointer) that contains the next instruction's address.
Input and Output Many devices exist for the purpose of getting the information into the computer and displaying the result outside the computer. The most basic input device is the keyboard, while the most basic output device is the monitor. For input we have among other things the mouse, digital scanners, CD disks, etc. For output, we have among other things printers, LED displays, and disks.
System bus System bus - bus connecting the CPU and memory. Combines the functions of a data bus to carry information, an address bus to determine where it should be sent, and a control bus to determine its operation.
Machine code instructions Instruction is made of two parts, the opcode (what the instruction does) and the operands (who it is to do it to). E.g., ADD instruction for a LC-3 computer. 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.
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 (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
Machine cycle Instructions are processed under the direction of the control unit in a step-by-step manner. The sequence of steps is called the instruction cycle and each step is referred to as a phase. Six phases to the instruction cycle: FETCH, DECODE, EVALUATE ADDRESS, FETCH OPERANDS, EXECUTE, STORE RESULT
Instruction cycle phases FETCH: obtains the next instruction from memory and loads it into the instruction register (IR) of the control unit. The program counter (PC) contains the address of the next instruction. The FETCH phase takes multiple steps: Step 1: Load the MAR with the contents of the PC, and simultaneously increment the PC. Step 2: Interrogate memory, resulting in the instruction being placed in the MDR. Step 3: Load the IR with the content of the MDR.
Instruction cycle phases DECODE: examines the instruction in order to figure out what is being asked to do. EVALUATE ADDRESS: computes the address of the memory location that is needed to process the instruction. FETCH OPERANDS: obtains the source operands needed to process the instruction. EXECUTE: carries out the execution of the instruction. STORE RESULT: the final phase of an instruction's execution. The result is written to its designated destination. Processing continues until something breaks this sequential flow.
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!
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.
Clock speed The CPU requires a fixed number of clock ticks, or cycles, to execute each instruction. The faster the clocks rate, the faster the CPU, or the faster it can execute instructions. Clock Speeds are usually determined in MHz, 1 MHz representing 1 million cycles per second, or in GHz, 1 GHz representing 1 thousand million cycles per second. The higher the CPU speed, the better a computer will perform, in a general sense. Other components can improve a computer's performance as well, like memory (RAM) and the motherboard, as well as the number of cores that a processor has, like dual core or quad core.
Machine Speed Instruction Rate Clock speed 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.
Cache 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
Cache 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)
Cache 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
Summary We have discussed... the structure of a simple computer its basic components (CPU, Main Memory, I/O) its operation (stored program concept, program execution
END OF LECTURE