Upload
rodger-matthews
View
215
Download
0
Embed Size (px)
DESCRIPTION
3 How Can We Do This? Field Programmable Gate Arrays Chips with a lot of circuits Chips with a lot of circuits Tens of thousands to millions of transistors Programmable Programmable We write “programs” describing design Tools translate to gates/wires Download pattern to chip
Citation preview
2
What’s Course About?What’s Course About? DigitalDigital logic,logic, focusing on the design of focusing on the design of
computerscomputers Stay above transistor levelStay above transistor level
Only one class on transistors and VLSIOnly one class on transistors and VLSI Each person designs a MIPS CPUEach person designs a MIPS CPU
and peripheral logic (VGA, joystick)and peripheral logic (VGA, joystick) Project like an Atari 2600 gameProject like an Atari 2600 game
High-level language High-level language Modern design practicesModern design practices
3
How Can We Do This?How Can We Do This? Field Programmable Gate ArraysField Programmable Gate Arrays
Chips with a lot of circuitsChips with a lot of circuitsTens of thousands to millions of transistorsTens of thousands to millions of transistors
ProgrammableProgrammable We write “programs” describing designWe write “programs” describing design Tools translate to gates/wiresTools translate to gates/wires Download pattern to chipDownload pattern to chip
6
VerilogVerilog/*/* * A 32-bit counter with only 4 bits of output. The idea is* 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.* to select which of the counter stages you want to pass on. ** * Anselmo Lastra, November 2002* Anselmo Lastra, November 2002 */*/ module cntr_32c(clk,res,out);module cntr_32c(clk,res,out); input clk;input clk; input res;input res; output [3:0] out;output [3:0] out;
reg [31:0] count;reg [31:0] count;
always @ (posedge res or posedge clk)always @ (posedge res or posedge clk) if(res)if(res)
count <= 0;count <= 0;elseelse
count <= count + 1;count <= count + 1; assign out[3] = count[28];assign out[3] = count[28]; assign out[2] = count[27];assign out[2] = count[27]; assign out[1] = count[26];assign out[1] = count[26]; assign out[0] = count[25];assign out[0] = count[25];
endmoduleendmodule
7
Binary SignalingBinary Signaling Zero voltsZero volts
FALSE or 0FALSE or 0 3.3 or 5 volts3.3 or 5 volts
TRUE or 1TRUE or 1Modern chips down to 1VModern chips down to 1V
Why not multilevel signaling?Why not multilevel signaling?
8
Discrete DataDiscrete Data Some data inherently discreteSome data inherently discrete
Names (sets of letters)Names (sets of letters) Some quantizedSome quantized
Music recorded from microphoneMusic recorded from microphone Note that other examples like music from CD or Note that other examples like music from CD or
electronic keyboard already quantizedelectronic keyboard already quantized Mouse movement is quantizedMouse movement is quantized
Well, some miceWell, some mice
9
BCDBCD Binary Coded DecimalBinary Coded Decimal Decimal digits stored in binaryDecimal digits stored in binary
Four bits/digitFour bits/digit Like hex, except stops at 9Like hex, except stops at 9 ExampleExample
931 is coded as 1001 0011 0001931 is coded as 1001 0011 0001 Remember: these are just Remember: these are just encodingsencodings. Meanings are . Meanings are
assigned by us.assigned by us.
10
Other Codes ExistOther Codes Exist Non positionalNon positional Example: Gray CodeExample: Gray Code
Only one bit changes at a timeOnly one bit changes at a time 000,001,011,010,110,111,101,100000,001,011,010,110,111,101,100 Why is this useful?Why is this useful?
Actually there’s a family of Gray codesActually there’s a family of Gray codes
Ref: http://lib-www.lanl.gov/numerical/bookcpdf/c20-2.pdf
12
Character CodesCharacter Codes From numbers to lettersFrom numbers to letters ASCIIASCII
Stands for American Standard Code for Information Stands for American Standard Code for Information InterchangeInterchange
Only 7 bits definedOnly 7 bits defined UnicodeUnicode You may make up your own code for the MIPS You may make up your own code for the MIPS
VGAVGA
14
Even ParityEven Parity Sometimes high-order bit of ASCII coded to Sometimes high-order bit of ASCII coded to
enable detection of errorsenable detection of errors Even parity – set bit to make number of 1’s Even parity – set bit to make number of 1’s
eveneven ExamplesExamples
A (01000001) with even parity is 01000001A (01000001) with even parity is 01000001C (01000011) with even parity is 11000011C (01000011) with even parity is 11000011
15
Odd ParityOdd Parity Similar except make the number of 1’s oddSimilar except make the number of 1’s odd ExamplesExamples
A (01000001) with odd parity is 11000001A (01000001) with odd parity is 11000001C (01000011) with odd parity is 01000011C (01000011) with odd parity is 01000011
16
Error DetectionError Detection Note that parity detects only simple errorsNote that parity detects only simple errors
One, three, etc. bitsOne, three, etc. bits More complex methods existMore complex methods exist Some that enable Some that enable recoveryrecovery of original info of original info
Cost is more redundant bitsCost is more redundant bits
17
Today’s TopicsToday’s Topics IntroductionIntroduction Digital logicDigital logic Number systemsNumber systems ArithmeticArithmetic CodesCodes ParityParity The encoding is keyThe encoding is key
Standards are used to agree on encodingsStandards are used to agree on encodings Special purpose codes for particular usesSpecial purpose codes for particular uses
18
HomeworkHomework None, but…None, but… I expect you to know number systems well and be I expect you to know number systems well and be
able to do conversions and arithmeticable to do conversions and arithmetic Decimal – BinaryDecimal – Binary Binary – DecimalBinary – Decimal Decimal – HexDecimal – Hex Hex – DecimalHex – Decimal
Can do some of the problems – 1-2, 1-4, 1-7 if you Can do some of the problems – 1-2, 1-4, 1-7 if you think you need a refresher. Answers on book website.think you need a refresher. Answers on book website.
19
Binary – Powers of 2Binary – Powers of 2 Positional representation Positional representation Each digit represents a power of 2Each digit represents a power of 2
So 101 binary isSo 101 binary is 1 1 •• 2 222 + 0 + 0 • • 2211 + 1 + 1 •• 2 200
oror 1 1 • 4 + • 4 + 0 0 • 2 + • 2 + 1 1 • 1 = 5• 1 = 5
20
Converting Binary to DecimalConverting Binary to Decimal Easy, just multiply digit by power of 2Easy, just multiply digit by power of 2 Just like a decimal number is representedJust like a decimal number is represented Example follows Example follows
21
Binary Binary Decimal Example Decimal Example
77 66 55 44 33 22 11 00
2277 2266 2255 2244 2233 2222 2211 2200
128128 6464 3232 1616 88 44 22 11
11 00 00 11 11 11 00 00
128 + 0 + 0 + 16 + 8 + 4 + 0 + 0 = 156 128 + 0 + 0 + 16 + 8 + 4 + 0 + 0 = 156
What is 10011100 in decimal?What is 10011100 in decimal?
22
Decimal to BinaryDecimal to Binary A little more work than binary to decimalA little more work than binary to decimal Some examplesSome examples
3 = 2 + 1 = 3 = 2 + 1 = 1111 (that’s 1 (that’s 1••2211 + 1 + 1••2200))5 = 4 + 1 = 5 = 4 + 1 = 101101 (that’s 1 (that’s 1••2222 + 0 + 0••2211 + 1 + 1••2200))
23
Algorithm – Decimal to BinaryAlgorithm – Decimal to Binary Find largest power-of-two smaller than decimal Find largest power-of-two smaller than decimal
numbernumber Make the appropriate binary digit a ‘1’Make the appropriate binary digit a ‘1’ Subtract the power of 2 from decimalSubtract the power of 2 from decimal Do the same thing againDo the same thing again
24
Decimal Decimal Binary Example Binary Example Convert 28 decimal to binaryConvert 28 decimal to binary
77 66 55 44 33 22 11 002277 2266 2255 2244 2233 2222 2211 2200
128128 6464 3232 1616 88 44 22 11
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
25
HexadecimalHexadecimal Strings of 0s and 1s too hard to writeStrings of 0s and 1s too hard to write Use base-16 or Use base-16 or hexadecimalhexadecimal – 4 bits – 4 bits
DecDec BinBin HexHex00 00000000 0011 00010001 1122 00100010 2233 00110011 3344 01000100 4455 01010101 5566 01100110 6677 01110111 77
DecDec BinBin HexHex88 10001000 8899 10011001 991010 10101010 ??1111 10111011 ??1212 11001100 ??1313 11011101 ??1414 11101110 ??1515 11111111 ??
26
HexadecimalHexadecimal Letters to represent 10-15Letters to represent 10-15
DecDec BinBin HexHex00 00000000 0011 00010001 1122 00100010 2233 00110011 3344 01000100 4455 01010101 5566 01100110 6677 01110111 77
DecDec BinBin HexHex88 10001000 8899 10011001 991010 10101010 aa1111 10111011 bb1212 11001100 cc1313 11011101 dd1414 11101110 ee1515 11111111 ff
•Power of 2Power of 2•Size of byteSize of byte
Why useWhy usebase 16?base 16?
27
Hex to BinaryHex to Binary
Convention – write 0x before numberConvention – write 0x before number Hex to Binary – just convert digitsHex to Binary – just convert digits
BinBin HexHex
00000000 00
00010001 11
00100010 22
00110011 33
01000100 44
01010101 55
01100110 66
01110111 77
10001000 88
10011001 99
10101010 aa
10111011 bb
11001100 cc
11011101 dd
11101110 ee
11111111 ff
0x2ac0x2ac
00100010 10101010 110011000x2ac = 0010101011000x2ac = 001010101100
No magic – remember hex digit = 4 bitsNo magic – remember hex digit = 4 bits
28
Binary to HexBinary to Hex
Just convert groups of 4 bitsJust convert groups of 4 bits
BinBin HexHex
00000000 00
00010001 11
00100010 22
00110011 33
01000100 44
01010101 55
01100110 66
01110111 77
10001000 88
10011001 99
10101010 aa
10111011 bb
11001100 cc
11011101 dd
11101110 ee
11111111 ff
101001101111011101001101111011
10111011
55 33 77 bb
101001101111011 = 0x537b101001101111011 = 0x537b
0101 0101 0111 0111 0011 0011
29
Hex to DecimalHex to Decimal Just multiply each hex digit by decimal Just multiply each hex digit by decimal
value, and add the results.value, and add the results.
161633 161622 161611 161600
40964096 256256 1616 11
0x2ac0x2ac
2 2 • 256• 256 + 10 + 10 • 16• 16 + 12 + 12 • 1• 1 = 684= 684
DecDec HexHex00 0011 1122 2233 3344 4455 5566 6677 7788 8899 991010 aa1111 bb1212 cc1313 dd1414 ee1515 ff
30
Decimal to HexDecimal to HexAnalogous to decimal Analogous to decimal binary. binary.
1.1. Find largest power-of-16 smaller than Find largest power-of-16 smaller than decimal numberdecimal number
2.2. Divide by power-of-16. The integer result Divide by power-of-16. The integer result is hex digit.is hex digit.
3.3. The remainder is new decimal number.The remainder is new decimal number.4.4. Do the same thing againDo the same thing again
31
Decimal to HexDecimal to Hex
161633 161622 161611 161600
40964096 256256 1616 11
DecDec HexHex00 0011 1122 2233 3344 4455 5566 6677 7788 8899 991010 aa1111 bb1212 cc1313 dd1414 ee1515 ff
684684684/256 = 2684/256 = 2 0x2__
684%256 = 172684%256 = 172172/16 = 10 = a172/16 = 10 = a 0x2a_
172%16 = 12 = c172%16 = 12 = c 0x2ac
32
OctalOctal Octal is base 8Octal is base 8 Similar to hexadecimalSimilar to hexadecimal
ConversionsConversions Less convenient for use with 8-bit bytesLess convenient for use with 8-bit bytes
33
Arithmetic -- additionArithmetic -- addition Binary similar to decimal arithmeticBinary similar to decimal arithmetic
00 11 11 00 00++ 11 00 00 00 11
11 11 11 00 11
No carries 11 00 11 11 00 0011 00 11 11 00
++ 11 00 11 11 11
11 00 11 11 00 11
Carries
1+1 is 2 (or 102), which results in a carry
34
Arithmetic -- subtractionArithmetic -- subtraction
11 00 11 11 00-- 11 00 00 11 00
00 00 11 00 00
No borrows 00 00 11 11 0011 11 11 11 00
-- 11 00 00 11 11
00 11 00 11 11
Borrows
0 - 1 results in a borrow
35
Arithmetic -- multiplicationArithmetic -- multiplication
11 00 11 1100 00 00 00
11 00 11 11
11 11 00 11 11 11
Successive additions of multiplicand or zero,multiplied by 2 (102).
Note that multiplication by 102 just shifts bits left.
11 00 11 11XX 11 00 11