CS 3330 Introduction Daniel and Charles CS 3330 Computer - - PowerPoint PPT Presentation

cs 3330 introduction
SMART_READER_LITE
LIVE PREVIEW

CS 3330 Introduction Daniel and Charles CS 3330 Computer - - PowerPoint PPT Presentation

CS 3330 Introduction Daniel and Charles CS 3330 Computer Architecture 1 Charles and I will be splitting lectures lecturers same(ish) lecture in each section Take Home Quizzes: Midterms (2): 30% 10% (10% dropped) Grading Final Exam


slide-1
SLIDE 1

CS 3330 Introduction

Daniel and Charles

CS 3330 Computer Architecture 1
slide-2
SLIDE 2

lecturers

  • Charles and I will be splitting lectures

same(ish) lecture in each section

slide-3
SLIDE 3

Grading

CS 3330 Computer Architecture 3

Take Home Quizzes: 10% (10% dropped) Midterms (2): 30% Final Exam (cumulative): 20% Homework + Labs: 40%

slide-4
SLIDE 4

late policy

❑ exceptional circumstance? contact us. ❑ otherwise, for homework only:

❑ -10% 0 to 48 hours late ❑ -15% 48 to 72 hours late ❑ -100% otherwise

❑ late quizzes, labs: no

we release answers talk to us if illness, etc.

CS 3330 Computer Architecture 4

slide-5
SLIDE 5

Coursework

❑ quizzes — pre/post week of lecture

❑ you will need to read

❑ labs — grading: did you make reasonable progress?

❑ collaboration permitted

❑ homework assignments — introduced by lab (mostly)

❑ due at 9am on the next lab day (mostly) complete individually

❑ exams — multiple choice/short answer — 2 + final

CS 3330 Computer Architecture 5

slide-6
SLIDE 6

Collaboration Policy

  • You are encouraged to discuss

homework and final project assignments with other students in the class, as long as the following rules are followed:

CS 3330 Computer Architecture 6
slide-7
SLIDE 7

Collaboration Policy

CS 3330 Computer Architecture 7

You can’t view other peoples

  • code. That includes pseudo

code. You can discuss the assignment generally. Sharing code in labs is allowed

slide-8
SLIDE 8

Attendance?

CS 3330 Computer Architecture 8

Lecture: strongly recommended but not

  • required. lectures are

recorded to help you review Lab: electronic, remote- possible submission, usually.

slide-9
SLIDE 9

lecture/lab/HW synchronization

CS 3330 Computer Architecture 9

main problem: want to cover material before you need it in lab/HW labs/HWs not quite synchronized with lectures

slide-10
SLIDE 10

Quizzes?

  • linked off course website (First quiz, due 11 of September)
  • pre-quiz, on reading – released by Saturday evening, due

Tuesdays, 12:15 PM (Which is just before lecture)

  • post-quiz, on lecture topics — released Thursday evening,

due following Saturday, 11:59 PM

  • each quiz 90 minute time limit (+ adjustments if SDAC

says) lowest 10% (approx. 2 quizzes) will be dropped (Quizzes are multiple choice and normally about 5 questions)

CS 3330 Computer Architecture 10

slide-11
SLIDE 11

TAs/Office Hours

  • Office hours will be posted on the

calendar on the website

  • Still discussion hours with TAs.
  • Office hours will start next week.
CS 3330 Computer Architecture

11

slide-12
SLIDE 12

Your TODO list

❑ Quizzes!

❑ post-quiz after Thursday lecture pre-quiz before Tuesday lecture

❑ lab account and/or C environment working

❑ lab accounts should happen by this weekend

❑ before lab next week

CS 3330 Computer Architecture 12

slide-13
SLIDE 13

Questions?

CS 3330 Computer Architecture 13

slide-14
SLIDE 14

Let’s Build a simple machine

CS 3330 Computer Architecture 14
slide-15
SLIDE 15

How will store information in our machine?

CS 3330 Computer Architecture 15

slide-16
SLIDE 16

0.0V 0.2V 0.9V 1.1V 1

Everything is bits

  • Each bit is 0 or 1
  • Why bits? Electronic Implementation
  • Reliably transmitted on noisy and inaccurate wires

CS 3330 Computer Architecture 16

slide-17
SLIDE 17

There are different ways to represent bits

CS 3330 Computer Architecture 17

slide-18
SLIDE 18

Encoding Byte Values

  • Byte = 8 bits
  • Binary 000000002 to 111111112
  • Decimal: 010 to 25510
  • Hexadecimal 0016 to FF16
  • Base 16 number representation
  • Use characters ‘0’ to ‘9’ and ‘A’ to ‘F’
  • Write FA1D37B16 in C as
  • 0xFA1D37B
  • 0xfa1d37b

