Www.monash.edu.au FIT1001- Computer Systems Lecture 12 Introduction to System Software.
-
Upload
cara-bready -
Category
Documents
-
view
224 -
download
0
Transcript of Www.monash.edu.au FIT1001- Computer Systems Lecture 12 Introduction to System Software.
Week 12: FIT1001 Computer Systems S12 2006 2
Lecture12 : Learning Objectives
• Describe the relationship between machine language, assembler code and high level language
• Understand the use of system software tools including assemblers, linkers, loaders, editors, compilers, interpreters and debuggers
• describe the concept of relocatability of program code
• explain some methods used to define the syntax of computer languages including syntax (“railroad”) diagrams and BNF
• list the stages of high level program compilation• differentiate between link/loader systems that
perform early, late and dynamic binding
Week 12: FIT1001 Computer Systems S12 2006 4
Introduction
• The biggest and fastest computer in the world is of no use if it cannot efficiently provide beneficial services to its users.
• Users see the computer through their application programs. These programs are ultimately executed by computer hardware.
• System software can be defined as a collection of programs and associated data that supports the use of a computer system
Week 12: FIT1001 Computer Systems S12 2006 5
Programming Tools OverviewProgramming Tools Overview
• This study guide will cover program development tools
– EditorsEditors– AssemblersAssemblers– DebuggersDebuggers– CompilersCompilers– LinkersLinkers– LoadersLoaders– InterpretersInterpreters
• Integrated Development Environments (IDEs) Integrated Development Environments (IDEs) combine several of the above programming toolscombine several of the above programming tools
Week 12: FIT1001 Computer Systems S12 2006 6
The Program Translation Process
Translator
Linker
Loader
Source
Object
Executable
Week 12: FIT1001 Computer Systems S12 2006 7
Program Text Editors
• Word processors format the appearance of the text• Text editors
– Format the spacing between words for legibility
– Ideal for structured languages
– Text is the same font size
• Examples– DOS – Edit
– Windows – Notepad, Wordpad
– Unix / Linux – ed, vi, emacs
• IDEs– MS Visual C++
Week 12: FIT1001 Computer Systems S12 2006 8
Programming Language Categories
• Machine Language– Binary coded instructions
• Assembly Language– Symbolic coded instructions
• Procedural Languages– procedural statements or arithmetic notation
• Fourth-Generation Languages– Natural language and nonprocedural statements
• Object-oriented Languages– Combination of objects and procedures
Week 12: FIT1001 Computer Systems S12 2006 9
Assembly Language
• When to use – When speed or size of program is critical– Hybrid approach – Hardware Drivers– Can use specialized instructions
• Disadvantages – Inherently machine specific– Architectures may become obsolete– Lack of programming structure
Week 12: FIT1001 Computer Systems S12 2006 10
Assemblers
• Binary code = machine code• Hex code• Assembly Language
– Mnemonic names op codes– Labels memory addresses– Comments– Symbol table– Operations table– Memory Relocation
• Cross Assembler
Week 12: FIT1001 Computer Systems S12 2006 11
Procedural Languages
• COBOL– Wordy but easier to maintain
• FORTRAN– Scientists and engineers
• BASIC• Pascal
– Highly structured teaching language
• C– high-level commands and low-level access to hardware
Week 12: FIT1001 Computer Systems S12 2006 12
Object-Oriented Languages
• SmallTalk• C++• Java
– Based on C++– Platform independent
Week 12: FIT1001 Computer Systems S12 2006 13
Compilers
• Translates high-level language into low-level instructions
• High-level language: Source code• Machine-level: Object code• Changes, including bug fixes, require recompiling
Week 12: FIT1001 Computer Systems S12 2006 15
Machine Language of MARIE(SG4)
• Consider the simple MARIE program given below– A set of mnemonic instructions stored at addresses 100 - 106
(hex):
Week 12: FIT1001 Computer Systems S12 2006 16
Assemblers
• Mnemonic instructions such as LOAD 104 – Easy for humans to write and understand– Impossible for computers to understand
• Assemblers are the simplest of all programming tools. They translate mnemonic instructions to machine code.
• Most assemblers carry out this translation in two passes over the source code.
– The first pass partially assembles the code and builds the symbol table
– The second pass completes the instructions by supplying values stored in the symbol table.
• Macro Assemblers can define a recurring code sequence.
Week 12: FIT1001 Computer Systems S12 2006 17
Relocatable Code
• The output of most assemblers is a stream of relocatable binary code.
– In relocatable code, operand addresses are relative to where the operating system chooses to load the program.
– The origin directive of the assembler implies or specifies the load point.
– Absolute (nonrelocatable) code is most suitable for device and operating system control programming.
• When relocatable code is loaded for execution, special registers provide the base addressing.
• Addresses specified within the program are interpreted as offsets from the base address.
Week 12: FIT1001 Computer Systems S12 2006 18
Binding
• The process of assigning physical addresses to program variables is called binding.
• Binding can occur at compile time, load time, or run time.
• Compile time binding gives us absolute code.
• Load time binding assigns physical addresses as the program is loaded into memory.
– With load time, binding the program cannot be moved!
• Run time binding requires a base register to carry out the address mapping.
Week 12: FIT1001 Computer Systems S12 2006 20
Language Components
Language can be defined as three interrelated components:
• Lexicon– All legal words in the language– Meaning and type
• Syntax– Form and structure– grammar rules
• Semantics– meaning of command
Week 12: FIT1001 Computer Systems S12 2006 21
Computer Language Descriptions
Expressing the grammar of high-level computer language requires formal and precise syntax specifications
• Narrative descriptions– the method of description useful to the programmer,
reference source– Difficult to implement in a compiler
• Syntax (Railroad) Diagrams– Formal definition of grammar for a programming language
• BNF– Backus-Naur Form
> Most precise method of describing the grammar of a computer language
> Also known as Context-Free Grammar
Week 12: FIT1001 Computer Systems S12 2006 26
Compilers
Compilers bridge the semantic gap between the higher level language and the machine’s binary instructions.
Most compilers effect this translation in a six-phase process. The first three are analysis phases:
1. Lexical analysis extracts tokens, eg. reserved words and variables.
2. Syntax analysis (parsing) checks statement construction.
3. Semantic analysis checks data types and the validity of operators.
Week 12: FIT1001 Computer Systems S12 2006 27
Compilers
The last three compiler phases are synthesis phases:4. Intermediate code generation creates three
address code to facilitate optimization and translation.
5. Optimization creates assembly code while taking into account architectural features that can make the code efficient.
6. Code generation creates binary code from the optimized assembly code.
Through this modularity, compilers can be written for various platforms by rewriting only the last two phases.
Week 12: FIT1001 Computer Systems S12 2006 29
Process of Parsing
• Lexical analysis– Also known as scanning– Divides the string of input characters into single elements,
tokens, based on strict computer punctuation
• Syntactic analysis– Checks for errors in grammar rules
• Semantic parsing– Determines the meaning of the string
Week 12: FIT1001 Computer Systems S12 2006 30
Source Code Instructions
• Data declarations: – Data type such as floating point, integer
• Data operations– Instructions that update or compute data value
(lots of moving around!)
• Control Structures– Branches, Goto (yetch!), If-then-else,
loops such as While-do and Repeat-until
• Function, procedure, or subroutine calls– Receives control via a call instruction, receives and possibly
modifies parameters, and returns control to the instruction after the call
Week 12: FIT1001 Computer Systems S12 2006 31
Optimization
• Compiler analyzes code in order to– Reduce amount of code– Eliminate repeated operations– Reorganize parts of of the program to execute faster
and more efficiently– Use computer resources more effectively
• Example– Move a calculation repeated within the body of a loop that
does not use any value modified by the loop
• Different compilers can produce different results!
Week 12: FIT1001 Computer Systems S12 2006 32
Interpreters
• Interpreters produce executable code from source code in real time, one line at a time.
• Consequently, this not only makes interpreted languages slower than compiled languages but it also affords less opportunity for error checking.
• Interpreted languages are, however, very useful for teaching programming concepts, because feedback is nearly instantaneous, and performance is rarely a concern.
• Examples of interpreted languages– Java, BASIC, LISP
Week 12: FIT1001 Computer Systems S12 2006 33
Interpreter vs. Compiler
Resources during execution Interpreter Compiler
Contents in memory
Interpreter/compiler Yes No
Source code Partial No
Executable code Yes Yes
CPU cycles
Translation operations Yes No
Library linking Yes No
Application program Yes Yes
Week 12: FIT1001 Computer Systems S12 2006 35
Linking
Object file
Object file or
moduleLinker Executable
file
C library
Week 12: FIT1001 Computer Systems S12 2006 36
Linkers
• Searches program libraries to find library routines used by the program
– Library: collection of pre-written functions and subroutines made available to perform commonly required activities
• Determines the memory locations that code from each module will occupy and relocates instructions by adjusting absolute references
• Resolves references among files • Like assemblers, link editors perform two passes:
The first pass creates a symbol table and the second resolves references to the values in the symbol table.
Week 12: FIT1001 Computer Systems S12 2006 37
Why Link?
• Construct single executable program from multiple object code files compiled at different times
• Program can be subdivided into components and parceled out to different developers
• Example– Main program and multiple subroutines written and compiled
by different programmers at different times
Week 12: FIT1001 Computer Systems S12 2006 38
Loader
• Loads binary files that have been linked into main memory
• Program is ready for execution• There are four link/loading scenarios
– Absolute code generated at the end of a development cycle, not requiring link editing, eg. Single-user embedded control environment
– Using a loader several times without repeat linking, early binding
– Using memory efficiently and linker/loader functions are combined, late binding
– Using dynamic link library modules, dynamic binding
Week 12: FIT1001 Computer Systems S12 2006 40
Dynamic Linking
• Dynamic linking is when the link editing is delayed until load time or at run time.
• External modules are loaded from from dynamic link libraries (DLLs).
• Load time dynamic linking slows down program loading, but calls to the DLLs are faster.
• Run time dynamic linking occurs when an external module is first called, causing slower execution time.
– Dynamic linking makes program modules smaller, but carries the risk that the programmer may not have control over the DLL.
Week 12: FIT1001 Computer Systems S12 2006 42
Debuggers
• Assembly language debuggers• Source code debuggers• Step through programs• Check variable values