Computer's Language College Notes
Computer's Language College Notes
NCNU_2013_DD_1_1
Digital Systems
• Digital age:
– digital systems play a prominent role in everyday life; used in communication, business
transactions traffic control,
transactions, control spacecraft guidance
guidance, medical treatment,
treatment weather monitoring,
monitoring the
Internet, and many other commercial, industrial, and scientific enterprises
• Digital system examples:
– mobile phone
– digital camera
– digital versatile disc (DVD),
(DVD) personal digital assistance (PDA),
(PDA) MP3,
MP3 …
– digital TV
– most, if not all, of these devices have an embedded specialpurpose digital computer
• Digital computers: What you will learn in the micro-processor course.
– generality or flexibility
– users can specify
if andd change
h the
h program, a sequence off iinstructions,
i or the
h data
d according
di to
the specific need
– generalpurpose digital computers can perform a variety of informationprocessing tasks that
range over a wide spectrum of applications
NCNU_2013_DD_1_2
Signal
• Digital systems manipulate discrete elements of information represented in a digital
system by physical quantities called signals.
•VVoltages
lt and
d currents
t are the
th mostt common electrical
l t i l signals.
i l
• The signals in most presentday electronic digital systems use just two discrete values or
binaryy values
• Binary values are represented abstractly by:
- digit: 0 and 1 A binary digit is called a bit.
- logic: False (F) and True (T)
- level: Low (L) and High (H)
- word: Yes and No
- state: On and Off.
• Discrete elements of information are represented with groups of bits called binary codes.
For example: 01112 = 710
• Analogtodigital converters perform quantization process on analog (continuous)
signals to form a digital (discrete) signals.
signals
NCNU_2013_DD_1_3
General-purpose Digital Computer
• The major parts of a computer are a memory unit, a central processing unit (CPU), and
input–output units (I/O). [check these in your Computer course]
• Memory
M unit
it stores
t programs as well
ll as input,
i t output,
t t andd intermediate
i t di t data.
d t
• CPU performs arithmetic and dataprocessing operations as specified by the program.
• The program and data prepared by a user are transferred into memory by means of an
input device such as a keyboard.
• An output device, such as a printer, receives the results of the computations, and the
printed
i d results
l are presentedd to the
h user.
• Voice, image, finger touch, gesture, brain wave, …, also can be used as input or output.
• Communication unit provides interaction with other users through the Internet.
Internet
• A digital computer can perform not only arithmetic computations and logical operations
but also can make decisions based on internal and external conditions.
NCNU_2013_DD_1_4
Hardware Description Language (HDL)
• A digital system is an interconnection of digital modules.
• To understand the operation of each digital module, it is necessary to have a basic
k
knowledge
l d off digital
di it l circuits
i it and d th
their
i llogical
i l function.
f ti
• A major trend in digital design methodology is the use of a hardware description
g g ((HDL)) to describe and simulate the functionality
language y of a digital
g circuit.
• An HDL resembles a programming language and is suitable for describing digital
circuits in textual form, simulating a digital system to verify its operation before
hardware is built,
built and automating the design process in conjunction with logic synthesis
tools.
• Ignorance of industry’s practices on HDL modeling will lead to cute, but worthless,
HDL models that may simulate a phenomenon, but that cannot be synthesized by design
tools, or to models that waste silicon area or synthesize to hardware that cannot operate
correctly.
y [take
[ the Digital
g System
y g course for more learning
Design g on HDL]]
NCNU_2013_DD_1_5
Decimal Numbers
• Decimal number (base-10 or radix-10) digit
… a5a4a3a2a1a0.a1a2a3… aj
Decimal point Power
105 a5 104 a4 103 a3 102 a2 101 a1 100 a0 101 a1 102 a2 103 a3
Example:
NCNU_2013_DD_1_6
Base-r Numbers
Example: Base-2, binary
(11010.11) 2 (26.75)10
1 24 1 23 0 22 1 21 0 20 1 2 1 1 2 2
Example: Base-5
Base 5
(4021.2)5
4 53 0 52 2 51 1 50 2 51 (511.5)
(511 5)10
Example: Base-16, hexadecimal, (A, B, C, D, E, and F are used for the digits 10 ~ 15, respectively)
Special Powers of 2
NCNU_2013_DD_1_8
Powers of Two
• Multiplication
The binary multiplication table is simple:
0 0 = 0, 1 0 = 0, 0 1 = 0, 1 1 = 1
Extending multiplication to multiple digits:
Multiplicand 1011
Multiplier 101
Partial Products 1011
0000-
1011
1011--
Product 110111
NCNU_2013_DD_1_10
Number-Base Conversion
Name Radix Digits
Binary 2 01
0,1
Octal 8 0,1,2,3,4,5,6,7
Decimal 10 0,1,2,3,4,5,6,7,8,9
Hexadecimal 16 0123456789ABCDEF
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
The six letters A, B, C, D, E, and F in hexadecimal represent: 10, 11, 12, 13, 14, and 15,
p y
respectively.
NCNU_2013_DD_1_11
Decimal to Binary Conversion
Example1.1
Convert decimal 41 to binary. The quotient-divided-2 process is continued until the
integer quotient becomes 0.
Integer
Quotient Remainder Coefficient
41/2 = 20 1 a0 = 1
20/2 = 10 0 a1 = 0
10/2 = 5 0 a2 = 0
5/2 = 2 1 a3 = 1
2/2 = 1 0 a4 = 0
1/2 = 0 1 a5 = 1
NCNU_2013_DD_1_12
Long Division
The arithmetic process can be manipulated more conveniently as follows:
÷2
41 = 20 × 2 + 1
= (10 × 2 + 0) × 2 + 1
= ((5 × 2 + 0) × 2 + 0) × 2 + 1
= (((2 × 2 + 1) × 2 + 0) × 2 + 0) × 2 + 1
= ((((1 × 2 + 0) × 2 + 1) × 2 + 0) × 2 + 0) × 2 + 1
= (((1 × 2 + 0) × 2 + 1) × 2 + 0) × 22 + 0 × 21 + 1 × 20
= ((1 × 2 + 0) × 2 + 1) × 23 + 0 × 22 + 0 × 21 + 1 × 20
= (1 × 2 + 0) × 24 + 1 × 23 + 0 × 22 + 0 × 21 + 1 × 20
= 1 × 25 + 0 × 24 + 1 × 23 + 0 × 22 + 0 × 21 + 1 × 20
NCNU_2013_DD_1_13
Decimal to Octal Conversion
Example 1.2
Convert decimal 153 to octal. The required base r is 8.
153 = 19 × 8 + 1
= (2 × 8 + 3) × 8 + 1
= 2 × 82 + 3 × 81 + 1 × 80
NCNU_2013_DD_1_14
Decimal Fraction Number to Binary
Example1.3
Convert (0.6875)10 to binary. The multiplied-by-2 process is continued until the
fraction becomes 0 or until the number of digits has sufficient accuracy.
accuracy
NCNU_2013_DD_1_15
Decimal Fraction Number to Octal
E l 14
Example1.4
Convert (0.513)10 to octal.
The conversion of decimal numbers with both integer and fraction parts is done by
g the integer
converting g and the fraction separately
p y and then combining
g the two
answers.
From Examples 1.1 and 1.3: (41.6875)10 = (101001.1011)2
From Examples 1.2 and 1.4: (153.513)10 = (231.406517)8
NCNU_2013_DD_1_16
Numbers with Different Bases
23 = 8 & 24=16
16
each octal/hexadecimal digit corresponds to three/four binary digits
NCNU_2013_DD_1_17
Octal and Hexadecimal Numbers 23 = 8, 24 = 16
Conversion
i from
f binary
bi to octall can be
b done
d by
b positioning
i i i theh binary
bi number
b into
i
groups of three digits each, starting from the binary point and proceeding to the
left and to the right.
(10 110 001 101 011 . 111 100 000 110) 2 = (26153.7406)8
2 6 1 5 3 7 4 0 6
Conversion from binary to hexadecimal is similar, except that the binary number is
divided into groups of four digits:
Conversion
C i from
f octall or hexadecimal
h d i l to binary
bi i done
is d b reversing
by i the
h preceding
di
procedure.
NCNU_2013_DD_1_18
Complements of Numbers
Complements
C l t are usedd in
i digital
di it l systems
t to
t simplify
i lif theth subtraction
bt ti operation
ti
There are two types of complements for each base-r system: the radix complement and
diminished radix complement.
the
h r's complement
l andd the
h second h ((r 1)'s
d as the ) complement.
l
■ Diminished Radix Complement
Example:
NCNU_2013_DD_1_19
Complements of Numbers
■ Radix Complement
The r's complement of an n-digit number N in base r is defined as rn – N for N ≠ 0
0 Comparing with the (r 1) 'ss complement
and as 0 for N = 0. complement, we note that the rr'ss
complement is obtained by adding 1 to the (r 1) 's complement, since rn – N =
[(rn 1) – N] + 1.
Example: Base-10
Example: Base-2
NCNU_2013_DD_1_20
Subtraction with Complements
• The subtraction of two n-digit unsigned numbers M – N in base r can be done as follows:
• M ≥ N the sum will produce an end carry rn, which can be discarded, what is
left
e t iss the
t e result
esu t M-N
N
• M < N the sum does not produce an end carry, and is equal to rn- (N –M)
NCNU_2013_DD_1_21
10’s Complement Subtraction
Example 1.5
Using 10's complement, subtract 72532 – 3250.
Example 1.6
Using 10's complement, subtract 3250 – 72532
NCNU_2013_DD_1_23
1’s Complement Subtraction
Subtraction
S b i off unsigned
i d numbers
b can also l be b done
d by
b means off the ( 1)'s
h (r 1)'
complement. Remember that the (r 1) 's complement is one less then the r's
complement.
Example 1.8
Repeat Example 1.7, but this time using 1's complement.
E l Al
Example: Although
h h there
h iis only
l one way to represent +9,
9 there
h are three
h diff
different
ways to represent -9 with eight bits:
NCNU_2013_DD_1_25
NCNU_2013_DD_1_26
Arithmetic Addition with Signed Binary Numbers
The
Th addition
ddi i off two numbers
b iin the
h signed-magnitude
i d i d system follows
f ll the
h rules
l off
ordinary arithmetic.
If the signs
g are the same,, add the two magnitudes
g and ggive the sum the common
sign.
If the signs are different, subtract the smaller magnitude from the larger and give
th difference
the diff the
th sign
i if the
th larger
l magnitude.
it d
The addition of negative numbers represented in signed-2's-complement form is
obtained from the addition of the two numbers, including
g their sign
g bits.
A carry out of the sign-bit position is discarded.
Example: signed-2's-complement arithmetic
NCNU_2013_DD_1_27
Arithmetic Subtraction
In 2’s-complement form:
1. Take the 2’s complement of the subtrahend (including the sign bit) and add it to
the minuend (including sign bit).
2. A carry out of sign-bit position is discarded.
( A) ( B ) ( A) ( B )
( A) ( B ) ( A) ( B )
Example:
(11111010 + 00001101)
Since binary numbers in signedcomplement system are added and subtracted by the
same basic addition and subtraction rules as unsigned numbers, computers need
only one common hardware circuit to handle both types of arithmetic.
NCNU_2013_DD_1_28
Binary Codes
• An nbit binary code can have up to 2n distinct combinations of 1’s and 0’s, with each
combination representing one element of the information set that is being coded.
• A sett off ffour elements
l t can be
b coded
d d with
ith two
t bits:
bit 00,
00 01,
01 10,
10 11.
11
• A set of eight elements requires a 3bit code and a set of 16 elements requires a 4bit
code. ((What are these codes?))
• The bit combination of an nbit code is the count in binary from 0 to 2n - 1.
• Each element must be assigned a unique binary bit combination, and no two elements
can have
h the
h same value;
l otherwise,
h i the
h coded assignment
i will
ill bbe ambiguous.
bi
• Although the minimum number of bits required to code 2n distinct quantities is n, there is
no maximum number of bits that may be used for a binary code. For example, the 10
decimal digits can be coded with 10 bits, and each decimal digit can be assigned a bit
combination of nine 0’s and a 1. In this particular binary code, the digit 6 is assigned the
bit combination 0001000000.
0001000000 (It is called one-hot code.)
code )
NCNU_2013_DD_1_29
Binary-Coded Decimal (BCD)
A number with k decimal digits will require
4k bits in BCD.
Decimal 396 is represented in BCD with 12
bits as 0011 1001 0110, with each group of
4 bits representing
p g one decimal digit.
g
A decimal number in BCD is the same as its
equivalent binary number only when the
number
b iis between
b t 0 andd 9.
9
A BCD number greater than 10 looks
different from its equivalent
q binary
y number,,
even though both contain 1's and 0's.
The binary combinations 1010 through
1111 are not used and have no meaning in
BCD.
NCNU_2013_DD_1_30
BCD Conversion and Addition
Example:
Consider decimal 185 and its corresponding value in BCD and binary:
■ BCD Additi
Addition
If the decimal addition has carry, correct the results by adding 6 = 0110.
NCNU_2013_DD_1_31
BCD Addition
Example:
Consider the addition of 184 + 576 = 760 in BCD:
■ Consider the addition (+375) + (-240) = +135, done in the signedcomplement system:
NCNU_2013_DD_1_32
Other Decimal Codes
NCNU_2013_DD_1_33
Gray Code
Gray
G code
d changes
h only
l one bit in
i the
th code
d
group going from one number to the next.
For example,
p , ggoing
g from 7 to 8,, the Grayy code
changes from 0100 to 1100. Only the first bit
changes, from 0 to 1; the other three bits remain
the same
same.
If binary numbers are used, a change, for
example, from 0111 to 1000 may produce an
i
intermediate
di erroneous number b 1001 if theh
value of the rightmost bit takes longer to change
than do the values of the other three bits.
NCNU_2013_DD_1_34
Gray Code (Continued)
• Does this special Gray code property have any value?
• Example: Optical Shaft Encoder
G2
G1
111 G0
101 010 011
NCNU_2013_DD_1_35
Gray Code Generation
• Gray codes
0 00 000 0000
1 01 001 0001
11 011 0011
10 010 0010
110 0110
111 0111
101 0101
100 0100
1100
1101
1111
1110
1010
1011
1001
1000
NCNU_2013_DD_1_36
ASCII Character Code
• Digital computers handle not only the numbers, but also other characters or symbols,
such as the letters of the alphabet.
•A
An alphanumeric
l h i character
h t sett is
i a sett off elements
l t that
th t includes
i l d theth 10 decimal
d i l digits,
di it
the 26 letters of the alphabet, and a number of special characters. Such a set contains
between 36 and 64 elements if only capital letters are included, or between 64 and 128
elements if both uppercase and lowercase letters are included.
• The American Standard Code for Information Interchange (ASCII) uses seven bits to
code 128 characters, as shown in Table 1.7 .
• The 7 bits of the code are designated by b1 through b7, with b7 the most significant bit.
• The letter A, for example, is represented in ASCII as 1000001 (column 100, row 0001).
• The ASCII code also contains 94 graphic characters that can be printed and 34
nonprinting characters used for various control functions.
• Th
The graphic
hi characters
h t consist
i t off the
th 26 uppercase letters
l tt (A through
th h Z),
Z) the
th 26
lowercase letters (a through z), the 10 numerals (0 through 9), and 32 special printable
characters, such as %, *, and $.
NCNU_2013_DD_1_37
ASCII Character Set
NCNU_2013_DD_1_38
ASCII Control Characters
NCNU_2013_DD_1_39
UNICODE
• UNICODE extends ASCII to 65,536 universal characters codes
– For encoding characters in world languages
– Available in many modern applications
– 2 byte (16
(16-bit)
bit) code words
– See Reading Supplement – Unicode on the Companion Website
http://www.prenhall.com/mano
NCNU_2013_DD_1_40
Error-Detecting Code
To detect errors in data communication and processing, an eighth bit is
sometimes added to the ASCII character to indicate its parity.
A parity bit is an extra bit included with a message to make the total
number of 1's either even or odd.
Example:
Consider the following two characters and their even and odd parity:
parity bit
NCNU_2013_DD_1_41
Memory: Binary Storage and Registers
■ Registers
The binary information in a digital computer must have a physical existence
in some medium for storing individual bits
bits.
A binary cell is a device that possesses two stable states and is capable of
storing one bit of information (0 or 1).
A register is a group of binary cells.
A register with n cells can store any discrete quantity of information that
contains n bits.
bits
n cells 2n possible states
The
Th content
t t off a register
i t (the
(th information
i f ti stored
t d in
i it) iis iinterpreted
t t d diff
differently
tl
depending on the application of CPU.
NCNU_2013_DD_1_42
Register Transfer of information
NCNU_2013_DD_1_43
Binary Information Processing
Binary
Bi variables
i bl are manipulated
i l t d by
b
means of digital logic circuits.
Data is commonly
y hold in registers.
g
Digital logic circuits and registers are
covered in Chapters 2 through 6.
Memory unit
i is
i explained
l i d in
i Chapter
h 7.
The description of register operations and
the design of digital systems are covered
in Chapter 8 .
NCNU_2013_DD_1_44
A Digital Computer Example
Memory
Control
CPU unit Datapath
Inputs:
p Outputs:
Keyboard, mouse, LCD, modem, speakers
modem, microphone Input/Output
Synchronous or Asynchronous?
NCNU_2013_DD_1_45
Binary Logic
Binary logic consists of binary variables and a set of logical operations
operations.
The variables are designated by letters of the alphabet, such as A, B, C, x, y, z, etc,
with each variable having two and only two distinct possible values: 1 and 0.
There are three basic logical operations: AND, OR, and NOT.
N represented
AND: p byy a dot or by
y the absence of an operator.
p
• x·y = z or xy = z is read “x AND y is equal to z.”
• z = 1 if and only if x = 1 and y = 1; otherwise z = 0. (Remember that x, y, and z are
bi
binary variables
i bl andd can be b equall either
ith tot 1 or 0,
0 andd nothing
thi else.)
l )
OR: represented by a plus sign.
• x + y = z is read “x O
OR y is equal
q to z,”
, meaningg that z = 1 if x = 1 or if y = 1 or if
both x = 1 and y = 1.
• If both x = 0 and y = 0, then z = 0.
NOT: represented
NOT d bby a prime
i (sometimes
( i by
b an overbar).
b )
• x’ = z (or x = z ) is read “not x is equal to z,” meaning that z is what x is not.
• If x = 1,, then z = 0,, but if x = 0,, then z = 1.
• also referred to as the complement operation, since it changes a 1 to 0 and a 0 to 1.
NCNU_2013_DD_1_46
Truth Table of Logic Operation
NCNU_2013_DD_1_47
Binary Logic Levels
Binary logic levels have evolved from a higher
voltage to lower for saving power consumption.
5 V 3 V 1.8
18V…
Typically,
a high voltage region (VDD) represents logic 1
a low voltage region (GND) represents logic 0
The transition region is forbidden for proper logic
operation.
The required signal range for logic is different at
the input and output sides of logic elements.
elements The
signal range at output side is more stringent than
that at input side. The difference is called noise
margin.
margin
NCNU_2013_DD_1_48
Basic Logic Gates
Graphic Symbols and Input Output Signals for Logic gates:
Input-Output
NCNU_2013_DD_1_49
Multiple-Input Gates
F = (AB)(CD) = ABCD
A A
B F B F
C
C
D
D
NCNU_2013_DD_1_50
Inverting Gates
NOT + AND = NAND A B F
0 0 1
A A F 0 1 1
F
1 0 1
B B 1 1 0
NOT + OR = NOR A B F
A F A 0 0 1
F 0 1 0
B B 1 0 0
1 1 0
1.4
18
1.8
1.18
1.22
1 36
1.36
NCNU_2013_DD_1_52