CS 3330 Computer Architecture 18

0000 1 1 0001 2 2 0010 3 3 0011 4 4 0100 5 5 0101 6 6 0110 7 7 0111 8 8 1000 9 9 1001 A 10 1010 B 11 1011 C 12 1100 D 13 1101 E 14 1110 F 15 1111

Q: 0x605C + 0x5 = 0x606

slide-19
SLIDE 19

Boolean Algebra

  • Developed by George Boole in 19th Century
  • Algebraic representation of logic
  • Encode “True” as 1 and “False” as 0
  • The symbols here are how you do these operation in c

CS 3330 Computer Architecture 19

And

◼ A&B = 1 when both A=1 and B=1

Or

◼ A|B = 1 when either A=1 or B=1

Not

◼ ~A = 1 when A=0

Exclusive-Or (Xor)

◼ A^B = 1 when either A=1 or B=1, but not both

Not an I

slide-20
SLIDE 20

Boolean Algebra

  • Could we develop a machine that adds two one-bit numbers using any of

these gates

  • Encode “True” as 1 and “False” as 0

CS 3330 Computer Architecture 20

And

◼ A&B = 1 when both A=1 and B=1

Or

◼ A|B = 1 when either A=1 or B=1

Not

◼ ~A = 1 when A=0

Exclusive-Or (Xor)

◼ A^B = 1 when either A=1 or B=1, but not both

slide-21
SLIDE 21

Simple One Bit Adder (Not Quite)

CS 3330 Computer Architecture 21

Suppose that we had extra place to hold that last result bit what gate could we use to find it?

slide-22
SLIDE 22

A B C S 1 1 1 1 1 1 1

Binary for 2

Simple Half Adder (Not Quite)

CS 3330 Computer Architecture 22

And Gate

slide-23
SLIDE 23

Half Adder Bread board

CS 3330 Computer Architecture 23

slide-24
SLIDE 24

http://www.circuitstoday.com/wp-content/uploads/2012/03/ripple-carry- adder.png

Ripple Carry Adder

CS 3330 Computer Architecture 24

slide-25
SLIDE 25

Now we have a machine that can add large numbers (Bundle of wires)

CS 3330 Computer Architecture 26

A 64 bits B 64 bits ADDER carry Registers 64 bundle of wires

slide-26
SLIDE 26

CS 3330 Computer Architecture 27

How do we program it?

slide-27
SLIDE 27

We could put one and zeros in manually

CS 3330 Computer Architecture 28

slide-28
SLIDE 28

The solution: Abstraction

CS 3330 Computer Architecture 29

slide-29
SLIDE 29

Layers of abstraction

CS 3330 Computer Architecture 30

Gates / Transistors / Wires / Registers Hardware Design Language: HCLRS/ VHDL Machine code

0010 0001

Assembly

addq %rdi %rsi

“Higher-level” language: C

x += y Y86 64 bit simplified

slide-30
SLIDE 30

Now we have a machine that can add large numbers

CS 3330 Computer Architecture 31

A 64 bits B 64 bits ADDER How do we program it? carry Registers 0010 0001

slide-31
SLIDE 31

We are computer scientists why should we care about hardware?

CS 3330 Computer Architecture 32

slide-32
SLIDE 32

Why

  • Understanding computer architecture will

help you:

  • Write fast programs
  • And understand strange program

behaviors like segmentation faults.

slide-33
SLIDE 33

Let’s look at a simple example

CS 3330 Computer Architecture 34

slide-34
SLIDE 34

Memory System Performance Example

  • Hierarchical memory organization
  • Performance depends on access patterns
  • Including how step through multi-dimensional array

CS 3330 Computer Architecture 35

void copyji(int src[2048][2048], int dst[2048][2048]) { int i,j; for (j = 0; j < 2048; j++) for (i = 0; i < 2048; i++) dst[i][j] = src[i][j]; } void copyij(int src[2048][2048], int dst[2048][2048]) { int i,j; for (i = 0; i < 2048; i++) for (j = 0; j < 2048; j++) dst[i][j] = src[i][j]; }

81.8ms 4.3ms

2.0 GHz Intel Core i7 Haswell

slide-35
SLIDE 35

program performance: is su es

  • (Hardware) Parallelism
  • How do we write program to take

advantage of parrallelism

  • (Hardware) caching
  • accessing things recently accessed is faster
  • need reuse of data/code
  • (Software) (more in other classes: algorithmic

efficiency) (Time and Space Complexity Big O)

CS 3330 Computer Architecture 36

slide-36
SLIDE 36

Let’s start by looking at high- level over of architecture of a system

CS 3330 Computer Architecture 37

slide-37
SLIDE 37

processors and memory

CS 3330 Computer Architecture 38

processor I/O Bridge memory to I/O devices

keyboard, mouse, wifi,…

slide-38
SLIDE 38

CS 3330 Computer Architecture 39

More detail

slide-39
SLIDE 39

Memory Address bus Get me value at 0x0003

http://www.ti.com/product/MSP430G2553

Memory Data bus Your data was: 0xffff

CS 3330 Computer Architecture 40

Schematic

slide-40
SLIDE 40

Endianess

CS 3330 Computer Architecture 41

slide-41
SLIDE 41

CS 3330 Computer Architecture 42

little endian (least significant byte has lowestaddress) big endian (most significant byte has lowestaddress)

value 0x … DE address 0xFFFFFFFF 0xFFFFFFFE 0xFFFF …FFFD 0x00042006 0x00042005 0x00042004 0x00042003 0x00042002 0x00042001 0x00042000 0x14 0x45

int *x = (int*)0x42000; cout << *x << endl;

0x06 0x05 0x04 0x03 0x02 0x01 0x00 0x03 0x00041FFF 0x0004 …1FFE 0x00000002 0x00000001 0x … 60 0xFE 0xE0

0x03020100 = 50462976 0x00010203 = 66051

Endianess

slide-42
SLIDE 42

mem memor

  • ry

CS 3330 Computer Architecture

43

value 0x … DE 0x … 60 0xFE address 0xFFFFFFFF 0xFFFFFFFE 0xFFFF …FFFD 0x00042006 0x00042005 0x00042004 0x00042003 0x00042002 0x00042001 0x00042000 0x00041FFF 0x0004 …1FFE 0x00000002 0x00000001 0x00000000 0xE0 0xA0 0x14 0x45 0x06 0x05 0x04 0x03 0x02 0x01 0x00 0x03 value 0x … FE 0x … 06 0xDE address 0x00000000 0x00000001 0x0000 …0002 0x00041FFE 0x00041FFF 0x00042000 0x00042001 0x00042002 0x00042003 0x00042004 0x00042005 0x0004 …2006 0xFFFFFFFD 0xFFFFFFFE 0xFFFFFFFF 0x45 0x14 0xA0 0xE0 0x60 0x03 0x00 0x01 0x02 0x03 0x04 0x05

slide-43
SLIDE 43

Endianess

CS 3330 Computer Architecture 44

little endian (least significant byte has lowestaddress) big endian (most significant byte has lowestaddress)

value 0x … DE address 0xFFFFFFFF 0xFFFFFFFE 0xFFFF …FFFD 0x00042006 0x00042005 0x00042004 0x00042003 0x00042002 0x00042001 0x00042000 0x14 0x45 0x06 0x05 0x04 0x03 0x02 0x01 0x00 0x03 0x00041FFF 0x0004 …1FFE 0x00000002 0x00000001 0x … 60 0xFE 0xE0

0x03020100 = 50462976 0x00010203 = 66051 0x03020101 = 50462977

slide-44
SLIDE 44

To write efficient code we also need to understand the process of going from c to machine code?

What does the compiler Do?

CS 3330 Computer Architecture 45

slide-45
SLIDE 45

compilation pipeline

CS 3330 Computer Architecture 46

compile main.c (C code) main.s (assembly) assemble main.o (object file) (machine code) linking main.exe (executable) (machine code) main.c: #include <stdio.h> int main(void) { printf("Hello, World!\n"); } printf.o (object file)

slide-46
SLIDE 46

compilation pipeline

CS 3330 Computer Architecture 47

main.c (C code) compile main.s (assembly) assemble main.o (object file) (machine code) linking main.exe (executable) (machine code)

27

slide-47
SLIDE 47

compilation pipeline

CS 3330 Computer Architecture 48

compile main.c (C code) main.s (assembly) assemble main.o (object file) (machine code) linking main.exe (executable) (machine code) main.c: #include <stdio.h> int main(void) { printf("Hello, World!\n"); }

slide-48
SLIDE 48

compilation pipeline

CS 3330 Computer Architecture 49

compile main.c (C code) main.s (assembly) assemble main.o (object file) (machine code) linking main.exe (executable) (machine code) main.c: #include <stdio.h> int main(void) { printf("Hello, World!\n"); } printf.o (object file)

slide-49
SLIDE 49

what’s in those files?

CS 3330 Computer Architecture 50

