Вы находитесь на странице: 1из 5

Hardware and Software

• A computer is a machine designed to perform


operations specified with a set of instructions
called a program.
• Hardware refers to the computer equipment.
Introduction to Scientific – keyboard, mouse, terminal, hard disk, printer,
Computer Programming – CPA
Computer Concepts and C • Software refers to the programs that describe the
steps we want the computer to perform.

Computer Hardware Computer Organization


•  CPU – • Input Unit
– Central processing unit – Receives data into the computer (receiving section)
•  ALU – • Output Unit
– Arithmetic and logic unit – Outputs information (shipping section)
• Memory Unit
•  ROM –
– Called the primary memory, the warehouse section
– Read only memory
• Arithmetic and Logic Unit
•  RAM – – Performs calculations and makes decisions
– Random access memory • Central Processing Unit
– Supervises all operations of the other sections
• Secondary Storage Unit
– Stores programs and data currently not needed
3 4

Software: Operating System Computer Software: Applications


•  A system of computer programs that control •  Application Software (Software Tools)
the interaction of the user and the computer – Word processors (Microsoft Word,
hardware. WordPerfect, ...)
– Examples: Linux, Windows, QNX,…
– Spreadsheet programs (Excel, Lotus1-2-3, ...)
•  Purposes of the operating system
– Computer games
– Controls communication between input and output
– hardware and each process running in the computer. – Communication software (email, chat, web
– Directs and orders all operations of the computer
browser…)
– Allocates and shares resources (memory,processor…) – Telecommunication software (VOIP, …)
– Controls access to resources and data (security)
– Provides a user interface (UI) and/or graphical user
interface (GUI)
– Stores and accesses data and applications 5 6

1
Computer Software: Languages Machine language
•  Some Computer Languages •  Each type of processor (like Pentium 4,
– Machine language (machine instruction set) Athalon, Z80, …) has its own instruction set
– assembly language •  Each instruction in an instruction set does a
– high level languages single thing like access a piece of data, add two
– C, C++, Ada, Fortran, Basic, Java pieces of data, compare two pieces of data …
•  Each instruction is represented by a unique
•  Do YOU know of any others? number This # may be different for different
– mathematical computation tools (MATLAB, instruction sets, but no two instructions in the
Mathematica, ...) same instruction set will have the same #

•  Application software is written using


computer languages.
7 8

Machine Language Programs Assembler


•  In machine language a program is a list of •  Assembler languages make it easier for the
instructions programmer.
– Each instruction is represented by a number – Assembler is easier for humans to read/write
– Inside the memory of the computer each number is – The numbers that identify each of the instructions in the
represented in binary (as a constant length string of 1’s instruction set are replaced with mnemonics like ADD,
and 0’s) CMP, …
– The long string of 0’s and 1’s is easy for the computer – The code, written using these mnemonics is written into
to understand and very difficult for a Human to read or a text file.
write

9 10

Assembler Programs Programs in High Level Languages


•  The code for an Assembler program is •  Assembler is easier to read/write than
written into a text file. machine language. It is still very cumbersome
•  The computer read 1’s and 0’s not text •  High level languages are easier to write than
•  How do we translate to machine readable assembler
form? – The compiler is more complex, but that is a tool you
– A computer program called a compiler is used to use, not one you write
translate the text file (called a source file) containing the
assembler code into machine readable code
– The compiler writes a binary file containing the machine
readable code (called an object file)

11 12

2
History of C C Standard Library
• C evolved from two previous languages • C program consists of modules or pieces called
– BCPL in 1967 by Martin Richards functions.
– B in 1970 by Ken Thompson • The C Standard Library contains a extensive
• From B, Dennis Ritchie developed C at Bell collection of functions to form a C program.
Laboratories in 1972. • In creating a program in C, usually, you would use
– Today, virtually all Operating Systems are developed the following:
using the C language, or the C++. – The C Standard Library functions
– Functions you create yourself
– Functions others have created, and are now available
for you

13 14

C Program Execution Source files


• There are six phases a C programs goes •  Contains the text you type into a text editor
through to be executed •  The text is a program
1. Editing
– Typing in and saving of program files on disk •  The program is a list of instructions written in a
2. Preprocessing special Human readable language (C)
– Completes preprocessor directives (e.g. includes…) •  The program can be translated, from the
3. Compiling
Human readable language (in source file) to a
– Translation of C program to machine language code
4. Linking machine readable language (in object file), by a
– Links object code with the libraries and saves on disk compiler
5. Loading •  A compiler is a special piece of software used
– Places program in memory
to translate from source files to object files
6. Executing
– Processing of instructions (program execution)

15 16

Source files Perfect Code? Finding Errors 1


•  Write using a text editor •  It is highly unlikely than any of us will always
•  Do not write your code using a word processor write perfect code that contains no errors
like Microsoft Word. A word processor will save in •  How do we find errors?
a special format. – Are there different kinds of errors? Yes
•  The compiler reads only text, not special •  A computer program can contain syntax
• formats. errors, semantic errors, or logical errors
•  Beware: your text does not differentiate •  When and how can we detect and correct
between a word processor and an editor • errors?
– Compile errors
– Link errors
– Run Time Errors

17 18

3
Syntax Errors Semantic Errors
•  A computer program can contain syntax errors •  A computer program can contain semantic
•  A computer language follows simple rules errors
– how words and punctuation of different types may be •  Semantics relates to the meaning of the words
combined. in a sentence or a computer language command
– In English syntax is similar to grammatical structure – Just like a grammatically correct English sentence can
•  The compiler for a high level language can be nonsense, a syntactically correct high level
detect errors that break those simple of syntax computer language command can also contain
semantic errors
(syntax errors)
•  Some semantic errors may be found by the
•  Syntax Errors are usually detected at compile
compiler, some will be found when the program is
time
linked, some may be found at run time

19 20

Logical Errors Perfect Code? Finding Errors 2


•  When your program completes but gives an •  If your code contains compile time errors is it
unexpected answer it usually means there is a correct? NOT NECESSARILY
error in the logic in your solution of the problem •  How do we find the remaining errors?
•  Logic errors can also cause a program to fail – Use a tool that does more checks than the compiler
part way through execution (splint).
– Move on to linking the code to libraries etc.
– The linker resolves references, words in your program
than are defined elsewhere
• Errors occur when the definitions cannot be
found
• Errors occur when the use of the word does not
correspond to the definition
21 22

Summary:
Perfect Code? Finding Errors 3
Executing a Computer Program
•  If your code compiles and contains no errors •  Compiler
that can be found by the linker (or splint) is it – Converts a source file (containing your human readable
correct? NOT NECESSARILY program in C) to and object file (computer readable
binary file)
•  How do we find the remaining logic and
semantic errors? •  Linker
– When you run your executable program it may not – Converts object program to executable program
complete (may or may not generate error message)
– It may complete and give the wrong answer

23 24

4
Summary: Types of Errors
•  Syntax errors
– Errors in syntax, how words are combined and used
reported by the compiler or splint
Introduction to
•  Semantic errors
– Errors in the meaning of words, Scientific
– Reported by the linker (linker errors) Computer Programming
– Reported by the compiler (compile time errors)
– Found at execution time (run-time errors) – Computer Concepts
•  Logic errors and C
– Errors causing the incorrect results, not reported
– Errors causing program failure (run-time errors)

25

Вам также может понравиться