Assembly and high-level programming lanaguges

Assembly code

Assembly language

Rather than machine code, programs can be written in human readable form. For example, we can use short English language strings instead of hexidecimal or binary.

Assemblers

Assembly code can be converted to machine code using an assembler.

The assembler takes the assembly code as input and returns machine code.

High-level programming languages

Compilers

Directly to machine code

Interpreters

Evaluate each line as it is run

Trans-compilers

Compile to code in intermediate language which has its own compiler for further compiling

Variables

Direct storage and pointers

Variables can either refer to a part of memory, reserving that space for just that variable, alternatively, rather than store value, we can store pointer.

Pointers

So in first case we have $$x=2$$ and $$y=2$$, and then we want to change both to $$3$$.

In first example, initiate both and store $$2$$ in memory twice. update both.

In second example we can have x and y have the same value of a pointer, pointing to a third memory location. we can the update this memory location to change both to $$3$$.

Two variable can be the same by value, but additionally by pointer.

eg $$x=2$$ and $$y=2$$. $$x==y$$, but if they have the same pointer, they are the same thing. changing one changes the other.

We can update $$x$$ and $$y$$ will automatically update

When we say $$x=2$$, $$y=x$$ we are either making $$y$$ mutable or immutable. mutable means same pointer. language specific rules apply.

Integer caching

If we set $$x=2$$ we can either create $$2$$ in memory, or simply point $$x$$ to $$2$$, which is already in memory

That means if we do $$x=2$$ $$y=2$$ they have the same pointer.

Can also cache some other common data values, eg empty lists.

Makes sense if pointer is smaller in memory than value.

Functions

Macros

Not separate, code is replaced before it is run

Call by value and call by name

Two ways of giving args to parameters, value evals when func called, name evals whenever needed.

Memory allocation and stack buffer overflow

Can cause change of state outside of function.

Stack overflows

Write too many instructions to stack. can be caused by infinite recursion. eg fun x() return x()).

Logic

Zero-order logic

Equality, inequality

Other

Integer caching

if we set x =2 we can either create 2 in memory, or simply point x to 2, which is already in memory

that means if we do x=2 y=2 they have the same pointer

can also cache some other common data values, eg empty lists

makes sense if pointer is smaller in memory than value