csc 252: computer organization spring 2020: lecture 11€¦ · carnegie mellon!3 announcement...

145
CSC 252: Computer Organization Spring 2020: Lecture 11 Instructor: Yuhao Zhu Department of Computer Science University of Rochester

Upload: others

Post on 30-May-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

CSC 252: Computer Organization Spring 2020: Lecture 11

Instructor: Yuhao Zhu

Department of Computer ScienceUniversity of Rochester

Page 2: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!2

Announcement• Programming assignment 3 is out

• Details: https://www.cs.rochester.edu/courses/252/spring2020/labs/assignment3.html

• Due on Feb. 28, 11:59 PM • You (may still) have 3 slip days

Today

Due

Page 3: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!3

Announcement• Grades for lab2 are posted.• If you think there are some problems

• Take a deep breath • Tell yourself that the teaching staff like you, not the opposite • Email/go to Shuang or Sudhanshu’s office hours and explain to them

why you should get more points, and they will fix it for you

Page 4: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!4

Announcement• Programming assignment 3 is in x86 assembly language. Seek

help from TAs.• TAs are best positioned to answer your questions about

programming assignments!!!• Programming assignments do NOT repeat the lecture materials.

They ask you to synthesize what you have learned from the lectures and work out something new.

Page 5: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Y86 Instruction Encoding

�5

0 1 2 3 4 5 6 7 8 9Byte

pushq rA A 0 rA F

jXX Dest 7 fn

popq rA B 0 rA F

call Dest 8 0

V

D

D

Dest

Dest

cmovXX rA, rB 2 fn rA rB

irmovq V, rB 3 0 F rB

rmmovq rA, D(rB) 4 0 rA rB

mrmovq D(rB), rA 5 0 rA rB

OPq rA, rB 6 fn rA rB

ret 9 0

nop 1 0

halt 0 0

Page 6: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?

!6

jXX Dest 7 fn

call Dest 8 0

D

Dest

rmmovq rA, D(rB) 4 0 rA rB

OPq rA, rB 6 fn rA rB

Dest

Page 7: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?

!6

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100

jXX Dest 7 fn

call Dest 8 0

D

Dest

rmmovq rA, D(rB) 4 0 rA rB

OPq rA, rB 6 fn rA rB

Dest

Page 8: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?

!6

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100 40 64 1c 04 00 00 00 00 00 00

jXX Dest 7 fn

call Dest 8 0

D

Dest

rmmovq rA, D(rB) 4 0 rA rB

OPq rA, rB 6 fn rA rB

Dest

Page 9: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?

!6

90

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100 40 64 1c 04 00 00 00 00 00 00

jXX Dest 7 fn

call Dest 8 0

D

Dest

rmmovq rA, D(rB) 4 0 rA rB

OPq rA, rB 6 fn rA rB

Dest

Page 10: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?

!6

90

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100

60 06

40 64 1c 04 00 00 00 00 00 00

jXX Dest 7 fn

call Dest 8 0

D

Dest

rmmovq rA, D(rB) 4 0 rA rB

OPq rA, rB 6 fn rA rB

Dest

Page 11: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?

!6

90

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100

60 06

80 00 01 00 00 00 00 00 00

40 64 1c 04 00 00 00 00 00 00

jXX Dest 7 fn

call Dest 8 0

D

Dest

rmmovq rA, D(rB) 4 0 rA rB

OPq rA, rB 6 fn rA rB

Dest

Page 12: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?

!6

90

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100

60 06

80 00 01 00 00 00 00 00 00

70 ????????

40 64 1c 04 00 00 00 00 00 00

jXX Dest 7 fn

call Dest 8 0

D

Dest

rmmovq rA, D(rB) 4 0 rA rB

OPq rA, rB 6 fn rA rB

Dest

Page 13: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?

!6

30 f2 cd ab 00 00 00 00 00 00

90

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100

60 06

80 00 01 00 00 00 00 00 00

70 ????????

40 64 1c 04 00 00 00 00 00 00

jXX Dest 7 fn

call Dest 8 0

D

Dest

rmmovq rA, D(rB) 4 0 rA rB

OPq rA, rB 6 fn rA rB

Dest

Page 14: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?

!6

30 f2 cd ab 00 00 00 00 00 00

90

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100

60 06

80 00 01 00 00 00 00 00 00

0x100 + the lengths of all instructions in-between

70 ????????

40 64 1c 04 00 00 00 00 00 00

jXX Dest 7 fn

call Dest 8 0

D

Dest

rmmovq rA, D(rB) 4 0 rA rB

OPq rA, rB 6 fn rA rB

Dest

Page 15: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?

!6

30 f2 cd ab 00 00 00 00 00 00

90

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100

60 06

80 00 01 00 00 00 00 00 00

0x200

0x100 + the lengths of all instructions in-between

70 ????????

40 64 1c 04 00 00 00 00 00 00

