Introduction to Computer Science
CSCI 109
Andrew Goodney
Spring 2018
China – Tianhe-2
Readings
- St. Amant, Ch. 3
Introduction to Computer Science CSCI 109 Readings St. Amant, Ch. - - PowerPoint PPT Presentation
Introduction to Computer Science CSCI 109 Readings St. Amant, Ch. 3 China Tianhe-2 Andrew Goodney Spring 2018 Lecture 2: Architecture Jan 22 nd , 2018 Reminders u Take the survey if you havent already v
Spring 2018
China – Tianhe-2
uTake the survey if you haven’t already
v https://usc.qualtrics.com/jfe/form/SV_0dKlS7wjGvUMiGh
uWork on HW #1. It is due 1/29. uQuiz #1 is on 1/29. It will cover material taught
1
2
uThe von Neumann architecture uThe Central Processing Unit (CPU) uStorage uInput and Output
3
4
5
u Controller + ALU = Central Processing Unit (CPU) u CPU has a small amount of temporary memory within it
v Registers v A special register called the program counter (PC)
u CPU performs the following cycle repeatedly
u Read an instruction from memory u Direct ALU to do some arithmetic or logic operation u Transfer data from one place to another u Prepare for next instruction to be read u Send a directive to input or output device
6
Input Output Controller Arithmetic and Logic Unit Memory
u Perform an arithmetic operation on the contents of
u Perform a logical operation on the contents of registers
7
Input Output Controller Arithmetic and Logic Unit Memory
u Faster clock (~GHz on modern computers) u Specialized ALU (e.g., GPU) or more than one ALU u Multiprocessing (more than one CPU) u Streamlining Controller-ALU cooperation (pipelining) u More complex ALU instructions ?
8
Input Output Controller Arithmetic and Logic Unit Memory
u How is storage organized ? u Linear ordering v Each stored item has a an address (which is a number) v To retrieve an item you have to know this number v Retrieval is by address
9
Input Output Controller Arithmetic and Logic Unit Memory
u Analogy with office files v Each (physical) file has a number v When a file is needed, you ask for it by number v In the office, files may be stored in shelves, on tables,
u Storage is modular: as long as the person who wants
u Or where they are stored: Files may be stored in a
10
u Only one item can be stored at one memory location u Random access (RAM) – all locations in memory are (on
u Storage is hierarchical
11
Input Output Controller Arithmetic and Logic Unit Registers Disk RAM CPU Input Output Controller Arithmetic and Logic Unit Memory
12
Input Output Controller Arithmetic and Logic Unit Registers Disk RAM CPU
Registers RAM (memory) Secondary Storage (Disk Space)
Cheaper Faster
u Volatile: memory is erased when power turned off v Registers, RAM (often called primary storage) u Non-volatile: memory intact when power turned off v Secondary storage (disk) u Booting and ROM (read-only memory) u Cache: small, fast memory between registers and RAM
13
Input Output Controller Arithmetic and Logic Unit Registers CPU Disk RAM Cache Input Output Controller Arithmetic and Logic Unit Registers Disk RAM CPU
u Small (but bigger than registers) u Volatile u Fast (not as fast as registers, but faster than RAM) u What to keep in the cache ? v Things that programs are likely to need in the future v Locality principle:
u Look at what items in memory are being used u Keep items from nearby locations (spatial locality) u Keep items that were recently used (temporal locality)
14
u Input: Interrupt-driven
v e.g., Key strokes are slow, CPU treats them like special
u Output: Write to special memory (e.g., video memory)
15
Input Output Controller Arithmetic and Logic Unit Registers CPU Disk RAM Cache
u Adding four numbers in C is easy
u Equivalent assembly code
u Which one is better ? Are the two equivalent ?
16
u C code
u Assembly code
u Machine code 00000010001100100100000000100000
17
u C code
u Assembly code
u Machine code 00000010001100100100000000100000
18
u ADD Ri Rj Rk
Add contents of registers Ri and Rj and put result in register Rk
u SUBTRACT Ri Rj Rk
Subtract register Rj from register Ri and put result in register Rk
u AND Ri Rj Rk
Bitwise AND contents of registers Ri, Rj and put result in register Rk
u NOT Ri
Bitwise NOT the contents of register Ri
u OR Ri Rj Rk
Bitwise OR the contents of registers Ri, Rj and put result in register Rk
u SET Ri value
Set register Ri to given value
u SHIFT-LEFT Ri
Shift bits of register Ri left
u SHIFT-RIGHT Ri
Shift bits of register Ri right
u MOVE Ri Rj
Copy contents from register Ri to register Rj
u LOAD Mi Ri
Copy contents of memory location Mi to register Ri
u WRITE Ri Mi
Copy contents of register Ri to memory location Mi
u GOTO Mi
Jump to instruction stored in memory location Mi
u COND_GOTO Ri Rj Mi
If Ri > Rj and R2, jump to instruction stored in memory location Mi
19
u Central processing: Connie and Alun u The bus: Buster u Storage (Memory): Mr. Lager u Input and output
20
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END What does this program do?
PC R1 R2 R3 R4 R5 R6 M1 M2 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3 M106 2 1 3 2 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3 M106 2 1 3 2 3 M107 2 3 1 3 2 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3 M106 2 1 3 2 3 M107 2 3 1 3 2 3 M108 2 3 1 3 2 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3 M106 2 1 3 2 3 M107 2 3 1 3 2 3 M108 2 3 1 3 2 3 M104 2 3 1 5 2 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3 M106 2 1 3 2 3 M107 2 3 1 3 2 3 M108 2 3 1 3 2 3 M104 2 3 1 5 2 3 M105 2 3 1 5 1 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3 M106 2 1 3 2 3 M107 2 3 1 3 2 3 M108 2 3 1 3 2 3 M104 2 3 1 5 2 3 M105 2 3 1 5 1 3 M106 1 3 1 5 1 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3 M106 2 1 3 2 3 M107 2 3 1 3 2 3 M108 2 3 1 3 2 3 M104 2 3 1 5 2 3 M105 2 3 1 5 1 3 M106 1 3 1 5 1 3 M107 1 5 1 5 1 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3 M106 2 1 3 2 3 M107 2 3 1 3 2 3 M108 2 3 1 3 2 3 M104 2 3 1 5 2 3 M105 2 3 1 5 1 3 M106 1 3 1 5 1 3 M107 1 5 1 5 1 3 M108 1 5 1 5 1 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3 M106 2 1 3 2 3 M107 2 3 1 3 2 3 M108 2 3 1 3 2 3 M104 2 3 1 5 2 3 M105 2 3 1 5 1 3 M106 1 3 1 5 1 3 M107 1 5 1 5 1 3 M108 1 5 1 5 1 3 M104 1 5 1 6 1 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3 M106 2 1 3 2 3 M107 2 3 1 3 2 3 M108 2 3 1 3 2 3 M104 2 3 1 5 2 3 M105 2 3 1 5 1 3 M106 1 3 1 5 1 3 M107 1 5 1 5 1 3 M108 1 5 1 5 1 3 M104 1 5 1 6 1 3 M105 1 5 1 6 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3 M106 2 1 3 2 3 M107 2 3 1 3 2 3 M108 2 3 1 3 2 3 M104 2 3 1 5 2 3 M105 2 3 1 5 1 3 M106 1 3 1 5 1 3 M107 1 5 1 5 1 3 M108 1 5 1 5 1 3 M104 1 5 1 6 1 3 M105 1 5 1 6 3 M106 5 1 6 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3 M106 2 1 3 2 3 M107 2 3 1 3 2 3 M108 2 3 1 3 2 3 M104 2 3 1 5 2 3 M105 2 3 1 5 1 3 M106 1 3 1 5 1 3 M107 1 5 1 5 1 3 M108 1 5 1 5 1 3 M104 1 5 1 6 1 3 M105 1 5 1 6 3 M106 5 1 6 3 M107 6 1 6 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3 M106 2 1 3 2 3 M107 2 3 1 3 2 3 M108 2 3 1 3 2 3 M104 2 3 1 5 2 3 M105 2 3 1 5 1 3 M106 1 3 1 5 1 3 M107 1 5 1 5 1 3 M108 1 5 1 5 1 3 M104 1 5 1 6 1 3 M105 1 5 1 6 3 M106 5 1 6 3 M107 6 1 6 3 M108 6 1 6 3
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3 M106 2 1 3 2 3 M107 2 3 1 3 2 3 M108 2 3 1 3 2 3 M104 2 3 1 5 2 3 M105 2 3 1 5 1 3 M106 1 3 1 5 1 3 M107 1 5 1 5 1 3 M108 1 5 1 5 1 3 M104 1 5 1 6 1 3 M105 1 5 1 6 3 M106 5 1 6 3 M107 6 1 6 3 M108 6 1 6 3 M109 6 1 6 3 6
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3 M106 2 1 3 2 3 M107 2 3 1 3 2 3 M108 2 3 1 3 2 3 M104 2 3 1 5 2 3 M105 2 3 1 5 1 3 M106 1 3 1 5 1 3 M107 1 5 1 5 1 3 M108 1 5 1 5 1 3 M104 1 5 1 6 1 3 M105 1 5 1 6 3 M106 5 1 6 3 M107 6 1 6 3 M108 6 1 6 3 M109 6 1 6 3 6 M110 6 1 6 3 6
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
PC R1 R2 R3 R4 R5 R6 M1 M2 3 M100 3 3 M101 3 3 M102 3 1 3 M103 3 1 3 M104 3 1 3 3 M105 3 1 3 2 3 M106 2 1 3 2 3 M107 2 3 1 3 2 3 M108 2 3 1 3 2 3 M104 2 3 1 5 2 3 M105 2 3 1 5 1 3 M106 1 3 1 5 1 3 M107 1 5 1 5 1 3 M108 1 5 1 5 1 3 M104 1 5 1 6 1 3 M105 1 5 1 6 3 M106 5 1 6 3 M107 6 1 6 3 M108 6 1 6 3 M109 6 1 6 3 6 M110 6 1 6 3 6
M100 SET R1 MI M101 SET R2 0 M102 SET R3 1 M103 SET R6 0 M104 ADD R1 R2 R4 M105 SUB R1 R3 R5 M106 MOVE R5 R1 M107 MOVE R4 R2 M108 COND_GOTO R1 R6 104 M109 WRITE R2 M2 M110 END
45
u 8008 – Intel 1971
46
u 8080 – Intel 1974
47
u 6502 – MOS Tech. (later Commodore)
v Used in Atari 2600, Apple II, many others
48
u M68000 – Motorola 1979
v Used in Apple Macintosh, many, many others
49
u Intel Core i7 - current
50