Title: System Software
1System Software
2Overview of this Section
- Languages
- Assemblers
- Compilers
- Function
- Components
- Interpreters
- The JVM
- Compiled versus Interpreted systems
3GENERATIONS OF APPLICATION PROGRAMMING LANGUAGES
- 1st. Since 1940s. MACHINE LANGUAGE binary code
- 2nd. Since early 50s. ASSEMBLY LANGUAGE
mnemonics for numeric code - 3rd. Since mid 50s. HIGH-LEVEL LANGUAGES
- 4th. Since late 70s. MODERN APPLICATION
PACKAGES - 5th. Object oriented programming languages.
4Types of Application Programming Languages
5Examples of Commands in Different Levels of
Languages
6We have a problem ?
7Options 1. Speaker learns English 2. Class
learns Chinese 3. Use a translator
8Now, here is the solution !
Talks Chinese
Understands English
Speaker
Translator
Class
Translates Chinese to English
9Interpreters and Compilers
Writes High Level Language
Understands Machine Language
Programmer (Human)
Interpreter/ Compiler
Computer (machine)
Translates High Level Language to Machine Language
10The Language Translation Process
- Compiler
- Interpreter
- Assembler
Source Program
Language Translation Process
Written in BASIC, COBOL, etc.
11Assembler
- Small ratio between the statements in the
language and the machine code instructions - Instructions consist of bit patterns, some are
operator some are operand - Could write programs like this
- complicated
- error prone
- time consuming
- Assembly language uses symbols (mnemonics)
instead of bit patterns - E.g. ADD may translate as 100
- Programs must be translated from mnemonics to bit
patterns - Different assembler for each processor
- No abstraction
- Parses symbols and translates into machine code
- Two passes
12- Linker
- Many source modules can be linked together in the
same executable program. - Symbols defined in one module can be accessed in
another - Saves time
- Libraries
- Loader
- Loads the linker output into memory
- Transfers control to the start address of the
program - Bootstrap loader loads the loader
13Compilation
- A compiler is more complicated than an assembler
- one high-level instruction can correspond to
several machine instructions. Ex. x (y3) / z - fancier data structures. Ex.
- arrays address calculations must be done for
references to array elements - records similar to arrays, but less regular
- Procedures/subroutines/functions/methods - must
write machine language code to - copy input parameter values
- save return address
- start executing at beginning of procedure code
- copy output parameter values at end of procedure
- set PC to return address
14Functions of a compiler?
- Lexical analysis Break up strings of characters
into logical components, called tokens, and
discard comments, spaces, etc. - Parsing Decide how tokens are related.Ex. Sum
55.32 is an arithmetic expression, and total
sum 55.32 is an assignment statement. - Code generation Generate machine instructions
for each high-level instruction. - Important to optimize the generated code. Ex.
- 1. X Y Z
- 2. W X Z
- After line 1, X and Z are already in registers,
so dont load the registers for line 2 - The resulting machine language program, called
object code, is written to disk. - Object code is then linked into an executable
15Components of a compiler
- Syntax checker
- Checks the code for errors
- Can be integrated into an IDE, or standalone
- Provides feedback of errors
- lexical analyser
- Lexical analysis Break up strings of characters
into logical components, called tokens, and
discard comments, spaces, etc. - Parsing Decide how tokens are related.Ex. Sum
55.32 is an arithmetic expression, and total
sum 55.32 is an assignment statement. - code generator
- Generate machine instructions for each high-level
instruction. - Linker
- Links all the compiled modules together into a
standalone program
16Compiler Generation
Line 3 push ebp mov ebp, esp push ecx mov DW
ORD PTR ebp-4, -858993460 ccccccccH Line
6 mov DWORD PTR _iebp, 0 jmp SHORT
L578 L579 mov eax, DWORD PTR
_iebp add eax, 1 mov DWORD PTR _iebp,
eax L578 cmp DWORD PTR _iebp, 10
0000000aH jge SHORT L580 Line 7 mov ecx,
DWORD PTR _iebp push ecx push OFFSET
FLATSG581 call _printf add esp, 8 Line
8 jmp SHORT L579 L580 Line 9 add esp,
4 cmp ebp, esp call __chkesp mov esp,
ebp pop ebp ret 0 _main ENDP _TEXT ENDS END
- include ltstdio.hgt
- main()
- int i
- for (i 0 i lt 10 i )
- printf("d", i)
-
17Issues
- Different machine languages
- Machine languages are incompatible
18Interpreters vs. Compilers
- Interpreter
- Converts one line of high level language to
machine language and then performs it. - Compiler
- Converts entire program to machine language code
the machine language can then be executed. - A compiler defines a translation from one
programming language to another,usually so that
the program can be efficiently interpreted - An interpreter defines a program evaluator
19The Java Solution - Write Once, Run Anywhere
Java Code (High Level)
Byte Code (can be understood by JVM)
JVM for Machine 1
Machine 1
Java Compiler
Translates BC to ML for Machine 2
Translates Java Code to Byte Code
JVM for Machine 2
Machine 2
BC - Byte Code ML - Machine Language JVM - Java
Virtual Machine
Translates BC to ML for Machine 2
20Java programs
- javac - The Java compiler
- javac HelloWorld.javaproduces HelloWorld.class
- java - The JVM
- java HelloWorldruns HelloWorld.class in the JVM.
21Summary
- Compiler/Interpreter translates high level
language to machine language - Interpreter translates line by line
- Compiler translates entire program at once
- Java code compiles to intermediate byte code
using javac, then JVM interprets byte code (java).
22Just-In-Time
- In the Java programming language and environment,
a just-in-time (JIT) compiler is a program that
turns Java bytecode (a program that contains
instructions that must be interpreted) into
instructions that can be sent directly to the
processor.
23Advantages Disadvantages of Interpreted Java
and Compiled C