Lecture overview - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Lecture overview

Description:

Since both translators/compilers and interpreters are actually software that run ... Compiler-interpreters converts the whole of a HLL program file into a sequence ... – PowerPoint PPT presentation

Number of Views:74
Avg rating:3.0/5.0
Slides: 26
Provided by: martin159
Category:

less

Transcript and Presenter's Notes

Title: Lecture overview


1
Lecture overview
  • In this lecture I will cover
  • introduction to a simple processor and its
    machine language
  • introduce the general problem of language
    processing

2
Introduction to Simpletron
  • In order to illustrate what we will be talking
    about I will first introduce you to a simulation
    for a very simple computer system called
    Simpletron.
  • Simpletron is the GUI front end which allows you
    to interact with the simulation of a simple
    processor which executes Simple Machine Language
    (SML). The simulation itself is called
    SimpleVirtualMachine (SVM for short).

3
  • SVM effectively executes SML programs by
    simulating the operation of the simple processor
    and memory.
  • Programmers view of SVM looks at the structure of
    the SVM in terms of the operations defined by the
    SML instructions

4
SimpleVirtualMachine - Programmers view
5
  • Basic unit of size for information transfer and
    storage is a word
  • word size is 4 hexadecimal digits
  • instructions (4 digits in size) fetched from
    memory at location specified by program counter
    into instruction register
  • instruction word is decoded into
  • operation code (first 2 digits) and
  • operand (second 2 digits) which gives location
    (memory address) of data to be used
  • memory size is 0x100 words (i.e. hex 100 256)
    addressed from 00 to FF

6
  • program counter is incremented to point to next
    memory location
  • operation code is then executed - involving use
    of accumulator for most instructions
  • SML programs always start executing with the
    instruction held at location 00 in memory i.e.
    programs are loaded into memory at consecutive
    positions starting from 00
  • accumulator - holds operand data for operations
    and results of operations - but temporary store
    i.e. data overwritten if not stored into memory
    location

7
  • Example instruction operation codes in SML
  • 20 - loads a word from memory location specified
    in operand into accumulator
  • 30 - adds word from location specified in operand
    to word in accumulator, leaving the result in
    accumulator
  • 21 - stores word value in accumulator into
    location specified in operand

8
  • Thus assuming 2 values represented by X and Y
    exist in locations 10 and 11 respectively and
    TOTAL value is held at location 12 then the
    following example high level language code
  • TOTAL X Y
  • may be translated into the following SML code in
    order for the high level language actions to be
    executed on the Simpletron processor
  • 2010
  • 3011
  • 2112

9
SML instructions
  • The numeric code is the 2 digit value that is
    actually used to represent SML instructions -
    mnemonics is just to help us talk about them

10
Consequences of choice of word size and structure
  • We have to remind ourselves of the structure of
    an instruction word in SML,
  • ltdigits for instruction code, address of operandgt
  • Number of digits used for instruction code
    determines the maximum number of different
    instructions that can be recognised by the
    virtual machine e.g. 2 digits gives values in
    range 00 to FF (maximum possible is 162 256
    instructions).

11
  • Similarly the number of digits used for address
    determines the maximum possible range of
    locations that can addressed - e.g. 2 digits only
    permits 00-FF address locations to be identified
    (256 locations), and thus 256 in the maximum size
    of memory that can be addressed. Code example

12
  • size of word in digits also determines the range
    of integer values that can be used as data i.e.
    instructions only operate on words, thus number
    of digits in word determine the range of numbers
    that can be operated on e.g. 4 digits gives -FFFF
    to FFFF. Code example

13
High level languages and low level languages
  • computer languages are used to define algorithms
    in a precise and structured form
  • high level languages use constructs, instructions
    and data components that are similar to normal
    human thought e.g.
  • TOTAL X Y

