Computer Hardware (Section 1.2)

 

Main Memory

 

 

Two kinds of Main 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.

 

Secondary Memory – used for additional storage of data and programs that cannot fit in main memory.

 

 

Secondary Storage

 

CPU – Central Processor Unit

 

 


Input Units and Output Units

 

 

Computer Software (Section 1.3)

 

Operating Systems

 

 

Unix

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

 

High Level Language Programs

 

Sequence of Actions for Writing, Translating, and Executing a Program (Fig 1.12)

 

 

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.