- What does a program consist of?
→ instructions and data
→ what does data consist of? (from a high level language)
⇒ Integer/char/ float/double
→ this probably went too quickly, because what do we actually have?
⇒ Fundamental types, aggregate types.
⇒ fundamental types:
• integer/char/float/double
• int: 4 bytes
• char: 1 byte
• short: 2 bytes
• float: often 64 bits (8 bytes) but depends on machine/implementation
⇒ Aggregate types:
• arrays/structs/unions
→ We also have instructions. what are they?
⇒ we essentially have 3 types.
• sequential operations
◇ assignment statements
◇ function calls (single statements)
• conditionals
◇ if-then
◇ if-then-else
◇ switch
• loops/repetition
◇ pretest (while)
◇ post test (do while)
◇ deterministic (for) called deterministic because we know the start and stop.

We could generate a simple C program such as
int x;
main(){
x = 3;
printf(....


- from the diagram, we remember that:
→ src code goes through compiler
→ creates object file
→ goes through linker
→ links other obj files from libraries
→ produces executable
→ goes through loader
→ loader takes the executable and loads it into primary memory, starts execution
- In order to execute this program, the translation by the compiler etc etc has to actually do what we specified in the source code.
- today, we're going to look at what the CPU does when a program is loaded

What's the difference between interpreted languages and compiled ones?


(this dude just said java is an interpreted language ..?)

C -> compiler -> exe
for running the exe, the target machine is a real machine.
the executable is in the native language of the computer.
assume we compiled out program to run on an intel machine.
this executable will not run on a macintosh, because the underlying language of the machine is different, that is, the ISA of the machines are different.
Instructions compiled for an intel machine won't be compatible with others.
Emulators are one way to get around this issue. Then we can run the intel executable on the emulator, on the macintosh, but still not directly on the mac.

The original idea behind interpreted languages is, the interpreter was intended to grab a line of your source code, translate it, and execute it.
If every machine has an interpreter that interprets the same language, you can run the same code on any machine. We do not produce a permanent executable, but any machine can run the code. It's not very fast tho

Java can be run interpretively, but the preferred approach is a compiler that compiles the code for the Java Virtual Machine. Most machines have the ability to run the JVM.

By compiling the code, what have we eliminated?
In an interpreted loop, each instruction has to be interpreted repeatedly. However if the code is compiled for the VM, it can avoid this.

Most interpreted languages now, actually create code for a VM instead.

Guy asked if the VM has an OS lol

Emulator execution will be slower because of the extra layer of translation.


What happens when the linker can't find a specific obejct file?


- there has to be a directive to the linker that the function is missing.
- The linker has to go thorugh its directives to find out what to do when it comes across “EXT printf” (external function)
- it will look in its library of object files and pull in the assembly code for printf.
- the code for printf (whatever function) is tacked on to the source code of the original program.

- The linker is not designed to test for errors in assembly code, it just looks for externals and ties things together.

Index