Anda di halaman 1dari 22

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Introduction to Computing Systems:


From Bits and Gates to C and Beyond
2nd Edition

Yale N. Patt Sanjay J. Patel


Original slides from Gregory Byrd, North Carolina State University Modified by Chris Wilcox, S. Rajopadhye Colorado State University

CS270 Spring 2012 - Colorado State University

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Lecture Goals
! Review course logistics
n n n n

Assignments Policies Organization Grading Criteria Role of Abstraction Software versus Hardware Universal Computing Devices Layered Model of Computing

! Introduce key concepts


n n n n

CS270 Spring 2012 - Colorado State University

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Logistics
! Lectures: Tue and Thu from 9:30-10:45 in Glover 130 ! Recitations: Tue 11:00-11:50, 1:00-1:50, Wed 11:00-11:50 in CSB 215 ! Exams:
n

One midterm in class (1 page notes, no calculator, no electronic aid) final on Wednesday May 9 6:20-8:20 in class (same rules) http://www.cs.colostate.edu/~cs270 http://ramct.colostate.edu
CS270 Spring 2012 - Colorado State University 3

! Materials on the website and RamCT:


n n

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Name cards
! Fold your card LENGTHWISE so that it can be placed on your desk ! Neatly write your name (how you want to be addressed) in BIG, BOLD LETTERS, using the markers that are circulating ! Prop it up on your desk so that it can be seen from the front of the classroom

CS270 Spring 2012 - Colorado State University

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Instructor
! Name: Sanjay Rajopadhye ! Pronunciation (optional): In Indian names, a is almost always pronounced as a short u sound as in gun, fun, etc., or a long aa sound as in calm, bard, etc. ! Sanjay is pronounced as Sun-juy ! Rajopadhye Raaj-Oh-paath-yay (in the paath make the t sound like a d). Dont worry if you dont get it right, its almost always mispronounced, even in India). ! These pronunciation rules are used in many parts of Asia, e.g., pronounce Bagdad? ! Interesting fact: Everyone in my family was born in a different country
CS270 Spring 2012 - Colorado State University 5

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

TeachingAssistant
! Name: Nirmal Prajapati ! Call me: Nirmal (like normal, but with an i) ! Pronunciation (optional): nearly normal Nirmal ! Major: Computer Science (Ph.D., 1st year) ! Interesting fact:

CS270 Spring 2012 - Colorado State University

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Assignments
Assignments and quizzes are posted on RamCT: ! Weekly assignments combination of written and programming assignments ! Written (hardcopy) assignments are due Thursday at 9:30 pm (start of class) ! Programming assignments are submitted in electronic form Mondays at 5:00 PM. ! Reading Quizzes are online, the due date is Monday at 11:59pm

CS270 Spring 2012 - Colorado State University

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Policies
! Grading Criteria
n n n n n

Homework Assignments (45%) Reading Quizzes (5%) Recitations (5%) Midterm Exam (20%) Final Exam (25%) Accepted up to 48 hours after posted date with 10% penalty per 24 hrs delay Not accepted after 48 hr delay http://www.cs.colostate.edu/~info/student-info.html Be smart about Spring 2012 - Colorado State University CS270 Internet resources

! Late Policy
n

! Academic Integrity
n n 8

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Organization
! 1/3 computer hardware: numbers and bits, transistors, gates, digital logic, state machines, von Neumann model, instruction sets, LC-3 architecture ! 1/3 assembly code: instruction formats, branching, control, LC-3 programming, I/O, subroutines, memory model ! 1/3 C programming: data types, language syntax, variables and operators, control structures, functions, pointers and arrays, memory model, recursion, I/O, data structures
CS270 Spring 2012 - Colorado State University 9

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Grading Criteria
How to be successful in this class: 1) Attend all classes and recitations, information will presented that you cant get anywhere else. 2) Do all the homework assignments, ask questions (early!) if you run into trouble. 3) Read the textbook, take the quizzes, work through the end of chapter problems. 4) Use office hours

CS270 Spring 2012 - Colorado State University

10

Chapter 1 Welcome Aboard

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Introduction to the World of Computing


! Computer: electronic genius?
n n

NO! Electronic idiot! Does exactly what we tell it to, nothing more. You will be able to understand how computers are built, and write programs in C and understand what s going on underneath. Build understanding from the bottom up. Bits Transistors Gates Logic Processor Instructions Assembly Code C Programming
CS270 Spring 2012 - Colorado State University 12

! Goal of the course:


n

! Approach:
n n

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Two Recurring Themes


! Abstraction
n

Productivity enhancer dont need to worry about details Can drive a car without knowing how the internal combustion engine works. until something goes wrong! Where s the dipstick? What s a spark plug? Important to understand the components and how they work together.
CS270 Spring 2012 - Colorado State University 13

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Two Recurring Themes


! Hardware vs. Software
n

It s not either/or both are components of a computer system that cooperate. Even if you specialize in one, you should understand capabilities and limitations of both. The best programmers understand the computer systems which run their programs. Computers are an entire ecosystem with multiple levels of abstraction.

CS270 Spring 2012 - Colorado State University

14

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Big Idea #1: Universal Computing Devices


! All computers, given enough time and memory, are capable of computing exactly the same things.

=
PDA Workstation

=
Supercomputer
15

CS270 Spring 2012 - Colorado State University

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Turing Machine
! Mathematical model of a device that can perform any computation Alan Turing (1937)
n n

ability to read/write symbols on an infinite tape state transitions, based on current state and symbol

! Every computation can be performed by some Turing machine. (Turing s thesis)


a,b

Tadd

a+b

a,b

Tmul

ab

Turing machine that adds


For more info about Turing machines, see http://www.wikipedia.org/wiki/Turing_machine/

Turing machine that multiplies


For more about Alan Turing, see http://www.turing.org.uk/turing/
16

CS270 Spring 2012 - Colorado State University

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Universal Turing Machine


! A machine that can implement all Turing machines -- this is also a Turing machine!
n

inputs: data, description of computation (other TMs)


Tadd, Tmul a,b,c

c(a+b)

Universal Turing Machine

Universal machine is programmable so is a computer!


instructions are part of the input data a computer can emulate a Universal Turing Machine

A computer is a universal computing device.


CS270 Spring 2012 - Colorado State University 17

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

From Theory to Practice


! In theory, computer can compute anything ! that s possible to compute
n

given enough memory and time

! In practice, solving problems involves computing under constraints.


n

time
! weather forecast, next frame of animation, ...

cost
! cell phone, automotive engine controller, ...

power
! cell phone, handheld video game, ...
CS270 Spring 2012 - Colorado State University 18

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Big Idea #2: Transformations Between Layers


Problems Algorithms Language Instruction Set Architecture Microarchitecture Circuits Devices
CS270 Spring 2012 - Colorado State University 19

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

! A systematic sequence of transformations between layers of abstraction. Problem

How do we solve a problem using a computer?

Software Design: choose algorithms and data structures Algorithm Programming: use language to express design Program
Instr Set Architecture

Compiling/Interpreting: convert language to machine instructions


CS270 Spring 2012 - Colorado State University 20

10

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Deeper and Deeper


Instr Set Architecture

Processor Design: choose structures to implement ISA Microarch Logic/Circuit Design: gates and low-level circuits to implement components Process Engineering & Fabrication: develop and manufacture lowest-level components
CS270 Spring 2012 - Colorado State University 21

Circuits

Devices

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Descriptions of Each Level


! Problem Statement
n n

stated using "natural language" may be ambiguous, imprecise step-by-step procedure, guaranteed to finish definiteness, effective computability, finiteness express the algorithm using a computer language high-level language, low-level language specifies the set of instructions the computer can perform data types, addressing mode
CS270 Spring 2012 - Colorado State University 22

! Algorithm
n n

! Program
n n

! Instruction Set Architecture (ISA)


n n

11

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Descriptions of Each Level (cont.)


! Microarchitecture
n n

detailed organization of a processor implementation different implementations of a single ISA combine basic operations to realize microarchitecture many different ways to implement a single function (e.g., addition) properties of materials, manufacturability

! Logic Circuits
n n

! Devices
n

CS270 Spring 2012 - Colorado State University

23

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Many Choices at Each Level


Solve a system of equations
Red-black SOR Gaussian elimination C Intel x86 Pentium 4 C++ Jacobi iteration Java Atmel AVR Xeon Multigrid

FORTRAN PowerPC Centrino

Tradeoffs: cost speed power (etc.)

Ripple-carry adder CMOS Bipolar

Carry-lookahead adder GaAs


24

CS270 Spring 2012 - Colorado State University

12

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Book Outline
! Bits and Bytes
n

How do we represent information using electrical signals? How do we build circuits to process information? How do we build a processor out of logic elements? What operations (instructions) will we implement? How do we use processor instructions to implement algorithms? How do we write modular, reusable code? (subroutines) How does processor communicate with outside world? How do we write programs in C?
CS270 Spring 2012 - Colorado State University 25

! Digital Logic
n

! Processor and Instruction Set


n n

! Assembly Language Programming


n n

! I/O, Traps, and Interrupts


n

! C Programming
n

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Our Outline (CSU tweak)


! First C programming
n n

You already know how to program in Java Learning C will be much faster than the book s speed (Ch 11-13) Digital Logic Processor & Instruction Set Assembly Language Programming I/O, Traps, Interrupts Functions, procedures, activations/frames, etc. Reinforcement of ideas Second look at the same ideas

! Follow the text sequentially


n n n n n

! Write a LC3 simulator and LC3 assembler in C


n n

CS270 Spring 2012 - Colorado State University

26

13

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

How to succeed in this class


1) Most university classes require two to three times the contact hours. 2) So a 15 credit student should spend 60 hours in school related activity.
1) 2)

Yeah right!!! BUT ITS TRUE ABOUT THIS CLASS 30 mins Quiz 4 hrs contact hours 30 mins review class notes (15 x 2) 8-11 hrs assignments
CS270 Spring 2012 - Colorado State University 27

3) Time management:
1) 2) 3) 4)

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Before next lecture


Read the notes at:

http://www.cs.colostate.edu/~cs270/.Spring12/Notes/ NumberSystems.pdf

Spend 1 hour on it.

CS270 Spring 2012 - Colorado State University

28

14

Chapter 2 Bits, Data Types, and Operations

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

How do we represent data in a computer?


!
n

At the lowest level, a computer is an electronic machine.


works by controlling the flow of electrons

Easy to recognize two conditions:


1. presence of a voltage we ll call this state 1 2. absence of a voltage we ll call this state 0

!
n

Could base state on value of voltage, but control and detection circuits more complex.
compare turning on a light switch to measuring or regulating voltage
CS270 Spring 2012 - Colorado State University 30

15

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Computer is a binary digital system.


Digital system:
finite number of symbols

Binary (base two) system:


has two states: 0 and 1

! Basic unit of information is the binary digit, or bit. ! Values with >2 states require multiple bits.
n

A collection of two bits has four possible states: 00, 01, 10, 11 A collection of three bits has eight possible states: 000, 001, 010, 011, 100, 101, 110, 111 A collection of n bits has 2n possible states.
CS270 Spring 2012 - Colorado State University 31

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

What kinds of data do we need to represent?


n n n n n n n

Numbers signed, unsigned, integers, floating point, complex, rational, irrational, Text characters, strings, Logical true, false Images pixels, colors, shapes, Sound waveforms Instructions representation and operations within the computer

! Data type:
n

! We ll start with numbers


CS270 Spring 2012 - Colorado State University 32

16

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Unsigned Integers
! Non-positional notation
n

could represent a number ( 5 ) with a string of ones ( 11111 ) problems? like decimal numbers: 329 3 is worth 300, because of its position, while 9 is only worth 9

! Weighted positional notation


n n

329
102 101 100
3x100 + 2x10 + 9x1 = 329

most significant

101
21

least significant

22

20

1x4 + 0x2 + 1x1 = 5


33

CS270 Spring 2012 - Colorado State University

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Seen on a geek T Shirt


! There are only 10 kinds of people ! Those that know binary ! Those that don t

CS270 Spring 2012 - Colorado State University

34

17

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Unsigned Integers (cont.)


! An n-bit unsigned integer represents 2n values: from 0 to 2n-1.
22 0 0 0 0 1 1 1 1 21 0 0 1 1 0 0 1 1 20 0 1 0 1 0 1 0 1 0 1 2 3 4 5 6 7
35

CS270 Spring 2012 - Colorado State University

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Unsigned Binary Arithmetic


! Base-2 addition just like base-10!
n

add from right to left, propagating carry

10010 + 1001 11011

10010 + 1011 11101 10111 + 111

1111 + 1 10000

Subtraction, multiplication, division,


CS270 Spring 2012 - Colorado State University 36

18

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Signed Integers
! With n bits, we have 2n distinct values.
n n n

assign about half to positive integers (1 through 2n-1) assign about half to negative (- 2n-1 through -1) that leaves two values: one for 0, and one extra just like unsigned zero in most significant (MS) bit 00101 = 5 sign-magnitude set sign bit to show negative 10101 = -5 one s complement flip every bit to represent negative 11010 = -5 in either case, MS bit indicates sign: 0=pos., 1=neg.
CS270 Spring 2012 - Colorado State University 37

! Positive integers
n

! Negative integers
n

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Two s Complement
! Problems with sign-magnitude, 1 s complement
n n

two representations of zero (+0 and 0) arithmetic circuits are complex ! How to add two sign-magnitude numbers?
n

e.g., try 2 + (-3) e.g., try 4 + (-3)

! How to add two one s complement numbers?


n

CS270 Spring 2012 - Colorado State University

38

19

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Two s Complement
! Two s complement representation developed to make circuits easy for arithmetic.
n

for each positive number (X), assign value to its negative (-X), such that X + (-X) = 0 with normal addition, ignoring carry out

00101 (5) + 11011 (-5) 00000 (0)

01001 (9) +
(-9) 00000 (0)

CS270 Spring 2012 - Colorado State University

39

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Two s Complement Representation


! If number is positive or zero,
n

normal binary representation, zeroes in upper bit(s) start with positive number flip every bit (i.e., take the one s complement) then add one

! If number is negative,
n n n

00101 (5) 11010 (1 s comp) + 1 11011 (-5)

01001 (9)
(1 s comp)

1
(-9)
40

CS270 Spring 2012 - Colorado State University

20

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Two s Complement Shortcut


! To take the two s complement of a number:
n n

copy bits from right to left until (and including) first 1 flip remaining bits to the left

011010000 100101111 + 1 100110000

011010000
(1 s comp) (flip) (copy)

100110000

CS270 Spring 2012 - Colorado State University

41

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Two s Complement Signed Integers


! MS bit is sign bit it has weight 2n-1. ! Range of an n-bit number: -2n-1 through 2n-1 1.
n

The most negative number has no positive counterpart.


22 0 0 0 0 1 1 1 1 21 0 0 1 1 0 0 1 1 20 0 1 0 1 0 1 0 1 0 1 2 3 4 5 6 7 -23 1 1 1 1 1 1 1 1 22 0 0 0 0 1 1 1 1 21 0 0 1 1 0 0 1 1 20 0 1 0 1 0 1 0 1 -8 -7 -6 -5 -4 -3 -2 -1
42

-23 0 0 0 0 0 0 0 0

CS270 Spring 2012 - Colorado State University

21

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Converting Binary (2 s C) to Decimal


1. If leading bit is one, take two s complement to get a positive number. 2. Add powers of 2 that have 1 in the corresponding bit positions. 3. If original number was negative, add a minus sign. X = 01101000two = 26+25+23 = 64+32+8 = 104ten
Assuming 8-bit 2 s complement numbers.
CS270 Spring 2012 - Colorado State University 43

n 2n
0 1 2 3 4 5 6 7 8 9 10 1 2 4 8 16 32 64 128 256 512 1024

22

Anda mungkin juga menyukai