Skip to main content
gamedev.net
🔒 Locked

compilers

Started by jharkey 8 replies 350+ views
Original Post
jharkey
jharkey
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.
Shannon Barber
Shannon Barber
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.


  
//in a .cpp somewhere


unsigned long RDTSC()
{
unsigned long ulTicks;
__asm{
xor eax, eax
xor ebx, ebx
xor ecx, ecx
xor edx, edx
//This is how you use op codes that the compiler doesn''t know about

_emit 0x0f // CPUID

_emit 0xa2
_emit 0x0f // RDTSC

_emit 0x31
mov [ulTicks], eax
}
return(ulTick);
}
BTW Sp5 is available now...



Magmai Kai Holmlor
- The disgruntled & disillusioned
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Spencer
Spencer
hrrm....hang on a second here...
doesn''t compilers that create .exe files create opcodes (in som hexadecimal form or whatever) rather than assembly code??


--Spencer
--Spencer"All in accordance with the prophecy..."
Martee
Martee
I think they create ASM first. Translation from ASM to machine code is a relatively simple process.

~~~~~~~~~~
Martee
http://www.csc.uvic.ca/~mdill
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
amish1234
amish1234
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.
___________________________________________________________Where to find the intensity (Updated Dec 28, 2004)Member of UBAAG (Unban aftermath Association of Gamedev)
EEPROM
EEPROM
The huge post above was me. It comes out as anonymous. >:|

"Simple is beautiful"
"Simple is beautiful"
Eraserhead
Eraserhead
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.

Qoy
Qoy
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.