3.3 Flashcards
3.3.1 Low level language
Mnemonics.
One line generates one instruction in machine code.
Microprocessor specific.
A very limited range of instructions is available. Every task, even the simplest, has to be built up from the smallest steps.
There are no strings, integers or real numbers, just binary, so you have to decide how to represent your data. You also have to decide and manage where it is stored in memory.
3.3.1 high level language
English-like keywords.
One line generates multiple instructions in machine code.
Very abstracted instructions that are portable across different architectures, wherever there is a translator.
Complex programming constructs (if, for) available for working at a more abstracted level.
Enforced data types help manage storage.
3.3.2 interpreter
translates the high level code line by line into machine code. it is needed each time the program is run.
+ works across different platforms because the machine code is not sent,
+ simpler to test as it reads source and runs it.
+ can be easier to debug because source code is always available.
- execution is slower
- source code is public because you have to send it to whomever you want to run the program.
- whomever wants to run the source code must have the interpreter for the language,
3.3.2 assembler
translates the mnemonics of assembly language machine-code instructions.
very similar to machine code.
there is one assembly code instruction for each machine code instruction.
3.3.2 compiler
translates the source code to a stand alone machine code program that can be executed by the processor.
+ can be optimised to run very quickly on the targeted CPU.
+ the source code is private because you don’t have to send it to everyone you want to execute the file.
+ once compiled, the machine code us saved to disk in a file and its immediately ready to rum.
- executable file is not portable across different platforms.
- compilation is an extra step that is required each time the source file is changed
- source code has to be recompiled to target each different type of CPU.
low level language (MBCS)
Machine code has the least abstraction; processors execute it directly
Assembly and high level code must be translated to machine code.
Machine code is specific to a processor (not portable)
Assembly languages are low level, but more abstracted
They use simple mnemonics
They also are specific to hardware and have a mostly one to one relationship with machine code.
high level language (MBCS)
Most like ordinary languages, so are far easier to use
They are portable, they can be executed on many computers.
Slower to execute
Interpreter (MBCS)
High level → machine code
Works line by line
Translates a line, then immediately executes it
Every time you want to execute code, it must be translated again.
Stop as soon as it reaches an error.
Both the interpreter and the source code are needed at all times.
Slower then compiler.
Compiler (MBCS)
High lever → machine code
A compiler scans the whole code, and translate it all into machine code
A compiled program can be directly executed
After translation, the compiler and source code are no longer needed.
You cna distribute your ptogram without the source code.
Error messages are only shown after scanning the while code.
Time consuming.
Interpreter vs compiler
Both compilers and interpreters are used to translate high level programming languages to machine code. Compilers do this by converting all of the high level code into machine code before running the program. This allows programs to run quickly, since the entire program is ready to be run immediately. However, it can be difficult to locate problems with the program because the compiler does not identify which line is causing the problem.
Interpreters however, translate high level code one line at a time, and run each line before translating the next one. This allows the bugs in the program to be easily identified, since the program will only stop when it reaches a line that causes a problem. However, since it runs one line at a time, an interpreter runs slower than a compiler.