jXX Dest 7 fn

call Dest 8 0

D

Dest

rmmovq rA, D(rB) 4 0 rA rB

OPq rA, rB 6 fn rA rB

Dest

Page 16: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?

!6

30 f2 cd ab 00 00 00 00 00 00

90

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100

60 06

80 00 01 00 00 00 00 00 00

0x200

0x100 + the lengths of all instructions in-between

70 ????????

40 64 1c 04 00 00 00 00 00 00

00 02 00 00 00 00 00 00

jXX Dest 7 fn

call Dest 8 0

D

Dest

rmmovq rA, D(rB) 4 0 rA rB

OPq rA, rB 6 fn rA rB

Dest

Page 17: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?• The assembler is a program that translates assembly code to binary code• The OS tells the assembler the start address of the code (sort of…)• Translate the assembly program line by line• Need to build a “label map” that maps each label to its address

!7

30 f2 cd ab 00 00 00 00 00 00

90

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100

60 06

80 00 01 00 00 00 00 00 00

0x200

0x100 + the lengths of all instructions in-between

70 ????????

40 64 1c 04 00 00 00 00 00 00

00 02 00 00 00 00 00 00

Page 18: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?• What if the ISA encoding uses relative address for jump and call?

!8

30 f2 cd ab 00 00 00 00 00 00

90

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100

60 06

80 06 00 01 00 00 00 00 00 00

0x200

70 00 02 00 00 00 00 00 00

40 64 1c 04 00 00 00 00 00 00

0x185

0x180

Page 19: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?• What if the ISA encoding uses relative address for jump and call?

!8

30 f2 cd ab 00 00 00 00 00 00

90

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100

60 06

80 06 00 01 00 00 00 00 00 00

0x200

70 00 02 00 00 00 00 00 00

40 64 1c 04 00 00 00 00 00 00

0x185

0x180

relative addr: -0x80

Page 20: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?• What if the ISA encoding uses relative address for jump and call?

!8

30 f2 cd ab 00 00 00 00 00 00

90

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100

60 06

80 06 00 01 00 00 00 00 00 00

0x200

70 00 02 00 00 00 00 00 00

40 64 1c 04 00 00 00 00 00 00

0x185

0x180

relative addr: -0x80

00 00 00 11 11 11 11 11

Page 21: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?• What if the ISA encoding uses relative address for jump and call?

!8

30 f2 cd ab 00 00 00 00 00 00

90

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100

60 06

80 06 00 01 00 00 00 00 00 00

0x200

70 00 02 00 00 00 00 00 00

40 64 1c 04 00 00 00 00 00 00

0x185

0x180

relative addr: -0x80

0x7B

00 00 00 11 11 11 11 11

Page 22: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?• What if the ISA encoding uses relative address for jump and call?

!8

30 f2 cd ab 00 00 00 00 00 00

90

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100

60 06

80 06 00 01 00 00 00 00 00 00

0x200

70 00 02 00 00 00 00 00 00

40 64 1c 04 00 00 00 00 00 00

7B 00 00 00 00 00 00 000x185

0x180

relative addr: -0x80

0x7B

00 00 00 11 11 11 11 11

Page 23: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?• What if the ISA encoding uses relative address for jump and call?• If we use relative address, the exact start address of the code

doesn’t matter. Why?

!8

30 f2 cd ab 00 00 00 00 00 00

90

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100

60 06

80 06 00 01 00 00 00 00 00 00

0x200

70 00 02 00 00 00 00 00 00

40 64 1c 04 00 00 00 00 00 00

7B 00 00 00 00 00 00 000x185

0x180

relative addr: -0x80

0x7B

00 00 00 11 11 11 11 11

Page 24: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

How Does An Assembler Work?• What if the ISA encoding uses relative address for jump and call?• If we use relative address, the exact start address of the code

doesn’t matter. Why?• This code is called Position-Independent Code (PIC)

!8

30 f2 cd ab 00 00 00 00 00 00

90

rmmovq %rsi,0x41c(%rsp)

addq %rax,%rsi

jmp .L0

ret

<foo>

… …

… …

.L0 irmovq $0xabcd, %rdx

call <foo>

0x100

60 06

80 06 00 01 00 00 00 00 00 00

0x200

70 00 02 00 00 00 00 00 00

40 64 1c 04 00 00 00 00 00 00

7B 00 00 00 00 00 00 000x185

0x180

relative addr: -0x80

0x7B

00 00 00 11 11 11 11 11

Page 25: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!9

Today: Circuits Basics• Transistors• Circuits for computations• Circuits for storing data

Page 26: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!10

Basic Logic Gates

A | B ~(A | B)

A & B ~(A & B)

Page 27: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Computing with Logic Gates

• Outputs are Boolean functions of inputs• Respond continuously to changes in inputs with some small delay• Different gates have different delays (b/c different transistor combinations)

�11

ab out

