COMP 541 160 Digital Logic and Computer Design

  • Slides: 59
Download presentation
COMP 541 (160) Digital Logic and Computer Design Montek Singh Jan 12, 2010 1

COMP 541 (160) Digital Logic and Computer Design Montek Singh Jan 12, 2010 1

Today’s Topics ã Course description l What’s it about l Mechanics: grading, etc. ã

Today’s Topics ã Course description l What’s it about l Mechanics: grading, etc. ã Material from Chapter 1 (self-study review) l What is digital logic? l Binary signaling l Number systems l Codes 2

What’s Course About? ã Digital logic, focusing on the design of computers ã Stay

What’s Course About? ã Digital logic, focusing on the design of computers ã Stay mostly at a high level (i. e. , above transistors) ã Each person designs a MIPS CPU l and peripheral logic (VGA, joystick) l Project like an Atari 2600 game ã High-level language l Modern design practices 3

Focus ã Stay above transistor level l At most one class on transistors and

Focus ã Stay above transistor level l At most one class on transistors and VLSI ã Expect you to know assembly language programming 4

More Than Just Architecture ã Designing and implementing a computer is also about l

More Than Just Architecture ã Designing and implementing a computer is also about l Managing complexity (hierarchy, modularity, regularity). l Debugging l Testing and verifying 5

The Three -Y’s ã Hierarchy l A system divided into modules and submodules ã

The Three -Y’s ã Hierarchy l A system divided into modules and submodules ã Modularity l Having well-defined functions and interfaces ã Regularity l Encouraging uniformity, so modules can be easily reused

How Can We Do This? ã Labs on Fridays ã Use: Field Programmable Gate

How Can We Do This? ã Labs on Fridays ã Use: Field Programmable Gate Arrays (FPGAs) l Chips with a lot of circuits Ø Tens of thousands to millions of transistors l Programmable ã We write descriptions of the design l “programs” describing design ã Tools translate to gates/wires ã Download pattern/interconnection to chip l Sort of like burning music to a rewritable CD 7

We Will Use This Board What’s on it? 8

We Will Use This Board What’s on it? 8

Schematic Diagram • Old fashioned way to describe logic • Still useful for documentation

Schematic Diagram • Old fashioned way to describe logic • Still useful for documentation 9

Verilog /* * A 32 -bit counter with only 4 bits of output. The

Verilog /* * A 32 -bit counter with only 4 bits of output. The idea is * to select which of the counter stages you want to pass on. * * Anselmo Lastra, November 2002 */ module cntr_32 c(clk, res, out); input clk; input res; output [3: 0] out; reg [31: 0] count; always @ (posedge res or posedge clk) if(res) count <= 0; else count <= count + 1; assign out[3] = count[28]; assign out[2] = count[27]; assign out[1] = count[26]; assign out[0] = count[25]; endmodule 10

Xilinx Software ã Use design tools from chip maker ã Have full version on

Xilinx Software ã Use design tools from chip maker ã Have full version on lab PCs ã Can install on your PC l Download from web 11

Class Web Pages ã Will be up by Thursday’s class ã Linked from my

Class Web Pages ã Will be up by Thursday’s class ã Linked from my home page http: //www. cs. unc. edu/~montek ã All lecture slides posted there l Will try to put them there before class ã Schedule, homework, etc. posted there ã Lab documents there also ã See Blackboard for scores/grades 12

Textbook ã Harris and Harris ã Digital Design and Computer Architecture ã Morgan Kaufmann,

Textbook ã Harris and Harris ã Digital Design and Computer Architecture ã Morgan Kaufmann, 2007 ã Amazon has for $70 ã Extra material on http: //www. elsevierdirect. com/companion. jsp? ISBN=9780123704979 13

Overview of Textbook ã Chapters 1 -5: Digital logic l Combinational, sequential, basic circuits,

