title: Correctly compiling and linking multiple asm files into a .vfd - for Oracle VM?
body: <p>Lately I've been wanting to get into assembly coding, just to have some experience under my belt. I decided to look into it and was getting some good results(though its simple asm), however everything is still blurry, and I would much appreciate some input from others on how to correctly build <strong>multiple</strong> .asm files into <strong>.. &amp;.. &amp;..</strong> to finish with a <strong>.vfd</strong> or a <strong>.img</strong> file for <strong>Oracle VM</strong>.</p>
  
  <p>So over the past few weeks in my spare time, I've been researching around the web trying to find a working method that will enable me to: </p>
  
  <pre><code>1. Compile my .asm files into individual .obj files
  2. Link these multiple files into one .bin
  3. Place this .bin into a .vfd or .img
  4. Finally ran on the Oracle VM.
  </code></pre>
  
  <p>The programs i am currently using on my <strong>windows 7 64bit system</strong> are:</p>
  
  <p>(all through <strong>MinGW</strong>)</p>
  
  <pre><code>1. nasm   - to compile the asm to .obj / .bin files
  2. ld     - to link .obj files into a .bin (I think)
  3. dd     - to create a .img file from a .bin file
  </code></pre>
  
  <p>After some time of messing about I've been able to compile a <strong>single .asm</strong> file <strong>into</strong> a .bin file, and then placed it into a <strong>.img</strong> using <strong>dd</strong> (the below was from tutorials online):</p>
  
  <p>(a bat file which executes these commands in the order below)</p>
  
  <pre><code>1. nasm -f bin -o bootloader.bin bootloader.asm  
  2. dd if=bootloader.bin of=output.img count=1440
  </code></pre>
  
  <p>and then I just ran the Oracle VM which reads the output.img and displays it correctly. YAY.</p>
  
  <p>Now. I've coded in Visual <strong>c++</strong> for some years now, and i typically use many files in single solution. I feel that when coding in asm, I should also be able to have <strong>multiple files</strong>. So I've read around and many use <strong>'ld'</strong> - a <strong>linker</strong> which '<em>joins</em>' .obj files into .bin files?</p>
  
  <p>So I edited the above bat file to the following:</p>
  
  <pre><code>1a. nasm -f bin -o bootloader.bin bootloader.asm 
  1b. nasm -f bin -o kernel.bin     kernel.asm 
  2.  ld -o link.bin bootloader.obj kernel.obj 
  3.  dd if=link.bin of=output.img  count=1440
  </code></pre>
  
  <p>The first error i got was: "cannot perform PE operations on non PE output file". After 
  I Googled.. and <em>Googled</em>... and <strong>Googled</strong>.... and <strong><em>Googled</em></strong>..... (one link to the next) and I couldn't find any other methods that worked - I just got more errors! I'm honestly lost. - I tried several different programs (eg objcopy), <strong>lots of different parameters</strong>,  etc.. and I haven't made too much progress. I need guidance. :) </p>
  
  <p>And here is my final questions. Will <strong>''linking''</strong> these files together <strong>with</strong> ld give me the desired results <strong>I seek</strong>? (multiple files in one final binary file) and how can I do it <strong>correctly</strong> on my <strong>windows system</strong>?</p>
  
  <p>I'm not all to in-depth with asm or these programs so <strong>I've tried</strong> to read up as <strong>much as I could</strong> before i got here. So please if you could keep the explanations nice and clear. Im sorry if its a lot to ask for, and please no grilling. :) </p>
  
  <p>Thanks!</p>