ab out a out

out = a && b out = a || b out = !a

And Or Not

Voltage

Time

a

b

Page 28: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Computing with Logic Gates

• Outputs are Boolean functions of inputs• Respond continuously to changes in inputs with some small delay• Different gates have different delays (b/c different transistor combinations)

�11

ab out

ab out a out

out = a && b out = a || b out = !a

And Or Not

Voltage

Time

a

ba && b

Page 29: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Computing with Logic Gates

• Outputs are Boolean functions of inputs• Respond continuously to changes in inputs with some small delay• Different gates have different delays (b/c different transistor combinations)

�11

ab out

ab out a out

out = a && b out = a || b out = !a

And Or Not

Voltage

Time

a

ba && b

Rising Delay

Page 30: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Computing with Logic Gates

• Outputs are Boolean functions of inputs• Respond continuously to changes in inputs with some small delay• Different gates have different delays (b/c different transistor combinations)

�11

ab out

ab out a out

out = a && b out = a || b out = !a

And Or Not

Voltage

Time

a

ba && b

Rising Delay Falling Delay

Page 31: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Combinational Circuits

• A Network of Logic Gates• Continuously responds to changes on primary inputs • Primary outputs become (after some delay) Boolean functions of

primary inputs

�12

PrimaryInputs

PrimaryOutputs

Page 32: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bit Equality

�13

Page 33: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bit Equality

�13

Page 34: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bit Equality

�13

a

b

Page 35: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bit Equality

�13

a

b

Page 36: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bit Equality

�13

a

b

Page 37: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bit Equality

�13

a

b

Page 38: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bit Equality

�13

a

b

Page 39: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bit Equality

�13

a

b

eq

Page 40: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bit Equality

�13

Bit equala

b

eq

Page 41: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Delay of Bit Equal Circuit

• What’s the delay of this bit equal circuit?• Assuming 1-input NOT takes 1 unit of time, 2-input AND takes 4.3,

and 2-input OR takes 4.7

�14

Bit equala

b

eq

Page 42: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Delay of Bit Equal Circuit

• What’s the delay of this bit equal circuit?• Assuming 1-input NOT takes 1 unit of time, 2-input AND takes 4.3,

and 2-input OR takes 4.7

�14

Bit equala

b

eq1

4.3

4.7

Page 43: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Delay of Bit Equal Circuit

• What’s the delay of this bit equal circuit?• Assuming 1-input NOT takes 1 unit of time, 2-input AND takes 4.3,

and 2-input OR takes 4.7• The delay of a circuit is determined by its “critical path”

• The path between an input and the output that the maximum delay • Estimating the critical path delay is called static timing analysis

�14

Bit equala

b

eq1

4.3

4.7

Page 44: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Delay of Bit Equal Circuit

• What’s the delay of this bit equal circuit?• Assuming 1-input NOT takes 1 unit of time, 2-input AND takes 4.3,

and 2-input OR takes 4.7• The delay of a circuit is determined by its “critical path”

• The path between an input and the output that the maximum delay • Estimating the critical path delay is called static timing analysis

�14

Bit equala

b

eq1

4.3

4.7

Critical Path

Page 45: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

64-bit Equality

�15

=B

A

Eq

Page 46: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

64-bit Equality

�15

b63Bit equal

a63

eq63

b62Bit equal

a62

eq62

b1Bit equal

a1

eq1

b0Bit equal

a0

eq0

Eq

=B

A

Eq

Page 47: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bit-Level Multiplexor (MUX)• Control signal s• Data signals A and B• Output A when s=1, B when s=0

�16

s

B

AOutMUX

Page 48: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bit-Level Multiplexor (MUX)• Control signal s• Data signals A and B• Output A when s=1, B when s=0

�16

bool out = (s&&a)||(!s&&b)

s

B

AOutMUX

Page 49: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bit-Level Multiplexor (MUX)• Control signal s• Data signals A and B• Output A when s=1, B when s=0

�16

bool out = (s&&a)||(!s&&b)

s

b

a

out

Bit MUX

s

B

AOutMUX

Page 50: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

4-Input Multiplexor• Control signal s; Data signals A, B, C, and D• Output: A when s = 00, B when s = 01, C when s = 10, D when s = 11

�17

Page 51: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

4-Input Multiplexor• Control signal s; Data signals A, B, C, and D• Output: A when s = 00, B when s = 01, C when s = 10, D when s = 11

�17

s[0]

A

C

Bit MUX

Page 52: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

4-Input Multiplexor• Control signal s; Data signals A, B, C, and D• Output: A when s = 00, B when s = 01, C when s = 10, D when s = 11

�17

s[0]

A

C

Bit MUX

s[0]

B

D

Bit MUX

Page 53: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

4-Input Multiplexor• Control signal s; Data signals A, B, C, and D• Output: A when s = 00, B when s = 01, C when s = 10, D when s = 11

