compiler-construction

Questions about compilers


When a compiler compiles my code in text form, it converts the text code to a low level code, in the case of the GCC in codeblocks, assembly.

  1. Can I run this compiled program directly on my machine, without needing the windows operating system?

  2. Is the .exe a compiled file with the built-in assembly instructions to my program?

  3. How does Windows run assembly programs if it is already a giant assembly program?

  4. If a assembly language program is in bytecode, why when I record a PIC with a PIC burner, I write hexacode to it?

  5. The x64 architecture is a new architecture with new instructions, but that still have the x86 instructions with it? True or false?

  6. How do I read the low level code generated by my compiler?


Solution

  • While I agree with templatetypedef's comment that this should be split into smaller questions, I will endeavour to give some pointers on each of your questions here.

    Can I run this compiled program directly on my machine, without needing the windows operating system?

    Technically, yes, but this would involve modifying the normal boot procedure. This relates to your third question. Windows itself is a form of application loader, it is an application designed to launch other applications (and do other useful things). At the moment, when your computer boots, its first instruction is likely a JUMP instruction telling the computer to 'jump to' the memory location of your OS and start its initialisation. From then on, the OS is relatively self-contained.

    Is the .exe a compiled file with the built in assembly instructions to my program?

    A .exe file is just one type of executable file. Others include ELF and Mach-O and a whole range of others. A .exe file is just like any other file except for its 'header' which tells the machine that the following data is in the form of machine-executable instructions (1s and 0s). Don't confuse assembly languages with machine instructions. An assembly instruction like mov %eax, %ebx is NOT read by the machine. First it is passed through an assmebler and translated into 1s and 0s.

    If a assembly language program is in bytecode, why when I record a PIC with a PIC burner, I write hexacode to it?

    As above. Bytecode is a word with many meanings. Hexadecimal is just another (shorter) way of representing binary. Everything reduces down to binary at the end of the day.

    The x64 architeture is a new architecture with new instructions but that still have the x86 instructions with it? True or false?

    True. Intel does its best to maintain full backwards-compatibility. This does not necessarily hold true for operating systems.

    How do I read the low level code generated by my compiler?

    By low level I assume you mean the assembly code, not the 1s and 0s. The most common way is to use the -S flag with a compiler like gcc. This will output a .s assembly file instead of a .o object or .exe(etc) executable.

    If you want to know more about assembly, this is the God Reference for Intel processors (IA-32 ('x86') and x86-64). Be warned, it is extremely heavy going. You're probably better of looking for Windows or OS X assembly tutorials on Google. NASM is a free multi-platform assembler if you want to get started, it has a slightly different syntax to others though. Before you undertake any of this though I recommend learning the basics of computer systems - how a processor works, etc. Perhaps learn a simpler assembly language first like DLX or MIPS.