computer organization lecture 03

12
IT225: Computer Organizations August 25, 2014 (Monday) Lecture 3

Upload: skiloh1

Post on 19-Jul-2016

222 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Computer Organization Lecture 03

IT225: Computer Organizations

August 25, 2014 (Monday)Lecture 3

Page 2: Computer Organization Lecture 03

Overview Today

1.5 (metric units) Ch 2.1.1-2.1.4 (processors and CPU)

For Wednesday 2.1.5-2.1.6 (instruction-level parallelism, Processor-level

parallelism) 2.2.1-2.2. (memory) Homework #1 Due On Wednesday at 11:55pm Will need book for Homework #2 Carbon Nanotubes for CPU production https://www.youtube.com/watch?v=19nzPt62UPg https://www.youtube.com/watch?v=ikYhyjPjKBs

Page 3: Computer Organization Lecture 03

Metric Units

The principal metric prefixes.

NOTE: - Memory size is represented in “binary number” Therefore, 1MB is 1024 kilobytes, or 1048576 (1024x1024) bytes, not one million bytes - However, network bandwidth is represented in “decimal number”. Therefore, 1Mbps is 1000000bytes/second

Page 4: Computer Organization Lecture 03

CPU

• The brain of a computer is the central processing unit or CPU. This device contains all the circuitry that the computer needs to manipulate data and execute instructions. The CPU is amazingly small given the immense amount of circuitry it contains. The circuits of a computer are made of gates. Gates, however are also made of another tiny component called a transistor, and a modern CPU has millions and millions of transistors in its circuitry. The image to the below left shows just how compact a CPU can be.

• The CPU is composed of five basic components: RAM, registers, buses, the ALU, and the Control Unit. Each of these components are pictured in the diagram on the next page. The diagram shows a top view of a simple CPU with 16 bytes of RAM. To better understand the basic components of the CPU, we will consider each one in detail.

Page 5: Computer Organization Lecture 03

CPU

• RAM: this component is created from combining latches with a decoder. The latches create circuitry that can remember while the decoder creates a way for individual memory locations to be selected.

• Registers: these components are special memory locations that can be accessed very fast. Three registers are shown: the Instruction Register (IR), the Program Counter (PC), and the Accumulator.

• Buses: these components are the information highway for the CPU. Buses are bundles of tiny wires that carry data between components. The three most important buses are the address, the data, and the control buses.

• ALU: this component is the number cruncher of the CPU. The Arithmetic / Logic Unit performs all the mathematical calculations of the CPU. It is composed of complex circuitry similar to the adder presented in the previous lesson. The ALU, however, can add, subtract, multiply, divide, and perform a host of other calculations on binary numbers.

• Control Unit: this component is responsible for directing the flow of instructions and data within the CPU. The Control Unit is actually built of many other selection circuits such as decoders and multiplexors. In the diagram above, the Decoder and the Multiplexor compose the Control Unit.

http://courses.cs.vt.edu/csonline/MachineArchitecture/Lessons/CPU/sumprogram.html

Page 6: Computer Organization Lecture 03

How the CPU works

https://www.youtube.com/watch?v=B9ITn5IbMnU

https://www.youtube.com/watch?v=l019HZwGBnY

Page 7: Computer Organization Lecture 03

CPU• In order for a CPU to accomplish meaningful work, it must have two inputs: instructions and data. Instructions tell the CPU what actions need to be performed on the data. We have already seen how data is represented in the computer, but how do we represent

instructions? The answer is that we represent instructions with binary codes just like data. In fact, the CPU makes no distinction about the whether it is storing instructions or data in RAM. This concept is called the stored-program concept.

• Both inputs to the CPU are stored in memory, and the CPU functions by following a cycle of fetching an instruction, decoding it, and executing it. This process is known as the fetch-decode-execute cycle. The cycle begins when an instruction is transferred from memory to the IR along the data bus. In the IR, the unique bit patterns that make up the machine-language are extracted and sent to the Decoder. This component is responsible for the second step of the cycle, that is, recognizing which operation the bit pattern represents and activating the correct circuitry to perform the operation. Sometimes this involves reading data from memory, storing data in memory, or activating the ALU to perform a mathematical operation. Once the operation is performed, the cycle begins again with the next instruction. The CPU always knows where to find the next instruction because the Program Counter holds the address of the current instruction. Each time an instruction is completed, the program counter is advanced by one memory location.

Page 8: Computer Organization Lecture 03

CPU

a) Each machine instruction is composed of two parts: the op-code and the operand. According to Brookshear [1997], "the bit pattern appearing in the op-code field indicates which of the elementary operations, such as STORE or JUMP, is requested by the instruction. The bit patterns found in the operand field provide more detailed information about the operation specified by the op-code. For example, in the case of a STORE operation, the information in the operand field indicates which register contains the data to be stored and which memory cell is to receive the data." The image below shows the format of an instruction for our CPU. The first three bits represent the op-code and the final six bits represent the operand. The middle bit distinguishes between operands that are memory addresses and operands that are numbers. When the bit is set to '1', the operand represents a number. Notice that all the op-codes are given an English mnemonic to simplify programming. Together these mnemonics are called an assembly language. Programs written in assembly language must be converted to their binary representation before the CPU can understand them. This usually done by another program called an assembler, hence the name.

Page 9: Computer Organization Lecture 03

A simple machine languageOp-code Mnemonic Function Example

001 LOADLoad the value of the operand into the

Accumulator LOAD 10

010 STORE Store the value of the Accumulator at the address specified by the operand STORE 8

011 ADD Add the value of the operand to the Accumulator ADD #5

100 SUB Subtract the value of the operand from the Accumulator SUB #1

101 EQUAL If the value of the operand equals the value of the Accumulator, skip the next instruction EQUAL #20

110 JUMP Jump to a specified instruction by setting the Program Counter to the value of the operand JUMP 6

111 HALT Stop execution HALT

•In the machine language to the right, notice that some of the operands include a # symbol. This symbol tells the CPU that the operand represents a number rather than a memory address. Thus, when the assembler translates an instruction with a # symbol, the resulting machine code will have a '1' in the position of the number bit. Also notice the central role that the Accumulator register plays. Nearly all the operations affect the value of this register since the Accumulator acts as a temporary memory location for storing calculations in progress. With our machine language defined, we are ready to take a look at some simple programs.

Page 10: Computer Organization Lecture 03

Sum Program

•The first program is called Sum. This program adds the numbers stored in two memory locations. Mathematically, this program represents the formulas x = 2, y = 5, x + y = z where the variables x, y, and z correspond with the memory locations 13, 14, and 15 respectively. The instructions for the program are listed below. Read through the program, and then view the animation of this program by clicking the "View Animation" link.

•http://courses.cs.vt.edu/csonline/MachineArchitecture/Lessons/CPU/sumprogram.html

# Machine code Assembly code Description

0 001 1 000010 LOAD   #2 Load the value 2 into the Accumulator

1 010 0 001101 STORE  13 Store the value of the Accumulator in

memory location 13

2 001 1 000101 LOAD   #5 Load the value 5 into the Accumulator

3 010 0 001110 STORE  14 Store the value of the Accumulator in

memory location 14

4 001 0 001101 LOAD   13 Load the value of memory location 13 into

the Accumulator

5 011 0 001110 ADD    14 Add the value of memory location 14 to

the Accumulator

6 010 0 001111 STORE  15 Store the value of the Accumulator in

memory location 15

7 111 0 000000 HALT      Stop execution

Page 11: Computer Organization Lecture 03

Count Program

•The second program is called Count. This program counts up to a number specified by the programmer in the first instruction. Notice that this program incorporates a loop construction by using the JUMP and EQUAL instructions. Every time the value in the Accumulator is incremented, the count is tested to see if it has reached the specified amount.

•http://courses.cs.vt.edu/csonline/MachineArchitecture/Lessons/CPU/countprogram.html

# Machine code Assembly code Description

0 001 1 000101 LOAD   #5

These two operations set the count value to five

1 010 0 001111 STORE  15

2 001 1 000000 LOAD   #0 Initialize the count to zero

3 101 0 001111 EQUAL  15

Test to see if count is complete; if yes, skip next instruction and go to instruction

5; if no, go to next instruction

4 110 1 000110 JUMP   #6 Set Program Counter to 6

5 111 0 000000 HALT     Stop execution

6 011 1 000001 ADD    #1 Increment the count in the Accumulator

7 110 1 000011 JUMP   #3 Set Program Count to 3

Page 12: Computer Organization Lecture 03

Conclusion