0% found this document useful (0 votes)
25 views35 pages

Lec 07,08

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views35 pages

Lec 07,08

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 35

 Numbering and coding systems

OUTLINES
 Digital primer
 Inside the computer

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 2
L
 Human beings use base 10 (decimal)
NUMBERING
AND CODING arithmetic
SYSTEMS  There are 10 distinct symbols, 0, 1, 2, …,
9
Decimal and  Computers use base 2 (binary)
Binary Number system
Systems
 There are only 0 and 1
 These two binary digits are commonly
referred to as bits

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 3
L
 Divide the decimal number by 2
NUMBERING
AND CODING
repeatedly
SYSTEMS  Keep track of the remainders
 Continue this process until the quotient
Converting becomes zero
from Decimal
to Binary
 Write the remainders in reverse order
to obtain the binary number
Ex. Convert 2510 to binary
Quotient Remainder
25/2 = 12 1 LSB (least significant
12/2 = 6 bit) 0
6/2 = 3 0
3/2 = 1 1
1/2 = 0 1 MSB (most significant
Therefore 2510 = 110012 bit)
Department of Computer Science and Information Engineering
HANE National Cheng Kung University, TAIWAN 4
L
 Know the weight of each bit in a binary
NUMBERING number
AND CODING  Add them together to get its decimal
SYSTEMS
equivalent
Converting Ex. Convert 110012 to decimal
from Binary to Weight: 24 23 22 21 20
Decimal Digits: 1 1 0 0 1
Sum: 16 8 + 0+ 0+ 1 = 2510
+
 Use the concept of weight to convert a
decimal number to a binary directly
Ex. Convert 3910 to binary
32 + 0 + 0 + 4 + 2 + 1 = 39
Therefore, 3910 = 1001112
Department of Computer Science and Information Engineering
HANE National Cheng Kung University, TAIWAN 5
L
 Base 16, the
NUMBERING
AND CODING
hexadecimal system, Decimal Binary Hex

SYSTEMS is used as a 0 0000 0


1 0001 1
convenient 2 0010 2
Hexadecimal representation of 3 0011 3
4 0100 4
System binary numbers 5 0101 5
 ex. 6 0110 6
7 0111 7
It is much easier to 8 1000 8
represent a string of 0s 9 1001 9
and 1s such as 10 1010 A
100010010110 as its 11 1011 B
hexadecimal equivalent of 12 1100 C
896H 13 1101 D
14 1110 E
15 1111 F

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 6
L
 To represent a binary number as its
NUMBERING equivalent hexadecimal number
AND CODING  Start from the right and group 4 bits at a
SYSTEMS
time, replacing each 4-bit binary
number with its hex equivalent
Converting
between Binary Ex. Represent binary 100111110101 in hex
and Hex 1001 1111 0101
= 9 F 5

 To convert from hex to binary


 Each hex digit is replaced with its 4-bit
binary equivalent
Ex. Convert hex 29B to binary
2 9 B
= 0010 1001 1011
Department of Computer Science and Information Engineering
HANE National Cheng Kung University, TAIWAN 7
L
 Convert to binary first and then
NUMBERING
AND CODING
convert to hex
SYSTEMS  Convert directly from decimal to hex
by repeated division, keeping track of
Converting the remainders
from Decimal
to Hex Ex. Convert 4510 to hex
32 16 2 1
8 0 1 32 + 8 + 4 + 1 = 45
4510 = 0010 11012 = 42D16
1 0
Ex. Convert 62910 to hex
1
512 256 1281 64 32 16 8 4 2 1
1 0 0 1 1 1 0 1 0 1
62910 = 512+64+32+16+4+1 = 0010 0111 01012 =
27516
Department of Computer Science and Information Engineering
HANE National Cheng Kung University, TAIWAN 8
L
 Convert from hex to binary and then to
NUMBERING
AND CODING
decimal
SYSTEMS  Convert directly from hex to decimal
by summing the weight of all digits
Converting
from Hex to Ex. 6B216 = 0110 1011 00102
Decimal 1024 512 256 128 64 32 16 8 4 2 1
1 1 0 1 0 1 1 0 0 1 0
1024 + 512 + 128 + 32 + 16 + 2 = 171410

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 9
L
 Adding the digits together from the
NUMBERING
AND CODING
least significant digits
SYSTEMS  If the result is less than 16, write that digit
as the sum for that position
Addition of Hex  If it is greater than 16, subtract 16 from it
Numbers to get the digit and carry 1 to the next
digit
Ex. Perform hex addition: 23D9 + 94BE

23D9 LSD: 9 + 14 = 23 23 – 16 = 7 w/ carry


+ 94BE 1 + 13 + 11 = 25 25 – 16 = 9 w/ carry
B897 1+3+4=8
MSD: 2 + 9 = B

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 10
L
 If the second digit is greater than the
