Computer components Main Memory Used for storage of data and instructions. Data can be in form of numbers, letters, pictures, etc. All data is 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) ROM usually contains the computer start up instructions which are “burned in” at the factory and never change. 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 (but not ROM) is 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 32 Megabytes, 64 Megabytes (64 Million bytes), or 128 Megabytes for today’s PCs. Usually the amount of RAM may be expanded up to 128 Megabytes if it is smaller to begin with by adding more memory “chips”. Information (data or instructions) must be stored in RAM before and after processing. 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 peformed as a result of commands issued to the operating system of the computer (more on this later). 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 10 Gigabytes – 10 x 1,000 Megabytes or 10 billion bytes. Floppy disks can store 1.4 Megabytes each, zip disks around 100 Megabytes each, CD ROMs around 350 Megabytes. Information such as a C program or a collection of data is stored as a “file” on a secondary storage device. Users store a collection of related files in a “directory” or “folder” (for example, all your C programs could be in a directory). For example, if you have a disk that you use for your school work, personal correspondence, and your C programs, you might have 3 directories (school, personal, Cprograms). 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 400 MegaHerz. It may take 4 clock cycles to do an arithmetic operation (100 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 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. 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 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: (For reference, see http://laurel.ocs.mq.edu.au/~helpdesk/Docs/unixcom.html ) 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). cc 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. 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 capability is provided by a program called a “compiler”. 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. 4. Link the object file with other system files needed to create an “executable” file. 5. Load the executable file into main memory and execute it. Unix commands for this process: pico first.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 first.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 first.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.