CHAPTER-1-6
CHAPTER-1-6
Fundamental Idea: Both programs and data A Web browser usually displays a hyperlink in
are saved in computer memory in the same a distinguishing color (usually blue). When you
way. The electronics of computer memory click on it, the browser asks the operating
(both main memory and secondary memory) system to get a particular Web page from
make no distinction between programs and another computer connected to the Internet.
data.
The Web page to get is specified with
Communications equipment makes no a uniform resource locator URL. A URL
distinction between programs and data, specifies the exact computer (among all the
either. It is all information as far as it is Internet computers in the world) and the
concerned, and all information is transmitted exact Web page on that computer.
the same way. The Internet is like a worldwide
To see some examples of URLs, keep watching
package delivery service. It is concerned with
the box at the top of your browser labeled
moving packages from one address to
"Address".
another, without concern about what is in the
packages. CHAPTER 2 — Analog and Binary
The Internet provides the hardware and the Signals
information transmission protocols for
the World-Wide Web. Data intended for the Everyone knows that computers are "digital"
Web is transmitted over the Internet just like and that they use "binary" numbers. You
any data. What makes Web data special is that probably have some idea of what these terms
it is intended for Web browsers (such as the mean. But we need to be clear about their
one you are probably looking at). A browser is precise meaning and to be clear about why
a program that can read Web pages and computers are digital.
display them in a nicely formatted way. Binary
A Web page is a package of data that contains Binary means "two states." The two states are
information on how it is to be displayed on a sometimes called "1" and "0", or called "true"
monitor. This information is given using a and "false", or called "on" and "off", (or other
language called Hypertext Markup Language names.) The essential characteristic is that a
(HTML). If you want to see the HTML that single binary device can be in just one of two
describes this page, look at the menu at the possible states.
top of your Web browser, and select
Tools/Web Developer/Page Source. For older A bit is a single on/off value.
browsers, select View in the menu then left- A good example is a toggle switch, such as a
click on Source. On some browsers, hit light switch. You can turn it on or off but not
control-U. This will bring up a new window (in normal operation) anything else. A light
with the HTML of this page in it. After you are switch holds one bit of information.
done viewing, close the window by clicking on
the close button in its upper right corner (the A light dimmer is not a binary device: it has
button marked with X). many positions between off and fully on. If
you want a light dimmer to be set to 25%, you
Hyperlinks must carefully adjust it.
One Web page is connected to another with Why Computers use Binary
a hyperlink. If you have been reading these
There are many advantages to binary. Here just dropped into place. The method is robust
are four (somewhat overlapping) important and reliable; mistakes can be corrected. The
reasons for using binary: type can be reused many times.
1. Binary devices are Simple and easy to Advances in technology often lead to easy
build. ways to do previously difficult tasks.
Woodcarving is complex; setting type is easy.
2. Binary signals are Unambiguous
Building special-purpose electronic equipment
(which gives them noise immunity).
is complex; programming a general-purpose
3. Flawless copies can be made of binary computer is (relatively) easy.
data.
The computer revolution (ca. 1950–) is often
4. Anything that can be represented with compared to the Gutenberg revolution (ca.
some sort of pattern can be 1450–).
represented with patterns of bits.
Advantage of Binary 2: Unambiguous Signals
These characteristics of binary were realized
Here again are the advantages of binary:
by Claude Shannon, a mathematician at Bell
Telephone Laboratories. His 1948 paper A 1. Simple, easy to build.
Mathematical Theory of Communication is
2. Unambiguous signals (hence noise
the foundation of information theory and
immunity).
much of computer science.
3. Flawless copies.
Advantage of Binary 1: Simple, easy to build
4. Anything represented with patterns
An on/off switch is simple and easy to
can be represented with patterns of
build. An on/off switch moves two pieces of
bits.
metal together or moves them apart. A light
dimmer must gradually and smoothly change Unambiguous Signals: Consider Paul Revere,
the current that reaches the light. It has more waiting for news of the attack of the British
components that an on/off switch and must troops. He is expecting to see a signal lantern
be carefully assembled. An accurate dimmer in the tower of Old North Church telling him
(where 25% means exactly 25%) is even how the British are attacking:
harder to build.
1.32456 if by land, 1.71922 if by sea.
The same is true for the tiny devices inside of
a silicon chip. Silicon on/off switches are The signal shines out! ...but Paul Revere's
relatively easy to fabricate. The devices are famous ride is delayed for several hours as he
cheap, small, and reliable, and millions of tries to figure out exactly how bright that
them fit into a small area. signal is.
An Analog Signal
When a program is running, it has a section of Usually the component called the hard disk of
memory for the data it is using. Locations in a computer system contains many individual
that section can be changed as many times as disks and read/write heads like the above. The
the program needs. For example, if a program disks are coated with magnetic material on
is adding up a list of numbers, the sum will be both sides (so each disk gets two read/write
kept in main memory (probably using several heads) and the disks are all attached to one
bytes.) As new numbers are added to the sum, spindle. All the disks and heads are sealed into
it will change and main memory will have to a dust-free metal can. Since the operation of a
be changed, too. hard disk involves mechanical motion (which
is much slower than electronic processes),
Other sections of main memory might not reading and writing data is much slower than
change at all while a program is running. For with main memory.
example, the instructions that make up a
program do not (usually) change as a program Files
is running. The instructions of a running Hard disks (and other secondary memory
devices) are used for long-term storage of
large blocks of information, such as programs system has to keep track of everything, all
and data sets. Usually disk memory is other programs ask it to do file manipulation
organized into files. tasks. For example, say that a program has just
calculated a set of numbers and needs to save
A file is a collection of information that has
them. The following might be how it does this:
been given a name and is stored in secondary
memory. The information can be a program or 1. Program: asks the operating system to
can be data. create a file with a name RESULTS.DAT
Information in a file is represented the same 2. Operating System: gets the request;
as with any digital information — it consists of finds an unused section of the disk
bits, usually grouped into eight bit bytes. Files and creates an empty file. The
are frequently large; their size is measured in program is told when this has been
kilobytes or megabytes. completed.
If you have never worked with files on a 3. Program: asks the operating system to
computer before study the documentation save the numbers in the file.
that came with your operating system, or look
4. Operating System: gets the numbers
at a book such as Windows for Dummies (or
from the program's main memory,
whatever is appropriate for your computer.)
writes them to the file. The program is
One of the jobs of a computer's operating told when this has been completed.
system is to keep track of file names and
5. Program: continues on with whatever
where they are on its hard disk. For example,
it is doing.
in DOS the user can ask to run the program
DOOM like this: So when an application program is running, it
is constantly asking the operating system to
C:\> DOOM.EXE
perform file manipulation tasks (and other
The "C:\>" is a prompt; the user typed in tasks) and waiting for them to be
"DOOM.EXE". The operating system now has completed. If a program asks the operating
to find the file called DOOM.EXE somewhere system to do something that will damage the
on its hard disk. The program will be copied file system, the operating system will refuse to
into main storage and will start running. As do it. Modern programs are written so that
the program runs it asks for information they have alternatives when a requests is
stored as additional files on the hard disk, refused. Older programs were not written this
which the operating system has to find and way, and do not run well on modern
copy into main memory. computers.
Most collections of data outside of main As far as the hard disk is concerned, all files
storage are organized into files. Keeping track are the same. At the electronic level, there is
of all this information is one of the jobs of the no difference between a file containing a
operating system. If the computer is part of a program and a file containing data. All files are
network, keeping track of all the files on all named collections of bytes. Of course, what
the computers is a big job, and involves all the the files are used for is different. The
operating systems on the network. operating system can take a program file, copy
it into main memory, and start it running. The
Application programs (including programs that
operating system can take a data file, and
you might write) do not directly read, write,
create, or delete files. Since the operating
supply its information to a running program Machine Instructions
when it asks.
Users and programmers of computers usually
Often then last part of a file's name don't think about the billions of tiny electronic
(the extension) shows what the file is operations that go on each second. The
expected to be used for. For example, situation is (very roughly) similar to when you
in mydata.txt the .txt means that the file is are driving your car. You think about the "big
expected to be used as a collection of text, operations" it can perform, such as
that is, characters. "accelerate", "turn left", "brake", and so on.
With doom.exe the .exe means that the file is You don't think about tiny operations, such as
an "executable," that is, a program that is the valves in your engine opening and closing
ready to. With program1.java the .java means 24,000 times per minute or the crankshaft
that the file is a source program in the spinning at 3000 revolutions per minute.
language Java (there will be more about
Each tiny electronic operation that a processor
source programs later on in these notes.) To
core can perform is called a machine
the hard disk, each of these files is the same
operation. A processor (a "machine")
sort of thing: a collection of bytes holding bit
performs these one at a time, but billions of
patterns.
them in a second.
CHAPTER 4 — The Processor A machine instruction consists of several
Electronic Operations of a Processor bytes in memory that tell the processor to
perform one machine operation. The
When a program is running on a computer the processor looks at machine instructions in
processor is constantly performing very many main memory one after another, and
tiny electronic operations. performs one machine operation for each
For example, one such operation reads one machine instruction. A collection of machine
byte of data from main memory into the instructions in main memory is called
processor. Another operation tests if one of a machine language program or (more
the bits in a byte is a 1 bit or a 0 bit. Most commonly) an executable program.
processors are able to perform several Don't panic if the above seems
thousand types of tiny operations like these, incomprehensible. It takes some getting used
and can perform billions of them per second. to. (And to really understand it all takes
Those are the only things that a processor can several courses.)
do. It has a set of tiny electronic operations Machine Language Program
that it can to perform, and that is all. These
tiny electronic operations are performed one This is, of course, a silly example. Actual
at a time. But billions of them are performed processors have many more machine
per second, and billions of small operations instructions and the instructions are much
can add up to a large and useful action. more detailed. A typical processor has a
thousand or more different machine
Everything that a processor does is built out of instructions. Those instructions do not directly
these tiny operations! Luckily, you don't need affect any output device (such as our light
to know the details of these operations to bulb.)
write programs in Java. The purpose of a high-
level language like Java is to organize the tiny Even the simplest controller has much more
electronic operations into large, useful units memory. But the essential ideas of the
represented by program statements. example are these:
A machine language program is a A modern processor executes billions of
sequence of machine language instructions per second. A program without
instructions in main memory. loops would execute for only a few seconds
even if it had billions of instructions.
A machine instruction consists of one
or more bytes (in this example, only A typical processor is made up of millions of
one). transistors on a small wafer of silicon called
an integrated circuit (also called a chip.) The
The processor runs a program one
light bulb's processor could probably be built
machine instruction at a time.
with just a few hundred transistors. Integrated
All the little machine operations add circuits are used for other electronic parts of a
up to something useful. computer. For example main memory is
implemented with memory chips.
In days long ago, the ones and zeros of a
machine language program were entered into Most modern processor chips have two or
main memory by flipping switches on the more processors on them. Each of the
front panel of a computer. The on-or-off state processors on the chip is called a "processor
of each bit was displayed by lights. You may core" or often just called a core. Each core has
have seen this in old science fiction movies. the same set of tiny electronic operations and
These days there are more convenient ways to runs programs independently of the other
put ones and zeros into main memory. But the cores. When a program is running, it runs on a
idea is still the same: machine instructions are single core, which performs the tiny electronic
patterns of ones and zeros, and data are operations of the program one at a time.
patterns of ones and zeros.
Different Processors
Executing Instructions
There are many types of processors used in
The word "execute" is often used to mean computer systems. You probably know
"perform the machine operation that an something about the processors used in many
instruction asks for." So you can say that desktop computers, Intel Corporation's Core
"execute the instruction 00000000 to stop the processors. But there are other types of
processor," or "billions of instructions execute processors, such as the processors used in cell
per second." "Execute" is also used for an phones and game machines. A computer
entire program or part of a program: "to system is designed around its processor. The
execute the program, turn the switch to on." electronics of a computer system are designed
for a particular type of processor.
Most programs have groups of instructions
that are executed again and again. The light Different types of processors have different
bulb program does this with an instruction machine operations and different machine
that causes the processor to return to the languages. A machine language program for a
beginning of the program and so to repeat typical Intel system would make no sense to a
what it just did. computer built around a different processor
type.
A group of machine instructions that executes
repeatedly is called a loop. However, the machine operations available
with all types of processors can be used to
You will in the near future write programs in build the same things. All processor types
Java that run continuously. Underneath your have enough power in their little machine
program, way down at the machine level, operations to create the same large
there will be machine operations performing a applications. Anything one processor can do
loop.
with its machine language program another The machine operations that correspond to
processor can do with a program written in its this big operation set up a part of main
machine language. For example, cell phones memory to hold a number, store the number
are built around a variety of processor types, zero there, and arrange things so other parts
but all cell phones can do the same things. of the program can use it. It might take a
hundred machine operations to do all
The architecture of a processor is the choices
this. Obviously, it is easier for a human
that have been made for its machine
programmer to ask for all these operations
operations, how they have been organized
using C.
and implemented, and how they interact with
main memory and other Source Programs
components. Architecture is concerned with
Programmers create programs by writing
the general plan and functions of a processor;
commands in a high level language. A high
it is not much concerned with electronic
level language program consists of lines of
details. A course in computer architecture is
text that have been created with a text editor
part of most computer science departments
and are kept in a file on the hard disk. For
High Level Programming Languages example, here is a complete program in C
(Java will be discussed later):
It is rare for programmers to write programs in
machine language like we did for the light #include <stdio.h>
bulb. The executable files (the directly
main()
runnable machine language programs) for
most applications contain hundreds of {
thousands (or even millions) of machine
language instructions. It would be very hard to int sum = 0;
create something like that from scratch. sum = 2 + 2;
As an experiment, look through your hard disk printf( "%d\n", sum );
with the file listing utility (the "Explorer" on
Microsoft systems.) Look at the size of }
the something.EXE files. There are about four This program could be saved on the hard disk
bytes per machine instruction on Intel in a file called addup.c. Like all files, it consists
processors, so divide by four to get the of a sequence of bytes. Since it is a text file,
number of instructions. these bytes represent character data. You can
Most programs are created using a high level edit the file with a text editor and print the file
programming language such as Java, C, C++, on a printer. It does not contain machine
or BASIC. With a high level language, a instructions. If the bytes are copied into main
programmer creates a program using memory, they cannot run as a program
powerful, "big" operations which will later be without some extra work being done.
converted into many little machine A source program is a text file that contains
operations. instructions written in a high level language. It
For example, here is a line from a program in can not be executed (made to run) by a
the language C: processor without some additional steps.