12
IB Computer Science Topic 2 Computer Organisation 2.1 Computer Architecture Computers are electronic devices; fundamentally the gates and circuits of the CPU control the flow of electricity. We harness this electricity to perform calculations and make decisions. Understanding the architecture of the computer is almost equal parts Computer Science and equal parts Electrical Engineering. Before going too deep into this part of the course, it is useful to have a fundamental understanding of how the binary number system works as this section explores how the computer use electric signals to represent and manipulate binary values. Any given electric signal has a level of voltage. As we know binary consists of 2 values, 1 and 0 or high and low to think of it another way. The tricky thing is representing this in voltage. Computers consider a signal of between 0 and 2 volts to be “low” and therefore a 0 in binary. The voltage level between 2 and 5 is considered “high” and therefore is 1. Gates are devices that perform basic operations on electrical signals. Gates can accept one or more inputs and produce a single output signal. Several types of gate exist but we will only consider the 6 fundamental types. Each gate performs a particular logical function. Gates can be combined to create circuits. Circuits can perform one or more complicated tasks. For example, they could be designed to perform arithmetic and store values. In a circuit, the output value of one gate often becomes the input for another. The flow of electricity in circuits is controlled by these gates. George Boole, a nineteenth century mathematician, invented a form of algebra in which functions and variables can only have 1 of 2 values(1 and 0). His notation is an elegant and powerful way to demonstrate the activity of electrical circuits. This algebra is appropriately named Boolean Algebra. A logic diagram is a way of representing a circuit in a graphical way. Each gate is represented by a specific symbol. By connecting them in various ways we can represent an entire circuit this way. A truth table defines the function of a gate by listing all possible combinations of inputs and the output produced by each. The tables can have extra rows added to increase the complexity of the circuit they represent.

IB Computer Science - Computer Architecture

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: IB Computer Science - Computer Architecture

IB Computer Science

Topic 2 Computer Organisation

2.1 Computer Architecture

Computers are electronic devices; fundamentally the gates and circuits of the CPU control the flow of electricity. We harness this electricity to perform calculations and make decisions. Understanding the architecture of the computer is almost equal parts Computer Science and equal parts Electrical Engineering. Before going too deep into this part of the course, it is useful to have a fundamental understanding of how the binary number system works as this section explores how the computer use electric signals to represent and manipulate binary values.

Any given electric signal has a level of voltage. As we know binary consists of 2 values, 1 and 0 or high and low to think of it another way. The tricky thing is representing this in voltage. Computers consider a signal of between 0 and 2 volts to be “low” and therefore a 0 in binary. The voltage level between 2 and 5 is considered “high” and therefore is 1.

Gates are devices that perform basic operations on electrical signals. Gates can accept one or more inputs and produce a single output signal. Several types of gate exist but we will only consider the 6 fundamental types. Each gate performs a particular logical function.

Gates can be combined to create circuits. Circuits can perform one or more complicated tasks. For example, they could be designed to perform arithmetic and store values. In a circuit, the output value of one gate often becomes the input for another. The flow of electricity in circuits is controlled by these gates.

George Boole, a nineteenth century mathematician, invented a form of algebra in which functions and variables can only have 1 of 2 values(1 and 0). His notation is an elegant and powerful way to demonstrate the activity of electrical circuits. This algebra is appropriately named Boolean Algebra.

A logic diagram is a way of representing a circuit in a graphical way. Each gate is represented by a specific symbol. By connecting them in various ways we can represent an entire circuit this way.

A truth table defines the function of a gate by listing all possible combinations of inputs and the output produced by each. The tables can have extra rows added to increase the complexity of the circuit they represent.

Page 2: IB Computer Science - Computer Architecture

Gates

Gates are sometimes referred to as logic gates as they each perform a single logical operation. The type of gate determines the number of inputs and the corresponding output.

NOT Gate

This gate takes a single input and gives a single output. Below are three ways to represent the NOT gate, the truth table(Boolean notation), the logic diagram symbol(real and IB forms) and the Boolean expression. Note: the input in each case is A and the output is X. The NOT gate simply inverts the input it is given. As it only has one input, there are only 2 possibilities for input.

Boolean Expression Logic Diagram Symbol Truth Table

X = ‘A This is acceptable in IB However, the actual symbol is this:

A X 0 1 1 0

AND Gate

This gate differs from the NOT gate in many ways. Firstly it accepts two inputs. Both inputs have an influence on the output. If both inputs in the AND gate are 1, then the output is 1, otherwise the output is 0. Note the Boolean Algebra symbol for AND is ∙, sometimes an asterisk is used and at other times the symbol is ignored entirely e.g. X = AB

Boolean Expression Logic Diagram Symbol Truth Table

