In-Class
Compiler generated assembly 1
Let us get some experience reading assembly code generated by the compiler.
- Write a C program that swaps two integers.
- Save, Compile, and Run the program to verify it works.
- Output the assembly from that program (Save it as sample_int.s).
- Use: clang sample_int.c -S -o sample_int.s
- Now modify your program to swap to long's.
- Save, Compile, and Run the program to verify it works.
- Output the assembly from that program (Save it as sample_long.s).
- Compare each of the two assembly files using diff. See what changed.
- diff syntax
- diff -y sample_int.s sample_long.s
Compiler generated assembly 2
Let us get more experience an infer some assembly code generated by the compiler.
- Write a C program that swaps two integers in a function (You may use today's slide as a reference).
- Save, Compile, and Run the program to verify it works.
- Output the assembly from that program (Save it as sample_int.s).
- Do the instructions use memory/registers in a different way?
Compiler generated assembly 3
Let us get more experience an infer some assembly code generated by the compiler.
- Write a C program that has an array of 4 integers.
- Set each value to something (do not use a loop) (e.g. myArray[0]=1; myArray[1]=2; etc)
- Save, Compile, and Run the program to verify it works.
- Output the assembly from that program (Save it as sample_int.s).
- How much are the offsets from the address?