Fundamentals of Computer Systems: Types of program translator

From Wikibooks, open books for an open world
Jump to: navigation, search

UNIT 2 - ⇑ Fundamentals of Computer Systems ⇑

← Generations of programming language Types of program translator

Assembler[edit]

An assembler translates assembly language into machine code. Assembly language consists of mnemonics for machine opcodes so assemblers perform a 1:1 translation from mnemonic to a direct instruction. For example:

LDA #4 converts to 0001001000100100

Conversely, one instruction in a high level language will translate to one or more instructions at machine level.

Advantages of using an Assembler:

plus pointVery fast in translating assembly language to machine code as 1 to 1 relationship
plus pointAssembly code is often very efficient (and therefore fast) because it is a low level language
plus pointAssembly code is fairly easy to understand due to the use of English-like mnemonics


Disadvantages of using Assembler:

minus point Assembly language is written for a certain instruction set and/or processor
minus point Assembly tends to be optimised for the hardware it's designed for, meaning it is often incompatible with different hardware
minus point Lots of assembly code is needed to do relatively simple tasks, and complex programs require lots of programming time


Compiler[edit]

A Compiler is a computer program that translates code written in a high level language to a lower level language, object/machine code. The most common reason for translating source code is to create an executable program (converting from a high level language into machine language).

Advantages of using a compiler

plus pointSource code is not included, therefore compiled code is more secure than interpreted code
plus pointTends to produce faster code than interpreting source code
plus pointProduces an executable file, and therefore the program can be run without need of the source code


Disadvantages of using a compiler

minus point Object code needs to be produced before a final executable file, this can be a slow process
minus point The source code must be 100% correct for the executable file to be produced


Interpreter[edit]

An interpreter program executes other programs directly, running through program code and executing it line-by-line. As it analyses every line, an interpreter is slower than running compiled code but run on your PC, MAC, games console and Mobile phone.

Advantages of using an Interpreter

plus pointEasier to debug(check errors) than a compiler
plus pointEasier to create multi-platform code, as each different platform would have an interpreter to run the same code
plus pointUseful for prototyping software and testing basic program logic


Disadvantages of using an Interpreter

minus point Source code is required for the program to be executed, and this source code can be read making it insecure
minus point Interpreters are generally slower than compiled programs due to the per-line translation method
Types of program translator

Name the three types of program translator and describe what level of language each translates

Answer :

  • Assembler - Low Level (Assembly)
  • Compiler - High Level
  • Interpreter - High Level

Why might you want to use a compiler instead of an interpreter?

Answer :

A compiler makes faster, more secure code

Why might you want to use an interpreter instead of a compiler?

Answer :

Interpreters allow for code to run on multiple platforms, it allows you to debug and test code without having to re-compile the entire source code

For a computer game running on a home console, would you use a compiler or an interpreter? Explain why.

Answer :

Compiler: as it produces faster code. Also object code that is produced is difficult to read, meaning competitors won't easily be able to steal or users hack the code.

OR:

Interpreter (harder to get marks for this): As more and more developers create games for multiple platforms, an interpreted language would allow for code written once to be run on different consoles and even phone platforms

For a simple learning tool that will be released on the web for school children to use at home, what would be the best choice of translator? Explain why.

Answer :

Interpreter : Students will be using different operating systems and hardware at home, so it is necessary to create code that is multi-platform. As it is an educational tool, it probably wouldn't need the speed boost that a compiler would provide.