NUMBERING
AND CODING
first, borrow 16 from the preceding
SYSTEMS digit
Ex. Perform hex subtraction: 59F – 2B8
Subtraction of
Hex 59F LSD: 15 – 8 = 7
Numbers – 2B8 9 + 16 – 11 = 14 = E16
2E7 5–1–2=2

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 11
L
 The ASCII (pronounced “ask-E”) code
NUMBERING assigns binary patterns for
AND CODING  Numbers 0 to 9
SYSTEMS  All the letters of English alphabet,
uppercase and lowercase
ASCII Code  Many control codes and punctuation
marks
 The ASCII system uses 7 bits to
represent each code
Hex Symbol Hex Symbol
Selected ASCII codes 41 A 61 a
42 B 62 b
43 C 63 c
44 D 64 d
... ... ... …
59 Y 79 y
5A Z 7A z
Department of Computer Science and Information Engineering
HANE National Cheng Kung University, TAIWAN 12
L
 Two voltage levels can be represented
DIGITAL
as the two digits 0 and 1
PRIMER  Signals in digital electronics have two
Binary Logic distinct voltage levels with built-in
tolerances for variations in the voltage
 A valid digital signal should be within
either of the two shaded areas
5
Logic 1
4
3
2
1
Logic 0
0

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 13
L
 AND gate
DIGITAL

PRIMER
Logic Gates

Computer Science Illuminated, Dale and Lewis

 OR gate

Computer Science Illuminated, Dale and Lewis

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 14
L
 Tri-state buffer
DIGITAL
 Inverter
PRIMER
Logic Gates
(cont’)

Computer Science Illuminated, Dale and Lewis

 XOR gate

Computer Science Illuminated, Dale and Lewis

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 15
L
 NAND gate
DIGITAL

PRIMER
Logic Gates
(cont’)
Computer Science Illuminated, Dale and Lewis

 NOR gate

Computer Science Illuminated, Dale and Lewis

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 16
L
DIGITAL
Half adder
PRIMER
Logic Design
Using
Gates

Full adder

Digital Design, Mano

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 17
L
DIGITAL

PRIMER 4-bit adder


Logic Design
Using Gates
(cont’)

Digital Design, Mano

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 18
L
 Decoders
DIGITAL
 Decoders are widely used for address
PRIMER decoding in computer design
Logic Design Address Decoders
Using Gates
(cont’)

Address decoder for 9 (10012) Address decoder for 5 (01012)


The output will be 1 if and The output will be 1 if and
only if the input is 10012 only if the input is 01012

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 19
L
 Flip-flops
DIGITAL
 Flip-flops are frequently used to store data
PRIMER
Logic Design
Using Gates
(cont’)
Digital Design, Mano

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 20
L
 The unit of data size
INSIDE THE
 Bit : a binary digit that can have the value
COMPUTER 0 or 1
Important  Byte : 8 bits
Terminology  Nibble : half of a bye, or 4 bits
 Word : two bytes, or 16 bits
 The terms used to describe amounts of
memory in IBM PCs and compatibles
 Kilobyte (K): 210 bytes
 Megabyte (M) : 220 bytes, over 1 million
 Gigabyte (G) : 230 bytes, over 1 billion
 Terabyte (T) : 240 bytes, over 1 trillion

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 21
L
 CPU (Central Processing Unit)
INSIDE THE  Execute information stored in memory
 I/O (Input/output) devices
COMPUTER  Provide a means of communicating with
Internal CPU
Organization of  Memory
Computers  RAM (Random Access Memory) –
temporary storage of programs that
computer is running
 The data is lost when computer is off
 ROM (Read Only Memory) – contains
programs and information essential to
operation of the computer
 The information cannot be changed by use,
and is not lost when power is off
– It is called nonvolatile memory

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 22
L
INSIDE THE

COMPUTER
Internal Address bus
Organization of
Computers Memory
Peripherals
(cont’) CPU (monitor,
(RAM, ROM)
printer, etc.)

Data bus

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 23
L
 The CPU is connected to memory and
INSIDE THE
I/O through strips of wire called a
COMPUTER bus
Internal  Carries information from place to place
Organization of  Address bus
Computers  Data bus
(cont’)  Control bus
Address bus

RAM ROM Printer Disk Monitor Keyboard


CPU

Data bus
Read/

Write Control bus

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 24
L
 Address bus
INSIDE THE  For a device (memory or I/O) to be
recognized by the CPU, it must be
COMPUTER assigned an address
Internal  The address assigned to a given device must
Organization of be unique
Computers  The CPU puts the address on the address bus,
(cont’) and the decoding circuitry finds the device
 Data bus
 The CPU either gets data from the device
or sends data to it
 Control bus
 Provides read or write signals to the
device to indicate if the CPU is asking for
information or sending it information

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 25
L
 The more data buses available, the
INSIDE THE
better the CPU
COMPUTER  Think of data buses as highway lanes
More about  More data buses mean a more
Data Bus expensive CPU and computer
 The average size of data buses in CPUs
