🔒 Locked
compilers
Advertisement
Original Post
hello, im learning assembly language now, and am already good in c++. and can do some basic, and a little pascal. my question is, how do these compilers actually work. do they compile all code down into assembly language? i know this is a pretty pointless question, i just wondered what was going on when compiling. i find it amazing that 2 such different languages(c++ & assembly) can both create the same kind of results. how? and how can vc++ insert assembly code into c++ with the inline assembler?
and does anyone know of a free assembly compiler. i tried to get the new masm with the vc++ processor pack, but it requires service pack 4, and i only have 3. i would download the service pack, but its over 100 mb i think.
There''s another asm compiler also called MASM, search for Icezillian, it lets you program windows in asm.
Compilers that create .exe create assembly code. All of C eventually falls back onto some asm routine. The compiler inserts some op codes to setup function calls and variables, then inserts the code for the functions that are called. You can load any .exe with VC and look at the op codes (and even step through the program, op code by op code).
Soo, an assembler and a C compiler won''t produce the exact same code; though it may produce the same results. There''s nothing to prevent you from linking to the C libraries using an assembler, and calling all the C functions ''manually''. Even then the code is likely to be slightly different.
Magmai Kai Holmlor
- The disgruntled & disillusioned
Compilers that create .exe create assembly code. All of C eventually falls back onto some asm routine. The compiler inserts some op codes to setup function calls and variables, then inserts the code for the functions that are called. You can load any .exe with VC and look at the op codes (and even step through the program, op code by op code).
Soo, an assembler and a C compiler won''t produce the exact same code; though it may produce the same results. There''s nothing to prevent you from linking to the C libraries using an assembler, and calling all the C functions ''manually''. Even then the code is likely to be slightly different.
|
Magmai Kai Holmlor
- The disgruntled & disillusioned
I think they create ASM first. Translation from ASM to machine code is a relatively simple process.
~~~~~~~~~~
Martee
http://www.csc.uvic.ca/~mdill
~~~~~~~~~~
Martee
http://www.csc.uvic.ca/~mdill
Martee is correct. VC++ converts the code to assembler and stores it in .obj (or .ojb)files (i can''t remember offhand which file extension). From these files it creates the .exe file, which is in machine code. If you want to look at your program in asm, try opening an obj/ojb file. I have never tried this, so I don''t know if it will work.
quote:
Original post by amish1234
VC++ converts the code to assembler and stores it in .obj (or .ojb)files (i can''t remember offhand which file extension).
.obj files does _not_ contain assembly. They basically contain compiled code and data which still has unresolved references. Its the linker''s job to link several .obj files together to resolve those references.
I believe, however, that there is a switch for VC++ to make it generate assembly output in addition to/instead of object files. At least other compilers have a switch like that.
gcc _does_ generate assembly at an intermediate stage, which it then feeds to gas, the gnu assembler.
For reference, the VC++ command line params to generate assembly are:
/FAs /Fa{listing filename}
That will generate an assembly listing with C/C++ code in comments. (I don't remember the modifications to generate machine code, or the other options.)
In the IDE, the options are found in the C/C++ tab of the Project Settings box, in the "Listing Files" section.
Edited by - Qoy on April 9, 2001 4:24:13 AM
/FAs /Fa{listing filename}
That will generate an assembly listing with C/C++ code in comments. (I don't remember the modifications to generate machine code, or the other options.)
In the IDE, the options are found in the C/C++ tab of the Project Settings box, in the "Listing Files" section.
Edited by - Qoy on April 9, 2001 4:24:13 AM
Here is a link to a web site that contains a free book on compilers. It also gives a good intro to assembly languages. Check out chapters one through four.
Compilers and Compiler Generators
Compilers and Compiler Generators
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement