cs 3330 introduction daniel and charles

56
CS 3330 Introduction Daniel and Charles CS 3330 Computer Architecture 1

Upload: others

Post on 24-Apr-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 3330 Introduction Daniel and Charles

CS 3330 Introduction Daniel and Charles

CS 3330 Computer Architecture 1

Page 2: CS 3330 Introduction Daniel and Charles

lecturers• Charles and I will be splitting lectures

same(ish) lecture in each section

Page 3: CS 3330 Introduction Daniel and Charles

Grading

CS 3330 Computer Architecture 3

Take Home Quizzes: 10% (10% dropped)

Midterms (2): 30%

Final Exam (cumulative): 20%

Homework + Labs: 40%

Page 4: CS 3330 Introduction Daniel and Charles

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: nowe release answers talk to us if illness, etc.

CS 3330 Computer Architecture 4

Page 5: CS 3330 Introduction Daniel and Charles

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

Page 6: CS 3330 Introduction Daniel and Charles

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

Page 7: CS 3330 Introduction Daniel and Charles

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

Page 8: CS 3330 Introduction Daniel and Charles

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.

Page 9: CS 3330 Introduction Daniel and Charles

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

Page 10: CS 3330 Introduction Daniel and Charles

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

Page 11: CS 3330 Introduction Daniel and Charles

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

Page 12: CS 3330 Introduction Daniel and Charles

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

Page 13: CS 3330 Introduction Daniel and Charles

Questions?

CS 3330 Computer Architecture 13

Page 14: CS 3330 Introduction Daniel and Charles

Let’s Build a simple machine

CS 3330 Computer Architecture 14

Page 15: CS 3330 Introduction Daniel and Charles

How will store information in our machine?

CS 3330 Computer Architecture 15

Page 16: CS 3330 Introduction Daniel and Charles

0.0V0.2V

0.9V1.1V

0 1 0

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

Page 17: CS 3330 Introduction Daniel and Charles

There are different ways to represent bits

CS 3330 Computer Architecture 17

Page 18: CS 3330 Introduction Daniel and Charles

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

0 0 00001 1 00012 2 00103 3 00114 4 01005 5 01016 6 01107 7 01118 8 10009 9 1001A 10 1010B 11 1011C 12 1100D 13 1101E 14 1110F 15 1111

Q: 0x605C + 0x5 = 0x606

Page 19: CS 3330 Introduction Daniel and Charles

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

Page 20: CS 3330 Introduction Daniel and Charles

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

Page 21: CS 3330 Introduction Daniel and Charles

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?

Page 22: CS 3330 Introduction Daniel and Charles

A B C S

0 0 0 0

0 1 0 1

1 0 0 1

1 1 1 0

Binary for 2

Simple Half Adder (Not Quite)

CS 3330 Computer Architecture 22

And Gate

Page 23: CS 3330 Introduction Daniel and Charles

Half Adder Bread board

CS 3330 Computer Architecture 23

Page 24: CS 3330 Introduction Daniel and Charles

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

Ripple Carry Adder

CS 3330 Computer Architecture 24

Page 25: CS 3330 Introduction Daniel and Charles

Now we have a machine that can add large numbers

(Bundle of wires)

CS 3330 Computer Architecture 26

A 64 bits

B 64 bits

AD

DE

R

carry

Registers

64 bundle of wires

Page 26: CS 3330 Introduction Daniel and Charles

CS 3330 Computer Architecture 27

How do we program it?

Page 27: CS 3330 Introduction Daniel and Charles

We could put one and zeros in manually

CS 3330 Computer Architecture 28

Page 28: CS 3330 Introduction Daniel and Charles

The solution: Abstraction

CS 3330 Computer Architecture 29

Page 29: CS 3330 Introduction Daniel and Charles

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

Page 30: CS 3330 Introduction Daniel and Charles

Now we have a machine that can add large numbers

CS 3330 Computer Architecture 31

A 64 bits

B 64 bits

AD

DE

R

How do we program it?

carry

Registers

0010 0001

Page 31: CS 3330 Introduction Daniel and Charles

We are computer scientists why should we care about hardware?

CS 3330 Computer Architecture 32

Page 32: CS 3330 Introduction Daniel and Charles

Why

• Understanding computer architecture will help you:

• Write fast programs

• And understand strange program behaviors like segmentation faults.

Page 33: CS 3330 Introduction Daniel and Charles

Let’s look at a simple example

CS 3330 Computer Architecture 34

Page 34: CS 3330 Introduction Daniel and Charles

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.8ms4.3ms2.0 GHz Intel Core i7 Haswell

