CSC 200 - University of Rhode Island

Download Report

Transcript CSC 200 - University of Rhode Island

CSC 200
Spring 2006
Instructor: Matt Kayala
What is a “Computer”?
• We all use them for all kinds of tasks:
– Games
– Word Processing
• Good at repetitive tasks.
• Tasks not built in need to be programmed.
Program/Programming
• Computers can perform a small set of
instructions
– Add, Subtract, Send to Screen
• Program – Sequence of detailed steps to
perform a task.
• Programming – the act of designing and
implementing a program
Von Neumann Architecture
• Programs and Data
stored in memory
• ALU can do limited
number of ops
• Control Unit “fetches”
instructions from
memory
Machine Code
• At Von Neumann (hardware) level, instructions
very primitive
– (a) Move data stored in mem loc 19D8 to register B.
– (b) Subtract 100 from register B.
– (c) If result is negative, jump to instruction at mem loc
102C.
• In fact, all instructions encoded as numbers.
• Example: Instruction (a) might be encoded as
“0012 19D8”
• Not very readable/user friendly.
Assembly Language
• To move away from number encodings, people
began using mnemonics for instructions
• Example: Instruction (a) might be written as
“mov 19D8”.
• Mnemonics easily translated to Machine Code.
• Better, but still not great.
– Lots of instructions still, even for simple tasks.
– Different hardware (processors) all have different
assembly langs.
Higher Level Languages
• In the 1950’s higher level languages appeared.
• Example: The whole set of three instructions
two slides back might be written (abstractly)
– “if (theNum < 100) then…”
• The key to these langs was the development of
“Compilers”, special progs which translate
higher langs to machine code.
• Better, and the best you’re gonna get:
– Hardware independent
– Many “flavors”
Language Design and Evolution
• 100’s of different languages
• Specific vs. General Purpose
– Java, C++, Pascal – General
– TSQL, Prolog – Specific
• Grown vs. Planned
– C++ - Grown
– Pascal - Planned
Simple C++ Program
Notes on Simple Program
• Case Sensitive
– “main” != “Main”
• Free-form
– Whitespace (spaces, tabs, new lines) does
not matter
– Format chosen for clarity (line spacing,
indentation)
• Also, source code needs to be “compiled”
Compilation Process
•
•
•
•
For semester we will use Dev C++, an IDE.
IDE – Integrated Development Environment
Does all of the above steps.
Also includes a “debugger”.
Errors
• Two types of errors in programs:
– Syntax – keep source from compiling.
– Logic – compiles, but errors in logic make
program perform not as designed.
• Errors WILL happen!
• Program in a manner to minimize.
– Structured, modular thought.
– Follow the Edit – Compile – Debug – Test
Process.
Testing and Debugging
• Debugger – Special program to track
down syntax errors and run program
traces.
• Debugging – the act of fixing these errors.
• Testing – job of the programmer to test for
logic errors.
• Trace – Stepping through a program one
line at a time to discover errors.
Algorithms
• Programming is really process of designing and
implementing algorithms
• Algorithm – series of steps to complete a
specific task where each step is:
– Unambiguous
– Executable
– Terminating
• Example: Calculate interest accrual over n
years.
• Counterexample: Paint a masterpiece.