What happens when you press the little green button?
You have your program, written in a High Level Language, or an Assembly language.
These are called our source modules.
How do we go from that to machine code?
Program consists of instructions and data.
HLL: a = b + c
- How do we express the data in a HLL?
→ declare variables
- How do we express the data in AL?
→ C DATA
→ A DATA
→ B DATA
→ ADD B C
→ STORE A
- In both cases, we have instructions and data.
The machine also has instructions and data, but it will be in Machine Language
- The machine consists of:
→ CPU
⇒ Follows the instructions from the memory. ADD, STORE...
→ Memory
⇒ What does the memory hold?
⇒ Instructions and Data
⇒ What we have on the source modules has to be set up in such a way that the machine can handle it
→ Bus
⇒ Gives the CPU access to the memory, which contains I&D
→ Devices
- Something needs to translate our higher level languages into something the machine can deal with.
- How do we do this?
Compilers
- What does a compiler do?
→ It's a piece of software
→ it runs on the machine, it also has instructions and data
→ it takes our program and creates another program consisting of instructions and data.
→ takes what we have written and puts it into a format that's closer to something the machine can execute.
Assemblers
- What does the assembler do?
→ Takes the assembly language and produces another program with instructions and data
→ less complex than a compiler
We refer to the files that the assemblers and compilers produce as OBJECT MODULES
Compilers and Assemblers can't run by themselves.
- In our code, we have instructions like printf. These functions come from elsewhere. We include them with #include
- We are telling the compiler that these functions exist. Otherwise the compiler will complain that it can't find them.
Linkers
- Takes the object files, other object files that have been written, and links everything together. (other people's modules + our modules)
- resolves things from other modules.
- linker needs to know what's included so it can look up the correct module in its library of modules.
- ex: starting module which initializes the system.
→ the program exists in main. where does main go?
→ main is the first function that runs.
→ we also know that main can be put anywhere, so how does the machine know where main starts?
→ The starting module starts (essentially) at position 0, and calls main.
→ it doesn't matter where main is, because the linker takes care of it.
- The linker produces a module that could be referred to as:
→ EXECUTABLE MODULE
→ MACHINE CODE
→ these contain instructions and data as well.
→ these are in secondary memory.
→ a.out on unix, exe in windows
Loaders
- move the module from external memory onto the machine.
Different languages have different compilers, and therefore different linkers.
rule of thumb: do one thing and do it well.
Directives:
- Compiler directives:
→ #include
→ meta information that's needed for compilation
- Assembler directives:
→ DATA
→ X EQU 3 , a directive saying x should be set up as a constant, equal to 3
- Linker directives
→ include stdio.h
- modules created by these items all contain I&D&directives.
- Directives could be embedded in machine language
Alternative:
- Compiler translates to assembly.
- Linked takes information in assembly language
- The assembly language is arguably a 1-1 translation from the HLL to machine instructions
- After the compiler and linker are done, we have our full program (start module, linked modules, our modules) all in assembly language.
- Run the assembler after the linker,
- this produces the exe or a.out (executable, in machine language,)
FLOW:
HLL -> COMPILER -> LINKER -> ASSEMBLER -> LOADER -> MACHINE
---compile time---------link time-----assembly time----load time----runtime--->
- compiler translates to assembly
→ produces an obj file
- linker links all modules, pulls in modules from included library
→ produces a fully linked assembly (obj) file
- assembler produces the executable
→ machine language
- Lloader puts the executable onto the actuall machine memory
- machine runs the code.
- We will be using the XM-23 assembler
- we will be writing XM-23 assembly code
- XMX is the language they used last year.
- XM-23 has a different ISA
- we need an emulator that allows us to test the code before we put it on actual hardware
- for the assignment he wants us to write an XM23 emulator???
→ takes instructions and data
→ emulator does what the machine would do. Index