�17

s[0]

A

C

Bit MUX

s[0]

B

D

Bit MUX out

s[1] Bit MUX

Page 54: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

4-Input Multiplexor• Control signal s; Data signals A, B, C, and D• Output: A when s = 00, B when s = 01, C when s = 10, D when s = 11

�17

s[0]

A

C

Bit MUX

s[0]

B

D

Bit MUX out

s[1] Bit MUX

What’s the latency of this implementation?

1

4.74.3

Page 55: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Logic Design and VLSI• The number of inputs of a gate (fan-in) and the number of

outputs of a gate (fan-out) will affect the gate delay.

!18

Page 56: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Logic Design and VLSI• The number of inputs of a gate (fan-in) and the number of

outputs of a gate (fan-out) will affect the gate delay.• Think of logic gates as LEGOs, using which you/synthesis tool

generate the gate level circuit design for complex functionalities.

!18

Page 57: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Logic Design and VLSI• The number of inputs of a gate (fan-in) and the number of

outputs of a gate (fan-out) will affect the gate delay.• Think of logic gates as LEGOs, using which you/synthesis tool

generate the gate level circuit design for complex functionalities.• A standard cell library is a collection of well defined and

appropriately characterized logic gates (delay, operating voltage, etc.) that can be used to implement a digital design.

!18

Page 58: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Logic Design and VLSI• The number of inputs of a gate (fan-in) and the number of

outputs of a gate (fan-out) will affect the gate delay.• Think of logic gates as LEGOs, using which you/synthesis tool

generate the gate level circuit design for complex functionalities.• A standard cell library is a collection of well defined and

appropriately characterized logic gates (delay, operating voltage, etc.) that can be used to implement a digital design.

• The logic synthesis tool will automatically generate the “best” gate-level implementation of a piece of logic.

!18

Page 59: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Logic Design and VLSI• The number of inputs of a gate (fan-in) and the number of

outputs of a gate (fan-out) will affect the gate delay.• Think of logic gates as LEGOs, using which you/synthesis tool

generate the gate level circuit design for complex functionalities.• A standard cell library is a collection of well defined and

appropriately characterized logic gates (delay, operating voltage, etc.) that can be used to implement a digital design.

• The logic synthesis tool will automatically generate the “best” gate-level implementation of a piece of logic.

• Take a Logic Design or Very Large Scale Integrated-Circuit (VLSI) course if you want to know more about circuit design.

• Logic design uses the gate-level abstractions • VLSI tells you how the gates are implemented at transistor-level

!18

Page 60: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!19

Full (1-bit) AdderAdd two bits and carry-in,produce one-bit sum and carry-out. A B Cin S Cou

t

0 0 0 0 00 0 1 1 0

0 1 0 1 0

0 1 1 0 1

1 0 0 1 0

1 0 1 0 1

1 1 0 0 1

1 1 1 1 1

Page 61: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!19

Full (1-bit) AdderAdd two bits and carry-in,produce one-bit sum and carry-out. A B Cin S Cou

t

0 0 0 0 00 0 1 1 0

0 1 0 1 0

0 1 1 0 1

1 0 0 1 0

1 0 1 0 1

1 1 0 0 1

1 1 1 1 1

S = (~A & ~B & Cin)

Page 62: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!19

Full (1-bit) AdderAdd two bits and carry-in,produce one-bit sum and carry-out. A B Cin S Cou

t

0 0 0 0 00 0 1 1 0

0 1 0 1 0

0 1 1 0 1

1 0 0 1 0

1 0 1 0 1

1 1 0 0 1

1 1 1 1 1

S = (~A & ~B & Cin) | (~A & B & ~Cin)

Page 63: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!19

Full (1-bit) AdderAdd two bits and carry-in,produce one-bit sum and carry-out. A B Cin S Cou

t

0 0 0 0 00 0 1 1 0

0 1 0 1 0

0 1 1 0 1

1 0 0 1 0

1 0 1 0 1

1 1 0 0 1

1 1 1 1 1

S = (~A & ~B & Cin) | (~A & B & ~Cin)

| (A & ~B & ~Cin)

Page 64: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!19

Full (1-bit) AdderAdd two bits and carry-in,produce one-bit sum and carry-out. A B Cin S Cou

t

0 0 0 0 00 0 1 1 0

0 1 0 1 0

0 1 1 0 1

1 0 0 1 0

1 0 1 0 1

1 1 0 0 1

1 1 1 1 1

S = (~A & ~B & Cin) | (~A & B & ~Cin)

| (A & ~B & ~Cin)

| (A & B & Cin)

Page 65: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!19

Full (1-bit) AdderAdd two bits and carry-in,produce one-bit sum and carry-out. A B Cin S Cou

t

0 0 0 0 00 0 1 1 0

0 1 0 1 0

0 1 1 0 1

1 0 0 1 0

1 0 1 0 1