X = A ∙ B

In IB, this is acceptable But the actual symbol is this

A B X 0 0 0 0 1 0 1 0 0 1 1 1

NOT

AND

Page 3: IB Computer Science - Computer Architecture

OR Gate

Like the AND gate, the OR gate has 2 inputs. If both inputs are 0, then the output is 0. In all other cases the output is 1. The Boolean Algebra symbol for OR is +.

Boolean Expression Logic Diagram Symbol Truth Table

X = A + B

For IB, you can use this: However, the actual symbol is this:

A B X 0 0 0 0 1 1 1 0 0 1 1 1

XOR Gate

The eXclusive OR gate again uses 2 inputs. It behaves only very slightly differently to the OR Gate. It requires that only one of the inputs be 1 to produce an output of 1. If both are 0, the output is 0, the same when both inputs are 1. You can see the symbol for XOR is the symbol for OR inside a circle.

Boolean Expression Logic Diagram Symbol Truth Table

X = A ⊕ B

For IB, you can use this: However, the actual symbol is this:

A B X 0 0 0 0 1 1 1 0 1 1 1 0

NAND and NOR Gates

The final 2 gates we will look at are the NOR and NAND gates. Each accepts 2 inputs. They are essentially the opposite of AND and OR gates respectively. E.g they take the output produced by these gates and invert it.

OR

XOR

Page 4: IB Computer Science - Computer Architecture

NAND

Boolean Expression Logic Diagram Symbol Truth Table

X = (A ∙ B)’

For IB you can use this: However, the actual symbol is this:

A B X 0 0 1 0 1 1 1 0 0 1 1 0

NOR

Boolean Expression Logic Diagram Symbol Truth Table

X = (A + B)’

For IB, you can use: Bu the actual symbol is this:

A B X 0 0 1 0 1 0 1 0 0 1 1 0

You can see that there are no specific symbols for NAND and NOR gates in Boolean. We rely on the AND and OR expressions combined with a NOT to define them. You can also see that the Logic Diagram Symbols are like hybrids of AND or OR gates with a NOT. In fact, the circle before the output is known as the inversion bubble.

Outline the architecture of the central processing unit (CPU) and the functions of the arithmetic logic unit (ALU) and the control unit (CU) and the registers within the CPU.

Circuits

Circuits can be put into 2 categories, combinational and sequential. In a combinational circuit, the input values explicitly determine the output, in a sequential circuit, the output is a function of the input values as well as the existing state of the circuit, so sequential circuits usually involve the storage of some information.

NOR

NAND

Page 5: IB Computer Science - Computer Architecture

Combinational

Gates are combined into circuits, where the output of one gate is the input to another. Consider the following diagram:

You can see that the output of the AND gate(D, inputs A,B) is the first input to the OR gate, and the second input comes from the AND gate(E, inputs A,C). What this means is that for the overall output to be 1, either A∙B must be 1 or A∙C must be 1. We can represent this in a truth table like so, because there are three inputs to the system, there are eight possible combinations to consider:

A B C D(A∙B) E(A+B) X(A∙B + A∙C) 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 1 0 1 0 1 1 1 1 0 1 0 1 1 1 1 1 1 1

We can express this truth table as: (A∙B + A∙C)

The Boolean expression for the circuit is an interesting one, and one that we should look at more carefully. We could actually use some rules to generate an equivalent circuit. That’s the beauty of Boolean algebra, you can apply provable mathematical rules. These can be used to reduce the complexity of circuits. We can apply the distributive law:

(A∙B + A∙C) = A∙(B+C)

AND

AND

OR

A B

C

D

E

X

Page 6: IB Computer Science - Computer Architecture

Thus reducing the circuit to this:

If we look at the truth table for this circuit, it should prove the law:

A B C B+C A∙(B+C) 0 0 0 0 0 0 0 1 1 0 0 1 0 1 0 0 1 1 1 0 1 0 0 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1

The result in column 5, exactly matches the result in the previous truth table, proving the distributive law. Here are some other laws worth knowing about. You can try to prove them yourself by creating the truth tables.

Property AND OR Commutative A∙B = B∙A A+B = B+A

Associative (A∙B) ∙C = A∙(B∙C) (A+B) + C = A+(B+C) Distributive A∙(B+C) = A∙B + A∙C A+(B∙C) = (A+B) ∙ (A+C)

Identity A∙1 = A A+0 = A Complement A∙(A’) = 0 A+(A’)=1 De Morgan’s (A∙B)’ = A’ + B’ (A+B)’ = A’ ∙ B’

Adders

The most basic of operations a computer can perform is an addition. Fundamentally, this happens in binary, and the simplest of additions would be to add two binary digits together. Like addition in any number bas, there is the potential for a carry to take place. We can draw a truth table for the addition of two binary values:

