Computer Hardware (Section 1.2)
Main Memory
- Used for storage of data and instructions.
- Data can be in form of numbers, letters,
pictures, etc.
- All data and instructions are represented as a
sequence of binary digits (bits).
- The amount of storage needed to represent a
single character is a byte – 8 bits.
- Each byte in memory has a unique, fixed address (starting at 0 for the first byte).
Two kinds of Main Memory:
- RAM (Random Access
Memory) and ROM (Read Only Memory)
·
RAM is the memory
used to store the instructions and data for a program during its execution.
·
The contents of
RAM may be changed or “overwritten” so RAM is volatile memory. The contents
of RAM are lost when the computer power is turned off. Usually RAM is reset to
all 0’s when power is turned back on.
·
The initial size
of RAM is determined when the computer is built and may be 512 Megabytes for
today’s PCs.
- ROM usually contains
the computer start up instructions which are “burned in” at the factory
and never change.
Secondary Memory – used for additional storage of data and
programs that cannot fit in main memory.
- Information in main memory must be saved
(written) as a “file” in secondary memory before the computer is
turned off otherwise it will be lost.
- A program file or a data file must be copied
from secondary memory to main memory before it can be processed by the
CPU.
- These steps are usually performed as a result
of commands issued to the operating system of the computer (more on
this later).
- Users store a collection of related files in a “directory”
or “folder” (for example, all your C programs could be in a directory).
Secondary
Storage
- Common media for secondary storage are hard disks
(at least one), floppy disks (as many as you want), tapes, zip disks
(removable hard disks), and CD ROMs. All but CD ROMs can be used to store
new data.
- The contents are semi-permanent – they remain on
the disk until they are overwritten by the computer. The contents of a CD
ROM are permanent – cannot be overwritten. Except now there are writable
CDs.
- Hard disks can store 10s or 100s of Gigabytes
(1GB = 1 billion bytes). Floppy disks can store 1.4 Megabytes each, zip
disks around 100 Megabytes each, CD ROMs around 700 Megabytes.
CPU – Central Processor Unit
- Performs arithmetic (*, /, +. -) and logical operations
(compare contents of 2 memory locations for >, <, equal to).
- Clock speeds determine speed of CPU. Today’s PCs
have clock speeds up to 4 GigaHertz.
- It may take 4 clock cycles to do an arithmetic
operation (1000 Million additions per second).
Input Units and Output Units
- Used to enter information and display information
to the user.
- Input – keyboard, mouse, scanner, microphone
- Output – printer, screen, speaker
Computer Software (Section 1.3)
Operating Systems
- Each computer family has one or more operating
systems.
- An operating system is the “interface” between
the user and computer.
- Through interaction with the operating system,
the computer user tells the computer what kind of task he/she wants to do:
word processing, spreadsheet, file manager, run C program.
- What OS does:
- communicate with user (receiving commands,
responding to them)
- managing allocation of main memory and processor
time,
- managing input and output units,
- data transfer to/from secondary memory
- Examples are Windows 95, 98, and NT for IBM
Personal computers. Windows is a graphical user interface (GUI)
which means the user issues commands by clicking a mouse button on
pictures (icons) that you see on the screen.
Unix
- Unix is a command line operating system
which means the user types in a command line to tell the operating system
what to do.
- Unix is written in C and is available for almost every kind of
computer.
- Sample unix commands:
ls (means
list the files in the current directory)
mkdir Cprograms (make a
directory named Cprograms)
cd Cprograms (means change to the directory named Cprograms).
cd .. (means
change to the directory up one level)
pico first_prog.c (use pico editor to enter
or “edit” file first_prog.c).
pine (use
pine mail system).
gcc first.c (use C compiler to “compile” file first.c).
Programming Languages
- Used to write programs or sequences of
instructions for the computer to carry out.
- Examples are machine language, C, C++, Pascal,
Java.
- Each computer has its own machine language
which is composed of instructions in binary form (0s and 1s). Machine
language instructions can be executed by the CPU. (See Table 1.3)
High Level Language Programs
- High-level languages are more easily
understood by people, so we write programs in high-level language.
- Programs in a high-level language are portable
– they can be used on any computer that has the capability to translate
the high-level language program to its machine language.
- This translation from high-level to machine
language is achieved by a program called a compiler.
Sequence of Actions for Writing, Translating, and Executing
a Program (Fig 1.12)
- Generate source file (enter program in a
word processor);
- Compile and link source file (to obtain executable
file)
- Run program by calling the executable file by using OS (it is loaded into
main memory and executed instruction by instruction)
Our First C Program
/* hello.c --
The most famous program of them all ..
*/
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
}
Steps to execute a C program
1.
Use the pico editor and enter the
statements in the C language.
2. Save
your C program as a file on your computer’s hard disk and exit the
editor program.
3.
Use the C compiler to create an object file – a file with machine
language instructions; link the object file with other system files needed to
create an “executable” file.
4.
Load the executable file into main memory and execute it.
Unix commands for this process:
pico hello.c
You
get a blank screen and you can type in your program. When done, save it as file
first.c by using the command control x. (Press and
hold down the Control key and press letter x.).
To
compile this file, use the command:
cc hello.c
This
loads in the C compiler and causes it to translate program first.c.
If it cannot because the program has syntax (grammar) errors, you get a list of
error messages.
Use
the command
pico hello.c
again
and try to correct the errors. If successful, the result is a file called a.out.
When
your program is error free, type in
a.out
to
link, load, and execute the machine language program.