1 1 0 0 1

1 1 1 1 1

S = (~A & ~B & Cin) | (~A & B & ~Cin)

| (A & ~B & ~Cin)

| (A & B & Cin)

Cou = (~A & B & Cin)

| (A & ~B & Cin)

| (A & B & ~Cin) | (A & B & Cin)

Page 66: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!20

1-bit Full AdderAdd two bits and carry-in,produce one-bit sum and carry-out.

Cou = (~A & B & Cin)

| (A & ~B & Cin) | (A & B & ~Cin)

| (A & B & Cin)

Page 67: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!20

1-bit Full AdderAdd two bits and carry-in,produce one-bit sum and carry-out.

Cou = (~A & B & Cin)

| (A & ~B & Cin) | (A & B & ~Cin)

| (A & B & Cin)

AND Gates

OR Gates

Page 68: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!20

1-bit Full AdderAdd two bits and carry-in,produce one-bit sum and carry-out.

Cou = (~A & B & Cin)

| (A & ~B & Cin) | (A & B & ~Cin)

| (A & B & Cin)

AND Gates

OR Gates

Page 69: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!21

Four-bit Adder

Page 70: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!21

Four-bit Adder

• Ripple-carry Adder• Simple, but performance linear to bit width

Page 71: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!21

Four-bit Adder

• Ripple-carry Adder• Simple, but performance linear to bit width

• Carry look-ahead adder (CLA)• Generate all carriers simultaneously

Page 72: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

OFZFCF

Arithmetic Logic Unit

�22

ALU

Y

X

Result of some computation between X and Y

s

A

B

• An ALU performs multiple kinds of computations.• The actual computation depends on the selection signal s.• Also sets the condition codes (status flags)• For instance:

• X + Y when s == 00• X - Y when s == 01• X & Y when s == 10• X ^ Y when s == 11

• How can this ALU be implemented?

Page 73: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Arithmetic Logic Unit

• Implement 4 different circuits, one for each operation.• Then use a MUX to select the results

�23

OFZFCF

OFZFCF

OFZFCF

OFZFCF

+Y

X

X + Y

Y

X

X - Y

Y

X

X & Y

Y

X

X ^ Y

A

B

A

B

A

B

A

B

- & ^

MUXs

Out

Page 74: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!24

Today: Circuits Basics• Transistors• Circuits for computations• Circuits for storing data

Page 75: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!25

The Need for Storing Bits• Assembly programs set architecture (processor) states.

• Register File • Status Flags • Memory • Program Counter

Page 76: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!25

The Need for Storing Bits• Assembly programs set architecture (processor) states.

• Register File • Status Flags • Memory • Program Counter

• Every state is essentially some bits that are stored/loaded.

Page 77: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!25

The Need for Storing Bits• Assembly programs set architecture (processor) states.

• Register File • Status Flags • Memory • Program Counter

• Every state is essentially some bits that are stored/loaded.• Think of the program execution as an FSM.

Page 78: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!25

The Need for Storing Bits• Assembly programs set architecture (processor) states.

• Register File • Status Flags • Memory • Program Counter

• Every state is essentially some bits that are stored/loaded.• Think of the program execution as an FSM.• The hardware must provide mechanisms to load and store bits.

Page 79: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

!25

The Need for Storing Bits• Assembly programs set architecture (processor) states.

• Register File • Status Flags • Memory • Program Counter

• Every state is essentially some bits that are stored/loaded.• Think of the program execution as an FSM.• The hardware must provide mechanisms to load and store bits.• There are many different ways to store bits. They have trade-offs.

Page 80: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Build a 1-Bit Storage

�26

Q

D

C

Some Logic

•What I would like:• D is the data I want to store (0 or 1) • C is the control signal

• When C is 1, Q becomes D (i.e., storing the data) • When C is 0, Q doesn’t change with D (data stored)

Page 81: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bitstable Element

�27

Vin V1

V2

Vin = V2

Page 82: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bitstable Element

�27

Vin V1

V2

Vin = V2

1

Page 83: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bitstable Element

�27

Vin V1

V2

Vin = V2

10

Page 84: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bitstable Element

�27

Vin V1

V2

Vin = V2

10

1

Page 85: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bitstable Element

�27

Bistable Element

Q+

Q–

q

!q

q = 0 or 1

Vin V1

V2

Vin = V2

10

1

Page 86: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Bitstable Element

�27

Bistable Element

Q+

Q–

q

!q

q = 0 or 1

Vin V1

V2

Vin = V2

10

1

Q+ continuously outputs q.

Page 87: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Storing and Accessing 1 Bit

�28

Bistable Element

Q+

Q–

q

!q

q = 0 or 1

Page 88: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Storing and Accessing 1 Bit

�28

Bistable Element

Q+

Q–

q

!q

q = 0 or 1

Q+

Q–

R

S

OR

Page 89: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Storing and Accessing 1 Bit