#include <stdio.h> int main(void) { puts("Hello, World!"); return 0; }

hello.c

slide-50
SLIDE 50

what’s in those files?

CS 3330 Computer Architecture 51

#include <stdio.h> int main(void) { puts("Hello, World!"); return 0; }

hello.c

.text main: sub $8, %rsp mov $.Lstr, %rdi call puts xor %eax, %eax add $8, %rsp ret .data .Lstr: .string "Hello,␣World!"

hello.s

slide-51
SLIDE 51

what’s in those files?

CS 3330 Computer Architecture 52

#include <stdio.h> int main(void) { puts("Hello, World!"); return 0; }

hello.c

.text main: sub $8, %rsp mov $.Lstr, %rdi call puts xor %eax, %eax add $8, %rsp ret .data .Lstr: .string "Hello,␣World!"

hello.s

101 101 000 Calling convention

slide-52
SLIDE 52

what’s in those files?

CS 3330 Computer Architecture 53

#include <stdio.h> int main(void) { puts("Hello, World!"); return 0; }

hello.c

.text main: sub $8, %rsp mov $.Lstr, %rdi call puts xor %eax, %eax add $8, %rsp ret .data .Lstr: .string "Hello,␣World!"

hello.s

text (code) segment: 48 83 EC 08 BF 00 00 00 00 E8 00 00 00 00 31 C0 48 83 C4 08 C3 datasegment: 48 65 6C 6C 6F 2C 20 57 6F 72 6C 00 relocations : take 0s at and replace with text, byte 6 ( ) data segment, byte 0 text, byte 10 ( ) address of puts symboltable: main text byte 0

hello.o

slide-53
SLIDE 53

what’s in those files?

CS 3330 Computer Architecture 54

#include <stdio.h> int main(void) { puts("Hello, World!"); return 0; }

hello.c

.text main: sub $8, %rsp mov $.Lstr, %rdi call puts xor %eax, %eax add $8, %rsp ret .data .Lstr: .string "Hello,␣World!"

hello.s hello.o

text (code) segment: 48 83 EC 08 BF 00 00 00 00 E8 00 00 00 00 31 C0 48 83 C4 08 C3 data segment: 48 65 6C 6C 6F 2C 20 57 6F 72 6C 00 relocations: take 0s at and replace with text, byte 6 ( ) data segment, byte 0 text, byte 10 ( ) address of puts symboltable: main text byte 0

28

slide-54
SLIDE 54

what’s in those files?

CS 3330 Computer Architecture 55

#include <stdio.h> int main(void) { puts("Hello, World!"); return 0; }

hello.c

.text main: sub $8, %rsp mov $.Lstr, %rdi call puts xor %eax, %eax add $8, %rsp ret .data .Lstr: .string "Hello,␣World!"

hello.s hello.o

text (code) segment: 48 83 EC 08 BF 00 00 00 00 E8 00 00 00 00 31 C0 48 83 C4 08 C3 data segment: 48 65 6C 6C 6F 2C 20 57 6F 72 6C 00 relocations: take 0s at and replace with text, byte 6 ( ) data segment, byte 0 text, byte 10 ( ) address of puts symboltable: main text byte 0

Code puts Data hello Code hello Data puts Don’t know where it will get put in memory the linker will fill it in Instructions for link to find where put the addresses of data

slide-55
SLIDE 55

what’ s in thosefiles?

CS 3330 Computer Architecture 56

#include <stdio.h> int main(void) { puts("Hello, World!"); return 0; }

hello.c

.text main: sub $8, %rsp mov $.Lstr, %rdi call puts xor %eax, %eax add $8, %rsp ret .data .Lstr: .string "Hello,␣World!"

hello.s hello.o

text (code) segment: 48 83 EC 08 BF 00 00 00 00 E8 00 00 00 00 31 C0 48 83 C4 08 C3 data segment: 48 65 6C 6C 6F 2C 20 57 6F 72 6C 00 relocations: take 0s at and replace with text, byte 6 ( ) data segment, byte 0 text, byte 10 ( ) address of puts symboltable: main text byte 0 48 65 6C 6C 6F 2C 20 57 6F 72 6C 00 (actually binary, but shown as hexadecimal) … 48 83 EC 08 BF A7 02 04 00 E8 08 4A 04 00 31 C0 48 83 C4 08 C3 … …(code from stdio.o) … … …(data from stdio.o) …

hello.exe + stdio.o

Updated with address

  • f hello

Word

slide-56
SLIDE 56

Memory Address bus Get me value at x0003

http://www.ti.com/product/MSP430G2553

Memory Data bus Your data was: xffff

CS 3330 Computer Architecture 57