CodeBlocks question

I have a program for a course that requires C++ code and the output be assembly. With optimization levels activated as well. I don't know much about this setting or what I need to do exactly.

I don't understand how or what the -S or -fverbose_asm is or where to find them.
I only need assistance with the settings requirements. I have the code written.

Again, I use CodeBlocks v17.12

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
             Computer A Computer B Computer C
Program 1      1               10             20
Program 2    1000           100            20
Program 3     500           1000           50
Program 4     100            800          100
Table 1: Benchmark Data For Problem 1

1. Table 1 shows the execution time in minutes of a process running a program contains 100, 000, 000 instructions.
Calculate the MIPS values for each computer in the program. 
Then compute the means and medians for the
four programs and rank the performance of the different programs based on the means.

2. Write a function in C++ that , given a pointer to an dynamically allocated array of integers and an integer
size, uses the insertion sort algorithm to sort the array in place. 
Write a driver program that creates an array
of 1000 random integers and then uses your function to sort the array in place.
Using GCC, compile this program on an X86 machine four times, starting with optimization level 0 and
increase the optimization level up to 3.
 Ask GCC to generate assembly language for each optimization level.
Provide a summary of how the code generated for your insertion sort function change from optimization level
to optimization level?

HINT: The -S option forces GCC to output the assembler code it generates for a program. Use that option
and the -fverbose_asm option to generate output for this problem.

NOTE: For submission, all I need to see is your C++ code and a write-up of your observations. You don’t
need to submit the generated assembly language code.
Last edited on
there should be a place in your project or whatever it is called to set compiler options, and that area should allow you to type in flags on top of having check boxes etc for common ones.

You want optimization level to be O2 or O3 (in g++ terms which I believe are near universal?) which gets rid of debugging info in the executable. The other flag -- verbose assembly I believe puts the c++ code with the related assembler for it, so you can see a nearly one to one conversion of the c++ to assembly, and then it should generate a text file something.asm is usual for your code.

Does any of this make sense when looking at the settings for your IDE?
You should be able to assemble (in your assembler program) the output, but this sometimes is tricky to set up to get all the libraries etc into the assembler (its not that hard but its more than just masm filename sometimes).
Last edited on
I don't want to sound too dumb, I found the Optimization options in the Compiler settings. I believe I can only select one at a time. But I'm unable to find where it produces the assembly output. Nor have I found the "verbose_asm" option. I found a few articles online about this, such as compiling from CMD. Unable to get this option to produce results.
see if this guy's post helps.

https://stackoverflow.com/questions/20953907/how-to-generate-assembly-listings-in-codeblocks

compiler settings, make files/build configurations, and other such things are critical to learn for when you get a job, and they are not trivial. This is a good exercise... google around, see if you can make it work
Last edited on
Topic archived. No new replies allowed.