Lecture 1(Engr. Irshad Hussain)
Lecture 1(Engr. Irshad Hussain)
module cntr_32c(clk,res,out);
input clk;
input res;
output [3:0] out;
endmodule
How is it done
Draw your schematics
Write it down in Verilog HDL
Simulate using a simulator like ModelSIM
Use ModelSIM to create timing diagram
See if your model works
Digital Systems and
Information
Overview
Introduction to Digital Systems
Digital Systems (examples and general remarks)
Basic Digital System Structure (basic components and their function)
Number Systems
Positional Number Systems (decimal, binary, octal, and hexadecimal)
Number Conversions (r-to-decimal, decimal-to-r, other conversions)
Representations of Numbers in Digital Computers
Integer Numbers (unsigned and signed representations)
Real Numbers (floating-point representation)
Arithmetic Operations
General Remarks
Unsigned, Signed, and Floating-Point Binary Operations
Decimal Codes
BCD code, Excess-3 code, Seven-Segment Code
Alphanumeric Codes
ASCII and Unicode
Digital vs. Analog
Analog – infinite resolution
Like (old fashioned) radio dial
We’ll do very little with analog
VGA, maybe sound
Digital – a finite set of values
Like money
Can’t get smaller than cents
Typically also has maximum value
Digital Systems: Example
Modern Digital Computers
The best known example of a digital system
Most striking properties are: generality and flexibility
Basic Digital System Structure
CPU: Central Processing
Unit
Data Path: arithmetic and
logic operations
Control Unit: make sure
that the sequence of
data path operations is
correct
Storage: no memory = no
system
Input/Output: allow the
system to interact with
the outside world
Digital Systems: More Examples
Binary Signaling
Zero volts
FALSE or 0
3.3 or 5 volts
TRUE or 1
Modern chips down to 1V
(letters)
The decimal number system uses an alphabet of 10 symbols
(digits)
What about the alphabet of the Digital Systems?
The Digital Systems’ Alphabet is
Binary
Digital Systems use only one alphabet with two symbols (digits)
‘0’ and ‘1’ (hence binary ).
A binary digit is called a bit
Information is represented by groups of bits
can only be “on” or “off”, i.e., two discrete values ‘0’ and ‘1’ can
be distinguished.
An electronic device, called a transistor, physically implements
the switch.
The two discrete values are physically represented by ranges of
Example:
Decimal number system (we know it very well and use it in everyday
arithmetic).
585.5 is a decimal number in positional code – “5 hundreds plus 8
tens plus 5 units plus 5 tenths”. The hundreds, tens, units, and tenths
are powers of 10 implied by the position of the digits.
Decimal number system is said to be of base or radix 10 because it
uses10 distinct digits (0 – 9) and the digits are multiplied by power of
10:
585.5 = 5x102 + 8x101 + 5x100 + 5x10-1
Non-positional number systems
Old Roman numbers: for example, XIX equals to 19
Positional Number Systems
We can represent numbers in any number system with
base r
Number in positional code
(An-1An-2…A1A0.A-1A-2…A-m+1A-m)r
r is the base (radix) of the system, r Є {2, 3, …, I}.
every digit Ai Є {0, 1, 2, …, r-1}, where {0, 1, 2, …, r-1} is
the digit set.
“.” is called the radix point.
An-1 is referred to as the most significant digit.
A-m is referred to as the least significant digit.
Number in base r expressed as power series of r
.
Example: a number in number systems with base 5
(132.4)5 = 1x52 + 3x51 + 2x50 + 4x5-1 = 25 + 15 + 2 + 0.8 =
(42.8)10
Binary Number System
This is the system used for arithmetic in all digital computers
Number in positional code
(b b …b b b b …b
n-1 n-2 1 0 -1 -2 -m+1b-m)r
r = 2 is the base of the binary system.
= 8 + 2 + 1 + 0.25 =(11.25)10
Burn this table into your memory
POWER OF TWO TABLE
Other Useful Number System
Apart from the ordinary binary number system, the octal (base-8) and the
hexadecimal (base-16) number systems are useful for representing
binary quantities indirectly because their bases are powers of two.
These systems have a more compact representation of binary
quantities.
Octal number system
(on-1on-2…o1o0.o-1o-2…o-m+1o-m)8
every digit oi Є {0, 1, 2, 3, 4, 5, 6, 7}.
on-18 n-1 + on-28 n-2 +…+ o18 1 + o08 0 + o-18 -1 + o-28 -2 +…+ o-m+18 –m+1 +o-m8 –m
(127.4)8 = 1x82 + 2x81 + 7x80 + 4x8-1 = (87.5)10 = (001 010 111.100)2
Hexadecimal number system
(hn-1hn-2…h1h0.h-1h-2…h-m+1h-m)16
every digit hi Є {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}.
hn-116 n-1 + hn-216 n-2 +…+ h116 1 + h016 0 + h-116 -1 + h-216 -2 +…+ h-m+116 –m+1+ h-
m16
–m
(B6F.4)16 = 11x162 + 6x161 + 15x160 + 4x16-1 = (2927.25)10
= (1011 01101111.0100)2
Hexadecimal
Strings of 0s and 1s too hard to write
Use base-16 or hexadecimal – 4 bits
Dec Bin Hex 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 ?
Hexadecimal
Letters to represent 10-15
(An-1An-2…A1A0.A-1A-2…A-m+1A-m)r =
An-1 r n-1 + An-2 r n-2 +…+ A1 r 1 + A0 r 0 + A-1 r -1 + A-2 r -2 +…+ A-m+1 r –m+1 + A-m r –m
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
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)
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
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
Conversion from Decimal to base
rIf the number has a radix point then separate the number into an integer
The conversion is done as follows:
1.
part and a fraction part, since the two parts must be converted differently.
2. The conversion of a decimal integer part to a number in base r is done by
dividing the integer part and all successive quotients by r and
accumulating the remainders.
3. The conversion of a decimal fraction part to a number in base r is done by
multiplying the fractional parts by r and accumulating integers.
Octal to Hexadecimal
Octal → Binary → Hexadecimal
Bin Hex
Hex to Binary 0000 0
0001 1
Convention – write 0x before number
0010 2
Hex to Binary – just convert digits 0011 3
0100 4
0x2ac 0101 5
0110 6
0111 7
1000 8
0010 1010 1100
1001 9
0x2ac = 001010101100 1010 a
1011 b
1100 c
No magic – remember hex digit = 4 bits 1101 d
1110 e
1111 f
Bin Hex
Binary to Hex 0000 0
0001 1
0010 2
0011 3
Just convert groups of 4 bits 0100 4
101001101111011 0101 5
0110 6
684/256 = 2 0x2__ 3
4
3
4
684%256 = 172 5
6
5
6
172/16 = 10 = a 0x2a_ 7 7
8 8
172%16 = 12 = c 0x2ac 9 9
10 a
11 b
163 162 161 160 12 c
4096 256 16 1 13 d
14 e
15 f
Number Ranges
The range of numbers in base (radix) r depends on the number of digits
used to represent the numbers.
Assume the number (An-1An-2…A1A0.A-1A-2…A-m+1A-m)r represented by n
digits for the integer part and m digits for the fraction part.
The smallest integer number is 0 and the largest is (r-1) r n-1 + (r-1) r n-2 +…
+ (r-1)r 1 + (r-1) r 0 = rn-1 ,i.e., the range is from 0 to rn-1
The smallest fraction number is 0.0 and the largest is (r-1) r -1 + (r-1) r -2 +
…+ (r-1) r –m+1 + (r-1) r –m=1- r –m, i.e., the range is from 0.0 to 1- r –m
The range of numbers is from 0.0 to rn - r –m
Examples:
Largest 3-digit integer decimal (base 10) number is 10 3-1 = 1000 - 1 = 999
Largest 8-digit integer binary (base 2) number is (11111111) 2 ,i.e., 28-1 = 255
Largest 5-digit decimal (base 10) fraction is 1-10-5 = 1 – 0.00001 = 0.99999
Largest 16-digit binary (base 2) fraction is 1-2-16 = 0.9999847412
No carries 1 0 1 1 0 0 Carries
0 1 1 0 0 1 0 1 1 0
+ 1 0 0 0 1 + 1 0 1 1 1
1 1 1 0 1 1 0 1 1 0 1
No borrows 0 0 1 1 0 Borrows
1 0 1 1 0 1 1 1 1 0
- 1 0 0 1 0 - 1 0 0 1 1
0 0 1 0 0 0 1 0 1 1
0 - 1 results in a borrow
Arithmetic -- multiplication
1 0 1 1 Successive additions of
X 1 0 1 multiplicand or zero,
multiplied by 2 (102).
1 0 1 1
0 0 0 0
Note that multiplication
by 102 just shifts bits
1 0 1 1
left.
1 1 0 1 1 1
Binary Floating-point Operations
Decimal Codes
The binary number system is the most natural
system for a digital computer, but people are
accustomed to the decimal system.
How to resolve this difference?
Convert decimal numbers to binary, perform all arithmetic
calculations in binary, and then convert the binary result
back to decimal.
You already know how to do this.
Digital computers can do this as well, but:
We have to store the decimal numbers in the computer in a
way that they can be converted to binary.
Since the computer can accept only binary values, we must
represent the decimal digits by a code that contains 1’s and
0’s.
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.
Binary Coded Decimals (BCD) - 1
The BCD code is the most commonly used code.
Each decimal digit (0, 1, 2, …, 9) is coded by a4-bit
string (half a byte) called BCD digit.
A decimal number is converted to a BCD number by
replacing each decimal digit of the number with the
corresponding BCD digit code.
Example:
Ref: http://lib-www.lanl.gov/numerical/bookcpdf/c20-2.pdf
Shaft Encoder
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
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
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
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
Alphanumeric Codes
Many applications of digital computers require the handling of
data consisting not only of numbers, but also of letters.
Alphanumeric character set of English includes:
Boolean Equation
Canonical Sum-Of-Products (CSOP) form (unique)
Canonical Product-Of-Sums (CPOS) form (unique)
Standard Forms (NOT unique representations)
Maps (unique representation)
for F is:
F(X,Y,Z) = m1 + m2 + m4 + m6
= X’Y’Z + X’YZ’ + XY’Z’ + XYZ’.
Canonical Product-Of-Sums
It is a product of maxterms.
The maxterms included are
those Mj such that F( ) = 0 in
row j of the truth table for F( ).
Example:
Truth table for F(X,Y,Z) at right .
The canonical product-of-sums