1 what is a computer? “… [a] programmable electronic device that can store, retrieve and process...
Post on 22-Dec-2015
224 views
TRANSCRIPT
![Page 1: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/1.jpg)
1
What is a Computer?
“… [A] programmable electronic device that can store, retrieve and process data.”
![Page 2: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/2.jpg)
2
Components of a Computer
Computer
HardwarePhysical Devices
SoftwareInstructions & Data
DON’T PANIC!This discussion may be confusing at the moment;it’ll make more sense after you’ve written a few programs.
![Page 3: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/3.jpg)
3
Categories of Computer Hardware
• Central Processing Unit (CPU)• Storage– Primary: Cache, RAM– Secondary: Hard disk, removable (e.g., CD)
• I/O– Input Devices– Output Devices
![Page 4: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/4.jpg)
4
Central Processing Unit (CPU)
The Central Processing Unit (CPU), also called the processor, is the “brain” of the computer.
Harpertown exteriorhttp://blogs.zdnet.com/Apple/images/intel-xeon.jpg
![Page 5: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/5.jpg)
5
CPU Parts
Arithmetic/Logic UnitControl Unit Registers
Fetch Next Instruction Add Sub
Mult Div
And Or
Not …
Integer
Floating Point
Fetch Data Store Data
Increment Instruction Ptr
Execute Instruction
…
The CPU consists of three main parts:• Control Unit• Arithmetic/Logic Unit• Registers
![Page 6: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/6.jpg)
6
CPU: Control Unit
The Control Unit decides what to do next.For example:• memory operations: for example,– load data from main memory (RAM) into the
registers;– store data from the registers into main memory;
• arithmetic/logical operations: e.g., add, multiply;• branch: choose among several possible courses
of action.
![Page 7: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/7.jpg)
7
CPU: Arithmetic/Logic Unit
The Arithmetic/Logic Unit (ALU) performs arithmetic and logical operations.
• Arithmetic operations: e.g., add, subtract, multiply, divide, square root, cosine, etc.
• Logical operations: e.g., compare two numbers to see which is greater, check whether a true/false statement is true, etc.
![Page 8: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/8.jpg)
8
CPU: RegistersRegisters are memory-like locations inside the
CPU where data and instructions reside that are being used right now.
That is, registers hold the operands being used by the current arithmetic or logical operation, or the result of the arithmetic or logical operation that was just performed.
A typical CPU has only a few hundred to a few thousand bytes of registers.
![Page 9: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/9.jpg)
9
How Registers Are Used• Every arithmetic or logical operation has one or
more operands and one result.• Operands are contained in registers (“source”).• A “black box” of circuits performs the operation.• The result goes into a register (“destination”).
Exam
ple:
addend in R0
augend in R1ADD sum in R2
5
712
Register Ri
Register RjRegister Rk
operand
operand
result
Operation circuitry
![Page 10: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/10.jpg)
10
Multicore
• A multicore CPU is a chip with multiple, independent “brains,” known as cores.
• These multiple cores can run completely separate programs, or they can cooperate together to work simultaneously in parallel on different parts of the same program.
• All of the cores share the same connection to memory – and the same bandwidth (memory speed).
![Page 11: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/11.jpg)
11
Storage
There are two major categories of storage:• Primary– Cache– Main memory (RAM)
• Secondary– Hard disk– Removable (e.g., CD, floppy)
![Page 12: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/12.jpg)
12
Primary Storage
Primary storage is where data and instructions reside when they’re being used by a program that is currently running.
• Typically is volatile: The data disappear when the power is turned off.
• Typically comes in two subcategories:– Cache– Main memory (RAM)
![Page 13: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/13.jpg)
13
Cache
Cache memory is where data and instructions reside when they are going to be used very very soon, or have just been used.
• Cache is very fast (typically 5% - 100% of the speed of the registers).
• Therefore, it’s very expensive (e.g., $285 per MB) http://ark.intel.com/Product.aspx?id=31731http://ark.intel.com/Product.aspx?id=31794
• Therefore, it’s very small (e.g., 1/4 MB to 32 MB)
… but still much bigger than registers.
![Page 14: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/14.jpg)
14
From Cache to the CPU
Typically, data move between cache and the CPU at speeds closer to that of the CPU performing calculations.
CPU
Cache
27 GB/sec (9%) on a1.60 GHz Core2 Duo
Up to 307.2 GB/sec ona 1.60 GHz Core2 Duo
http://www.dell.com/
![Page 15: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/15.jpg)
15
Main Memory (RAM)Main memory (RAM) is where data and
instructions reside when a program that is currently running is going to use them at some point during the run (whether soon or not).
• Much slower than cache(e.g., less than 1% of CPU speed for RAM, vs 5-100% of CPU speed for cache)
• Therefore, much cheaper than cache(e.g., $0.03/MB for RAM vs $285/MB for cache)
• Therefore, much larger than cache(e.g., 1-64 GB for RAM vs 1/4 MB to 36 MB for cache)
![Page 16: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/16.jpg)
16
Main Memory LayoutMain memory is made up of locations, also known as cells.Each location has a unique integer address that never changes.Each location has a value – also known as the contents – that the CPU can look at and change.We can think of memory as one contiguous line of cells.
![Page 17: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/17.jpg)
17
RAM vs ROMRAM: Random Access Memory• Memory that the CPU can look at and change
arbitrarily (i.e., can load from or store into any location at any time, not just in a sequence).
• We often use the phrases Main Memory, Memory and RAM interchangeably.
• Sometimes known as core memory, named for an older memory technology. (Note that this use of the word “core” is unrelated to “dual core.”)
ROM: Read Only Memory• Memory that the CPU can look at arbitrarily, but
cannot change.
![Page 18: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/18.jpg)
18
Speed => Price => Size• Registers are VERY fast, because they are etched
directly into the CPU.• Cache is also very fast, because it’s also etched into
the CPU, but it isn’t directly connected to the Control Unit or Arithmetic/Logic Unit. Cache operates at speeds similar to registers, but cache is MUCH bigger than the collection of registers (typically on the order of 1,000 to 10,000 times as big).
• Main memory (RAM) is much slower than cache, because it isn’t part of the CPU; therefore, it’s much cheaper than cache, and therefore it’s much bigger than cache (for example, 1,000 times as big).
![Page 19: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/19.jpg)
19
How Data Travel Between RAM and CPUCPUThe bus is the
connection from the CPU to main memory;all data travel along it.
For now, we can think of the bus as a big wire connecting them.
![Page 20: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/20.jpg)
20
Loading Data from RAM into the CPU
![Page 21: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/21.jpg)
21
RAM is SlowCPU
4.4 GB/sec (1.4%) load,1.7 GB/sec (0.6%) store
Up to 307.2 GB/sec on a 1.60 GHz Core2 DuoRichard Gerber, The Software Optimization Cookbook: High-performance Recipes for the Intel Architecture. Intel Press, 2002, pp. 161-168.
Bottleneck
The speed of data transferbetween Main Memory and the CPU is much slower than the speed of calculating, so the CPU spends most of its time waiting for data to come in or go out.
![Page 22: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/22.jpg)
22
Why Have Cache?CPUCache is much faster than
RAM, so the CPU doesn’t have to wait nearly as long for stuff that’s already in cache: it can do more operations per second!
27 GB/sec (9%)
4.4 GB/sec (1.4%)
Up to 307.2 GB/sec on a 1.6 GHz Core DuoRichard Gerber, The Software Optimization Cookbook: High-performance Recipes for the Intel Architecture. Intel Press, 2002, pp. 161-168.
![Page 23: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/23.jpg)
23
Secondary Storage• Where data and instructions reside that are
going to be used in the future• Nonvolatile: data don’t disappear when
power is turned off.• Much slower than RAM, therefore much
cheaper, therefore much larger.• Other than hard disk, most are portable:
they can be easily removed from your computer and taken to someone else’s.
![Page 24: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/24.jpg)
24
I/O: Input Devices
We often say I/O as a shorthand for “Input/Output.”Input Devices transfer data into computer (e.g., from
a user into memory).For example:• Keyboard• Mouse• Scanner• Microphone• Touchpad• Joystick
![Page 25: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/25.jpg)
25
I/O: Output Devices
We often say I/O as a shorthand for “Input/Output.”
Output Devices transfer data out of computer (e.g., from memory to a user).
For example:• Monitor• Printer• Speakers
![Page 26: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/26.jpg)
26
Bytes
Byte: a sequence of 8 contiguous bits (typically)• On most platforms (kinds of computers), it’s
the smallest addressable piece of memory: typically, the CPU can load from or store into an individual byte.
• Possible integer values: 0..255 or -128..127 (to be explained later)
• Can also represent a character (e.g., letter, digit, punctuation; to be explained later)
![Page 27: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/27.jpg)
27
Words
Word: a sequence of 4 or 8 contiguous bytes (typically); i.e., 32 or 64 contiguous bits
• Standard size for storing a number (integer or real)
• Standard size for storing an address (special kind of integer)
![Page 28: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/28.jpg)
28
What is Software? A Program? Data?
Software, for our purposes, is just a word that means “programs.”
A program is a collection of data – on RAM, disk, etc – and a sequence of actions on those data.
The actions in a program are known as instructions.
In computing, data are values stored in storage locations: for example, RAM, disk, etc.
![Page 29: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/29.jpg)
29
What are Instructions?
The actions in a program are known as instructions.Examples:• Arithmetic/Logical calculation: e.g., add, subtract,
multiply, divide, square root, cosine, etc.• Memory operations: load from or store into RAM• I/O: read from or write to secondary storage• Branch: jump to an instruction that is out of
sequence• Repetition• Allocation of resources… and many more.
![Page 30: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/30.jpg)
30
What is a Programming Language?
A programming language is a well-defined set of rules for specifying a program’s collection of data and sequence of instructions.
Examples: C, C++, Fortran 90, Java, Basic, HTML, Perl, SAS, Haskell, Prolog, Pascal, Unix shell, x86 assembly language, etc.
![Page 31: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/31.jpg)
31
What is Source Code? What is a Source File?
Source code is a sequence of instructions, written in a human-readable programming language, that constitutes a program, or a piece of a program.
A source file is a file of source code.
![Page 32: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/32.jpg)
32
What is an Operating System?
An operating system is a program that manages interactions between:
• users and hardware;• users and software;• hardware and software;... and so much more.
![Page 33: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/33.jpg)
33
Operating System Examples
• MS Windows/MS-DOS• MacOS• Symbian (cell phones)• Android• Unix– Linux (portable)
• WebOS (Palm/HP Linux-based OS for phones, tablets etc)– FreeBSD (portable, underlies MacOS X)– Solaris (Sun Microsystems)– AIX (IBM)– IRIX (SGI)– Tru64 (Hewlett-Packard)– HP-UX (Hewlett-Packard)– Unicos (Cray)
![Page 34: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/34.jpg)
34
A Simple C++ Program/* ************************************************* *** Program: hello_world *** ************************************************* */#include <iostream.h>
int main (){ /* main */ /* ******************************** *** Execution Section (body) *** ******************************** * * Print the sentence to standard output * (i.e., to the terminal screen). */
cout<<"Hello, world!\n";} /* main */
![Page 35: 1 What is a Computer? “… [A] programmable electronic device that can store, retrieve and process data.”](https://reader031.vdocument.in/reader031/viewer/2022020922/56649d7a5503460f94a5f297/html5/thumbnails/35.jpg)
35
Anatomy of a Simple C++ Program/* ************************************************* *** Program: hello_world *** *** Author: Imran Rafique *** *** Course: CS 1313
*** *** Lab: Sec
*** *** Description: Prints the sentence *** *** "Hello, world!" to standard output. *** ************************************************* */#include <iostream.h>
int main (){ /* main */ /* ******************************** *** Execution Section (body) *** ******************************** * * Print the sentence to standard output * (i.e., to the terminal screen). */ cout<<"Hello, world!\n";} /* main */
Comment block
Preprocessor directive
Block open
Block close
Main function header
Execution section (also known as the program body)