chapter 1 computers, compilers, & unix. overview u computer hardware u unix u computer languages...

16
Chapter 1 Computers, Compilers, & Unix

Upload: britney-peters

Post on 21-Jan-2016

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers

Chapter 1

Computers, Compilers, & Unix

Page 2: Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers

Overview

Computer hardware Unix Computer Languages Compilers

Page 3: Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers

Computer Hardware

Central Processing Unit (CPU) The heart and brains of a computer The device that performs all calculations and data

manipulation in a computer Main Memory (RAM)

The place the CPU looks for instructions and data to process

Page 4: Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers

Computer Hardware

Mass Storage (hard drive) Holds information not immediately needed by CPU Holds massive amounts of data

Input/Output Devices keyboard, mouse, monitor, printer Devices used to move information into and out of the

computer

Page 5: Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers

Basic Architecture

Processor (CPU) Main Memory

volatile I/O devices

secondary memory communications terminals

System interconnection a bus is used to exchange data and control information

CPU Memory

System Bus

DiskController

NetworkController

Serial Device Controller

Page 6: Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers

What is an operating system?

Acts as interface between computer system resources (hardware) and applications

Manages the way other programs use system resources and communicate with each other

Common operating systems Windows XP, Macintosh OS, & Linux

In CS 201 we use Solaris, a type of Unix

Page 7: Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers

Unix file system Home directory

A directory set aside for your personal use The starting point when you log in

Working directory Whatever directory you are currently in

Initially, the working directory is the home directory The cd command is used to change the working directory

cd .. Moves up one level in the directory structure cd <directory> moves down one level, into the given directory

The pwd command gives the full path of the working directory

The ls command lists the contents of the working directory

Page 8: Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers

Programming Languages Common programming languages include …

C C++ Java Pascal Visual Basic FORTRAN COBOL Lisp Scheme Ada

These high-level languages Resemble human languages Are designed to be easy to read and write Use more complicated instructions than the CPU can follow Must be translated to zeros and ones for the CPU to execute a

program

Page 9: Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers

Low-level Languages An assembly language command such as

ADD X Y Z

might mean add the values found at x and y in memory, and store the result in location z.

Assembly language must be translated to machine language (zeros and ones) 0110 1001 1010 1011

The CPU can execute machine language instructions

Page 10: Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers

Compilers

Translate high-level language to machine language

Source code the original program in a high level language

Object code the translated version in machine language

Page 11: Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers

Linkers

Some programs we use are already compiled Their object code is available for us to use

Input and output routines

A Linker combines The object code for the programs we write

and The object code for the pre-compiled routines

intoThe machine language program the CPU can run

Page 12: Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers

From Source Code to Executable Program

#include <iostream>using namespace std;int main(){ cout << "Hello World!" << endl; return 0;}

#include <iostream>using namespace std;int main(){ cout << "Hello World!" << endl; return 0;}

compiler

linker

100101010001010100101010010010101001010010100100100101001010101010010010100100100101001010010100001001001001

library

100101010001010100101010010010101001010010100100100101001010101010010010100100100101001010010100001001001001

object file010010101001010010100100100101001010101010010010100100100101001010010100101010101010010010010001001001001001

executable file

Page 13: Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers

Algorithm A sequence of precise instructions which

leads to a solution

Program An algorithm expressed in a language the computer

can understand

Programming & Problem Solving

Page 14: Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers

Program Design

Programming is a creative process No complete set of rules for creating a program

Design process for CS-201 Problem Solving Phase

Produce an algorithm that solves the problem Implementation & Testing Phase

Translate into a valid, functioning program

Page 15: Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers

Problem Solving Phase

Be certain the task is completely specified What is the input? What information is in the output? How is the output organized?

Develop the algorithm before implementation Experience shows this saves time in getting your

program to run Test the algorithm for correctness

Page 16: Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers

Implementation & Testing Phase Translate the algorithm into a programming language

Easier as you gain experience with the language Compile the source code

The compiler identifies violations of the programming language's grammar

These are known as syntax errors

Run the program on sample data Verify correctness of results

If you made mistakes in your algorithm design, or in your translation to the programming language, you'll see errors

These are known as logic errors

Modify the algorithm and/or program and repeat