Programming Overview
What is a computer (abstractly)?
(What is an abstraction??)
Summary
volatile storage
+--------+ +------------+ +-------------+ numbered cells
| input |------->| |<--------->| memory | 000 (addresses)
| | | | +-------------+
+--------+ | CPU | | RAM | 001
| (ALU) | +-------------+
| |<---+ | | 002
+-------| | | +-------------+
| +------------+ | | | 003
+---------V+ ^ v +-------------+
| output | | | | | 004
| | | | +-------------+
+----------+ | | | |
| | + +
| | // . . . //
V | | | 971
+--------------+ | +-------------+
| non-volatile | | | | 972
| storage | | +-------------+
| (disk) | | | | 973
+--------------+ | +-------------+
| | | 974
| // . . . //
| . . .
^ . . . up to 4 or more
| Gigabytes these days
|
|
\
\ +==================
\ |
+----<-------> | Internet...
|
| email
| IM
| web, etc.
|
+==============
(1) Need something to do the work
[ processor... CPU ] carries out instructions
Intel Pentium, Xeon, Centrino, Celeron, Core2Duo, Atom
AMD Athlon, Phenom, Turion
Motorola 68000
Sun SPARC, UltraSPARC T2
[ memory ] stores instructions, data, addresses
divided into cells (storage boxes)
each cell is numbered (its ID, its address)
all this requires power to function ...
storage that holds data only while power is on is called "volatile storage"
volatile means that when power fails, data in memory vanishes
Main Operation Loop
called "fetch and execute cycle"
your processor does this over, and over, and over, until the program halts
+--------------<-------------------------+
| |
V |
^
IF: fetch next instruction (from memory) |
ID: instruction decode |
DF: data fetch |
EX: execute the instruction on the data |
RR: return result |
|
| |
| |
+--- repeat ------------------------>----+
example:
IF: fetch instruction
117300400500
( really something like 100101000100011101100001110111111101011110111.... )
ID: decode it
ADD 300, 400, 500
DF: data fetch
get contents of cell 300 (let's say it holds integer value 17 )
get contents of cell 400 (let's say it holds integer value 9 )
EX: execute the operation
add those two contents together ( 17 + 9 is 26 )
RR: return result
store the result of addition into cell 500 ( so now it holds value 26 )
it is in reality much more complex (this is an abstraction after all)
... COMP 411 Computer Organization
(2) Need storage for when the power is off
Called "non-volatile storage"
Data/information stored/saved/written here remains when power goes off
hard drive ---+
ext hard drive |
CD/DVD |
USB key +----- secondary storage
SD card | usually larger, cheaper, slower
Zip drive |
floppy drive ---+
there is a cost/speed tradeoff (slower media tend to be cheaper)
RAM is fastest (get 4 Gigabytes for $100)
Disk is cheapest (get 1 Terabyte for $100)
how many 4 gig chunks in 1 terabyte?
(3) Need a way to communicate with the world "outside"
Input/Output, or I/O
get data into the internal memory/storage
print/display computation results back to user
store results onto non-volatile storage
Input Output
------------- -----------------------------
keyboard monitor or flat panel screen
mouse speakers
camera printer
microphone disk
... lights, furnace, car brakes
How is information stored in a computer?>
Binary... 1's and 0's
00100111000111101111100010111001 <---- memory cells
11110010000010001111010010101011 <---- more memory cells
01110110000001100101001000010001
11111110000010000101110111111011
10000001000000011101101001001001
00000000000000010010000110000000
00001001000010001111100001000111
11011111100100100101010000100110
10011111111100010000000010000001
... etc
electrically... current is on or off
magnetically, north or south pole
logically, True or False
In Base 2 we can represent numbers
1 1 0 1
^ ^ ^ ^
| | | |
| | | +-------------- units (2^0)
| | +---------------- 2's (2^1)
| +------------------ 4's (2^2)
+-------------------- 8's (2^3)
in binary, 1101 is the decimal number 13
What is the largest decimal number we can represent with 4 binary digits?
1111 binary is 16 decimal
What about with 8 binary digits?
11111111 binary is 128+64+32+16+8+4+2+1 = 255 decimal
this is 2^8 - 1
What about with 32 binary digits? 2^32 - 1 decimal, or 4,294,967,295 decimal
What is the point of this? A computer has limits... there is a "biggest number" we
can store accurately.. since the memory is finite
for this class and your programs, you wont have problems with this...
its just for your enlightenment
Bits, Bytes, Words, etc.
A binary digit is a "BIT" value is either 0 or 1, on/off, T/F
8 bits is a "BYTE" 11010011 in binary is 128+64+0+16+0+0+2+1 = 211 decimal
a byte can store the an integer between 0 and 255 (or -128 to 127)
In a computer, every byte has an address/ID
We usually group bytes into clumps for ease of use internally...
a group of bytes is a "WORD"
common word sizes are 4 bytes, 8 bytes, 16 bytes
32 bits 64 bits 128 bits
this is what is means when you read that the latest DELL is a 64-bit machine...
it means the word size is 8 bytes
gives an indication of how much internal memory (RAM) you can have
a word is the largest address you can have
so 64-bit machine can address 2^64-1 bytes of RAM
how much is this numerically? 18,446,744,073,709,551,615 bytes
how big is this in practical terms?
2^10 is a kilobyte KB 1,024 bytes
2^20 is a megabyte MB 1,048,576 bytes
2^30 is a gigabyte GB 1,073,741,824 bytes
2^40 is a terabyte TB 1,099,511,627,776 bytes
which is 1000 gigabytes
current computers have 2, 3, 4 gig
so a 64 bit machine can address (use) 18 million TB
this is way more memory than we can practically afford, or even put
into a machine cabinet
Programming Concepts
- 4 + 5 ... arithmetic
- print 12 ... output
- variables... X, Y ... storage
- get something and put it in X ... input
- X + 3 ... retrieval of storage, use of stored values
- repeating operations ... loops
- if X < 15... selecting alternatives
print 4 + 5
input X
print X + 3
increment X
do this chunk 500 times { print 4 + 3 }
do this chunk 500 times { input X; print X + 3 }
X <- 1
do this chunk 500 times { print X; increment X }