Title: COMP541 (160) Digital Logic and Computer Design
1COMP541 (160) Digital Logic and Computer Design
- Montek Singh
- Jan 11, 2007
2Todays Topics
- Course description
- Whats it about
- Mechanics grading, etc.
- Material from Chapter 1 (review)
- What is digital logic?
- Binary signaling
- Number systems
- Codes
3Whats Course About?
- Digital logic, focusing on the design of
computers - Stay above transistor level
- Only one class on transistors and VLSI
- Each person designs a MIPS CPU
- and peripheral logic (VGA, joystick)
- Project like an Atari 2600 game
- High-level language
- Modern design practices
4How Can We Do This?
- Field Programmable Gate Arrays
- Chips with a lot of circuits
- Tens of thousands to millions of transistors
- Programmable
- We write programs describing design
- Tools translate to gates/wires
- Download pattern to chip
5We Will Use This Board
6Schematic Diagram
7Verilog
- /
- 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_32c(clk,res,out)
- input clk
- input res
- output 30 out
- reg 310 count
- always _at_ (posedge res or posedge clk)
- if(res)
- count lt 0
- else
- count lt count 1
8Xilinx Software
- Use design tools from chip maker
- Have full version on lab PCs
- Can install on your PC
- ModelSim simulator or built-in
9Class Web Pages
- Linked from my home pagehttp//www.cs.unc.edu/mo
ntek - All notes posted
- Will try to put them there before class
- Lab documents there also
- See Blackboard for grades
10Textbook and Syllabus
- Largely follow Prof. Lastras syllabus
- Morris Mano and Charles Kime
- Logic and Logic and Computer Design Fundamentals,
3rd Edition - Prentice Hall, 2004
- Will largely follow text
- Slightly different order
- More emphasis on HLL
11Overview of Textbook
- Chapters 1-6 Digital logic
- Combinational and sequential
- Chapter 7-8 Register Transfer and State Machines
- Chapter 9 Memories
- Chapters 10-12 Computer design
- Chapter 13 I/O
- Chapter 14 Memory Hierarchies
12Order of Topics
- Will change order from that in book
- To try to get you working on interesting labs
sooner - Move sequential design earlier
- Then backfill details on combinational design
13May Also Need
- COMP120 book
- For MIPS reference
- How many have one?
- I can copy the few necessary pages
- Verilog reference
- Book optional
- Web pages see course home page
14Grading
- Labs 35
- Easier at first later ones will count more
- Homework 20
- Two tests spaced evenly 12.5 each
- Final 20 (optional for some)
15Labs
- Paced slowly at first
- Familiarization with tools, simple combinational
design, design a digital lock or similar - Peripheral VGA, opt. keyboard interface or
joystick - Build up computer components
- Registers, ALU, decoder
- Assemble a simple MIPS
- Add more features, enough for simple computer
- Final demo game or similar
16Lab Sections
- No lab this Friday
- You need a little more info to begin
- Begin next week
- Lab is in SN 027, down the hall by the back
entrance
17Late Policy
- Homework assignments and lab reports due by class
time - Labs due on Tuesday after the lab period
- One class late, 10 points off
- Two classes late, 25 points off
- Not accepted later
18Whats Your Background?
- Course experience
- Work, etc.
- Which COMP120?
- Whats your intent in taking class?
- Questions?
19Office Hours
- Would like to wait a week to set
- Send email if you want to meet
20Now Shift to Technology
- Should be review for all of you
21Digital vs. Analog
- Analog infinite resolution
- Like (old fashioned) radio dial
- Well do very little with analog
- VGA, maybe sound
- Digital a finite set of values
- Like money
- Cant get smaller than cents
- Typically also has maximum value
22Binary Signaling
- Zero volts
- FALSE or 0
- 3.3 or 5 volts
- TRUE or 1
- Modern chips down to 1V
- Why not multilevel signaling?
23Discrete Data
- Some data inherently discrete
- Names (sets of letters)
- Some quantized
- Music recorded from microphone
- Note that other examples like music from CD or
electronic keyboard already quantized - Mouse movement is quantized
- Well, some mice
24Numbers and Arithmetic
- Ive put most of these slides at end
- Backup in case youve forgotten
- Review of binary numbers, Hexadecimal,Arithmetic
- Lets cover
- Other codes, parity
25BCD
- 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.
26Other Codes Exist
- Non positional
- Example Gray Code
- Only one bit changes at a time
- 000,001,011,010,110,111,101,100
- Why is this useful?
- Actually theres a family of Gray codes
Ref http//lib-www.lanl.gov/numerical/bookcpdf/c2
0-2.pdf
27Shaft Encoder
28Character 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
29ASCII table
30Even Parity
- Sometimes high-order bit of ASCII coded to enable
detection of errors - Even parity set bit to make number of 1s even
- Examples
- A (01000001) with even parity is 01000001
- C (01000011) with even parity is 11000011
31Odd Parity
- Similar except make the number of 1s odd
- Examples
- A (01000001) with odd parity is 11000001
- C (01000011) with odd parity is 01000011
32Error 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
33Todays Topics
- Introduction
- Digital logic
- Number systems
- Arithmetic
- Codes
- Parity
- The encoding is key
- Standards are used to agree on encodings
- Special purpose codes for particular uses
34Homework
- None, but
- I expect you to know number systems well and be
able to do conversions and arithmetic - Decimal Binary
- Binary Decimal
- Decimal Hex
- Hex Decimal
- Can do some of the problems 1-2, 1-4, 1-7 if
you think you need a refresher. Answers on book
website.
35Reading
- Skim chapter 1
- Quick read to make sure youre comfortable with
material - Read Chapter 2
36Next Week
- Combinational Logic Basics
- Lab preview
- Ill demo tools in class, probably Thursday
- Lab on Friday the 19th
- Schematic capture
- Maybe simple Verilog
- Run on FPGA
37Lab Walkthrough
- Lets go see the lab
- Shared with LEGO 1st year seminar
38Backup Slides
- Should be all review material
39Binary Numbers
- Strings of binary digits (bits)
- One bit can store a number from 0 to 1
- n bits can store numbers from 0 to 2n
40Binary 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
-
41Converting Binary to Decimal
- Easy, just multiply digit by power of 2
- Just like a decimal number is represented
- Example follows
42Binary ? 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 0 16 8 4 0 0
156
43Decimal to Binary
- A little more work than binary to decimal
- Some examples
- 3 2 1 11 (thats 121 120)
- 5 4 1 101 (thats 122 021 120)
44Algorithm 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
45Decimal ? 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
46Hexadecimal
- 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 ?
47Hexadecimal
- 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
48Hex to Binary
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
- Convention write 0x before number
- Hex to Binary just convert digits
0x2ac
0x2ac 001010101100
No magic remember hex digit 4 bits
49Binary to Hex
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
- Just convert groups of 4 bits
101001101111011
1011
0101 ?
0111 ?
0011 ?
101001101111011 0x537b
50Hex to Decimal
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
- Just multiply each hex digit by decimal value,
and add the results.
0x2ac
2 256
10 16
12 1
684
???? ???? ???? ????
163 162 161 160
4096 256 16 1
51Decimal to Hex
- 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
52Decimal to Hex
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
0x2__
684/256 2
684256 172
0x2a_
172/16 10 a
0x2ac
17216 12 c
???? ???? ???? ????
163 162 161 160
4096 256 16 1
53Octal
- Octal is base 8
- Similar to hexadecimal
- Conversions
- Less convenient for use with 8-bit bytes
54Arithmetic -- addition
- Binary similar to decimal arithmetic
1 0 1 1 0 0
1 0 1 1 0
1 0 1 1 1
No carries
Carries
0 1 1 0 0
1 0 0 0 1
1 0 1 1 0 1
1 1 1 0 1
11 is 2 (or 102), which results in a carry
55Arithmetic -- subtraction
0 0 1 1 0
1 1 1 1 0
- 1 0 0 1 1
No borrows
Borrows
1 0 1 1 0
- 1 0 0 1 0
0 1 0 1 1
0 0 1 0 0
0 - 1 results in a borrow
56Arithmetic -- multiplication
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
1 0 1 1
0 0 0 0
1 0 1 1
1 1 0 1 1 1
57Hexadecimal Arithmetic
- Similar
- If youre doing by hand, easiest to convert each
set of digits to decimal and back - Skill is not very useful