Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lesson Objectives Aims Understand how machine code is generated

Similar presentations


Presentation on theme: "Lesson Objectives Aims Understand how machine code is generated"— Presentation transcript:

1 Lesson Objectives Aims Understand how machine code is generated
Understand the role of Linkers and Loaders during compilation

2 Machine Code Generation
AST Identify Machine Code Blocks Binary Executable

3 The compiler will perform the following actions:
Convert AST nodes in to machine code Attempt a best fit model of allocating registers Machine code optimisation

4 Converting to machine code
Once code is split in to atomic elements, it becomes much easier to convert to machine code Languages all use pre-defined actions such as : Assignment Comparison Branching These can all be mapped to pre existing machine code templates

5 Allocation of registers
During any operation, registers will be used CPU’s only contain a certain number of registers Usually, each variable will need access to a register in order to be manipulated This means the compiler must assign registers to variables and some will share registers – clashes must be avoided!

6 This is a non deterministic problem
In other words, the “correct” answer can either never be found or is so computationally expensive you’d die before it did. Just like a sat-nav…

7 What kills CPU efficiency?
Optimisation What kills CPU efficiency? The optimisation stage will effectively try to rework code so that cpu disruption is minimised: Removing unnecessary branches Predicting probable program flow Using any CPU extensions/specific instructions instead of “generic” code (targeted compilation)

8 Linking and loading Libraries are a god send Back in t’ day, you had to code EVERYTHING yourself Then there became a need for “middleware” and libraries Why?

9 At this point, the compiler has to make sure that the libraries are included in the final executable. These can be: Static dynamic

10 Linker/Loader The linker will tell your code how to access external resources Static linking is where the library is COPIED to the executable This has obvious advantages and disadvantages…

11 Dynamically linked libraries are just that – linked
They keep file size small Can be updated without affecting the executable May not be present!

12 Loaders Loaders handle the connections to a dynamic library – loading them in to memory when necessary They are small utilities that handle the interaction between program and library This is because we don’t always know where in memory a dynamic library will reside

13 Review/Success Criteria
You should know: How code goes from high level languages to an executable!


Download ppt "Lesson Objectives Aims Understand how machine code is generated"

Similar presentations


Ads by Google