Author Topic: how to generate .s(assembly) file when compiling code ?  (Read 23722 times)

Offline huzhongshan

  • Multiple posting newcomer
  • *
  • Posts: 109
how to generate .s(assembly) file when compiling code ?
« on: August 02, 2010, 06:57:23 am »
I added -S in other options , but no response.
I found it generate .s in a tempory directory , but after compile , it disapseared.
I write inline assembly code ,but there is some error in it , I want to find the .s file to see where the bugs.
How can I get the .s file in ide.

I knew I could get it using command line gcc -S ... .....
but in IDE , how ?

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: how to generate .s(assembly) file when compiling code ?
« Reply #1 on: August 02, 2010, 07:29:49 am »
You can place it in "Compiler settings -> Other options".
The assembly code will be in the *.o-files in this case (because C::B uses the -o-option), and it will be done for all processed files.

Or you can change the build-command for your file in the files properties (tab "advanced"):
check "Use custom command ..." and add
Code: [Select]
$compiler $options $includes -S -c $file
$compiler $options $includes -c $file -o $object
.
The example is for c++-files.
I double the command, so the file will be processed twice, one-time only the assembly is generated, the second time I do the normal processing, otherwise your build will be broken due to missing object-file or because an old object-file is taken (if it exists).

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: how to generate .s(assembly) file when compiling code ?
« Reply #2 on: August 02, 2010, 03:53:52 pm »
you have to pass the "enable listings" options to the assembler
http://sourceware.org/binutils/docs/as/a.html#a


do this with the compiler-option "-Wa,"

e.g.
if you want to pass enable listing options "-alhds" to the assembler
you have to use the compiler-option "-Wa,-alhds"



you get the listing in the compiler-build-log, just enable "Save build log" in global compiler settings.


arp

  • Guest
Re: how to generate .s(assembly) file when compiling code ?
« Reply #3 on: August 07, 2010, 10:26:13 pm »
Add option "-save-temps".

Offline manmeetvirdi

  • Single posting newcomer
  • *
  • Posts: 6
Re: how to generate .s(assembly) file when compiling code ?
« Reply #4 on: August 19, 2011, 10:38:02 am »
Hi there
Just needed the knowhow for generating assembly code from C.
So I was trying to follow jens method but in mine case the "check" option is disabled as shown in attached picture !!
So how to proceed next?

Iam using codeblocks-ep

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: how to generate .s(assembly) file when compiling code ?
« Reply #5 on: August 19, 2011, 10:50:57 am »
Is your file part of a project ?
If not, this will not work, because would not be able to store the information (it is stored in the project-file).

Offline manmeetvirdi

  • Single posting newcomer
  • *
  • Posts: 6
Re: how to generate .s(assembly) file when compiling code ?
« Reply #6 on: August 19, 2011, 11:29:20 am »
Hi there Jens
Thanks for your help !!

Well mine file is a stand alone file "G2.C". I dint created it inside any project.
I created the file G2.C like this : File-->New-->Files-->c/C++ source

Then as suggested by you I created the project G3 like: File-->new-->Project-->console application and then proceeded ahead to create C project.
Once G3 project was created I included the file G2.C into this project.
Now sure enough  "check" option is now enabled as you said (shown in G2_asm2.jpg)

Jens also I found the other way
Settings-->Compiler and  Debugger-->Other settings --> advanced option (shown in G2_asm1.jpg)
and then included the lines which you mentined in post 2.
...and voila after compiling I got G2.S file

Offline manmeetvirdi

  • Single posting newcomer
  • *
  • Posts: 6
Re: how to generate .s(assembly) file when compiling code ?
« Reply #7 on: August 19, 2011, 11:34:14 am »
And this is what mine first assembly file contains

Code: [Select]
.file "G2.c"
.text
.def _printf; .scl 3; .type 32; .endef
_printf:
pushl %ebp
movl %esp, %ebp
pushl %ebx
subl $36, %esp
leal 12(%ebp), %eax
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
movl %eax, 4(%esp)
movl 8(%ebp), %eax
movl %eax, (%esp)
call ___mingw_vprintf
movl %eax, %ebx
movl %ebx, %eax
addl $36, %esp
popl %ebx
popl %ebp
ret
.def ___main; .scl 2; .type 32; .endef
.section .rdata,"dr"
LC0:
.ascii "\12\12Hi there\12\12\0"
.text
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $16, %esp
call ___main
movl $LC0, (%esp)
call _printf
leave
ret
.def ___mingw_vprintf; .scl 2; .type 32; .endef


Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: how to generate .s(assembly) file when compiling code ?
« Reply #8 on: August 19, 2011, 11:39:57 am »
Jens also I found the other way
Settings-->Compiler and  Debugger-->Other settings --> advanced option (shown in G2_asm1.jpg)
and then included the lines which you mentined in post 2.
...and voila after compiling I got G2.S file


That's what I posted here:
You can place it in "Compiler settings -> Other options".
The assembly code will be in the *.o-files in this case (because C::B uses the -o-option), and it will be done for all processed files.
[...]
I double the command, so the file will be processed twice, one-time only the assembly is generated, the second time I do the normal processing, otherwise your build will be broken due to missing object-file or because an old object-file is taken (if it exists).


But as stated it is done for every file in the project, and that can slow down the build process for larger projects.