Overview of Textbook ã Chapters 1 -5: Digital logic l Combinational, sequential, basic circuits, HDL ã Chapter 6: Architecture l Fast – review for those who took COMP 411 ã Chapter 7: Microarchitectures ã Chapters 8: Memories ã Appendix A: Implementation l FPGAs, etc. 14

Order of Topics ã Will change order from that in book l To try

Order of Topics ã Will change order from that in book l To try to get you working on interesting labs sooner 15

May Also Need ã COMP 411 textbook (Patterson/Hennessy) l For MIPS reference l How

May Also Need ã COMP 411 textbook (Patterson/Hennessy) l For MIPS reference l How many have one? l I can copy the few necessary pages ã Verilog reference l Book optional l Web pages – see course home page 16

Grading ã Labs – 35% l Easier at first; later ones will count more

Grading ã Labs – 35% l Easier at first; later ones will count more ã Homework – 20% ã Two tests spaced evenly – 12. 5% each ã Final – 20% (optional for some) 17

Labs ã Paced slowly at first l Familiarization with tools, simple combinational design, design

Labs ã Paced slowly at first l Familiarization with tools, simple combinational design, design a digital lock or similar ã Peripheral – VGA, opt. keyboard interface or joystick ã Build up computer components l Registers, ALU, decoder ã Assemble a simple MIPS ã Add more features, enough for simple computer ã Final demo – game or similar 18

Lab Sections ã No lab this Friday l You need a little more info

Lab Sections ã No lab this Friday l You need a little more info to begin l Begin next week ã Lab is in SN 027 19

Late Policy ã Homework assignments and lab reports due by class l Labs due

Late Policy ã Homework assignments and lab reports due by class l Labs due on Tuesday after the lab period ã One class late, 10 points off ã Two classes late, 25 points off ã Not accepted later 20

What’s Your Background? ã Course experience ã Work, etc. ã Which COMP 120? ã

What’s Your Background? ã Course experience ã Work, etc. ã Which COMP 120? ã What’s your intent in taking class? ã Questions? 21

Office Hours ã Would like to wait a week to set ã Send email

Office Hours ã Would like to wait a week to set ã Send email if you want to meet in the mean time 22

Now Shift to Technology Should be review for all of you 23

Now Shift to Technology Should be review for all of you 23

Digital vs. Analog ã Analog – infinite resolution l Like (old fashioned) radio dial

Digital vs. Analog ã Analog – infinite resolution l Like (old fashioned) radio dial l We’ll do very little with analog Ø VGA, maybe sound ã Digital – a finite set of values l Like money l Can’t get smaller than cents l Typically also has maximum value 24

Binary Signaling ã Zero volts l FALSE or 0 ã 5 or 3. 3

Binary Signaling ã Zero volts l FALSE or 0 ã 5 or 3. 3 (or 1. 8 or 1. 5) volts l TRUE or 1 Ø Modern chips down to 1 V ã Why not multilevel signaling? 25

Discrete Data ã Some data inherently discrete l Names (sets of letters) ã Some

Discrete Data ã Some data inherently discrete l Names (sets of letters) ã Some quantized l Music recorded from microphone l Note that other examples like music from CD or electronic keyboard already quantized l Mouse movement is quantized Ø Well, some mice 26

Numbers and Arithmetic ã I’ve put most of these slides at end l Backup

Numbers and Arithmetic ã I’ve put most of these slides at end l Backup in case you’ve forgotten ã Review of binary numbers, Hexadecimal, Arithmetic ã Let’s cover l Other codes, parity 27

BCD ã Binary Coded Decimal ã Decimal digits stored in binary l Four bits/digit

BCD ã Binary Coded Decimal ã Decimal digits stored in binary l Four bits/digit l Like hex, except stops at 9 l Example 931 is coded as 1001 0011 0001 ã Remember: these are just by us. encodings. Meanings are assigned 28

Other Codes Exist ã Non positional ã Example: Gray Code l Only one bit

