comp541 digital logic and computer design montek singh aug 20, 2014

54
COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

Upload: owen-tate

Post on 11-Jan-2016

214 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

COMP541 Digital Logic and Computer Design

Montek Singh

Aug 20, 2014

Page 2: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

Today’s Topics Course description

What’s this course about?Syllabus

Textbook and ResourcesCourse RequirementsGradingPolicies and Honor Code

Material from Chapter 1 (self-study review)What is digital logic?Binary signalingNumber systemsCodes

2

Page 3: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

What’s This Course About? Digital Logic

transistors (briefly)gatescombinational circuitsstate machines

Computer Designarithmetic circuitsmemoriesprocessor architecture input and output

Emphasis on high-level descriptionshardware description language (Verilog) instead of

circuitsmodern design practices 3

Page 4: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

Key Learning Objectives At the end of this course, you should be able

to:convert a specification into an implementationhierarchically decompose a complex spec

into simpler componentsunderstand concurrency

develop concurrent system specs and implementations test a given design for correctness

develop a test bench and performing simulationuse state-of-the-art software tools for hardware design

“computer-aided-design” (CAD) tools

Each student will have:designed a full microprocessor (basic MIPS) implemented it on a development kitprogrammed it in assembly to show a demo 4

Page 5: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

Who is this course for? Advanced course in digital logic and computer

design follow-up to COMP 411 (Computer Organization) full-gate level implementation of MIPS processor from

411 including memories and I/O

Who should take this course?undergrads who want to pursue a career or further

studies in the fields of:computer architecturechip design, or other engineering disciples

grad students looking to fill a gap in their courseworkanyone interested in learning how a digital system is

implemented, in a hands-on manner5

Page 6: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

6

How will we build an entire computer? Labs on Fridays

hands-on experience in designing digital circuits/systems

start small, but quickly go to higher levels of abstraction

We will write descriptions of design instead of drawing circuit diagramsdescriptions look like “code”

high-level languageBEWARE: these are not software programs!

use compilation tools to convert into gates and wiresmap (“burn”) these designs onto a reconfigurable chip

called Field Programmable Gate Array (FPGAs)chips with a lot of circuits (millions of transistors)sort of like burning music to a rewritable CD

Page 7: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

Development Kits Each student will be loaned a kit for the

semesterwe have two types: 25 new and 25 oldboth are more-than-sufficient for this course

a BIG thanks to NVIDIA for donating $$ for the Nexys 4 kits!!

7Nexys 3 Nexys 4

Page 8: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

How to represent circuits? Schematic Diagram: drawing showing

components and their interconnectionsvisual representation

good for documentationgood for small circuits infeasible for large-scale systems

typically use hierarchical drawings

8

Page 9: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

How to represent circuits? Hardware Description Language (HDL):

textual description of the circuiteasier to type than to draw!works well with automated design and test toolswe will use an HDL called Verilog

9

/* A Mod 4 counter* Montek Singh, August 2014*/ module CounterMod4 (clock, reset,

value); input clock; input reset; output reg[1:0] value = 0;

always @(posedge clock) begin value <= reset ? 0 : (value + 1); endendmodule

Page 10: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

How to compile HDL to circuits? Use design tools from the kit maker Each student must install her/his own copy

Download from web (linked from course website)Big download: ~6 GB (allow overnight)Do it before Friday’s lab session

DO IT TONIGHT!

Platforms:Windows 7/8 and Linux: best supportMac OS X: use Bootcamp + Windows

– harder to make it work with Parallels

10

Page 11: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

Grading Criteria Final grade will be based on:

Labs: 30%Final Project: 20%Homework: 15%Quizzes: 10%Midterm: 10%Final Exam: 15%

Bonus Points: Up to 5 extra points forextra credit workstellar work on lab assignments/projectclass participationparticipation on Piazza discussion board

11

Page 12: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

Grading Criteria Labs

