Download Class 3.2 Assembler. Compiler. Interpreter

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

Name mangling wikipedia , lookup

Program optimization wikipedia , lookup

Go (programming language) wikipedia , lookup

One-pass compiler wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

History of compiler construction wikipedia , lookup

Compiler wikipedia , lookup

Cross compiler wikipedia , lookup

Interpreter (computing) wikipedia , lookup

Assembly language wikipedia , lookup

Transcript
Assembler, Compiler, MIPS simulator
• Assembly, Assembler, Linker
Assembling, Linking.
When to use assembly. Drawbacks of
assembly
• SPIM simulator.
Writing a program. Running it.
• Syntax of MIPS assembly
Textbook: Appendix A - compilers, SPIM simulator and
MIPS assembly syntax.
Ch. 3.9. Starting a program. (156-163).
Assembly & Machine Instructions
What is Assembly ?
 Symbolic representation of a computer’s binary encoding machine language
 Programming view of the architecture of a particular
processor.
machine instruction
assembly language
statement
0000 0001 0010 1011 1000 0000 0010 0000
add $t0,$t1,$t2
Assembly vs. Machine Instructions
machine instruction
0000 0001 0010 1011 1000 0000 0010 0000
assembly language
statement
add $t0,$t1,$t2
 Machine instructions:
• Are beneficial to use in computers.
• It is hard for humans to keep track of machine instructions ones
and zeros.
 Assembly: By using symbols programmers gain flexibility in
describing the computation.
• Assembly language is a compact notation.
• Symbolic names for operations and locations
• Programming facilities – macros, pseudoinstructions.
Assembling, linking
•
A tool called an assembler translates assembly language into
binary instructions - object module.
•
Another tool, called a linker combines a collection of object
and library files into an executable file, which a computer can
run.
header
Compiling, linking
C source code
Compiler
Loadable Module
(Executable File)
 In a high level programming language like C or Java a programmer
is mostly unaware of computer architecture.
 The same source program can run (after compiling) on any
processor family.
 That is done by sophisticated compilers which know exactly how
to translate the high level program to the particular machine
language.
Interpreters
 There are two ways to run programs written in a highlevel language.
 The most common is to compile the program;
 the other method is to pass the program through an
interpreter.
 Interpreter is a program that executes instructions
written in a high-level language.
Interpreters vs. compilers
 Interpreting code is slower than running the compiled code
 because the interpreter must analyze each statement in the program
each time it is executed and then perform the desired action
 whereas the compiled code just performs the action within a fixed context
determined by the compilation
 This run-time analysis is known as "interpretive overhead".
 Access to variables is also slower in an interpreter because the mapping of
identifiers to storage locations must be done repeatedly at run-time rather
than at compile time.
Interpreter
High level
language source
code
Executable Code
Compiler
Interpreter
Intermediate
representation
(bytecode)
Where we need the Assembly
 The primary reason to program in assembly language, as
opposed to an available high-level language, is that the speed
or size of a program is critically important.
 A hybrid approach, in which most of a program is written in a highlevel language and time-critical sections are written in assembly
language, builds on the strengths of both languages
 Cases when no high-level language or compiler is available on a
particular computer
 Ability to exploit specialized instructions, for example, string
copy or pattern-matching instructions.
Assembly language disadvantages versus
High level languages
 Assembly programs are machine-specific and must be totally
rewritten to run on another computer architecture.
 Assembly language programs are longer than the equivalent
programs written in a high-level language.
 programmers write roughly the same number of lines of code per day
in assembly and in high-level languages
 longer programs are more difficult to read and understand and they
contain more bugs