Page 35: CS 3330 Introduction Daniel and Charles

program performance: issues

• (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

Page 36: CS 3330 Introduction Daniel and Charles

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

CS 3330 Computer Architecture 37

Page 37: CS 3330 Introduction Daniel and Charles

processors and memory

CS 3330 Computer Architecture 38

processor

I/O

Bridge

memory

to I/O devices

keyboard, mouse, wifi,…

Page 38: CS 3330 Introduction Daniel and Charles

CS 3330 Computer Architecture 39

More detail

Page 39: CS 3330 Introduction Daniel and Charles

Memory Address busGet me value at 0x0003

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

Memory Data busYour data was:

0xffff

CS 3330 Computer Architecture 40Schematic

Page 40: CS 3330 Introduction Daniel and Charles

Endianess

CS 3330 Computer Architecture 41

Page 41: CS 3330 Introduction Daniel and Charles

CS 3330 Computer Architecture 42

little endian

(least significant byte has lowestaddress)

big endian

(most significant byte has lowestaddress)

value

0x…DE

address0xFFFFFFFF

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

0x030x00041FFF

0x0004…1FFE

0x00000002

0x00000001

0x…60

0xFE

0xE0

0x03020100 = 50462976

0x00010203 = 66051

Endianess

Page 42: CS 3330 Introduction Daniel and Charles

memory

CS 3330 Computer Architecture 43

value

0x…DE

0x…60

0xFE

address0xFFFFFFFF

0xFFFFFFFE

0xFFFF…FFFD

0x00042006

0x00042005

0x00042004

0x00042003

0x00042002

0x00042001

0x00042000

0x00041FFF

0x0004…1FFE

0x00000002

0x00000001

0x000000000xE00xA0

0x14

0x45

0x06

0x05

0x04

0x03

0x02

0x01

0x00

0x03

value

0x…FE

0x…06

0xDE

address0x00000000

0x00000001

0x0000…0002

0x00041FFE

0x00041FFF

0x00042000

0x00042001

0x00042002

0x00042003

0x00042004

0x00042005

0x0004…2006

0xFFFFFFFD

0xFFFFFFFE

0xFFFFFFFF0x450x14

0xA0

0xE0

0x60

0x03

0x00

0x01

0x02

0x03

0x04

0x05

Page 43: CS 3330 Introduction Daniel and Charles

Endianess

CS 3330 Computer Architecture 44

little endian

(least significant byte has lowestaddress)

big endian

(most significant byte has lowestaddress)

value

0x…DE

address0xFFFFFFFF

0xFFFFFFFE

0xFFFF…FFFD

0x00042006

0x00042005

0x00042004

0x00042003

0x00042002

0x00042001

0x00042000

0x14

0x45

0x06

0x05

0x04

0x03

0x02

0x01

0x00

0x030x00041FFF

0x0004…1FFE

0x00000002

0x00000001

0x…60

0xFE

0xE0

0x03020100 = 50462976

0x00010203 = 66051

0x03020101 = 50462977

Page 44: CS 3330 Introduction Daniel and Charles

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

Page 45: CS 3330 Introduction Daniel and Charles

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)

Page 46: CS 3330 Introduction Daniel and Charles

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

Page 47: CS 3330 Introduction Daniel and Charles

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

}

Page 48: CS 3330 Introduction Daniel and Charles

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)

Page 49: CS 3330 Introduction Daniel and Charles

what’s in those files?

CS 3330 Computer Architecture 50

#include <stdio.h>

int main(void) {

puts("Hello, World!");

return 0;

}

hello.c

Page 50: CS 3330 Introduction Daniel and Charles

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

Page 51: CS 3330 Introduction Daniel and Charles

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

101101000

Calling convention

Page 52: CS 3330 Introduction Daniel and Charles

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 withtext, byte 6 ( ) data segment, byte 0

text, byte 10 ( ) address of puts

symboltable:

main text byte 0

hello.o

Page 53: CS 3330 Introduction Daniel and Charles

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.otext (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 withtext, byte 6 ( ) data segment, byte 0

text, byte 10 ( ) address of puts

symboltable:

main text byte 0

28

Page 54: CS 3330 Introduction Daniel and Charles

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.otext (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 withtext, 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

Page 55: CS 3330 Introduction Daniel and Charles

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.otext (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 withtext, byte 6 ( ) data segment, byte 0

text, byte 10 ( ) address of puts

symboltable:

main text byte 048 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 of hello

Word

Page 56: CS 3330 Introduction Daniel and Charles

Memory Address busGet me value at x0003

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

Memory Data busYour data was:

xffff

CS 3330 Computer Architecture 57