about one every week each builds upon the previous ones

important to follow sequence, and DO THEM ALL culminates in the final project

Project everyone builds a full microprocessor (basic MIPS from 411) write assembly code to show a demo (“game”) demo in front of whole class

and other faculty and students may be invited

Homework: 3-4 assignments Quizzes: 3-4

announced, ~15 min long Exams: Midterm and Final

12

Page 13: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

Course Policies Late Penalty

Labs:electronic submissionseveryone gets 7 “free late days”for each calendar day (or part of day) late, one free day is

spentonce free days are exhausted, each late day results in 1

point taken out of the final total lab score (out of 100)Homework:

due in hardcopy in class/lab sessionone session late: 25% penaltytwo sessions late: 50% penaltyafter then, not accepted

– no late work accepted once solutions are distributed

13

Page 14: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

Course Policies Missed classes, quizzes, exam conflicts

classes: while attendance is not required, there is no substitute to coming to class if you want a good grade

labs:many assignments require demos during lab sessions I provide lots of tips/hints during the session

quizzes: since the dates are announced, please see me well in advance if you have a compelling reason for absence

exams: bring any conflicts to my attention ASAP

14

Page 15: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

Honor Code Collaboration:

Allowed (even encouraged) to discuss basic conceptsuse discussion board on Piazzabonus points for active participation!

BUT: What you hand in must be your ownwrite solutions and code individually

Previous Semesters:Cannot use homework solutions from previous

offerings of this courseCannot obtain lab assignments/code from students

who have taken this course before

Not following these rules is a violation of honor code

15

Page 16: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

Textbook and Resources Textbook:

be sure to get the 2nd ed.25% discount coupon on

course website Other resources:

websitehomework, labs, lectures,

etc.Verilog language

referenceon course website

personal laptop computerWindows or LinuxMac OS with Bootcamp

development kits (provided)

16

Harris and Harris,Digital Design and Computer Architecture, 2nd ed. (July 2012),ISBN 9780123944245,Morgan Kaufmann

Page 17: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

17

Overview of Textbook Chapters 1-5: Digital logic

Combinational, sequential, basic circuits, HDL Chapter 6: Architecture

Fast – review for those who took COMP 411 Chapter 7: Microarchitectures Chapters 8: Memories Appendix A: Implementation

FPGAs, etc.

Order of topics:Will change order from that in book

to try to get you working on interesting labs sooner

Page 18: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

18

Class Web PageWebsite:

http://comp541fall14.web.unc.eduLinked from my home page

http://www.cs.unc.edu/~montek

All lecture slides, lab assignments posted thereSyllabus, homework, etc. posted thereSee Sakai for scores/gradesUse Piazza for questions/discussions

TA and Office Hours to be finalized by Friday, Aug 22

Page 19: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

Now Shift to Technology

Should be a review for all of you

Page 20: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

Complexity and Abstraction This course will span several

abstraction levelsfrom transistors …… to architecture

Mostly stay above transistor levelat most one class on

transistors and chip layout Mostly go “bottom up”

culminate in the design of a full computer in the labs

20

Page 21: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

The Three -Y’s Hierarchy

divide a system into modules and submoduleskeep dividing until pieces are easy to understand

Modularitymodules have well-defined functions and interfaces

so can be connected easily without surprises

Regularityencouraging uniformity, so modules can be easily

reusedso same set of basic building blocks can be usede.g., a 16-bit adder uses the same basic blocks as an 8-bit

adder

21

Page 22: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

22

Digital vs. Analog Analog – infinite resolution

Like (old fashioned) radio dialWe’ll do very little with analog

VGA, maybe sound

Digital – a finite set of valuesLike moneyCan’t get smaller than centsTypically also has maximum value

Page 23: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

23

Binary Signaling Zero volts

FALSE or 0 5 or 3.3 (or 1.8 or 1.5) volts

TRUE or 1Modern chips down to 1V

