Greets,
I am looking at http://www.madwizard.org win32Asm.
And in it he says "High level languages like C convert their own language to assembly, and the assembler converts it to binary codes".
Is that true?
Which C compilers do this?
Thanks---vmars316
All C compilers should AFAIK.
MS Visual C compiler uses MASM
Borland C compiler uses TASM
gcc uses GAS and AT&T syntax
could be wrong...
VMARS316,
If you use Visual Studio, you can make a setting that causes the compiler to emit ASM files. This is not the default setting, however.
Generating ASM Source Code from Visual C++ (http://kipirvine.com/asm/articles/genASMsource.pdf)
Here is an assembly output using GCC ( gcc foo.c -O2 -S -masm=intel )
.file "foo.c"
.intel_syntax noprefix
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "var is %X in hexidecimal.\n"
.section .text.startup,"ax",@progbits
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB18:
.cfi_startproc
push ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
mov ebp, esp
.cfi_def_cfa_register 5
and esp, -16
sub esp, 16
mov DWORD PTR [esp+4], 51966
mov DWORD PTR [esp], OFFSET FLAT:.LC0
call printf
mov DWORD PTR [esp], 0
call exit
.cfi_endproc
.LFE18:
.size main, .-main
.ident "GCC: (GNU) 4.6.0 20110530 (Red Hat 4.6.0-9)"
.section .note.GNU-stack,"",@progbits
Quote from: Gunner
All C compilers should AFAIK. MS Visual C compiler uses MASM could be wrong...
I think you'll find the code generation is completely independent of MASM (ie it can be absent from the system), going directly to object files, you can get the compiler to generate an assembler/code/listing file (-FAcs)
Some compilers do "inter-stage", where the only thing the compiler does is generate an assembler file, a couple of 68K C and Fortran compilers come to mind. The "compiler" application is often a wrapper which calls the actual compiler, perhaps multiple phases, and subsequently calls an assembler, and perhaps deletes some of the intermediate files in the process. Other compilers generate an intermediate code, a kind of generic assembler, and subsequent stages do pin hole optimization and code generation.
This much if you are going to use the VC compiler (CL.EXE), check the output after testing different options for optimisation as it seriously effects readability of code. Machine optimised code generally has the stack frame removed and usually uses all of the available registrs which makes the code very hard to read and even more difficult to modify. To get code that is readable and with enough registers to actually modify it, turn the optimisation OFF. The code is generally a lot slower but can be manually edited and re-optimised by hand.