How a Computer Works

advertisement
How a Computer Works
A computer is a device for storing and manipulating information.
In order to do this we need hardware that can do the following things:
1. Get information into and out of the computer.
This is done by input/output or I/O devices
2. Store the information in the computer temporarily or permanently.
Information is stored in various kinds of memory.
3. Manipulate the information.
The Central Processing Unit or CPU does this, under the direction of a recipe or
computer program.
Let’s look at these three pieces of computer hardware:
1. Input/Output or I/O devices
Input devices are used to get information into a computer.
The input devices you use most often are the keyboard and the mouse, but a CD
or DVD drive, when it is reading from a CD or DVD, is also an input device.
Output devices are used to get information out of a computer. The most
common output devices are the monitor (screen) and printer. When you ‘burn’ a
CD you are using the CD read/write drive as an output device.
Of course, when you download or upload files on-line, then the network interface
in your computer card is also doing input or output.
Generally speaking, I/O is the slowest part of any computing operation.
2. Memory
A computer has various forms of memory. The DRAM (Dynamic Radom Access
Memory) or RAM is relatively expensive, close to the CPU and fast. Today a
typical laptop has 1 to 3 gigabytes of RAM. (More about gigabytes below.)
An easy way to think about memory is like a series of numbered mail-boxes,
such as the mail-boxes found in a post office, with each box holding one byte of
data. Memory is addressable (by the “p. o. box number”).
Next to the CPU is some ROM or Read-Only Memory. While RAM may be both
read from and written to, ROM is used to hold things which are so important (e.g.
parts of the operating system) that you don’t want them to be written over.
Memory which is used to hold data expected to be used soon (or just used) is
called cache. (Cache is the French word for hidden.)
Most personal computers have a special piece of hardware for processing
graphic images, and these ‘cards’ often carry additional memory for that specific
use.
The hard drive is the main storage device for a personal computer. It holds all
your old Word files, photos, packages such as Office, etc. Today a laptop
typically has 80-250 gigabytes of memory on the hard drive. This memory is also
referred to as secondary memory.
Finally, you also have external portable memory – flash or thumbnail drives, CDs,
etc.
3. The Central Processing Unit or CPU
The CPU does the hard work of computing. It has two parts – a controller and
the Arithmetic/Logic Unit (ALU), which has several registers.
As a first approximation, you can think of the controller as traffic cop (it figures
out where to get the next instruction to execute and how to do it) and the ALU as
a set of very simple calculators. Actual logic, comparisons, and computations
take place in the ALU.
We will look at this in more detail after we talk about software and the stored
program model.
Memory, Stored Programs and Binary Representation of Data and Instructions:
1. Representing Data
The basic unit for storing information is the bit. A bit is a number which is either
0 or 1.
Typically bits are grouped together (usually 8 bits) to become bytes and each
byte gets one of those P.O. mailbox addresses. (‘Byte’ rhymes with ‘write’.)
OK – how do we represent numbers? If you remember your base arithmetic from
grade school, then you know that 234 = (2 x100) + (3 x 10) + (4 x 1).
We say that 4 is in the 1’s place, 3 is in the 10’s place, and 2 is in the 100’s or
102’s place.
This is called base 10 arithmetic but there is nothing magic about using 10 as the
base. (In fact when we use seconds-minutes-hours we use base 60.)
Computers do arithmetic using base 2. So, reading from right to left, we have a
1’s place, a 2’s place, a 4’s place, an 8’s place, etc. The number thirteen may
be written in base 2 as 1101 = (1x8) + (1x4) + (0x2) + (1x1).
There are very straightforward ways to take a number written in base 10 and
convert into base 2 and vice versa.
All numbers in a computer are stored as base 2 numbers.
You have just seen how integers are written. Real numbers such as Avogadro’s
number may be written in base 10 (using scientific notation) as 6.022 x 1023 A
similar thing is done in base 2. For example, 8 may be written as 1.0 x 23
Writing a number in this method uses two words – one for the 6.022 part and one
for the exponent (23).
Great! Now we know how to write numbers in base 2, so we can store them in
computer memory. What about letters? Well, this requires no intellectual
processes. There is simply a set of agreed upon abbreviations. For example,
using the ASCII sequence the letter ‘A’ is stored as 65, ‘B’ is 66 etc. ; a carriage
return (enter) is 104, and the whole sequence may be found at
http://en.wikipedia.org/wiki/File:ASCII_Code_Chart-Quick_ref_card.jpg
In other words we now know how data - numbers and letters (alpha-numeric
data) and punctuation marks - is stored in a computer.
Bits, Bytes, etc.
Recall that the smallest amount of information is a bit. You can think of it as a
yes-no answer or a true-false answer, and it is represented by a 0 or 1.
Bits are grouped together into bytes (usually a byte is 8 bits) and two bytes make
up a word. A byte is still a fairly small amount of information (enough to
represent one letter), so we normally need larger collections of bytes.
Look at the powers of 2, starting at 1 = 20, 2, 4, 8, 16, 32, 64, 128, 256, 512,
1024 = 210. So, 210 is very close to a thousand.
A kilobyte is 210 bytes (just a little over 1000 bytes). A megabyte is 210 kilobytes
(a bit over a million bytes), a gigabyte is 210 megabytes (something over a billion
bytes), and the next unit up is the terabyte or 210 gigabytes.
kb is the abbreviation for kilobytes, mg (in informal speech ‘a meg’) is the
abbreviation for megabyte, and gb (in informal speech ‘a gig’) is the abbreviation
for gigabytes.
To give you a sense of scale, I kb is a enough space to hold about ½ a
typewritten page, 1 mg holds a small novel, and 1 gb holds about 10 yards of
books on a shelf.
2. Programs as Data or the Stored Program
A program is simply a recipe or a set of steps. For example, if I have numbers
stored in ‘mailboxes’ 101, 102 and 103 then a program to add them together and
store the result in the next memory location might look like:
Clear Register 1 (Remember a register is like a calculator in the ALU)
and copy into it the number at location 101.
Add the number stored at location 102 to Register 1.
Add the number stored at location 103 to Register 1.
Store the number is Register 1 at location 104.
Any computer has a basic set of operations which it can perform (such as add,
store, etc.) and a set of steps written terms of these operations is called a machinelanguage program.
A typical instruction in a machine language program takes two bytes (or four) in
memory. The instruction uses the first few bits for the abbreviation for the operation.
(For example, the abbreviation for ‘add’ might be 100.), then the next few bits for the
register number and the last few bits for the memory location. So the instruction is
just another set of 0s and1s – and we can store it in the computer’s memory too.
The controller in the CPU will fetch an instruction from memory, interpret it (‘Oh, this
is an instruction to add a number in a memory location to a register) and then
execute it. This is referred to as the Fetch – Interpret – Execute cycle.
If the instruction that just finished executing was stored at location 1224 then the
controller will normally next go to location 1225 for the next instruction, and continue
on its merry way until it comes to an instruction which either tells it to start looking for
the next instruction at another place in memory or an instruction which says ‘Stop.’
3. What are the implications of the stored program (or von Neumann
Architecture)?
First we can store programs – so we can save them and modify them, just the
way you do with Word documents.
Second, you now have some idea about how the CPU (ALU and Controller)
works.
Third, we can actually get a program to operate on itself and modify itself. This
is, for example, one way a virus works.
4. Do people really write programs in machine language?
As little as possible. It is tedious. Most people write in ‘higher level languages”
and then there are special purposes programs (called interpreters and compilers)
which take the steps in this higher level language and translate it into steps in
machine language.
Some higher level languages which you may have heard of are Java, JavaScript,
C++ and MUMPS (a special language developed at the Brigham.) These
languages make it much easier to write programs.
The languages I have mentioned in the paragraph above all set out a sequence
of steps for you to follow – and they are called procedural and/or object-oriented.
When we come to talk about databases later in IT225 you will meet SQL
(Sequential Query Language), a higher level language where you specify the
result of what you want (Find all patients whose primary care physician is Dr. X)
rather than how to find it (Read the record for the first patient. Is the PCP Dr. X?
If so print it out, and if not go on to the next patient.). Languages such as SQL,
where you specify what you want, are called functional and they are very
powerful.
5. Is that what all software is? Yes and no – we usually divide software into
the following types:
a. The Operating System
b. General Purpose Packages
c. Dedicated Applications
a. The Operating System or OS
The operating system ‘comes with’ the computer. These days Macs use
Mac OS X, pc’s use either XP or Vista or Windows 7, and other machines
use Linux.
There are other OS’s too.
The OS does such things as keep track of all your files and folders, keep
files in line (‘queue’) when several are being printed out, recognize what kind
of a file you asked to open (Word, Excel, Java program, jpeg or photo) so it
can be interpreted and displayed properly.
Typically the OS also includes utilities for searching for files, etc.
b. General purpose packages and applications
Here I would include browsers, Word, Excel, etc.
c. Dedicated Applications
These are programs written for a specific purpose – e.g. to bill
health insurance companies, or to keep track of all the balances in the
accounts at BankAmerica, etc.
Download