A B Sum Carry 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1

AND

OR A

B C

X

Page 7: IB Computer Science - Computer Architecture

You can see that the sum column is the same as an XOR, whilst the Carry column matches the pattern for an AND. We can use this to construct the logic diagram for the adder:

This circuit will happily sum two single binary digits, but will not work for binary numbers of more than one digit as it takes not account of a carry in. It is in fact a half-adder, we can combine two of them to create a full-adder that takes account of a carry in.

It should also be noted that circuits play another important role: they can store information. These circuits form a sequential circuit, because the output of the circuit also serves as input to the circuit. E.g. the current state of the circuit is used in part to determine the next state. This is how memory is created.

Integrated circuits(chips) are pieces of silicon on which multiple gates have been embedded. The silicon is mounted on plastic and has pins that can be soldered onto circuit boards or inserted into appropriate sockets. The most important integrated circuit in the computer is the CPU.

The CPU

The CPU is essentially an advanced circuit with input and output lines. Each CPU chip contains multiple pins through which, all communication in a computer system takes place. The pins connect the CPU to memory and I/O devices, which at a fundamental level are actually circuits themselves.

Von Neumann Architecture

In 1944-1945 there was a realisation that the data and instructions needed to manipulate it were logically the same. This also meant that they could be stored in the same place. The computer design built upon this principle became known as the von Neumann architecture and is still the basis for computers today.

In this architecture there are some distinct features:

• There is a memory unit that holds both data and instructions • There is an arithmetic/logic unit that is capable of performing arithmetic and logic

operations on data • There is an input unit that moves data from the outside world into the computer • An output unit that can move results from inside the computer to the outside world • There is a control unit that acts like a conductor, ensuring all of components work in concert

XOR

OR

A

B

Sum

Carry

Page 8: IB Computer Science - Computer Architecture

The structure of such a computer might look something like this:

Arithmetic/Logic Unit(ALU)

This unit is capable of carrying out basic arithmetic such as adding, subtracting, dividing and multiplying 2 numbers. It is also capable of performing logic operations such as AND, OR and NOT. The ALU operates on ‘words’ a natural unit of data associated with a particular computer design. Historically, the ‘word length’ of a computer is the number of bits that can be processed at once by the ALU. It should be noted that Intel now define ‘word length’ as 16 bits and their processors can work with double words(32 bits) and quadwords(64 bits). We will use ‘word length’ in its traditional sense.

The ALU also has a small number of special storage units called registers. Registers can store one word temporarily. For example, consider the following calculation:

(value1 + value2) * (value3 + value4)

We know that the ALU can only deal with 2 numbers at one time, so the outcome of value1 + value2 needs to be stored before the ALU can add value3 and value4. Both outcomes are then required to do the multiplication. Rather than storing the values in memory and then having to retrieve them when required, the registers can be used to store the results and then retrieve them as necessary. Access to registers is much quicker than access to memory.

Control Unit

This is the organising force in the computer, it is in charge of the fetch-execute cycle(discussed further on in these notes). The control unit contains 2 special registers as you can see in the diagram, the PC –program counter and the IR- instruction register. The IR contains the current instruction being executed and the PC the address of the next instruction to be carried out.

Input Output CPU

Cache

Primary Memory

Control Unit Arithmetic/Logic Unit

MAR MDR

IR PC

Address bus

Data bus

Page 9: IB Computer Science - Computer Architecture

Buses

This diagram shows how a bus is used to allow data to flow through a von Neumann machine.

This is a very simplified view of how buses work. There are a number of different buses connecting each component. Buses allow data to travel throughout the computer. A bus is a collection of wires, meaning that if your bus is 16-bits wide, 16 bits can be transmitted at a single time. If your computer has a word length of 16 bits, then it is very helpful if your bus is the same width. If the bus was 8 bits wide for example, it would take two operations to move that data from memory to the ALU.

Buses can carry three types of information: data, address and control. Address information is sent to memory to tell it where to store data or where to retrieve it from. Address information might also indicate a device that data should be sent to. Data can then flow to memory and I/O from the CPU. Control information is used to manage the flow of address and data, typically the direction of the flow is managed in this way.

Address Bus and Data Bus

Buses are collections of wires through which data can be sent for example:

Single wire: 10011100 Destination

You can see that in order to send an 8-bit number through a single wire, you would have to do it sequentially, this means you would have to wait until the last bit arrived. By using a bus, a parallel group of wires, the data can be sent simultaneously, so it all arrives at the same time:

Bus

1 0 0 1 1 1 0 0

Destination

Input Devices Output Devices Main Memory CPU

Bus