Other Codes Exist ã Non positional ã Example: Gray Code l Only one bit changes at a time l 000, 001, 010, 111, 100 l Why is this useful? l Actually there’s a family of Gray codes Ref: http: //lib-www. lanl. gov/numerical/bookcpdf/c 20 -2. pdf 29

Shaft Encoder 30

Shaft Encoder 30

Character Codes ã From numbers to letters ã ASCII l Stands for American Standard

Character Codes ã From numbers to letters ã ASCII l Stands for American Standard Code for Information Interchange l Only 7 bits defined ã Unicode ã You may make up your own code for the MIPS VGA 31

ASCII table 32

ASCII table 32

Even Parity ã Sometimes high-order bit of ASCII coded to enable detection of errors

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 01000001 C (01000011) with even parity is 11000011 33

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

Odd Parity ã Similar except make the number of 1’s odd ã Examples A (01000001) with odd parity is 11000001 C (01000011) with odd parity is 01000011 34

Error Detection ã Note that parity detects only simple errors l One, three, etc.

Error Detection ã Note that parity detects only simple errors l One, three, etc. bits ã More complex methods exist ã Some that enable recovery of original info l Cost is more redundant bits 35

Today’s Topics ã Introduction ã Digital logic Number systems Arithmetic ã Codes ã Parity

Today’s Topics ã Introduction ã Digital logic Number systems Arithmetic ã Codes ã Parity ã The encoding is key ã ã l Standards are used to agree on encodings l Special purpose codes for particular uses 36

Homework ã None, but… ã I expect you to know number systems well and

Homework ã None, but… ã I expect you to know number systems well and be able to do conversions and arithmetic l l Decimal – Binary – Decimal – Hex – Decimal ã Can do some of the problems – 1. 7 to 1. 27 are all about conversion – if you think you need a refresher. Answers to odd numbered on book website. 37

Reading ã Read Chapter 1 38

Reading ã Read Chapter 1 38

Next Class ã Combinational Logic Basics Next Week: Lab preview l I’ll demo tools

Next Class ã Combinational Logic Basics Next Week: Lab preview l I’ll demo tools in class, probably Thursday 39

Lab Walkthrough ã Let’s go see the lab 40

Lab Walkthrough ã Let’s go see the lab 40

Backup Slides Should be all review material 41

Backup Slides Should be all review material 41

Binary Numbers ã Strings of binary digits (“bits”) l One bit can store a

Binary Numbers ã Strings of binary digits (“bits”) l One bit can store a number from 0 to 1 l n bits can store numbers from 0 to 2 n 42

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

Binary – Powers of 2 ã Positional representation ã Each digit represents a power of 2 So 101 binary is 1 • 2 2 + 0 • 21 + 1 • 2 0 or 1 • 4 + 0 • 2 + 1 • 1=5 43

Converting Binary to Decimal ã Easy, just multiply digit by power of 2 ã

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

Binary Decimal Example 7 6 5 4 3 2 1 0 27 26 25

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 What is 10011100 in decimal? 1 0 0 1 1 1 0 0 128 + 0 + 16 + 8 + 4 + 0 = 156 45

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

Decimal to Binary ã A little more work than binary to decimal ã Some examples l 3 = 2 + 1 = 11 (that’s 1 • 21 + 1 • 20) l 5 = 4 + 1 = 101 (that’s 1 • 22 + 0 • 21 + 1 • 20) 46

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

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 47

Decimal Binary Example ã Convert 28 decimal to binary 32 is too large, so

Decimal Binary Example ã Convert 28 decimal to binary 32 is too large, so use 16 Binary 10000 Decimal 28 – 16 = 12 Next is 8 Binary 11000 Decimal 12 – 8 = 4 Next is 4 Binary 11100 Decimal 4 – 4 = 0 7 6 5 4 3 2 1 0 27 26 25 24 23 22 21 20 128 64 32 16 8 4 2 1 48