14
  • machine languages use constructs, instructions
    and data components that produce operations by a
    physical computer e.g.
  • 2010
  • 3011
  • 2112
  • General problem HLL and ML are different and HLL
    program needs to be converted into computer
    operations that are specified by ML - and many
    computer operations are needed to execute a HLL
    statement
  • this is the case with any real hardware computer
    except the processor and the machine language
    code are considerably more complex

15
Language processors
  • A language processor is a program that accepts a
    high level language program as input and converts
    it into a sequence of operations that is or can
    be executed by the computer
  • in general 3 approaches to language processing
  • translation (or compilation)
  • interpretation
  • compilation/interpretation

16
Compiler/translator and interpreter analogies
  • Imagine the computer as a group of people who
    understand English and who can carry out various
    instructions given to them in English
  • English acts like their machine language
  • We will imagine that the solution to various
    problems have been written in Russian which thus
    acts like the HLL

17
  • A translator or compiler is like someone who
    takes a manual of instructions written in Russian
    and translates them into a manual in English. An
    English reader of the manual can then carry out
    the operations as specified in the manual.
  • An interpreter is like someone who takes a manual
    of instructions written in Russian and reads one
    Russian instruction and immediately carries out
    that instruction, before proceeding to the next
    instruction in the manual

18
  • Since both translators/compilers and interpreters
    are actually software that run on some machine it
    would be more accurate to think of them actually
    as manuals of instruction written in English that
    are being carried out
  • the compiler/translator manual specifies how to
    translate Russian manuals into English manuals
  • the interpreter manual specifies for any Russian
    instruction what action should be carried out

19
Compilers or Translators
  • Compilers (translators) convert all of the HLL
    program file (called source code) into the
    sequence of machine instructions (called the
    object code) that are necessary to carry out the
    actions specified by the HLL program on the some
    specific machine (called the target machine)
  • the sequence of machine language instructions are
    held in a file (called an executable file)

20
  • executable file can then be loaded into memory of
    target computer and then executed
  • machine instructions are executed directly by
    target machine
  • languages usually compiled include C, C,
    Pascal, Cobol, Fortran

21
Interpreters
  • interpreters take a single HLL statement from the
    program, one at a time
  • it analyses the statement to find out what action
    is required by that statement
  • the interpreter then itself carries out the
    actions required by the source code program by
    executing instructions within the interpreter
    code
  • languages usually interpreted include LISP,
    Prolog, JavaScript

22
some trade-offs
  • speed of execution compiled code just executes
    (fast), interpreted code is repeatedly analysed
    then executed (slow)
  • code complexity and size of language processor
    compilers analyse whole program and generate
    machine instructions (large and complex),
    interpreters analyse a statement at a time and
    execute actions instructions within interpreter
    code (smaller and simpler)

23
Compiler-Interpreters
  • Compiler-interpreters converts the whole of a HLL
    program file into a sequence of instructions
    (called intermediate code) held in a file. The
    file is then executed by an interpreter for the
    intermediate code.
  • Intermediate code instructions are selected to be
    easy to analyse (i.e. find out what machine
    action they require) and simple to execute (fewer
    machine instructions required to execute them)

24
Java approach
  • Java traditionally used compiler-interpreter
    approach (javac and java)
  • intermediate code produced by javac called
    bytecode because each intermediate code operation
    is specified by a single byte of data
  • the Java bytecode interpreter is the Java virtual
    machine (JVM)
  • java compiler is large and complex, while the
    interpreter is small - the code executes slower
    than compiled code but faster than pure
    interpreted code - but Just-in-Time and hot-spot
    compilers help

25
Just-In-Time Compilers
  • JIT Java compiler will convert Java intermediate
    code(bytecode) for a segment of code (normally
    single method) into a sequence of machine
    instructions in a temporary file in memory
  • these machine instructions will then be directly
    executed by hardware
  • when the method finishes executing, the method
    that is next to be executed in the byte code is
    JIT compiled
  • the byte code is compiled just in time for it
    to be executed
Write a Comment
User Comments (0)
About PowerShow.com