Page 10: IB Computer Science - Computer Architecture

MAR/MDR

These are the Memory Address Register and Memory Data Register respectively. The MAR is where the CPU sends address information when writing to or reading from memory. The MAR specifies to memory where the data should go or come from. The MDR is where the CPU sends data to be stored in memory and where the data being read from memory arrives in the CPU. It may be more useful to see how these registers play a big part in the stored program concept or Fetch-Execute Cycle, a little later in these notes.

Cache

On the diagram you can see an area of cache connected to the CPU. Many modern CPU architectures make use of cache to speed things up. Cache is a small amount of fast access memory where copies of frequently used data are stored. This might be values that have been computed previously or duplicates of original values that are stored elsewhere. The cache will be checked before accessing primary memory, which is a time consuming process, as the buses tend to slow things down. The CPU will check the cache to see whether it contains the data required, if does then we get a cache hit and access to data without using the buses. If it doesn’t then access to primary memory becomes a necessity.

RAM or ROM?

As mentioned previously, RAM and primary memory are considered to be the same thing. RAM stores programs and data whilst they are in use by the CPU, otherwise they are kept in secondary storage(hard disk). RAM is memory in which each location can be accessed, as well as being able to access each location, the contents can also be changed.

You may want to visualise RAM like so:

Address Content 000 Instruction 001 Instruction 010 Instruction 011 End 100 Data 101 Data

Of course the data and instructions would be stored as binary, but you can see that the instructions are stored contiguously and the data in a separate section of memory. This is helpful in the machine instruction cycle, as we can simply increment the pointer that keeps the place of the next instruction to be executed.

The address is used to access a particular location in RAM, so the CPU needs to pass this information when it wants to read a location, and when it wants to write to a location.

Page 11: IB Computer Science - Computer Architecture

ROM has very different behaviour to RAM. ROM stands for Read Only Memory, this means that the contents of ROM cannot be altered. The content of ROM is permanent and cannot be changed by stored operations. The content of ROM is ‘burned’ either at the time of manufacture or when the computer is assembled.

RAM and ROM also differ in another basic property, RAM is volatile, ROM is not. This means that whatever is in the contents of RAM when the computer is switched off, will not be there when it is restarted. ROM retains its contents even when the machine is turned off. Because ROM is stable it is used to store the instructions that the computer needs to start itself(bootstrap loader). Other frequently used software can be stored in ROM so that it does not have to be read into memory each time the machine is turned on.

Primary memory is usually made up of a combination of both RAM and ROM.

Machine Instruction Cycle

A computer is a device that can store, retrieve and process data (remember the fundamental operations). Therefore all of the instructions it is given relate to these three operations. The underlying principle of the von Neumann machine is that data and instructions are stored in memory and treated alike. This means that both are addressable (see notes on primary memory). Instructions are stored in contiguous memory locations; the data to be manipulated is stored in a different part of memory. To start the Machine Instruction Cycle (Fetch-Execute Cycle) the address of the first instruction is loaded into the Program Counter. The cycle then follows 4 steps:

• Fetch the next instruction • Decode the instruction • Get data if needed • Execute the instruction

Of course each of these is an abstraction of what actually takes place, so let’s look at each in a little more detail.

Fetch the next instruction

The PC contains the address of the next instruction to be executed. So the address from the PC is loaded into the MAR in order to access that location in memory, the address information travels along the address bus to main memory. The control unit tells memory that the CPU wishes to read the instruction at the address specified by the address bus. Primary memory accesses the contents of that memory location and sends the data to the CPU along the data bus. It arrives in the MDR where it is quickly passed to the Instruction Register to be decoded. Before decoding takes place, the Control Unit updates the address held in the PC to ensure it is for the next instruction.

Decode the instruction

In order to execute the instruction held in the IR, it first must be decoded to determine what it is. It could be an instruction to access data, from an input device, send data to an output device or to perform an operation on a value. The instruction is decoded into control signals. The logic circuitry in

Page 12: IB Computer Science - Computer Architecture

the CPU determines which operation is to be executed. This shows why a computer can only execute machine language instructions that are written in its own native language.

Get Data if needed

If the instruction is to use the contents of a certain memory location and add them to the contents of a register, memory will have to be accessed again to get the contents of the memory location.

Execute Instruction

After being decoded and any data that is needed is accessed, the instruction can be executed. Execution usually involves the control unit sending signals to the appropriate part of the CPU or system. For example if the instruction is to add the values stored in 2 registers, the CU sends a signal to the ALU to do so. The next instruction might be to store the result in a register or even a memory location. After execution, the next instruction is fetched and the process begins all over again, until the last instruction has been executed.

A useful animated version of the Machine Instruction Cycle can be found here: