800 likes | 988 Views
COMPSCI 210S1C 2014 Computer Systems 1 Introduction. Lecture 1. Introduction & Layers. Computer Science 210 s1c Computer Systems 1 2014 Semester 1 Lecture Notes. James Goodman (revised by Robert Sheehan). Lecturers Robert Sheehan (week 1-6) Office 303.488
E N D
Lecture 1 Introduction & Layers Computer Science 210 s1cComputer Systems 12014Semester 1Lecture Notes James Goodman (revised by Robert Sheehan)
Lecturers • Robert Sheehan (week 1-6) • Office 303.488 • E-mail: r.sheehan@auckland.ac.nz • Office hours: by appointment, after class, or whenever the office door is open • Xinfeng Ye (week 7-12) • Office 303.589 • E-mail: xinfeng@cs.auckland.ac.nz • Office hours: Tutors • Ahmad Obidat • a.obidat@auckland.ac.nz • Office hours: TBA • Class Representative TBD (volunteers?) • ArashHeidarian • ahei844@aucklanduni.ac.nz • Office hours: TBA
Forum We are using the Cecil discussion list. • Check it as often as you want. • The tutor/s will be regularly participating. I follow the discussion area of Cecil irregularly and participate as appropriate but likely not as quickly as the tutors. • Tutors Are available to help 4
Tutorials • Tutorials are not compulsory but are strongly recommended. All tutorials will start from week. • 9:00-10:00, Monday, 303S-191 (N.B. different room) • 10:00-11:00, Monday, 303S-G75 • 13:00-14:00, Monday, 303S-G75 • 16:00-17:00, Monday, 303S-G75 • 12:00-13:00, Tuesday, 303S-G75 • 17:00-18:00, Tuesday, 303S-G75 • 13:00-14:00, Wednesday, 303S-G75 • Tutor's office hours? • Tutorials will be available online • Lecture recordings in the Knowledge Map area of Cecil
Miscellaneous Come to class . It is very dangerous to fall behind. • Each new lecture will require you to know and understand the content of the previous lectures. • Lectures are tied to the content of the textbook. It is important to read the textbook – exam questions may require more detail than is covered in the lectures. • Tutorials are a great way to supplement lectures • Outside office hours and tutorials, tutors are not expected to be at hand
Course Outline • Bits and Bytes • How do we represent information using electrical signals? • Digital Logic • How do we build circuits to process information? • Computing Engines, Processors and Instruction Sets • How do we build a processor out of logic elements? • What operations (instructions) will we implement? • Assembly Language Programming • How do we use processor instructions to implement algorithms? • How do we write modular, reusable code? (subroutines) • I/O, Traps, and Interrupts • How does a processor communicate with the outside world? • C Programming • How do we write programs in C? • How do we implement high-level programming constructs?
http://highered.mcgraw-hill.com/sites/0072467509/ Textbook LC-3 simulator http://highered.mcgraw-hill.com/sites/0072467509/student_view0/lc-3_simulator.html
Data Representation Data • Binary • Octal • Decimal • Signed Numbers Performing Arithmetic • Addition • Subtraction • Shifting (Mul/Div) Types and Representation • Integer • Floating point -- IEEE format • Alpha-numeric representation
Low-level Processes • Introduction • Digital logic structures • Finite state machine • ISA/Memory organisation • Opcodes • Operate instructions, data movement operations • Control instructions (loop, if-then-else control) • The Assembly process • Input & Output • Sub-routines / Stacks • Coding examples Note that tutorials will closely follow the course materials progression offering you a chance to apply new knowledge immediately. This will be very important for both assembly and C.
C programming • Basic components • Data representation • Binary fraction • Floating point representation • Introduction to C • Operators • Control structure • Functions • Pointers, arrays, string • I/O • Advanced programming
Assignments • There will be three assignments. The assignments count 20% of your grade. • Don’t pass your work to someone else; don’t copy some one else’s work. Do not copy other sources. If you are caught you will receive zero for the entire assignment and your previous and future submissions will be scrutinised. • For assembly and C, an assignment not compiling will receive 0 marks • Submissions Deadline: an assignment due date means the assignment should be turned in by the time specified in the assignment description. The submission dropboxes normally stay open for late assignments but penalties apply.
Test • Tentative: During class on 30 April, Week 7 (28 April – 2 May) • Multiple-choice questions (MCQ) • Material through week 6 • See example from previous semesters • Worth 20% towards course grade
Exam • Multiple-choice questions (MCQ) • See examples from previous semesters • Worth 60% towards course grade
How to Do Well in CompSci 210 • 1. Read the lecture notes after each lecture • 2. Read the relevant textbook sections a. To learn more b. To complement lectures 3. If you have questions or do not understand something • Attend the tutorials • Check the forum • Discuss with other 210 students • Ask a tutor during office hours • E-mail or see me 4. How to prepare for exams • Do 1, 2 & 3 above • Do exercises of the course/tutorials/exercises/textbook • Study previous years’ exams: You can get these online from the library website
Introduction to Computing Systems:From Bits and Gates to C and Beyond2nd Edition Yale N. PattSanjay J. Patel Based on slides originally prepared by Gregory T. Byrd, North Carolina State University
Introduction to the World of Computing • Computer: electronic genius? • NO! Electronic idiot! • Does exactly what we tell it to, nothing more. • Goal of the course: • You will be able to write programs in Cand understand what’s going on underneath – no magic! • Approach: • Build understanding from the bottom up. • Bits Gates Processor Instructions C Programming
Two Recurring Themes • Abstraction • Productivity enhancer – don’t need to worry about details… Can drive a car without knowing howthe internal combustion engine works. • …until something goes wrong! Where’s the dipstick? What’s a spark plug? • Important to understand the components andhow they work together. • Hardware vs. Software • It’s not either/or – both are components of a computer system. • Even if you specialize in one, it is important to understand capabilities and limitations of both.
Big Idea #1: Universal Computing Device • All computers, given enough time and memory,are capable of computing exactly the same things. = = Smart phone Desktop Supercomputer
Tmul Tadd a,b ab a,b a+b Turing machine that multiplies Turing machine that adds Turing Machine • Mathematical model of a device that can performany computation – Alan Turing (1937) • 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) For more info about Turing machines, see http://www.wikipedia.org/wiki/Turing_machine/
U Tadd, Tmul a,b,c c(a+b) Universal Turing Machine Universal Turing Machine • A machine that can implement all Turing machines-- this is also a Turing machine! • inputs: data, plus a description of computation (other TMs) • U 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.
From Theory to Practice • In theory, a computer can compute anything • that’s possible to compute • given enough memory and time • In practice, solving problems involves computing under constraints. • time • weather forecast, next frame of animation, ... • cost • cell phone, automotive engine controller, ... • power • cell phone, handheld video game, ...
Big Idea #2: Transformations Between Layers Problems Algorithms Language Instruction Set Architecture Microarchitecture Circuits Devices
How do we solve a problem using a computer? • A systematic sequence of transformations between layers of abstraction. Problem Software Design: choose algorithms and data structures Algorithm Programming: use language to express design Program Compiling/Interpreting: convert language to machine instructions Instr Set Architecture
Deeper and Deeper… Instr Set Architecture Processor Design: choose structures to implement ISA Microarch Logic/Circuit Design: gates and low-level circuits toimplement components Circuits Process Engineering & Fabrication: develop and manufacturelowest-level components Devices
Descriptions of Each Level • Problem Statement • stated using "natural language" • may be ambiguous, imprecise • Algorithm • step-by-step procedure, guaranteed to finish • definiteness, effective computability, finiteness • Program • express the algorithm using a computer language • high-level language, low-level language • Instruction Set Architecture (ISA) • specifies the set of instructions the computer can perform • data types, addressing mode
Descriptions of Each Level (cont.) • Microarchitecture • detailed organization of a processor implementation • different implementations of a single ISA • Logic Circuits • combine basic operations to realize microarchitecture • many different ways to implement a single function (e.g., addition) • Devices • properties of materials, manufacturability
Solve a system of equations Jacobi iteration Gaussian elimination Red-black SOR Multigrid FORTRAN C C++ Java ARM Intel x86 NVIDIA Haswell Nehalem Atom Ripple-carry adder Carry-lookahead adder CMOS Bipolar GaAs Many Choices at Each Level Tradeoffs: cost performance power (etc.)
Course Outline • Bits and Bytes • How do we represent information using electrical signals? • Digital Logic • How do we build circuits to process information? • Processor and Instruction Set • How do we build a processor out of logic elements? • What operations (instructions) will we implement? • Assembly Language Programming • How do we use processor instructions to implement algorithms? • How do we write modular, reusable code? (subroutines) • I/O, Traps, and Interrupts • How does processor communicate with outside world? • C Programming • How do we write programs in C? • How do we implement high-level programming constructs?
Lecture 2 Data Representation Computer Science 210 s1cComputer Systems 12014Semester 1Lecture Notes James Goodman (revised by Robert Sheehan) Credits: Adapted from slides prepared by Gregory T. Byrd, North Carolina State University
How do we represent data in a computer? • At the lowest level, a computer is an electronic machine. • works by controlling the flow of electrons • Easy to recognize two conditions: • presence of a voltage – we’ll call this state “1” • absence of a voltage – we’ll call this state “0” • Could base state on value of voltage, but control and detection circuits more complex. • compare turning on a light switch tomeasuring or regulating voltage
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 more than two states require multiple bits. • 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 2npossible states.
What kinds of data do we need to represent? • Numbers – signed, unsigned, integers, floating point,complex, rational, irrational, … • Text – characters, strings, … • Images – pixels, colors, shapes, … • Sound • Logical – true, false • Instructions • … • Data type: • representation and operations within the computer • We’ll start with numbers…
329 102 101 100 Unsigned Integers • Non-positional notation • could represent a number (“5”) with a string of ones (“11111”) • problems? • Weighted positional notation • like decimal numbers: “329” • “3” is worth 300, because of its position, while “9” is only worth 9 most significant least significant 101 22 21 20 3x100 + 2x10 + 9x1 = 329 1x4 + 0x2 + 1x1 = 5
Unsigned Integers (cont.) • An n-bit unsigned integer represents any of 2n(integer) values:from 0 to 2n-1.
Unsigned Binary Arithmetic • Base-2 addition – just like base-10! • add from right to left, propagating carry carry 10010 10010 1111 + 1001 + 1011 + 1 11011 11101 10000 10111 + 111 Subtraction, multiplication, division,…
“There are 10 kinds of people in the world: those who understand binary, and those who don’t.”
Signed Integers • With n bits, we can distinguish 2n unique values • assign about half to positive integers (1 through 2n-1)and about half to negative (-2n-1 through -1) • that leaves two values: one for 0, and one extra • Positive integers • just like unsigned, but zero in most significant (MS) bit00101 = 5 • Negative integers • Sign-Magnitude (or Signed-Magnitude) – set MS bit to show negative, other bits are the same as unsigned10101 = -5 • One’s complement – flip every bit to represent negative11010 = -5 • In either case, MS bit indicates sign: 0=positive, 1=negative
Two’s Complement • Problems with sign-magnitude and 1’s complement • two representations of zero (+0 and –0) • arithmetic circuits are complex • How to add two sign-magnitude numbers? • e.g., try 2 + (-3) • How to add two one’s complement numbers? • e.g., try 4 + (-3) • Two’s complementrepresentation developed to makecircuits easy for arithmetic. • for each positive number (X), assign value to its negative (-X),such that X + (-X) = 0with “normal” addition, ignoring carry out 00101 (5) 01001 (9) + 11011(-5) +(-9) 00000 (0) 00000 (0)
Two’s Complement Representation • If number is positive or zero, • normal binary representation, zeroes in upper bit(s) • If number is negative, • start with positive number • flip every bit (i.e., take the one’s complement) • then add one 00101 (5)01001 (9) 11010 (1’s comp)(1’s comp) + 1+ 1 11011 (-5)(-9)
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. • The most negative number (-2n-1) has no positive counterpart.
“Biased” Representation of Signed Integers • All integers (positive & negative) are represented as an unsigned integer supplemented with a “bias” to be subtracted out. • Range of an n-bit number: (0 - bias) through (2n-1 - bias). • Bias 8:
“Biased” Representation of Signed Integers • All integers (positive & negative) are represented as an unsigned integer supplemented with a “bias” to be subtracted out. • Range of an n-bit number: (0 - bias) through (2n-1 - bias). • Bias 7:
Converting Binary (2’s C) to Decimal • If leading bit is one, take two’s complement to get a positive number. • Add powers of 2 that have “1” in thecorresponding bit positions. • 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.
More Examples X = 00100111two = 25+22+21+20 = 32+4+2+1 = 39ten X = 11100110two -X = 00011010 = 24+23+21 = 16+8+2 = 26ten X = -26ten Assuming 8-bit 2’s complement numbers.
Converting Decimal to Binary (2’s C) • First Method: Division • Find magnitude of decimal number. (Always positive.) • Divide by two – remainder is least significant bit. • Keep dividing by two until answer is zero,writing remainders from right to left. • Append a zero as the MS bit;if original number was negative, take two’s complement. X = 104ten104/2 = 52 r0 bit 0 52/2 = 26 r0 bit 1 26/2 = 13 r0 bit 2 13/2 = 6 r1 bit 3 6/2 = 3 r0 bit 4 3/2 = 1 r1 bit 5 X = 01101000two 1/2 = 0 r1 bit 6