FIXME. add suffixes to instructions
For Loop Elaboration
for.c
int f() {
for (int i = 0; i < 100; i++) {
x += i;
}
return x;
}
\(\leftrightarrow\)
while.c
int f() {
int x = 0;
int i = 0;
while (i < 100) {
x += i;
i++;
}
return x;
}
While Loop Translation
while.c
int f() {
int x = 0;
int i = 0;
while (i < 100) {
x += i;
i++;
}
return x;
}
\(\leftrightarrow\)
while.s
f:
mov $0, %edx
mov $0, %eax
jmp test
body:
add %edx, %eax
add $1, %edx
test:
cmp $99, %edx
jle body
rep ret
FIXME.
- this seems a bit simple
- need to talk about
rep ret