26
Introduction to Computer Systems Topics: Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives CMU Its Zip!” And gives Ithaca??

Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

Embed Size (px)

Citation preview

Page 1: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

Introduction to Computer Systems

Introduction to Computer Systems

Topics:Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book

15-213“The Class That Gives CMU Its Zip!”

And gives Ithaca??

Page 2: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 2 – COMP 210, S 15

Course ThemeCourse Theme Abstraction is good, but don’t forget reality!

Courses to date emphasize abstractionCourses to date emphasize abstraction Abstract data types (e.g., Comp 220) Asymptotic analysis (e.g., Comp 311)

These abstractions have limitsThese abstractions have limits Especially in the presence of bugs Need to understand underlying implementations Don’t believe what Ali says

Page 3: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 3 – COMP 210, S 15

Course ThemeCourse Theme

Useful outcomesUseful outcomes

Become more effective programmersAble to find and eliminate bugs efficientlyAble to tune program performance

Prepare for later “systems” classes Compilers, Operating Systems, Computer Networks, Computer

Architecture

Page 4: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 4 – COMP 210, S 15

Great Reality #1Great Reality #1

Information is Bits + ContextInformation is Bits + Context

ExamplesExamplesSource Program:

#include <stdio.h>

int main()

{

printf(“hello world\n”);

}

ASCII representation of the source program (text file):

# i n c l u d e <sp>

105 110 99 108 117 100 101 32

< s t d i o . h >

115 116 100 105 111 46 104 62

Etc….

Actual representation on the disk:

00100011 01101001 01100011 01101100 01110101 01100100 …

Page 5: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 5 – COMP 210, S 15

All information is represented as bitsAll information is represented as bits

Including disk files, programs in memory, user data in Including disk files, programs in memory, user data in memory, data transferred across the internet, …memory, data transferred across the internet, …

The only thing that distinguishes data objects is The only thing that distinguishes data objects is contextcontext

Same bits may represent an integer, floating-point number, character string, or machine instruction.

Page 6: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 6 – COMP 210, S 15

Great Reality #1 cont.Great Reality #1 cont.

IntInt’’s are not Integers, Floats are not Integers, Float’’s are not Realss are not Reals

Examples (see testint.c on arda in Examples/Student)Examples (see testint.c on arda in Examples/Student) Is x2 ≥ 0?

Float’s: Yes! Int’s:

» 40000 * 40000 --> 1600000000

» 50000 * 50000 --> ??

Is (x + y) + z = x + (y + z)?Unsigned & Signed Int’s: Yes!Float’s:

» (1e20 + -1e20) + 3.14 --> 3.14

» 1e20 + (-1e20 + 3.14) --> ??

-1794967296

0

see Student/Examples/chap1_mathProb.csee Student/Examples/chap1_mathProb.c

see Student/Examples/chap1_mathProb2.csee Student/Examples/chap1_mathProb2.c

Page 7: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 7 – COMP 210, S 15

Computer ArithmeticComputer Arithmetic

Does not generate random valuesDoes not generate random values Arithmetic operations have important mathematical

properties

Cannot assume “usual” propertiesCannot assume “usual” properties Due to finiteness of representations Integer operations satisfy “ring” properties

Commutativity, associativity, distributivity

Floating point operations satisfy “ordering” propertiesMonotonicity, values of signs

Page 8: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 8 – COMP 210, S 15

Computer ArithmeticComputer Arithmetic

ObservationObservation Need to understand which abstractions apply in which

contexts Important issues for compiler writers and serious

application programmers

Page 9: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 9 – COMP 210, S 15

Great Reality #2Great Reality #2

You’ve got to know assemblyYou’ve got to know assembly

Chances are, you’ll never write program in assemblyChances are, you’ll never write program in assembly Compilers are much better & more patient than you are

Understanding assembly key to machine-level execution modelUnderstanding assembly key to machine-level execution model Behavior of programs in presence of bugs

High-level language model breaks down Link-time errors hard to find

Tuning program performance Understanding sources of program inefficiency

Avoiding security holes Example: buffer overflow bugs

Implementing system software Compiler has machine code as target Operating systems must manage process state

Page 10: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 10 – COMP 210, S 15

CompilersCompilers

Programs are translated by other programs into Programs are translated by other programs into different formsdifferent forms A C program in text-file format must be translated in a low-

level binary format Humans can read the text-file Computers can read the binary Assembly is (basically) a human readable form of binary Translate source to binary in Unix by compiler driver:

unix> gcc –o hello hello.c

Page 11: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 11 – COMP 210, S 15

CompilersCompilers

Translation phases:Translation phases: Preprocessing phase. The preprocessor (cpp) modifies the

original C program according to directives that begin with # hello.c hello.i

Compilation phase. The compiler (ccl) translates the text file into a different text file containing an assembly level file. hello.i hello.s

Assembly phase. The assembler (as) translates the assembly file into a machine language (binary) format.

hello.s hello.o Linking phase. The linker (ld) merges separately compiled files,

libraries (like stdio), etc. into an executable object file that can be loaded into memory and run.

hello.0 printf.o hello

Page 12: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 12 – COMP 210, S 15

CompilersCompilers

Translation phases:Translation phases: figure 1.3

Pre-processor

(cpp)

hello.i Compiler(cc1)

hello.s Assembler(as)

hello.o Linker(ld)

hellohello.c

Sourceprogram

(text)

Modifiedsource

program(text)

Assemblyprogram

(text)

Relocatableobject

programs(binary)

Executableobject

program(binary)

printf.o

Page 13: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 13 – COMP 210, S 15

Executing programsExecuting programsProcessors Processors onlyonly understand binary programs understand binary programs

The hello.c program has been translated to the executable object file hello and stored on disk

To run, we type the program’s name:

unix> ./hello

hello world

unix> A shell loads and runs the program.

Page 14: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 14 – COMP 210, S 15

Executing programsExecuting programsOrganizationOrganization

To understand how the program is run, must understand how the hardware is organized.

Page 15: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 15 – COMP 210, S 15

Executing programsExecuting programsMotherboardMotherboard

Contains the processor, RAM, cache, bus interface

Page 16: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 16 – COMP 210, S 15

Executing programsExecuting programsCPUCPU

The “brains”

Page 17: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 17 – COMP 210, S 15

Executing programsExecuting programsOrganizationOrganization

We create abstract models of the hardware.

Page 18: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 18 – COMP 210, S 15

Executing programsExecuting programs Buses. Carry a number of bytes of information between

components. The number is a fundamental system parameter called a word.Example: Pentium word = 4 bytes; i7core = 8 bytes; embedded

controllers = 1 or 2 bytes.

Page 19: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 19 – COMP 210, S 15

Executing programsExecuting programsI/O Devices. The systemI/O Devices. The system’’s connection to the external s connection to the external

world.world.Example: keyboard, mouse, display, disk driveConnected to the I/O bus by either a controller or an adapter.Controllers are chip sets in the device or on the motherboard.Adapter is a card that plugs into a slot on the motherboard.

Disk controller

Graphicsadapter

USBcontroller

Disk

Page 20: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 20 – COMP 210, S 15

Executing programsExecuting programsMain Memory. A temporary storage device that holds Main Memory. A temporary storage device that holds

both a program and the data it manipulates. both a program and the data it manipulates. Consists of a collection of Dynamic Random Access Memory

(RAM) chips.Logically organized as a linear array of bytes, each with a unique

address. Instructions and data will take up a variable number of bytes in

RAM.

Mainmemory

Page 21: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 21 – COMP 210, S 15

Executing programsExecuting programsThe central processing unit (CPU). The engine that interprets (or The central processing unit (CPU). The engine that interprets (or

executes) instructions stored in main memory.executes) instructions stored in main memory. Consists of many electronic devices and small pieces of memory (registers):

» Control unit (CU)» Arithmetic/Logic Unit (ALU)» Program counter (PC) register that points at next instruction in main memory.» Other general and special purpose registers.

CU

Page 22: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 22 – COMP 210, S 15

Executing programsExecuting programsThe central processing unit (CPU). Continued.The central processing unit (CPU). Continued.

Performs the same basic tasks over and over again in a cycle (called the execution cycle)

» Fetch the next instruction from main memory» Decode (or interpret) the bits in the instruction» Executes the instruction» Update the PC to point at the next instruction

There are only a few simple operations (or instructions) that a processor can execute

Page 23: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 23 – COMP 210, S 15

Executing programsExecuting programsPutting it all together: running the Putting it all together: running the hellohello program program

When we type “./hello” the shell program reads each character and stores each into memory.

Mainmemory

I/O bridge

Bus interface

ALU

Register fileCPU

System bus Memory bus

Disk controller

Graphicsadapter

USBcontroller

MouseKeyboard DisplayDisk

I/O bus Expansion slots forother devices suchas network adapters

PC

"hello"

Usertypes

"hello"

Page 24: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 24 – COMP 210, S 15

Executing programsExecuting programsPutting it all together: running the Putting it all together: running the hellohello program program

When we hit the enter key, the shell loads the executable hello file by executing a sequence of instructions that copies the code and data from the disk to the memory. Uses DMA to

bypass the CPU

Mainmemory

I/O bridge

Bus interface

ALU

Register fileCPU

System bus Memory bus

Disk controller

Graphicsadapter

USBcontroller

MouseKeyboard DisplayDisk

I/O bus Expansion slots forother devices suchas network adapters

hello executable stored on disk

PC

hello code

"hello,world\n"

Page 25: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 25 – COMP 210, S 15

Executing programsExecuting programsPutting it all together: running the Putting it all together: running the hellohello program program

Now the CPU begins executing the instructions in the hello program.

» The program instructions copy the bytes in the string “hello world\n” from memory to the register file,

» then from there to the display device.

» The device displays the string on the screen.

» See next slide.

Page 26: Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book 15-213 “The Class That Gives

– 26 – COMP 210, S 15

Running the hello programRunning the hello program

Mainmemory

I/O bridge

Bus interface

ALU

Register file

CPU

System bus Memory bus

Disk controller

Graphicsadapter

USBcontroller

Mouse Keyboard Display

Disk

I/O bus Expansion slots forother devices suchas network adapters

hello executable stored on disk

PC

hello code

"hello,world\n"

"hello,world\n"