Course overview. Introduction to Computer Yung-Yu Chuang. with slides by Nisan & Schocken (

Similar documents
Course overview. Introduction to Computer Yung-Yu Chuang. with slides by Nisan & Schocken (

Course overview. Introduction to Computer Yung-Yu Chuang. with slides by Nisan & Schocken (

Introduction: From Nand to Tetris

Introduction: Hello, World Below

Course overview. Computer Organization and Assembly Languages Yung-Yu Chuang 2007/09/17. with slides by Kip Irvine

Virtual Machine. Part I: Stack Arithmetic. Building a Modern Computer From First Principles.

Virtual Machine Where we are at: Part I: Stack Arithmetic. Motivation. Compilation models. direct compilation:... 2-tier compilation:

Virtual Machine. Part II: Program Control. Building a Modern Computer From First Principles.

Assembler Human Thought

Computer Architecture

Chapter 8: Virtual Machine II: Program Control

Chapter 10: Compiler I: Syntax Analysis

Chapter 0: The grand Tour The Grand Tour 1. The true voyage of discovery consists not of going to new places, but of having a new pair of eyes.

Chapter 6: Assembler

Virtual machines. Virtual machines. Abstractions for computers. Abstractions for computers. Virtual machines

Chapter 11: Compiler II: Code Generation

Assembler. Building a Modern Computer From First Principles.

Compiler I: Sytnax Analysis

Machine (Assembly) Language

Machine (Assembly) Language Human Thought

Motivation. Compiler. Our ultimate goal: Hack code. Jack code (example) Translate high-level programs into executable code. return; } } return

Compiler II: Code Generation Human Thought

Compiler I: Syntax Analysis

Virtual Machine (Part II)

Boolean Arithmetic. From Nand to Tetris Building a Modern Computer from First Principles. Chapter 2

IWKS 3300: NAND to Tetris Spring John K. Bennett. Assembler

Chapter 6: The Assembler The Assembler Hack Assembly-to-Binary Translation Specification

Sequential Logic. Building a Modern Computer From First Principles.

EP1200 Introduction to Computing Systems Engineering. Computer Architecture

6.1 Combinational Circuits. George Boole ( ) Claude Shannon ( )

Chapter 9: High Level Language

Virtual Machine (Part II)

Computer Architecture

Real instruction set architectures. Part 2: a representative sample

Computer Organization

Boolean Logic. From Nand to Tetris Building a Modern Computer from First Principles. Chapter 1

Computer Architecture

CS 31: Intro to Systems Digital Logic. Kevin Webb Swarthmore College February 2, 2016

Basic Computer Architecture

Computer Systems. Binary Representation. Binary Representation. Logical Computation: Boolean Algebra

Chapter 1: Introduction. Oregon State University School of Electrical Engineering and Computer Science

Arithmetic Logic Unit (ALU)

378: Machine Organization and Assembly Language

CS 31: Intro to Systems Digital Logic. Kevin Webb Swarthmore College February 3, 2015

What is TOY? An imaginary machine similar to: ! Ancient computers. ! Today's microprocessors.

Latches. IT 3123 Hardware and Software Concepts. Registers. The Little Man has Registers. Data Registers. Program Counter

CMPUT 101 with Solutions Quiz 2 (50 minutes) November 16, 2000

Introduction to Microprocessor

CPSC 213. Introduction to Computer Systems. Introduction. Unit 0

IA-32 Architecture. Computer Organization and Assembly Languages Yung-Yu Chuang 2005/10/6. with slides by Kip Irvine and Keith Van Rhein

High Level Language (Jack)

THE MICROPROCESSOR Von Neumann s Architecture Model

COSC 122 Computer Fluency. Computer Organization. Dr. Ramon Lawrence University of British Columbia Okanagan

IB Computer Science Topic.2-

Computer Architecture Dr. Charles Kim Howard University

Multicycle Approach. Designing MIPS Processor

Computer and Hardware Architecture I. Benny Thörnberg Associate Professor in Electronics

Project 8: Virtual Machine Translator II

IWKS 2300/5300 Fall John K. Bennett. Machine Language

STEVEN R. BAGLEY THE ASSEMBLER

Computer Architecture I: Outline and Instruction Set Architecture. CENG331 - Computer Organization. Murat Manguoglu

Computer Systems Architecture

COMPUTER STRUCTURE AND ORGANIZATION

Programmable Machines

Programmable Machines

CS61C : Machine Structures

Electricity: Voltage. Gate: A signal enters the gate at a certain voltage. The gate performs operations on it, and sends it out was a new signal.

Course overview. Computer Organization and Assembly Languages Yung-Yu Chuang 2006/09/18. with slides by Kip Irvine

LC-3 Architecture. (Ch4 ish material)

More advanced CPUs. August 4, Howard Huang 1

Computer Architecture. Introduction. Lynn Choi Korea University

Micro computer Organization

Computer Architecture Dr. Charles Kim Howard University

Topics Power tends to corrupt; absolute power corrupts absolutely. Computer Organization CS Data Representation

EE 3170 Microcontroller Applications

Chapter 2 Lecture 1 Computer Systems Organization

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

CS 101, Mock Computer Architecture

Chapter 04: Instruction Sets and the Processor organizations. Lesson 20: RISC and converged Architecture

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

Computer Architecture. Fall Dongkun Shin, SKKU

CPSC 213. Introduction to Computer Systems. About the Course. Course Policies. Reading. Introduction. Unit 0

Moodle WILLINGDON COLLEGE SANGLI (B. SC.-II) Digital Electronics

Faculty of Science FINAL EXAMINATION

Where Does The Cpu Store The Address Of The

Computer Organization Chapter 4. Prof. Qi Tian Fall 2013

Slides for Lecture 6

Computers and Microprocessors. Lecture 34 PHYS3360/AEP3630

ECE 1160/2160 Embedded Systems Design. Midterm Review. Wei Gao. ECE 1160/2160 Embedded Systems Design

Chapter 4 The Von Neumann Model

EECE 321: Computer Organization

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

Instruction Set Architecture. "Speaking with the computer"

Microcomputer Architecture and Programming

Computer Architecture

Implementing the Control. Simple Questions

CSCE 312 Lab manual. Lab 4 - Computer Organization and Data Path Design. Instructor: Dr. Yum. Fall 2016

CSE 141 Computer Architecture Spring Lecture 3 Instruction Set Architecute. Course Schedule. Announcements

omputer Design Concept adao Nakamura

Computer System. Hiroaki Kobayashi 7/25/2011. Agenda. Von Neumann Model Stored-program instructions and data are stored on memory

Transcription:

Course overview Introduction to Computer Yung-Yu Chuang with slides by Nisan & Schocken (www.nand2tetris.org)

Logistics Meeting time: 2:20pm-5:20pm, Tuesday Instructor: 莊永裕 Yung-Yu Chuang Webpage: http://www.csie.ntu.edu.tw/~cyy/introcs id / password

Textbook The Elements of Computing Systems, Noam Nisan, Shimon Schocken, MIT Press Nand2Tetris on coursera Nand2Tetris2 on coursera

References (TOY) Princeton s Introduction to CS, http://www.cs.princeton.edu/intro cs/50machine/ http://www.cs.princeton.edu/intro cs/60circuits/

Grading (subject to change) Assignments (n projects, 50%) from the accompanying website Class participation (5%) Midterm quiz(20%) Final project (25%)

Early computers

Early programming tools

First popular PCs

Early PCs Intel 8086 processor 768KB memory 20MB disk Dot-Matrix printer (9-pin)

GUI/IDE

More advanced architectures Pipeline SIMD Multi-core Cache

More advanced software

More computers around us

My computers Desktop (Intel Core i7-6700 3.4GHz, GTX960) MacBook Air (dual-core Intel Core i5, 1.3GHz) Surface Pro 4 (Intel i5-6300 2.4GHz) iphone 6+ (A8, ARMv8-A)

The downside Once upon a time, every computer specialist had a gestalt understanding of how computers worked. As modern computer technologies have become increasingly more complex, this clarity is all but lost. Quoted from the textbook

How is it done? // First Example in Programming 101 class Main { function void main () { do Output.printString("Hello World"); do Output.println(); // New line return; } }

Main secret of computer science implementation Don t worry about the how Only about the what abstraction what our programming language promises to do Extremely complicated system Information hiding

Main secret of computer science Don t worry about the how But, someone has to, for example, you.

Goal of the course The best way to understand how computers work is to build one from scratch. Quoted from the textbook

The course at a glance Objectives: Understand how hardware and software systems are built and how they work together Learn how to break complex problems into simpler ones Learn how large scale development projects are planned and executed Have fun Methodology: Build a complete, general-purpose and working computer system Play and experiment with this computer, at any level of interest

TOY machine

TOY machine Starting from a simple construct

Logic gates NOT AND OR

Components Registers Cond Eval W Data PC 1 + Memory Addr R Data W Data W IR op d s t A Data B Data W Addr A Addr B Addr W A L U

Toy machine 1 0 PC 1 + 1 0 Memory Addr R Data W Data W IR op d s t 4 10 01 00 1 0 2 Registers W Data A Data B Data W Addr A Addr B Addr W Cond Eval A L U =0 >0 5 0 1 Clock 1-bit counter Opcode Execute Fetch Clock Control 25

TOY machine Almost as good as any computers

TOY machine int A[32]; A DUP 32 10: C020 i=0; Do { RD=stdin; if (RD==0) break; A[i]=RD; i=i+1; } while (1); lda R1, 1 lda RA, A lda RC, 0 read ld RD, 0xFF bz RD, exit add R2, RA, RC sti RD, R2 add RC, RC, R1 bz R0, read 20: 7101 21: 7A00 22: 7C00 23: 8DFF 24: CD29 25: 12AC 26: BD02 27: 1CC1 28: C023 printr(); exit jl RF, printr hlt 29: FF2B 2A: 0000

TOY machine

From NAND to Tetris The elements of computing systems Courses Software Cool stuffs

Pong on the Hack computer Pong, 1985 Pong, 2011 Pong, on our computer

Theme and structure of the book Human Thought Abstract design Chapters 9, 12 H.L. Language & Operating Sys. Compiler Chapters 10-11 Virtual Machine Software hierarchy VM Translator Chapters 7-8 Assembly Language Assembler Chapter 6 Machine Language Computer Architecture Chapters 4-5 Hardware hierarchy Hardware Platform Gate Logic Chapters 1-3 Chips & Logic Gates Electrical Engineering Physics (Abstraction implementation paradigm)

Application level: Pong (an example) Ball abstraction Bat abstraction

The big picture Human Thought Abstract design Chapters 9, 12 H.L. Language & Operating Sys. Compiler Chapters 10-11 Virtual Machine Software hierarchy VM Translator Chapters 7-8 Assembly Language Assembler Chapter 6 Machine Language Computer Architecture Chapters 4-5 Hardware hierarchy Hardware Platform Gate Logic Chapters 1-3 Chips & Logic Gates Electrical Engineering Physics

High-level programming (Jack language) /** A Graphic Bat for a Pong Game */ class Bat { field int x, y; // screen location of the bat's top-left corner field int width, height; // bat's width & height // The class constructor and most of the class methods are omitted /** Draws (color=true) or erases (color=false) the bat */ method void draw(boolean color) { do Screen.setColor(color); do Screen.drawRectangle(x,y,x+width,y+height); return; } Typical call to an OS method } /** Moves the bat one step (4 pixels) to the right. */ method void mover() { do draw(false); // erase the bat at the current location let x = x + 4; // change the bat's X-location // but don't go beyond the screen's right border if ((x + width) > 511) { let x = 511 - width; } do draw(true); // re-draw the bat in the new location return; } Ball abstraction Bat abstraction

Operating system level (Jack OS) /** An OS-level screen driver that abstracts the computer's physical screen */ class Screen { static boolean currentcolor; // the current color // The Screen class is a collection of methods, each implementing one // abstract screen-oriented operation. Most of this code is omitted. } /** Draws a rectangle in the current color. */ // the rectangle's top left corner is anchored at screen location (x0,y0) // and its width and length are x1 and y1, respectively. function void drawrectangle(int x0, int y0, int x1, int y1) { var int x, y; let x = x0; while (x < x1) { let y = y0; while(y < y1) { do Screen.drawPixel(x,y); let y = y+1; } let x = x+1; } } Ball abstraction Bat abstraction

The big picture Human Thought Abstract design Chapters 9, 12 H.L. Language & Operating Sys. Compiler Chapters 10-11 Virtual Machine Software hierarchy VM Translator Chapters 7-8 Assembly Language Assembler Chapter 6 Machine Language Computer Architecture Chapters 4-5 Hardware hierarchy Hardware Platform Gate Logic Chapters 1-3 Chips & Logic Gates Electrical Engineering Physics

A modern compilation model Some... language Some Other language... Jack language Proj. 9: building an app. Proj. 12: building the OS Some compiler Some Other compiler Jack compiler Projects 10-11 VM language VM implementation over CISC platforms VM imp. over RISC platforms VM emulator VM imp. over the Hack platform Projects 7-8 CISC machine language RISC machine language... written in a high-level language Hack machine language...... Projects 1-6 CISC machine RISC machine other digital platforms, each equipped with its VM implementation Any computer Hack computer

Compilation 101 > Intermediate code Source code push x (x + width) > 511 parsing + 511 Code generation push width add push 511 gt x width Abstraction Syntax Analysis Parse Tree Semantic Synthesis Implementation Observations: Modularity Abstraction / implementation interplay The implementation uses abstract services from the level below.

The virtual machine (VM modeled after JVM) if ((x+width)>511) { let x=511-width; } // VM implementation push x // s1 width x memory (before)......... 450 75 sp s2 75 450 push width // s2 add // s3 s4 s5 s9 push 511 // s4 gt // s5 if-goto L1 // s6 goto L2 // s7 sp 525 511 sp 1 sp 511 450 L1: push 511 // s8 push width // s9 sub // s10 pop x // s11 L2:... sp s10 61 width x memory (after)......... 450 61

The big picture Human Thought Abstract design Chapters 9, 12 H.L. Language & Operating Sys. Compiler Chapters 10-11 Virtual Machine Software hierarchy VM Translator Chapters 7-8 Assembly Language Assembler Chapter 6 Machine Language Computer Architecture Chapters 4-5 Hardware hierarchy Hardware Platform Gate Logic Chapters 1-3 Chips & Logic Gates Electrical Engineering Physics

Low-level programming (on Hack) Virtual machine program... push x push width add push 511 gt if-goto L1 goto L2 L1: push 511 push width sub pop x L2:...

Low-level programming (on Hack) Virtual machine program... push x push width add push 511 gt if-goto L1 goto L2 L1: push 511 push width sub pop x L2:... VM translator Assembly program // push 511 @511 D=A // D=511 @SP A=M M=D // *SP=D @SP M=M+1 // SP++

Low-level programming (on Hack) Virtual machine program... push x push width add push 511 gt if-goto L1 goto L2 L1: push 511 push width sub pop x L2: VM translator Assembly program // push 511 @511 D=A // D=511 @SP A=M M=D // *SP=D @SP @SP M=M+1 // SP++ Assembler Executable 0000000000000000 1110110010001000...

The big picture Human Thought Abstract design Chapters 9, 12 H.L. Language & Operating Sys. Compiler Chapters 10-11 Virtual Machine Software hierarchy VM Translator Chapters 7-8 Assembly Language Assembler Chapter 6 Machine Language Computer Architecture Chapters 4-5 Hardware hierarchy Hardware Platform Gate Logic Chapters 1-3 Chips & Logic Gates Electrical Engineering Physics

Machine language semantics (Hack) Code semantics, as interpreted by the Hack hardware platform Instruction code (0= address inst.) Address Code syntax 0000000000000000 1111110111001000 @0 M=M-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 1 1 1 0 0 1 0 0 0 Instruction code (1= compute inst.) ALU operation code Destination Code Jump Code (M-1) (M) (no jump) We need a hardware architecture that realizes this semantics The hardware platform should be designed to: o Parse instructions, and o Execute them.

Computer architecture (Hack) instruction Instruction Memory D A M ALU data out Data Memory (M) Program Counter address of next instruction data in RAM(A) A typical Von Neumann machine

The big picture Human Thought Abstract design Chapters 9, 12 H.L. Language & Operating Sys. Compiler Chapters 10-11 Virtual Machine Software hierarchy VM Translator Chapters 7-8 Assembly Language Assembler Chapter 6 Machine Language Computer Architecture Chapters 4-5 Hardware hierarchy Hardware Platform Gate Logic Chapters 1-3 Chips & Logic Gates Electrical Engineering Physics

Logic design Combinational logic (leading to an ALU) Sequential logic (leading to a RAM) Putting the whole thing together (leading to a computer) Using gate logic

Gate logic Hardware platform = inter-connected set of chips Chips are made of simpler chips, all the way down to elemantary logic gates Logic gate = hardware element that implements a certain Boolean function Every chip and gate has an interface, specifying WHAT it is doing, and an implementation, specifying HOW it is doing it. Interface Implementation a b Xor out a Not And a b out Or out 0 0 0 0 1 1 1 0 1 1 1 0 b Not And

Hardware description language (HDL) a Not And Or out b Not And CHIP Xor { IN a,b; OUT out; PARTS: Not(in=a,out=Nota); Not(in=b,out=Notb); And(a=a,b=Notb,out=w1); And(a=Nota,b=b,out=w2); Or(a=w1,b=w2,out=out); }

The tour ends: Interface One implementation option (CMOS) a b Nand out a b out 0 0 1 0 1 1 1 0 1 1 1 0

The tour map, revisited Human Thought Machine Language Abstract design Chapters 9, 12 Computer Architecture Chapters 4-5 Computer Architecture Hardware hierarchy H.L. Language & Operating Sys. Compiler Chapters 10-11 Operating System Hardware Platform Assembler Chapter 6 Gate Logic Chapters 1-3 Digital System Design Compiler Virtual Machine Software hierarchy VM Translator Chapters 7-8 Course overview: Building this world, from the ground up Chips & Logic Gates Electrical Engineering Electronics Assembly Language Physics

What you will learn Number systems Combinational logic Sequential logic Basic principle of computer architecture Assembler Virtual machine High-level language Fundamentals of compilers Basic operating system Application programming

In short