�28

0

1

0 1

1 0

Bistable Element

Q+

Q–

q

!q

q = 0 or 1

Q+

Q–

R

S

OR

Page 90: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Storing and Accessing 1 Bit

�28

Setting Q+ to 10

1

0 1

1 0

Bistable Element

Q+

Q–

q

!q

q = 0 or 1

Q+

Q–

R

S

OR

Page 91: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Storing and Accessing 1 Bit

�28

1

0

1 0

0 1

Setting Q+ to 10

1

0 1

1 0

Bistable Element

Q+

Q–

q

!q

q = 0 or 1

Q+

Q–

R

S

OR

Page 92: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Storing and Accessing 1 Bit

�28

Setting Q+ to 01

0

1 0

0 1

Setting Q+ to 10

1

0 1

1 0

Bistable Element

Q+

Q–

q

!q

q = 0 or 1

Q+

Q–

R

S

OR

Page 93: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Storing and Accessing 1 Bit

�28

Setting Q+ to 01

0

1 0

0 1

Setting Q+ to 10

1

0 1

1 0

0

0

!q q

q !q

Bistable Element

Q+

Q–

q

!q

q = 0 or 1

Q+

Q–

R

S

OR

Page 94: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Storing and Accessing 1 Bit

�28

Setting Q+ to 01

0

1 0

0 1

Setting Q+ to 10

1

0 1

1 0

Q+ value unchangedi.e., stored!

0

0

!q q

q !q

Bistable Element

Q+

Q–

q

!q

q = 0 or 1

Q+

Q–

R

S

OR

Page 95: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Storing and Accessing 1 Bit

�28

R-S Latch

Setting Q+ to 01

0

1 0

0 1

Setting Q+ to 10

1

0 1

1 0

Q+ value unchangedi.e., stored!

0

0

!q q

q !q

Bistable Element

Q+

Q–

q

!q

q = 0 or 1

Q+

Q–

R

S

OR

Page 96: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Storing and Accessing 1 Bit

�28

R-S Latch

Setting Q+ to 01

0

1 0

0 1

Setting Q+ to 10

1

0 1

1 0

Q+ value unchangedi.e., stored!

0

0

!q q

q !q

Bistable Element

Q+

Q–

q

!q

q = 0 or 1

Q+

Q–

R

S

OR

If R and S are different, Q+ is the same as S

Page 97: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

A Better Way of Storing/Accessing 1 Bit

�29

Q+

Q–

R

S

D

C

Data

Control

If R and S are different, Q+ is the same as S

Page 98: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

A Better Way of Storing/Accessing 1 Bit

�29

Q+

Q–

R

S

D

C

Data

Control

1

d !d !d !d d

d d !d

If R and S are different, Q+ is the same as S

Page 99: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

A Better Way of Storing/Accessing 1 Bit

�29

Q+

Q–

R

S

D

C

Data

Control

1

d !d !d !d d

d d !d

Q+ will continuously change as d changes

If R and S are different, Q+ is the same as S

Page 100: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

A Better Way of Storing/Accessing 1 Bit

�29

Q+

Q–

R

S

D

C

Data

Control

Storing Data (Latching)

1

d !d !d !d d

d d !d

Q+ will continuously change as d changes

If R and S are different, Q+ is the same as S

Page 101: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

A Better Way of Storing/Accessing 1 Bit

�29

Q+

Q–

R

S

D

C

Data

Control

Storing Data (Latching)

1

d !d !d !d d

d d !d0

d !d q

!q

!q

q0

0

Q+ will continuously change as d changes

If R and S are different, Q+ is the same as S

Page 102: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

A Better Way of Storing/Accessing 1 Bit

�29

Q+

Q–

R

S

D

C

Data

Control

Storing Data (Latching)

1

d !d !d !d d

d d !d0

d !d q

!q

!q

q0

0

Q+ will continuously change as d changes Q+ doesn’t change with d

If R and S are different, Q+ is the same as S

Page 103: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

A Better Way of Storing/Accessing 1 Bit

�29

Q+

Q–

R

S

D

C

Data

Control

Storing Data (Latching)

1

d !d !d !d d

d d !d

Holding Data

0

d !d q

!q

!q

q0

0

Q+ will continuously change as d changes Q+ doesn’t change with d

If R and S are different, Q+ is the same as S

Page 104: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

A Better Way of Storing/Accessing 1 Bit

�29

D Latch

Q+

Q–

R

S

D

C

Data

Control

Storing Data (Latching)

1

d !d !d !d d

d d !d

Holding Data

0

d !d q

!q

!q

q0

0

Q+ will continuously change as d changes Q+ doesn’t change with d

If R and S are different, Q+ is the same as S

Page 105: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

D-Latch is “Transparent”

�30

C

D

Q+

Time

Changing DLatching

1

d !d !d !d d

d d !d

D

C

Page 106: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

