FIT1001- Computer Systems Lecture 12 Introduction to System Software
Week 12: FIT1001 Computer Systems S 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
FIT1001- Computer Systems Program Translation
Week 12: FIT1001 Computer Systems S 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 S Programming Tools Overview This study guide will cover program development tools –Editors –Assemblers –Debuggers –Compilers –Linkers –Loaders –Interpreters Integrated Development Environments (IDEs) combine several of the above programming toolsIntegrated Development Environments (IDEs) combine several of the above programming tools
Week 12: FIT1001 Computer Systems S The Program Translation Process Translator Linker Loader Source Object Executable
Week 12: FIT1001 Computer Systems S 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 S 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 S 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 S 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 S 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 S Object-Oriented Languages SmallTalk C++ Java –Based on C++ –Platform independent
Week 12: FIT1001 Computer Systems S Compilers Translates high-level language into low-level instructions High-level language: Source code Machine-level: Object code Changes, including bug fixes, require recompiling
FIT1001- Computer Systems Machine Language and Assembler
Week 12: FIT1001 Computer Systems S Machine Language of MARIE(SG4) Consider the simple MARIE program given below –A set of mnemonic instructions stored at addresses (hex):
Week 12: FIT1001 Computer Systems S 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 S 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 S 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.
FIT1001- Computer Systems Programming Language Definition
Week 12: FIT1001 Computer Systems S 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 S 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 S Railroad Diagram Examples
Week 12: FIT1001 Computer Systems S Typical BNF Rules for Java
Week 12: FIT1001 Computer Systems S Parsed English Sentence
FIT1001- Computer Systems Compilers and Interpreters
Week 12: FIT1001 Computer Systems S 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 S 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 S The Stages of program Compilation
Week 12: FIT1001 Computer Systems S 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 S 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 S 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 S 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 S Interpreter vs. Compiler Resources during executionInterpreterCompiler Contents in memory Interpreter/compilerYesNo Source codePartialNo Executable codeYes CPU cycles Translation operationsYesNo Library linkingYesNo Application programYes
FIT1001- Computer Systems Linking and Loading
Week 12: FIT1001 Computer Systems S Linking Object file Object file or module Linker Executable file C library
Week 12: FIT1001 Computer Systems S 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 S 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 S 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 S Link Loading System With Early Binding
Week 12: FIT1001 Computer Systems S 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.
FIT1001- Computer Systems Debugging and Testing
Week 12: FIT1001 Computer Systems S Debuggers Assembly language debuggers Source code debuggers Step through programs Check variable values
Week 12: FIT1001 Computer Systems S Next… Revision of FIT1001 follows this lecture