Hexadecimal ã Strings of 0 s and 1 s too hard to write ã

Hexadecimal ã Strings of 0 s and 1 s too hard to write ã Use base-16 or hexadecimal – 4 bits Dec Bin Hex 0 0000 0 8 1000 8 1 0001 1 9 1001 9 2 0010 2 10 1010 ? 3 0011 3 11 1011 ? 4 0100 4 12 1100 ? 5 0101 5 13 1101 ? 6 0110 6 14 1110 ? 7 0111 7 15 1111 ? 49

Hexadecimal ã Letters to represent 10 -15 Dec Bin Hex 0 0000 0 8

Hexadecimal ã Letters to represent 10 -15 Dec Bin Hex 0 0000 0 8 1000 8 1 0001 1 9 1001 9 2 0010 2 10 1010 a 3 0011 3 11 1011 b 4 0100 4 12 1100 c 5 0101 5 13 1101 d 6 0110 6 14 1110 e 7 0111 7 15 1111 f Why use base 16? • Power of 2 • Size of byte 50

Hex to Binary Bin Hex 0000 0 0001 1 0010 2 ã Convention –

Hex to Binary Bin Hex 0000 0 0001 1 0010 2 ã Convention – write 0 x before number 0011 3 ã Hex to Binary – just convert digits 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 a 1011 b 1100 c 1101 d 1110 e 1111 f 0 x 2 ac 0010 1100 0 x 2 ac = 00101100 No magic – remember hex digit = 4 bits 51

Binary to Hex ã Just convert groups of 4 bits 1010011011 0101 0011 0111

Binary to Hex ã Just convert groups of 4 bits 1010011011 0101 0011 0111 1011 5 3 7 b 1010011011 = 0 x 537 b 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 52

Hex to Decimal Dec Hex 0 0 ã Just multiply each hex digit by

Hex to Decimal Dec Hex 0 0 ã Just multiply each hex digit by decimal value, 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 and add the results. 0 x 2 ac 2 • 256 + 10 • 16 + 12 • 1 = 684 163 162 161 160 4096 256 16 1 53

Decimal to Hex 1. 2. 3. 4. Analogous to decimal binary. Find largest power-of-16

Decimal to Hex 1. 2. 3. 4. Analogous to decimal binary. Find largest power-of-16 smaller than decimal number Divide by power-of-16. The integer result is hex digit. The remainder is new decimal number. Do the same thing again 54

Decimal to Hex 684 0 x 2__ 684/256 = 2 684%256 = 172 0

Decimal to Hex 684 0 x 2__ 684/256 = 2 684%256 = 172 0 x 2 a_ 172%16 = 12 = c 0 x 2 ac 172/16 = 10 = a 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 55

Octal ã Octal is base 8 ã Similar to hexadecimal l Conversions ã Less

Octal ã Octal is base 8 ã Similar to hexadecimal l Conversions ã Less convenient for use with 8 -bit bytes 56

Arithmetic -- addition ã Binary similar to decimal arithmetic 1 No carries 0 1

Arithmetic -- addition ã Binary similar to decimal arithmetic 1 No carries 0 1 1 0 0 1 0 1 1 0 + 1 0 0 0 1 + 1 0 1 1 0 1 0 Carries 1+1 is 2 (or 102), which results in a carry 57

Arithmetic -- subtraction No borrows - 1 0 1 0 0 - 0 0

Arithmetic -- subtraction No borrows - 1 0 1 0 0 - 0 0 1 1 1 1 0 0 1 1 Borrows 0 - 1 results in a borrow 58

Arithmetic -- multiplication 1 0 1 1 0 0 1 0 1 X 1

Arithmetic -- multiplication 1 0 1 1 0 0 1 0 1 X 1 Successive additions of multiplicand or zero, multiplied by 2 (102). Note that multiplication by 102 just shifts bits left. 1 59