D-Latch is “Transparent”

�30

C

D

Q+

Time

Changing DLatching

1

d !d !d !d d

d d !d

D

C

Page 107: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

D-Latch is “Transparent”

�30

C

D

Q+

Time

Changing DLatching

1

d !d !d !d d

d d !d

D

C

Page 108: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

D-Latch is “Transparent”

�30

C

D

Q+

Time

Changing DLatching

1

d !d !d !d d

d d !d

D

C

Page 109: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

D-Latch is “Transparent”

�30

C

D

Q+

Time

Changing DLatching

1

d !d !d !d d

d d !d

D

C

Page 110: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

D-Latch is “Transparent”

�30

C

D

Q+

Time

Changing DLatching

1

d !d !d !d d

d d !d

D

C

Page 111: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

D-Latch is “Transparent”

�30

C

D

Q+

Time

Changing DLatching

1

d !d !d !d d

d d !d

D

C

Page 112: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

D-Latch is “Transparent”

• When you want to store d, you have to first set C to 1, and then set d

�30

C

D

Q+

Time

Changing DLatching

1

d !d !d !d d

d d !d

D

C

Page 113: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

D-Latch is “Transparent”

• When you want to store d, you have to first set C to 1, and then set d• There is a propagation delay of the combinational circuit from D to Q+

and Q–. So hold C for a while until the signal is fully propagated

�30

C

D

Q+

Time

Changing DLatching

1

d !d !d !d d

d d !d

D

C

Page 114: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

D-Latch is “Transparent”

• When you want to store d, you have to first set C to 1, and then set d• There is a propagation delay of the combinational circuit from D to Q+

and Q–. So hold C for a while until the signal is fully propagated• Then set C to 0. Value latched depends on value of D as C goes to 0

�30

C

D

Q+

Time

Changing DLatching

1

d !d !d !d d

d d !d

D

C

Page 115: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

D-Latch is “Transparent”

• When you want to store d, you have to first set C to 1, and then set d• There is a propagation delay of the combinational circuit from D to Q+

and Q–. So hold C for a while until the signal is fully propagated• Then set C to 0. Value latched depends on value of D as C goes to 0• D-latch is transparent when C is 1

�30

C

D

Q+

Time

Changing DLatching

1

d !d !d !d d

d d !d

D

C

Page 116: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

D-Latch is “Transparent”

• When you want to store d, you have to first set C to 1, and then set d• There is a propagation delay of the combinational circuit from D to Q+

and Q–. So hold C for a while until the signal is fully propagated• Then set C to 0. Value latched depends on value of D as C goes to 0• D-latch is transparent when C is 1• D-latch is “level-triggered” b/c Q changes as the voltage level of C rises.

�30

C

D

Q+

Time

Changing DLatching

1

d !d !d !d d

d d !d

D

C

Page 117: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Edge-Triggered Latch (Flip-Flop)

�31

Q+

Q–

R

S

D

C

Data

Control

D

C

Page 118: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Edge-Triggered Latch (Flip-Flop)

�31

Q+

Q–

R

S

D

C

Data

Control

Page 119: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Edge-Triggered Latch (Flip-Flop)

�31

Q+

Q–

R

S

D

C

Data

Control 0

Page 120: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Edge-Triggered Latch (Flip-Flop)

�31

Q+

Q–

R

S

D

C

Data

Control 0

1

Page 121: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Edge-Triggered Latch (Flip-Flop)

�31

Q+

Q–

R

S

D

C

Data

Control 0

10

Page 122: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Edge-Triggered Latch (Flip-Flop)

�31

Q+

Q–

R

S

D

C

Data

Control

10

1

Page 123: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Edge-Triggered Latch (Flip-Flop)

�31

Q+

Q–

R

S

D

C

Data

Control

10

1

->1

Page 124: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Edge-Triggered Latch (Flip-Flop)

�31

Q+

Q–

R

S

D

C

Data

Control

10

1

->0->1

Page 125: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Edge-Triggered Latch (Flip-Flop)

�31

Q+

Q–

R

S

D

C

Data

Control

10

1

->0->1->0

Page 126: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Edge-Triggered Latch (Flip-Flop)

�31

Q+

Q–

R

S

D

C

Data

Control TTrigger

C

D

Q+

Time

T

10

1

->0->1->0

Page 127: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Edge-Triggered Latch (Flip-Flop)

• Flip-flop: Only latches data for a brief period

�31

Q+

Q–

R

S

D

C

Data

Control TTrigger

C

D

Q+

Time

T

10

1

->0->1->0

Page 128: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Edge-Triggered Latch (Flip-Flop)

• Flip-flop: Only latches data for a brief period• Value latched depends on data

as C rises (i.e., 0–>1); usually called at the rising edge of C

�31

Q+

Q–

R

S

D

C

Data

Control TTrigger

C

D

Q+

Time

T

10

1

->0->1->0

