Download DSA1-Overview-PartOne

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Programming language wikipedia , lookup

Java performance wikipedia , lookup

Comment (computer programming) wikipedia , lookup

Library (computing) wikipedia , lookup

Object-oriented programming wikipedia , lookup

Parsing wikipedia , lookup

Structured programming wikipedia , lookup

C Sharp syntax wikipedia , lookup

Abstraction (computer science) wikipedia , lookup

GNU Compiler Collection wikipedia , lookup

C++ wikipedia , lookup

Name mangling wikipedia , lookup

Go (programming language) wikipedia , lookup

Program optimization wikipedia , lookup

Assembly language wikipedia , lookup

Coding theory wikipedia , lookup

Compiler wikipedia , lookup

Cross compiler wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Interpreter (computing) wikipedia , lookup

Transcript
Data Structure
and
Algorithm
1
Yingcai Xiao
You
Me
The Course
(http://www.cs.uakron.edu/~xiao/dsa1/index.html)
The Course
Data Structure?
Algorithm?
Computer Science?
Computer?
Programming?
What is a Computer?
From the Webster’s New World Dictionary:
1. A person who computes.
2. A device used for computing (an
electronic machine which by means of
stored instructions and information,
perform rapid, often complex calculations
or compiles, correlates, and selects data).
Computer Science
The science of data processing.
Programming a Computer
Programming a Computer
Types of Computers
Analog: Analog Device, 1.2345678
Digital: Binary Device, 0 or 1
Programming a Computer
Wiring: Hardware, Bug, Ada
Coding: Software
Modern Computers: Voneumann Machines
•
Run stored programs (code reuse) to process stored
data.
•
Components: Memory, IO, CPU, Secondary Storage.
What is a program and what is programming?
Programs:
stored computer instructions for data
processing.
Programming
= Data Structures + Algorithms
Professor Donald E. Knuth
http://www-cs-faculty.stanford.edu/~knuth/
What is a program from a computer’s point of view?
Programs:
• Stored binary opcodes
• Different types of computers have
different opcodes
• Opcodes are not reusable on different
types computers
• Programs in binary codes are not reusable
on different types of computers
How data are stored on a computer?
Bits (0/1) and bytes (0-255):
0 0 0 0 0 0 1 0
Short Int (2 bytes):
0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
Endian (byte ordering):
little (Intel), big (Moterola, Sun),
bi (DEC Alpha, MIPS),
big-to-bi (Sun SPARK v9)
Is data reusable?
Is data saved on one type of computers reusable on
another type of computers?
No, in general.
Yes, for ASCII text
or any type of a byte in size.
ASCII text (ISO/IEC 8859-1) is platform-independent.
0 1 0 0 0 0 0 1
‘A’ (65)
What is a program and what is programming?
Programs:
stored binary opcodes
Punch Card Programming:
punch card machines
converts instructions
typed into binary codes
(0 no hole, 1 hole) on a
stack of cards.
Programming Languages
Assembly Languages
• English-like: load, add, save
• Assembler: a program that translates code written in an
assembly language into opcodes.
• Assembly languages are machine-dependent. An
assembly language is only valid for a specific CPU
architecture.
• Programs written in an assembly language are
machine-dependent and not reusable on a different
types of CPU architectures.
High-level Programming Languages
• English-like: if, for, switch, …
• Compiler: a program that translates code written in a
high-level programming language into opcodes. The
input is called the source code and output is called the
object code (.obj).
• Linker: a program that links object codes together to
make an executable (.exe).
• Object-codes and executables are machine-dependent.
• High-level languages are machine-independent.
High-level Programming Languages
• Object codes (from different high-level programming
languages) can be put together to make a library (.lib).
• Binary codes are reusable as libraries on computers of
the same architecture. (compile-time sharing).
• Libraries and object files on a computer are linked
together to form an executable. (compile-time sharing
of binary code).
• A dynamically-linked library (.dll) can be shared by all
programs on the same computer and by all the running
processes on the same computer (run-time sharing).
• Libraries (.lib and .dll) are machine-dependent.
High-level Programming Languages
• To use a library, one needs to include the header files
(.h) for the library in the source code.
• The header files contain the header (not the
implementation) of user defined data types and related
methods (functions), i.e., describe what’s in the library.
• The compiler use the information in the header files
to make type checking.
• Before compilation, the preprocessor of the compiler
copies everything in the header files into the source
code and generate an intermediate (.I) file.
High-level Programming Languages
• Source codes written in a high-level programming
language are reusable on different types of
computers.
• Binary codes (.obj, .lib, .dll, .exe) compiled from a
high-level programming language are reusable on
the computers of the same architecture but not
reusable on computers of different architecture.
Traditional Compilation
Source File (.cpp)
Preprocessing
Intermediate File (.I)
Compilation
Object File (.obj)
Linking
Binary File (.exe)
Common Binary Code?
(Binary Code Reuse Cross System Architectures)
Traditional Compilation
Source Code for Language 1
Source Code for Language 1
Language 1 Compiler on OS1
Language 1 Compiler on OS2
Binary Code for OS1
Binary Code for OS2
OS1
OS2
OS-Independent Code:
Intermediate Languages
The trend to support machine-independent
binary code is to compile the source code into the
binary format of an intermediate language.
And to provide an interpreter for the
intermediate language on each OS to translate the
binary code of the intermediate language into the
native binary code of the OS.
OS-Independent Compilation: Intermediate Language
Source Code for Language 1
Language 1 Compiler on OS1
Language 1 Compiler on OS2
Intermediate Binary Code for Language1
Intermediate Code Interpreter OS1
Intermediate Code Interpreter OS2
Binary Code for OS1
Binary Code for OS2
OS1
OS2
Java Intermediate Language: Java Bytecode
Java Source Code (.java)
Java Compiler (javac) on OS1
Java Compiler (javac) on OS2
Java Bytecode (.class)
Java Interpreter on OS1 (java)
Java Interpreter on OS2 (java)
Binary Code for OS1
Binary Code for OS2
OS1
OS2
Program statements are interpreted one at a time during the run-time.
JIT Compiler
An interpreter interprets intermediate code one
line at a time. Slow execution.
A JIT (Just-In-Time) compiler compiles the
complete code all at once just into native binary
code before execution. Faster execution.
JIT Complier: Java Bite Code Compiler
Java Source Code (.java)
Java Compiler (javac) on OS1
Java Compiler (javac) on OS2
Java Bytecode (.class)
Java JIT Compiler on OS1
Java JIT Compiler on OS2
Binary Code for OS1
Binary Code for OS2
OS1
OS2
All programming statements are compiled at compile time.
MSIL: Microsoft Intermediate Language (Used by .NET)
Source Code for Language 1
Language 1 Compiler on OS1
Language 1 Compiler on OS2
MSIL Code
MSIL JIT Compiler on OS1
MSIL JIT Compiler on OS2
Binary Code for OS1
Binary Code for OS2
OS1
OS2
.NET OS-Platform-Independence
JIT Compilation in .NET
All MSIL code are JIT-compiled to native binary
code before execution. No run-time interpretation,
faster execution.
A Common Language?
(Source Code Reuse Cross Languages)
.NET CTS/CLR
.NET Common Language Runtime
To make .NET language independent, CLR (Common
Language Runtime) is defined as the runtime
environment.
CLR defines CTS (Common Type System) which
should be followed by all languages to be used in the
.NET framework.
The code that follows CTS standard and runs through
CLR is called managed code.
Ex. multiple inheritance is allowed in C++ but not
allowed in Managed C++ since CTS doesn’t support it.
CLR: Common Language Runtime
Source Code for Language 1
Source Code for Language 2
Language 1 Compiler on OS1
Language 2 Compiler on OS2
MSIL Code Confirming CTS (Managed Code)
CLR on OS1
CLR on OS2
Binary Code for OS1
Binary Code for OS2
OS1
OS2
.NET Language-Independence
.NET Architecture for Language and Platform Independence
(fan-in and fan-out on MSIL)
Source Code for Language 1
Source Code for Language 2
Language 1 Compiler on OS1
Language 2 Compiler on OS2
MSIL Code Confirming CTS (Managed Code)
CLR for OS1
CLR for OS2
Binary Code for OS1
Binary Code for OS2
OS1
OS2
Data Structures
Algorithms
(To be continued)