NMCNTT-04-Data Manipulation
NMCNTT-04-Data Manipulation
L EC T U R E S L I D ES A R E A DA P T E D / M O D I F I E D F RO M S L I D ES
P ROV I D E D BY T H E T E X T B O O K , C O M P U T E R S C I E N C E : A N
OV E RV I E W BY J. G L E N N B RO O K S H EA R A N D D E N N I S B RY LOW
P U B L I S H E R P EA RS O N
Data Manipulation
Computer Architecture
Machine Language
Program Execution
Arithmetic/Logic Instructions
Communicating with Other Devices
Other Architectures
2
Computer Architecture
Computer Architecture
Central Processing Unit (CPU) or processor
◦ Arithmetic/Logic unit versus Control unit
◦ Registers
◦ General purpose
◦ Special purpose
Bus
Motherboard
4
CPU and main memory connected via a bus
5
Motherboards
The motherboard
◦ is the main printed circuit board.
◦ contains the buses, or electrical
pathways found in a computer.
Buses allow data to travel
among the various components.
◦ accommodates CPU, RAM,
expansion slots, heat sink/fan
assembly, BIOS chip, chip set,
sockets, internal and external
connectors, various ports, and the
embedded wires that interconnect the
motherboard components.
6
Central Processing Unit
The Central Processing Unit (CPU) is known as the
brain of the computer. It is also referred to as the
processor.
The CPU executes a program, which is a sequence
of stored instructions.
7
Central Processing Unit
Some CPUs incorporate hyperthreading or
hypertransport to enhance the performance of the
CPU.
The amount of data that a CPU can process at one
time depends on the size of the processor data bus.
Speed of the CPU is measured in cycles per second
- megahertz (MHz) or gigahertz (GHz).
Overclocking is a technique used to make a
processor work at a faster speed than its original
specification.
8
Central Processing Unit
The latest processor technology has resulted
in CPU manufacturers finding ways to incorporate
more than one CPU core onto a single chip.
◦ Dual Core CPU - Two cores inside a single CPU
◦ Triple Core CPU - Three cores inside a single CPU
◦ Quad Core CPU - Four cores inside a single CPU
◦ Hexa-Core CPU - Six cores inside a single CPU
◦ Octa-Core CPU - Eight cores inside a single CPU
9
The Arithmetic/Logic Unit
Subsystem that performs addition, subtraction, and
comparison for equality
Components
◦ Registers, interconnections between components, and the
ALU circuitry
Register
◦ Storage cell that holds the operands of an arithmetic
operation and holds its result
Bus
◦ Path for electrical signals
10
The Arithmetic/Logic Unit
Registers are similar to RAM with following minor
differences
◦ They do not have a numeric memory address but are
accessed by a special register designator such as A, X or R0
◦ They can be accessed much more quickly than regular
memory cells
◦ They are not used for general purpose storage but for
specific purposes such as holding the operands for an
upcoming arithmetic computations.
A typical ALU has 16, 32 or 64 registers.
11
The Control Unit
Control unit
◦ Tasks: fetch, decode, and execute
12
Machine Language
Stored Program Concept
A program can be encoded as bit patterns and
stored in main memory.
From there, the CPU can then extract the
instructions and execute them.
In turn, the program to be executed can be altered
easily.
14
Terminology MEANING : THUAT NGU
15
Machine Language Philosophies
Reduced Instruction Set Computing (RISC)
◦ Few, simple, efficient, and fast instructions
◦ Examples: PowerPC from Apple/IBM/Motorola and ARM
16
Machine Instruction Types
Data Transfer: copy data from one location to
another
Arithmetic/Logic: use existing bit patterns to
compute a new bit patterns
Control: direct the execution of the program
17
Adding values stored in memory
18
Dividing values stored in memory
19
An architecture of the machine
20
Parts of a Machine Instruction
Op-code: Specifies which operation to execute
Operand: Gives more detailed information about
the operation
◦ Interpretation of operand varies depending on op-code
21
The composition of an instruction
22
Decoding the instruction 35A7
23
A Simple Machine Language
24
A Simple Machine Language
25
A Simple Machine Language
14A3: Load
◦ The contents of the memory cell located at address A3 to
be placed in register 4.
20A3: Load
◦ The value A3 to be placed in register 0.
35B1: Store
◦ The contents of register 5 to be placed in the memory cell
whose address is B1.
40A4: Move
◦ The contents of register A to be copied into register 4.
26
A Simple Machine Language
5726: Add
◦ The binary values in registers 2 and 6 to be added and the
sum placed in register 7.
634E: Add
◦ The values in registers 4 and E to be added as floating-
point values and the result to be placed in register 3.
27
A Simple Machine Language
7CB4: Or
◦ The result of ORing the contents of registers B and 4 to be
placed in register C.
8045: And
◦ The result of ANDing the contents of registers 4 and 5 to
be placed in register 0.
95F3: Xor
◦ The result of XORing the contents of registers F and 3 to
be placed in register 5.
A403: Rotate
◦ The contents of registers 4 to be rotated 3 bits to the right
in a circular fashion.
28
A Simple Machine Language
B43C:
◦ Compare the contents of register 4 with the contents of
register 0.
◦ If equal, the pattern 3C would be placed in the program
counter so that the next execution executed would be the
one located at that memory address.
◦ Otherwise, nothing would be done.
C000:
◦ Stop program execution.
29
An encoded version of the instructions
30
Quiz
The following are instructions written in the above
simple machine language. Rewrite in English.
◦ 368A
◦ BADE
◦ 803C
◦ 40F4
31
Quiz
What is the difference between the instructions 15AB
and 25AB in the simple machine language?
32
Quiz
Here are some instructions in English. Translate each
of them into the simple machine language.
◦ LOAD register number 3 with the hexadecimal 56.
33
Quiz
Here are some instructions in English. Translate each
of them into the simple machine language.
◦ LOAD register number 3 with the hexadecimal 56.
2356
34
Program Execution
Program Execution
Controlled by two special-purpose registers
◦ Program counter: address of next instruction
◦ Instruction register: current instruction
Machine Cycle
◦ Fetch
◦ Decode
◦ Execute
36
The machine cycle
37
Decoding the instruction B258
38
A program stored in main memory
39
The fetch step of the machine cycle
40
The fetch step of the machine cycle
41
Arithmetic/Logic Instructions
Arithmetic/Logic Operations
Logic: AND, OR, XOR
◦ Masking
Rotate and Shift:
◦ circular shift (rotation)
◦ logical shift
◦ arithmetic shift
Arithmetic: add, subtract, multiply, divide
◦ Precise action depends on how the values are encoded
(two’s complement versus floating-point).
43
Masking
44
Circular shift
45
Logical shift
46
Quiz
What logical operation together with what mask can
you use to change ASCII codes of lower characters to
uppercase? What about uppercase to lowercase?
47
Quiz
Identify both the mask and the logical operation
needed to accomplish each of the following
objectives:
• Put 1s in the upper 4 bits of an 8-bit pattern
without disturbing the other bits.
• Complement the most significant bit of an 8-bit
pattern without changing the other bits.
• Complement a pattern of 8 bits.
• Put a 0 in the least significant bit of an 8-bit
pattern without disturbing the other bits.
48
Quiz
Identify both the mask and the logical operation needed
to accomplish each of the following objectives:
• Put 1s in the upper 4 bits of an 8-bit pattern without
disturbing the other bits.
OR 1111 0000
• Complement the most significant bit of an 8-bit
pattern without changing the other bits.
XOR 1000 0000
• Complement a pattern of 8 bits.
XOR 1111 1111
• Put a 0 in the least significant bit of an 8-bit pattern
without disturbing the other bits.
AND 1111 1110
49
Quiz
Identify both the mask and the logical operation
needed to accomplish each of the following
objectives:
• Put 1s in all but the most significant bit of an 8-bit
pattern without disturbing the most significant bit.
• Filter out all of the green color component from
an RGB bitmap image pixel in which the middle 8
bits of a 24-bit pattern store the green information.
• Invert all of the bits in a 24-bit RGB bitmap
• Set all the bits in a 24-bit RGB bitmap pixel to 1,
indicating the color “white”.
50
Quiz
Identify a logical operation (along with a
corresponding mask) that, when applied to an input
string of 8 bits, produces an output string of all 0s if
and only ifs the input string is 1000 0001.
51
Communicating with Other
Devices
Bo may trung gian
Communicating with Other Devices
Controller: An intermediary apparatus that handles
communication between the computer and a device
◦ Specialized controllers for each type of device
◦ General purpose controllers (USB and FireWire)
Port: The point at which a device connects to a
computer
Memory-mapped I/O: CPU communicates with
peripheral devices as though they were memory
cells
53
Controllers attached to a machine’s bus
54
A conceptual representation of memory-
mapped I/O
55
Communicating with Other Devices
Direct memory access (DMA): Main memory
access by a controller over the bus
Von Neumann Bottleneck: Insufficient bus speed
impedes performance
Handshaking: The process of coordinating the
transfer of data between components
56
Communicating with Other Devices
Parallel Communication: Several communication
paths transfer bits simultaneously.
Serial Communication: Bits are transferred one
after the other over a single communication path.
57
Data Communication Rates
Measurement units
◦ Bps: Bits per second
◦ Kbps: Kilo-bps (1,000 bps)
◦ Mbps: Mega-bps (1,000,000 bps)
◦ Gbps: Giga-bps (1,000,000,000 bps)
Bandwidth: Maximum available rate
58
Quiz
Assume that the machine (using the simple machine
language as described) uses memory-mapped I/O
and that the address B5 is the location within the
printer port to which data to be printed should be
sent.
a. If register 7 contains the ASCII code for the letter
A, what machine language instruction should be
used to cause that letter to be printed at the
printer?
b. If the machine executes a million instructions per
second, how many times can this character be
sent to the printer in one second?
59
Quiz
Assume that the machine (using the simple machine
language as described) uses memory-mapped I/O
and that the address B5 is the location within the
printer port to which data to be printed should be
sent.
c. If the printer is capable of printing five traditional
pages of text per minute, will it be able to keep up
with the characters being sent to it in (b)?
60
Quiz
Estimate how long it would take to transfer a 250-
page novel (about 500,000 characters) encoded in 16-
bit Unicode characters at a transfer rate of 54Mbps.
61
What’s on the Outside of the Box?
62
What’s on the Outside of the Box?
Connectors on a notebook may vary
63
Universal serial bus
USB (universal serial bus) ports
◦ Connects up to 127 peripheral devices
◦ USB 2.0 (high-speed USB)—fully compatible with USB 1.1
products, cables, and connectors
◦ Designed to replace older parallel and serial ports
◦ Connects a variety of devices to the computer, including:
◦ Keyboards
◦ Mice
◦ Printers
◦ Digital cameras
64
Universal serial bus
USB 2.0
◦ Uses an external bus
◦ Supports data transfer rates of 480 Mbps between the computer
and the peripheral device
◦ Supports hot swapping—ability to connect and disconnect devices
without shutting down the computer
◦ Plug-and-play (PnP)—allows computers to automatically detect
the device when you plug it in
USB 3.0 (2008): 5Gbps
USB 3.1 (2013): 10Gbps
USB hub
◦ Device that plugs into existing USB port
◦ Contains four or more additional ports
65
FireWire
FireWire (1395 ports)
◦ Created by Apple in 1995
◦ IEEE 1394 Higher Performance Serial Bus, also known as
Sony i.Link
◦ Offers high-speed connections for dozens of peripheral
devices (up to 63)
◦ Enables hot swapping and PnP
◦ Data transfer rates of FireWire
◦ FireWire 400—400 Mbps
◦ FireWire 800—800 Mbps
◦ Declared “dead” by Steve Jobs.
66
Video connectors
VGA (video graphics array)
◦ 15-pin male connector—works with standard monitor
cables
◦ Transmits analog video signals
◦ Used for legacy technology cathode ray (CRT) monitors
DVI (Digital visual Interface) port—lets LCD
monitors use digital signals
Onboard video—video circuitry built into the
motherboard where the video connector is on the
back of the system unit case
67
HDMI
High-Definition Multimedia
Interface
◦ A video/audio interface for transmitting
uncompressed video data, and
compressed/uncompressed audio data.
◦ Digital replacement for analog video
standards.
◦ Designed: 2002 (7 companies).
◦ HDMI 2.1: 48Gbps.
◦ Newer version: 3D, Ethernet data
connection, Consumer Electronics
Control (CEC) extensions.
68
Additional connectors
Telephone
Network
PC card slot
◦ PC card
◦ ExpressCard
Sound card
Game card
TV/sound capture
board
69
What’s on the Outside of the Box?
Legacy technology
◦ Older technology that is being phased out
◦ Examples:
◦ Serial ports
◦ Parallel ports
◦ PS/2 ports
◦ SCSI (small computer system interface) ports
70
Other Architechtures
Other Architectures
Technologies to increase throughput:
◦ Pipelining: Overlap steps of the machine cycle
◦ Parallel Processing: Use multiple processors
simultaneously
◦ SISD: No parallel processing
◦ MIMD: Different programs, different data
◦ SIMD: Same program, different data
72
Pipelining
73
Parallel processing
◦ Method where more than one processor performs at the
same time—faster processing
74