views:

107

answers:

3
+1  Q: 

from C to assembly

how can I get assembly code from C program I used this recommendation and I use something like this -c -fmessage-length=0 -O2 -S in Eclipse, but I've got an error, thanks in advance for any help

now I have this error

   atam.c:11: error: conflicting types for 'select'
/usr/include/sys/select.h:112: error: previous declaration of 'select' was here
atam.c:11: error: conflicting types for 'select'
/usr/include/sys/select.h:112: error: previous declaration of 'select' was here

this my function

int select(int board[],int length,int search){
    int left=0, right=length-1;

    while(1){
        int pivot_index=(right+left)/2;
        int ordered_pivot=partition(board,left,right,pivot_index);

        if(ordered_pivot==search){
            return board[ordered_pivot];
        }
        else if(search<ordered_pivot){
            right=ordered_pivot-1;
        }
        else{
            left=ordered_pivot+1;
        }
    }
}
+3  A: 

Eclipse is still treating the output as an object file

gcc -O0 -g3 -Wall -c -fmessage-length=0 -O2 -S -oatam.o ..\atam.c

is generating assembly like you want, but confusingly storing it in atam.o because of the -oatam.o passed to GCC (normally you would store assembly in atam.s). The next command:

gcc -oatam.exe atam.o

Attempts to link atam.o and generate an executable, but atam.o is an assembly source, not an object file, so the linker fails. You need to tell eclipse not to run the second command (and you probably want to change the output filename of the first)

Michael Mrozek
sorry, but what exactly have I enter?
lego69
@lego `gcc -S ..\atam.c` is all you strictly need; that will generate an assembly file named `atam.s`
Michael Mrozek
+1  A: 

-S instructs the compiler to not go through with the actual compilation and linking step and stop after emitting the assembly. On the other hand you're also telling the compiler to compile your file on the same line (in addition to other conflicting settings).

Try this:

gcc -O0 -S ../atam.c

Optimizations will take the assembly file generated farther away from your source code, so I instructed gcc to turn off optimizations. Also don't run the linker.

Blindy
I doesn't work:(
lego69
"It doesn't work" is never helpful. What error are you getting when you run that from the command line?
Blindy
+2  A: 

The error is happening because select is a Unix system call and your definition is clashing with the declaration in the relevant system header. You need to rename your function.

JeremyP
thanks, finally I did it
lego69
I was completely confused what you were talking about until I looked at the revision history; he apparently edited the question to say something completely different from the original question, and then edited again after you answered to take out most of the information, including all references to `select()`. I rolled it back since this appears to be the answer he's looking for
Michael Mrozek