Page 129: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Edge-Triggered Latch (Flip-Flop)

• Flip-flop: Only latches data for a brief period• Value latched depends on data

as C rises (i.e., 0–>1); usually called at the rising edge of C•Output remains stable at all

other times�31

Q+

Q–

R

S

D

C

Data

Control TTrigger

C

D

Q+

Time

T

10

1

->0->1->0

Page 130: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Registers

• Stores several bits of data• Collection of edge-triggered latches (D Flip-flops)• Loads input on rising edge of the C signal

�32

DC Q+

DC Q+

DC Q+

DC Q+

DC Q+

DC Q+

DC Q+

DC Q+

i7i6i5i4i3i2i1i0

o7

o6

o5

o4

o3

o2

o1

o0

C

Structure

Page 131: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Registers

• Stores several bits of data• Collection of edge-triggered latches (D Flip-flops)• Loads input on rising edge of the C signal

�32

I O

C

DC Q+

DC Q+

DC Q+

DC Q+

DC Q+

DC Q+

DC Q+

DC Q+

i7i6i5i4i3i2i1i0

o7

o6

o5

o4

o3

o2

o1

o0

C

Structure

Page 132: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Register Operation

�33

State = x

Output = xInput = yx

C

Page 133: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Register Operation

�33

State = x

Output = xInput = yx

C Rises

C

Page 134: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Register Operation

�33

State = x

Output = xInput = yx

C RisesState = y

Output = yy

C

Page 135: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Register Operation

• Stores data bits• For most of time acts as barrier between input and output• As C rises, loads input• So you’d better compute the input before the C signal rises if you want

to store the input data to the register

�33

State = x

Output = xInput = yx

C RisesState = y

Output = yy

C

Page 136: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Register Operation

• Stores data bits• For most of time acts as barrier between input and output• As C rises, loads input• So you’d better compute the input before the C signal rises if you want

to store the input data to the register

�33

State = x

Output = xInput = yx

C RisesState = y

Output = yy

C Output continuously produces y after the rising edge unless you cut off power.

Page 137: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Clock Signal

• A special C: periodically oscillating between 0 and 1• That’s called the clock signal. Generated by a crystal oscillator

inside your computer

�34

State = x

Output = xInput = yx

C RisesState = y

Output = yy

C

Page 138: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Clock Signal

• A special C: periodically oscillating between 0 and 1• That’s called the clock signal. Generated by a crystal oscillator

inside your computer

�34

State = x

Output = xInput = yx

C RisesState = y

Output = yy

C

Clock

Page 139: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Clock Signal

• A special C: periodically oscillating between 0 and 1• That’s called the clock signal. Generated by a crystal oscillator

inside your computer

�34

State = x

Output = xInput = yx

C RisesState = y

Output = yy

C

Clock

x0 x1 x2 x3 x4 x5In

Page 140: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Clock Signal

• A special C: periodically oscillating between 0 and 1• That’s called the clock signal. Generated by a crystal oscillator

inside your computer

�34

State = x

Output = xInput = yx

C RisesState = y

Output = yy

C

Clock

x0 x1 x2 x3 x4 x5In

x0 x1 x2 x3 x4 x5Out

Page 141: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Clock Signal

• Cycle time of a clock signal: the time duration between two rising edges.

�35

Clock

x0 x1 x2 x3 x4 x5In

x0 x1 x2 x3 x4 x5Out

Page 142: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Clock Signal

• Cycle time of a clock signal: the time duration between two rising edges.

�35

Clock

x0 x1 x2 x3 x4 x5In

x0 x1 x2 x3 x4 x5Out

Cycle time

Page 143: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Clock Signal

• Cycle time of a clock signal: the time duration between two rising edges.• Frequency of a clock signal: how many rising (falling) edges in 1 second.

�35

Clock

x0 x1 x2 x3 x4 x5In

x0 x1 x2 x3 x4 x5Out

Cycle time

Page 144: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Clock Signal

• Cycle time of a clock signal: the time duration between two rising edges.• Frequency of a clock signal: how many rising (falling) edges in 1 second.• 1 GHz CPU means the clock frequency is 1 GHz

�35

Clock

x0 x1 x2 x3 x4 x5In

x0 x1 x2 x3 x4 x5Out

Cycle time

Page 145: CSC 252: Computer Organization Spring 2020: Lecture 11€¦ · Carnegie Mellon!3 Announcement •Grades for lab2 are posted. •If you think there are some problems • Take a deep

Carnegie Mellon

Clock Signal

• Cycle time of a clock signal: the time duration between two rising edges.• Frequency of a clock signal: how many rising (falling) edges in 1 second.• 1 GHz CPU means the clock frequency is 1 GHz

• The cycle time is 1/10^9 = 1 ns

�35

Clock

x0 x1 x2 x3 x4 x5In

x0 x1 x2 x3 x4 x5Out

Cycle time