CS208, Wednesday 26 Jan 2022
Today
- Map memory by hand
- Run-through of a few x86_64 instructions and addressing modes
- What does a C loop look like in x86_64? An if-statement? A function call? Return values? Different types of parameters?
For your entertainment (?)
Exercise: 15+5 minutes
- Write a little program, say "memory-mapper.c" on mantis
- Use the & operator and printf's %p to figure out where
stuff gets placed in memory by the compiler.
- local variables
- literal strings
- memory allocated by malloc
- function parameters
- functions themselves
- sequences of local variables in the same function
- local variables in one function vs. local variables in a
function that the first one calls
- anything else you can think of
- Try to explore the boundaries of these regions of memory
- Draw a map--here's some sample code
Some x86_64 instructions and addressing modes
- mov (and movq, movl, movw, movb)
- addressing modes
- lea
- add (2- and 3-argument versions)
- push, pop
- jmp, js, jl, jle, je
- test, cmp, and the FLAGS register
(from https://nekosecurity.com/x86-64-assembly/part-6-arithmetic-operation)
A little note on optimization
- A tiny bit of compiler history
- Conflicting goals (performance, debuggability)
- Pedagogical goals (-O0? -Og?)
Mapping C constructs to x86_64 (probably Friday)
- if-else
- loop
- function call
- ??