varies between 8 and 64
 Data buses are bidirectional
 To receive or send data
 The processing power of a computer is
related to the size of its buses

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 26
L
 The more address buses available, the
INSIDE THE larger the number of devices that can
be addressed
COMPUTER
More about
 The number of locations with which a
Address CPU can communicate is always equal
Bus to 2x, where x is the address lines,
regardless of the size of the data bus
 ex. a CPU with 24 address lines and 16
data lines can provide a total of 224 or 16M
bytes of addressable memory
 Each location can have a maximum of 1
byte of data, since all general-purpose
CPUs are byte addressable
 The address bus is unidirectional

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 27
L
 For the CPU to process information,
INSIDE THE the data must be stored in RAM or
ROM, which are referred to as primary
COMPUTER memory
CPU’s Relation  ROM provides information that is fixed
to RAM and and permanent
ROM  Tables or initialization program
 RAM stores information that is not
permanent and can change with time
 Various versions of OS and application
packages
 CPU gets information to be processed
 first form RAM (or ROM)
 if it is not there, then seeks it from a mass
storage device, called secondary memory, and
transfers the information to RAM

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 28
L
 Registers
INSIDE THE
 The CPU uses registers to store
COMPUTER information temporarily
 Values to be processed
Inside CPUs
 Address of value to be fetched
from memory
 In general, the more and bigger the
registers, the better the CPU
 Registers can be 8-, 16-, 32-, or 64-bit
 The disadvantage of more and bigger registers
is the increased cost of such a CPU

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 29
L
Address Bus
INSIDE THE
Program Counter
COMPUTER
Inside CPUs
(cont’)
Instruction Register

Control Bus Data Bus


Flags ALU
Instruction decoder,
timing, and control

Internal Register A
buses
Register B
Register C
Register D

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 30
L
 ALU (arithmetic/logic unit)
INSIDE THE  Performs arithmetic functions such as add,
subtract, multiply, and divide, and logic
COMPUTER functions such as AND, OR, and NOT
Inside CPUs
(cont’)
 Program counter
 Points to the address of the next
instruction to be executed
 As each instruction is executed, the program
counter is incremented to point to the address
of the next instruction to be executed
 Instruction decoder
 Interprets the instruction fetched into the
CPU
 A CPU capable of understanding more
instructions requires more transistors to design

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 31
L
Ex. A CPU has registers A, B, C, and D and it has an 8-bit
INSIDE THE data bus and a 16-bit address bus. The CPU can access
memory from addresses 0000 to FFFFH
COMPUTER Assume that the code for the CPU to move a value to
Internal register A is B0H and the code for adding a value to
Working of register A is 04H
The action to be performed by the CPU is to put 21H into
register A, and then add to register A values 42H and 12H
Computers
...

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 32
L
Ex. (cont’)
INSIDE THE Action Code Data
Move value 21H into reg. A B0H 21H
COMPUTER Add value 42H to reg. A 04H 42H
Internal Add value 12H to reg. A 04H 12H
Working of
Mem. addr. Contents of memory address
1400 (B0) code for moving a value to register A
Computers 1401 (21) value to be moved
(cont’) 1402 (04) code for adding a value to register A
1403 (42) value to be added
1404 (04) code for adding a value to register A
1405 (12) value to be added
1406 (F4) code for halt

...

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 33
L
Ex. (cont’)
INSIDE THE The actions performed by CPU are as follows:
1. The program counter is set to the value 1400H,
COMPUTER indicating the address of the first instruction code to
Internal be executed
Working of 2.
Computers  The CPU puts 1400H on address bus and sends it
(cont’) out
 The memory circuitry finds the location
 The CPU activates the READ signal, indicating to
memory that it wants the byte at location
以動畫表示 1400H
 This causes the contents of memory location
1400H, which is B0, to be put on the data bus and
brought into the CPU
...

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 34
L
Ex. (cont’)
INSIDE THE 3.
 The CPU decodes the instruction B0
COMPUTER  The CPU commands its controller circuitry to bring
Internal into register A of the CPU the byte in the next
Working of memory location
 The value 21H goes into register A
Computers  The program counter points to the address of the
(cont’) next instruction to be executed, which is 1402H
 Address 1402 is sent out on the address bus to
fetch the next instruction

...

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 35
L
Ex. (cont’)
INSIDE THE 4.
 From memory location 1402H it fetches code 04H
COMPUTER  After decoding, the CPU knows that it must add to
Internal the contents of register A the byte sitting at the
Working of next address (1403)
 After the CPU brings the value (42H), it provides
Computers the contents of register A along with this value to
(cont’) the ALU to perform the addition
 It then takes the result of the addition from the
ALU’s output and puts it in register A
 The program counter becomes 1404, the address
of the next instruction

...

Department of Computer Science and Information Engineering


HANE National Cheng Kung University, TAIWAN 36
L

You might also like