In-Class
Compiler generated assembly 1
The C programming language has a 'goto' command.
- Write a C program using the goto command and a label.
- Save, Compile, and Run the program to verify it works.
- Output the assembly from that program (Save it as goto.s).
- Use: clang goto.c -S -o goto.s
- Observe what kind of jmp statement is inserted.
Compiler generated assembly 2
For-loops
- Write a C program using a for-loop that counts to 5.
- Save, Compile, and Run the program to verify it works.
- Output the assembly from that program (Save it as for.s).
- Use: clang for.c -S -o for.s
- Observe where the code goes for the condition statement (at the start or at the end?).
Compiler generated assembly 3
Switch Statements
- Write a C program using a switch statement (Sample here).
- Save, Compile, and Run the program to verify it works.
- Output the assembly from that program (Save it as switch.s).
- Use: clang switch.c -S -o switch.s
- See what code a switch statement generates. Is it optimal?
Compiler generated assembly 4
Add Function
- Write a C program that calls an add function(long add(long a, long b).
- Save, Compile, and Run the program to verify it works.
- Output the assembly from that program (Save it as add.s).
- Use: clang add.c -S -o add.s
- Observe the outputs
- Observe arguments put into registers
- Observe where 'popq' is called.