Why not multilevel signaling?

Page 24: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

24

Discrete Data Some data inherently discrete

Names (sets of letters) Some quantized

Music recorded from microphoneNote that other examples like music from CD or

electronic keyboard already quantizedMouse movement is quantized

Page 25: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

25

Numbers and Arithmetic I have put most of these slides at end

Backup in case you’ve forgotten Review of binary numbers,

Hexadecimal,Arithmetic

Let’s coverOther codes, parity

Page 26: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

26

BCD Binary Coded Decimal Decimal digits stored in binary

Four bits/digit Like hex, except stops at 9 Example

931 is coded as 1001 0011 0001

Remember: these are just encodings. Meanings are assigned by us.

Page 27: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

27

Other Codes Exist Non positional Example: Gray Code

Only one bit changes at a time000,001,011,010,110,111,101,100Why is this useful?

Actually there’s a family of Gray codes

Ref: http://lib-www.lanl.gov/numerical/bookcpdf/c20-2.pdf

Page 28: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

28

Shaft Encoder

Page 29: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

29

Character Codes From numbers to letters ASCII

Stands for American Standard Code for Information Interchange

Only 7 bits defined Unicode You may make up your own code for the MIPS

VGA

Page 30: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

30

ASCII table

Page 31: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

31

Even Parity Sometimes high-order bit of ASCII coded to

enable detection of errors Even parity – set bit to make number of 1’s

even Examples

A (01000001) with even parity is 01000001C (01000011) with even parity is 11000011

Page 32: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

32

Odd Parity Similar except make the number of 1’s odd Examples

A (01000001) with odd parity is 11000001C (01000011) with odd parity is 01000011

Page 33: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

33

Error Detection Note that parity detects only simple errors

One, three, etc. bits More complex methods exist Some that enable recovery of original info

Cost is more redundant bits

Page 34: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

34

Reading Read Chapter 1

Page 35: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

35

Next Class Combinational Logic Basics

Next class: Friday, Aug 22 I will demo toolsYou should have your tools installed and bring your

laptop

Page 36: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

Backup Slides

Should be all review material

Page 37: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

37

Binary Numbers Strings of binary digits (“bits”)

One bit can store a number from 0 to 1n bits can store numbers from 0 to 2n

Page 38: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

38

Binary – Powers of 2 Positional representation Each digit represents a power of 2

So 101 binary is 1 • 22 + 0 • 21 + 1 • 20

or 1 • 4 + 0 • 2 + 1 • 1 = 5

Page 39: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

39

Converting Binary to Decimal Easy, just multiply digit by power of 2 Just like a decimal number is represented Example follows

Page 40: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

40

Binary Decimal Example

7 6 5 4 3 2 1 0

27 26 25 24 23 22 21 20

128 64 32 16 8 4 2 1

1 0 0 1 1 1 0 0

128 + 0 + 0 + 16 + 8 + 4 + 0 + 0 = 156

What is 10011100 in decimal?

Page 41: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

41

Decimal to Binary A little more work than binary to decimal Some examples

3 = 2 + 1 = 11 (that’s 1•21 + 1•20)5 = 4 + 1 = 101 (that’s 1•22 + 0•21 + 1•20)

Page 42: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

42

Algorithm – Decimal to Binary Find largest power-of-two smaller than decimal

number Make the appropriate binary digit a ‘1’ Subtract the power of 2 from decimal Do the same thing again

Page 43: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

43

Decimal Binary Example Convert 28 decimal to binary

7 6 5 4 3 2 1 0

27 26 25 24 23 22 21 20

128 64 32 16 8 4 2 1

32 is too large, so use 16Binary 10000 Decimal 28 – 16 = 12

Binary 11000 Decimal 12 – 8 = 4Next is 8

Binary 11100 Decimal 4 – 4 = 0Next is 4

Page 44: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

44

Hexadecimal Strings of 0s and 1s too hard to write Use base-16 or hexadecimal – 4 bits

Dec Bin Hex

0 0000 0

1 0001 1

2 0010 2

3 0011 3

4 0100 4

5 0101 5

6 0110 6

7 0111 7

Dec Bin Hex

8 1000 8

9 1001 9

10 1010 ?

11 1011 ?

12 1100 ?

13 1101 ?

14 1110 ?

15 1111 ?

Page 45: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

45

Hexadecimal Letters to represent 10-15

Dec Bin Hex

0 0000 0

1 0001 1

2 0010 2

3 0011 3

4 0100 4

5 0101 5

6 0110 6

7 0111 7

Dec Bin Hex

8 1000 8

9 1001 9

10 1010 a

11 1011 b

12 1100 c

13 1101 d

14 1110 e

15 1111 f

• Power of 2

• Size of byte

Why usebase 16?

Page 46: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

46

Hex to Binary

Convention – write 0x before number Hex to Binary – just convert digits

Bin Hex

0000 0

0001 1

0010 2

0011 3

0100 4

0101 5

0110 6

0111 7

1000 8

1001 9

1010 a

1011 b

1100 c

1101 d

1110 e

1111 f

0x2ac

0010 1010 1100

0x2ac = 001010101100

No magic – remember hex digit = 4 bits

Page 47: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

47

Binary to Hex

Just convert groups of 4 bits

Bin Hex

0000 0

0001 1

0010 2

0011 3

0100 4

0101 5

0110 6

0111 7

1000 8

1001 9

1010 a

1011 b

1100 c

1101 d

1110 e

1111 f

101001101111011

1011

5 3 7 b

101001101111011 = 0x537b

0101 0111 0011

Page 48: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

48

Hex to Decimal Just multiply each hex digit by decimal

value, and add the results.

163 162 161 160

4096 256 16 1

0x2ac

2 • 256 + 10 • 16 + 12 • 1 = 684

Dec Hex

0 0

1 1

2 2

3 3

4 4

5 5

6 6

7 7

8 8

9 9

10 a

11 b

12 c

13 d

14 e

15 f

Page 49: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

49

Decimal to HexAnalogous to decimal binary.

1. Find largest power-of-16 smaller than decimal number

2. Divide by power-of-16. The integer result is hex digit.

3. The remainder is new decimal number.4. Do the same thing again

Page 50: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

50

Decimal to Hex

163 162 161 160

4096 256 16 1

Dec Hex

0 0

1 1

2 2

3 3

4 4

5 5

6 6

7 7

8 8

9 9

10 a

11 b

12 c

13 d

14 e

15 f

684

684/256 = 2 0x2__

684%256 = 172

172/16 = 10 = a 0x2a_172%16 = 12 = c 0x2ac

Page 51: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

51

Octal Octal is base 8 Similar to hexadecimal

Conversions Less convenient for use with 8-bit bytes

Page 52: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

52

Arithmetic -- addition Binary similar to decimal arithmetic

0 1 1 0 0

+ 1 0 0 0 1

1 1 1 0 1

No carries 1 0 1 1 0 0

1 0 1 1 0

+ 1 0 1 1 1

1 0 1 1 0 1

Carries

1+1 is 2 (or 102), which results in a carry

Page 53: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

53

Arithmetic -- subtraction

1 0 1 1 0

- 1 0 0 1 0

0 0 1 0 0

No borrows 0 0 1 1 0

1 1 1 1 0

- 1 0 0 1 1

0 1 0 1 1

Borrows

0 - 1 results in a borrow

Page 54: COMP541 Digital Logic and Computer Design Montek Singh Aug 20, 2014

54

Arithmetic -- multiplication

1 0 1 1

0 0 0 0

1 0 1 1

1 1 0 1 1 1

Successive additions of multiplicand or zero,multiplied by 2 (102).

Note that multiplication by 102 just shifts bits left.

1 0 1 1

X 1 0 1