Machine Model Abstraction
FIXME. fill in something about how we will build a progressively more complicated machine model
Types of Data
FIXME. talk about how each type of data is notated in x86-64
Immediates
Immediates are constants. There are several notations for them, but they consistently start with a dollar sign:
- Decimal Constants:
$11
= \(\left(11\right)_{10}\) - Hex Constants:
$0x11
= \(\left(11\right)_{16} = \left(17\right)_{10}\) - String Constants:
$str
Registers
Registers are variables of a fixed-width. For example:
Unlike variables, there are only so many registers, and we cannot “declare” more. They must be used judiciously.
Memory
FIXME. simple memory accesses need to be here for asmgen
mov
and retq
ten.c
int ten() {
return 10;
}
\(\leftrightarrow\)
clang -S ten.c
ten:
mov $10, %eax
retq
mov
Instruction
x86-64 [data to register]
mov $imm, %dst
mov %src, %dst
mov (%src), %dst
x86-64 [register to memory]
mov %src, (%dst)
mov $imm, (%dst)
x86-64 [memory displacement]
mov D(%src), %dst
mov %src, D(%dst)
\(\leftrightarrow\)
C Pseudocode
dst = imm
dst = src
dst = *src
C Pseudocode
*dst = src
*dst = imm
C Pseudocode
dst = *(src + D)
*(dst + D) = src
There is no instruction to mov
directly from memory to memory!
D
is an immediate without the $
prefix.
ret
Instruction
x86-64
retq
\(\leftrightarrow\)
C Pseudocode
return %eax
Notice that %eax
always contains the return value.
We cannot return any other register!
Identity Function (Arguments)
identity.c
int identity(int x) {
return x;
}
\(\leftrightarrow\)
clang -S identity.c
identity:
mov %edi, %eax
retq
More on Registers
FIXME. add section on registers
A Note about Suffixes
FIXME. introduce suffixes, explain that they’re not always necessary, but it’s good practice to include them anyway
- b = byte (8 bit)
- w = word (16 bit)
- l = long (32 bit)
- q = quad (64 bit)