• 沒有找到結果。

Course overview

N/A
N/A
Protected

Academic year: 2022

Share "Course overview"

Copied!
48
0
0

加載中.... (立即查看全文)

全文

(1)

Course overview

Introduction to Computer p Yung-Yu Chuang

with slides by Nisan & Schocken (www.nand2tetris.org)

(2)

Logistics

• Meeting time: 2:20pm-5:20pm, Tuesday Classroom: CSIE Room 104

• Classroom: CSIE Room 104

• Instructor: 莊永裕 Yung-Yu Chuang T hi i t t TBD

• Teaching assistant: TBD

• Webpage:

http://www.csie.ntu.edu.tw/~cyy/introcs

id / password p

• Mailing list: introcs@cmlab.csie.ntu.edu.tw Please subscribe via

Please subscribe via

https://cmlmail.csie.ntu.edu.tw/mailman/listinfo/introcs/

(3)

Textbook

The Elements of Computing Systems Noam Nisan

Systems, Noam Nisan,

Shimon Schocken, MIT Press

(4)

References (TOY)

Princeton’s Introduction to CS,

htt // i t d /i t

http://www.cs.princeton.edu/intro cs/50machine/

http://www.cs.princeton.edu/intro

cs/60circuits/

(5)

References

CODE: The Hidden Language of

C t H d d S ft

Computer Hardware and Software, Charles Petzold, Microsoft Press.

Digital Design and Computer Digital Design and Computer

Architecture, 2 nd Edition, David

Harris and Sarah Harris Morgan

Harris and Sarah Harris, Morgan

Kaufmann.

(6)

Grading (subject to change)

• Assignments (n projects, 60%) from the accompanying website

accompanying website

• Class participation (4%)

• Midterm exam (16%)

• Final project (20%) p j ( )

(7)

Early computers

(8)

Early programming tools

(9)

First popular PCs

(10)

Early PCs

• Intel 8086 processor processor

• 768KB memory

• 20MB disk

• Dot-Matrix

printer (9-pin)

(11)

GUI/IDE

(12)

More advanced architectures

• Pipeline SIMD

• SIMD

• Multi-core

• Cache

(13)

More advanced software

(14)

More “computers” around us

(15)

My computers

Desktop

(Intel Pentium D 3GHz Nvidia 7900)

VAIO Z46TD

(I l C 2 D P9700 2 8GH ) 3GHz, Nvidia 7900)

(Intel Core 2 Duo P9700 2.8GHz)

iPhone 5

iPad 2 ARM Cortex-A15?) (A6, iPad 2

(dual-core A5 1GHz)

(16)

Goal of the course

(17)

The course at a glance

Objectives:

U d t d h h d d ft t

• Understand how hardware and software systems are built and how they work together

• Learn how to break complex problems into simpler ones

• Learn how to break complex problems into simpler ones

• Learn how large scale development projects are planned and executed

planned and executed

• Have fun

Methodology:

B ild l t l d ki

• Build a complete, general-purpose and working computer system

Play and experiment with this computer at any level of

• Play and experiment with this computer, at any level of

interest

(18)

TOY machine

(19)

TOY machine

• Starting from a simple construct

(20)

TOY machine

• Build several components and connect them together

together

(21)

TOY machine

• Almost as good as any computers

(22)

TOY machine

A DUP 32

int A[32]; 10: C020

lda R1, 1 lda RA, A

20: 7101 21: 7A00 lda RC, 0

d ld RD 0 FF i=0;

Do {

RD tdi

22: 7C00 23 8DFF read ld RD, 0xFF

bz RD, exit add R2 RA RC RD=stdin;

if (RD==0) break;

23: 8DFF 24: CD29 25: 12AC add R2, RA, RC

sti RD, R2 add RC, RC, R1 A[i]=RD;

i=i+1;

25: 12AC 26: BD02 27: 1CC1 bz R0, read

it jl RF i t } while (1);

i t ()

28: C023 29 FF2B exit jl RF, printr

hlt

printr(); 29: FF2B

2A: 0000

(23)

From NAND to Tetris

• The elements of computing systems C

• Courses

• Software

• Cool stuffs

(24)

Pong on the Hack computer

Pong, 1985 Pong, 2011

Pong, on our g,

computer

(25)

Theme and structure of the book

abstract interface

Software

Human Abstract design

H.L. Language

&

Operating Sys.

abstract interface

Compiler

Chapters 10 - 11

VM Translator Vi t l

abstract interface

hierarchy

Thought

Chapters 9, 12

VM Translator

Chapters 7 - 8

Virtual Machine

Assembly Language

abstract interface

Assembler

Chapter 6

abstract interface

Computer Architecture

Chapters 4 - 5

Gate Logic Machine

Language

abstract interface

H d

abstract interface

Gate Logic

Chapters 1 - 3 Electrical

Engineering

Physics

Hardware hierarchy

Hardware Platform

Chips &

Logic Gates

abstract interface

hierarchy

(Abstraction–implementation paradigm)

(26)

Application level: Pong (an example)

Ball

abstraction Bat Bat

abstraction

(27)

The big picture

H.L. Language

&

abstract interface

Compiler

abstract interface

Software hierarchy

Human Thought

Abstract design

Chapters 9, 12

Operating Sys. Chapters 10 - 11

VM Translator

Chapters 7 - 8

Virtual Machine

Assembly

abstract interface

Assembler Ch t 6

Assembly Language

Chapter 6

Computer Architecture Machine

L

abstract interface

abstract interface Chapters 4 - 5

Gate Logic

Chapters 1 - 3 Electrical

Engineering

H d

Language

Hardware Platform

Chips &

abstract interface

Engineering

Physics

Hardware hierarchy

Chips &

Logic Gates

(28)

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);

Typical call to OS th d

g ( ,y, ,y g );

return;

}

/** Moves the bat one step (4 pixels) to the right. */

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 // 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

Ball abstraction

Bat abstraction

do draw(true); // re-draw the bat in the new location return;

} }

(29)

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 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) { 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

} } }

(30)

The big picture

abstract interface

Software

hi h

Human Th ht

Abstract design

H.L. Language

&

Operating Sys.

Compiler

Chapters 10 - 11

VM Translator Virtual

abstract interface

hierarchy

Thought

Chapters 9, 12

Chapters 7 - 8

Virtual Machine

Assembly Language

abstract interface

Assembler

Chapter 6

abstract interface

Computer Architecture

Chapters 4 - 5

Gate Logic Machine

Language

Hardware

abstract interface

g

Chapters 1 - 3 Electrical

Engineering

Physics

Hardware hierarchy

Hardware Platform

Chips &

Logic Gates

abstract interface

hierarchy

(31)

A modern compilation model

Some Other language

Jack language

. . .

Some

language

. . .

Proj. 9: building an app.

Proj. 12: building the OS

Projects Some

compiler Some Other compiler

Jack compiler

VM language

10-11

VM implementation

over CISC platforms

VM imp.

over RISC platforms

VM imp.

over the Hack platform

VM emulator

Projects 7-8

RISC machine

Hack hi CISC

machine

written in a high level

. . .

machine language

machine language machine

language

. . .

a high-level

language

. . .

Projects1 6

. . .

RISC machine

other digital platforms, each equipped with its VM implementation

Hack computer

CISC machine

Any computer

1-6

(32)

Compilation 101

Source code push x

Intermediate code

>

parsing Code

generation Source code

(x + width) > 511

push x

push width add

push 511

+ 511

push 511 gt

width x

Abstraction Syntax Implementation

Analysis Parse

Tree Semantic

Synthesis

Observations:

 Modularity

 Abstraction / implementation interplay

 The implementation uses abstract services from the level below.

(33)

The virtual machine (VM modeled after JVM)

if ((x+width)>511) {

let x=511-width; 75

memory (before)

s2

...

// VM implementation

let x 511 width;

}

75 450

sp

450

x width

75

...

push x // s1 push width // s2 add // s3

75

...

s4 s5 s9

push 511 // s4 gt // s5 if-goto L1 // s6

525 511

sp

1

sp

511 450

sp

goto L2 // s7 L1:

push 511 // s8 s10

memory (after)

push width // s9 sub // s10 pop x // s11

61

sp

450

...

width

...

memory (after)

L2:

...

x 61

...

(34)

The big picture

abstract interface

Software

hi h

Human Th ht

Abstract design

H.L. Language

&

Operating Sys.

Compiler

Chapters 10 - 11

VM Translator Virtual

abstract interface

hierarchy

Thought

Chapters 9, 12

Chapters 7 - 8

Virtual Machine

Assembly Language

abstract interface

Assembler

Chapter 6

abstract interface

Computer Architecture

Chapters 4 - 5

Gate Logic Machine

Language

Hardware

abstract interface

g

Chapters 1 - 3 Electrical

Engineering

Physics

Hardware hierarchy

Hardware Platform

Chips &

Logic Gates

abstract interface

hierarchy

(35)

Low-level programming (on Hack)

Virtual machine program

...

push x push width p add

push 511 gt

gt

if-goto L1 goto L2 L1:

L1:

push 511 push width

sub sub pop x L2:

...

(36)

Low-level programming (on Hack)

Virtual machine program

...

push x push width p add

push 511 gt

Assembly program

VM translator gt

if-goto L1 goto L2 L1:

// push 511

@511

D=A // D=511 L1:

push 511 push width

sub

D A // D 511

@SP A=M

M=D // *SP=D push 511

sub pop x L2:

M D // SP D

@SP

M=M+1 // SP++

...

(37)

Low-level programming (on Hack)

Virtual machine program

...

push x push width p add

push 511 gt

Assembly program

VM

translator gt

if-goto L1 goto L2 L1:

// push 511

@511

D=A // D=511 L1:

push 511 push width

sub

//

@SP A=M

M=D // *SP=D Assembler Executable

push 511

sub pop x L2:

M D // SP D

@SP

M=M+1 // SP++

0000000000000000 1110110010001000

@SP

M=M+1 // SP++

...

(38)

The big picture

abstract interface

Software

hi h

Human Th ht

Abstract design

H.L. Language

&

Operating Sys.

Compiler

Chapters 10 - 11

VM Translator Virtual

abstract interface

hierarchy

Thought

Chapters 9, 12

Chapters 7 - 8

Virtual Machine

Assembly Language

abstract interface

Assembler

Chapter 6

abstract interface

Computer Architecture

Chapters 4 - 5

Gate Logic Machine

Language

Hardware

abstract interface

g

Chapters 1 - 3 Electrical

Engineering

Physics

Hardware hierarchy

Hardware Platform

Chips &

Logic Gates

abstract interface

hierarchy

(39)

Machine language semantics (Hack)

Instruction code

Code semantics

, as interpreted by the Hack hardware platform

Code syntax

Instruction code

(0=“address” inst.) Address

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 0000000000000000

1111110111001000

@0 M=M-1

ALU operation code

Destination Code

Jump Code Instruction code

(1=“compute” inst.) operation code (M-1)

Code (M)

Code (no jump) (1 compute inst.)

• We need a hardware architecture that realizes this semantics

• The hardware platform should be designed to:

o Parse instructions, and ,

o Execute them.

(40)

Computer architecture (Hack)

instruction

Data Memory

(M)

ALU

Instruction

Memory A

D

data out (M)

M

data out

address of next instruction

Program Counter

instruction

data in RAM(A)

• A typical Von Neumann machine

(41)

The big picture

Software

Human Abstract design

H.L. Language

&

Operating Sys.

abstract interface

Compiler

Chapters 10 - 11

abstract interface

Software hierarchy

Human Thought

g

Chapters 9, 12

p g y

VM Translator

Chapters 7 - 8

Virtual Machine

Assembly Language

abstract interface

Assembler Chapter 6

Language

Computer Architecture

Chapters 4 - 5

Machine Language

abstract interface

abstract interface

Gate Logic

Chapters 1 - 3 Electrical

Engineering

Physics

Hardware

Hardware Platform

Chips &

Logic Gates

abstract interface

y

hierarchy

Logic Gates

(42)

Logic design

• Combinational logic (leading to an ALU) S i l l i (l di RAM)

• Sequential logic (leading to a RAM)

• Putting the whole thing together (leading to a computer)

Using … gate logic

(43)

Gate logic

 Hardware platform = inter-connected set of chips

 Chips are made of simpler chips, all the way down to elemantary logic gates h ps are made of s mpler ch ps, all the way down to elemantary log c 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

 Every chip and gate has an interface , specifying WHAT it is doing, and an implementation , specifying HOW it is doing it.

Interface

a

Implementation

Xor a

b

out And

O t

a

Not

0 0 0

0 1 1

a b out

And Not

Or out

0 1 1 1 0 1 1 1 0

b And

(44)

Hardware description language (HDL)

And

a

And

Or out

Not

And Not

b CHIP Xor { CHIP Xor {

IN a,b;

OUT out;

PARTS 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);

}

(45)

The tour ends:

Interface One implementation option (CMOS)

out a

b Nand

0 0 1

a b out

b

0 0 1

0 1 1

1 0 1

1 1 0

(46)

The tour map, revisited

Compiler

abstract interface

Software

hierarchy

Human Thought

Abstract design

Ch 9 12

H.L. Language

&

Operating Sys.

Compiler

Chapters 10 - 11

VM Translator Virtual

abstract interface

hierarchy

abstract interface

g Chapters 9, 12

Operating System

Machine Chapters 7 - 8

Assembly Language

abstract interface

Course overview:

Assembler Chapter 6

Computer

abstract interface

Course overview:

Building this world, from the ground up

C t A hit t

Computer Architecture

Chapters 4 - 5

Gate Logic Machine

Language

Hardware

abstract interface

abstract interface

Di it l S t D i

Computer Architecture

Chapters 1 - 3 Electrical Engineering

Physics

Hardware hierarchy

Platform

Chips &

Logic Gates

abstract interface

Electronics

Digital System Design

(47)

What you will learn

• Number systems C bi i l l i

• Combinational logic

• Sequential logic

• Basic principle of computer architecture

• Assembler

• Assembler

• Virtual machine Hi h l l l

• High-level language

• Fundamentals of compilers

• Basic operating system

• Application programming

• Application programming

(48)

In short

參考文獻

相關文件

Write the following problem on the board: “What is the area of the largest rectangle that can be inscribed in a circle of radius 4?” Have one half of the class try to solve this

 For students of other class levels, arrangements of reading out the papers / using screen readers / asking for pronunciations of words are only applicable

Each course at the Institute is assigned a number of units corresponding to the total number of hours per week devoted to that subject, including classwork, laboratory, and the

In digital systems, a register transfer operation is a basic operation that consists of a transfer of binary information from one set of registers into another set of

Beauty Cream 9001, GaTech DVFX 2003.

Life in Paints, GaTech DVFX 2003.. Tour

The remaining positions contain //the rest of the original array elements //the rest of the original array elements.

BLAST is still one of the most robust and efficient sequence-matching and sequence- alignment